Skip to content

Commit

Permalink
Using common xaml for indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Mar 19, 2019
1 parent 09983f2 commit 9fbfd93
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static ErrorProjectsIndicator()

public ErrorProjectsIndicator()
{
Description = UI.Resources.ErrorProjectsIndicator_Header;
Header = UI.Resources.ErrorProjectsIndicator_Header;
}
}
}
3 changes: 2 additions & 1 deletion src/BuildVision.UI/Controls/Indicators/ErrorsIndicator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using BuildVision.UI.Extensions;

namespace BuildVision.UI.Controls.Indicators
{
Expand All @@ -11,7 +12,7 @@ static ErrorsIndicator()

public ErrorsIndicator()
{
Description = UI.Resources.ErrorsIndicator_Header;
Header = UI.Resources.ErrorsIndicator_Header;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static MessagesIndicator()

public MessagesIndicator()
{
Description = UI.Resources.MessagesIndicator_Header;
Header = UI.Resources.MessagesIndicator_Header;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static SuccessProjectsIndicator()

public SuccessProjectsIndicator()
{
Description = UI.Resources.SuccessProjectsIndicator_Header;
Header = UI.Resources.SuccessProjectsIndicator_Header;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static UpToDateProjectsIndicator()

public UpToDateProjectsIndicator()
{
Description = UI.Resources.UpToDateProjectsIndicator_Header;
Header = UI.Resources.UpToDateProjectsIndicator_Header;
}
}
}
24 changes: 20 additions & 4 deletions src/BuildVision.UI/Controls/Indicators/ValueIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using BuildVision.UI.Extensions;

namespace BuildVision.UI.Controls.Indicators
{
public class ValueIndicator : Control
{
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), typeof(string), typeof(ValueIndicator));
public const string ResourcesUri = @"Resources/ValueIndicator.Resources.xaml";

public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(string), typeof(ValueIndicator));

public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(ControlTemplate), typeof(ValueIndicator), new PropertyMetadata(null));

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
nameof(Value),
Expand All @@ -26,16 +31,27 @@ static ValueIndicator()
DefaultStyleKeyProperty.OverrideMetadata(typeof(ValueIndicator), new FrameworkPropertyMetadata(typeof(ValueIndicator)));
}

public ValueIndicator()
{
Icon = VectorResources.TryGet(ResourcesUri, $"{GetType().Name}Icon");
}

public long Value
{
get { return (long) GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}

public string Description
public string Header
{
get { return (string)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}

public ControlTemplate Icon
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
get { return (ControlTemplate) GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}

static void OnValueChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using BuildVision.UI.Extensions;

namespace BuildVision.UI.Controls.Indicators
{
Expand All @@ -11,7 +12,7 @@ static WarningProjectsIndicator()

public WarningProjectsIndicator()
{
Description = UI.Resources.WarningProjectsIndicator_Header;
Header = UI.Resources.WarningProjectsIndicator_Header;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static WarningsIndicator()

public WarningsIndicator()
{
Description = UI.Resources.WarningsIndicator_Header;
Header = UI.Resources.WarningsIndicator_Header;
}
}
}
4 changes: 2 additions & 2 deletions src/BuildVision.UI/Extensions/VectorResources.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BuildVision.UI;
using BuildVision.UI;
using System;
using System.Collections.Generic;
using System.Management.Instrumentation;
Expand Down Expand Up @@ -43,4 +43,4 @@ public static ControlTemplate TryGet(string resourceDictionaryRelativeUri, strin
}
}
}
}
}
5 changes: 0 additions & 5 deletions src/BuildVision.UI/Styles/ControlViewStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
</Style.Triggers>
</Style>

<Style x:Key="IndicatorLabel">
<Setter Property="Label.Foreground" Value="{DynamicResource ToolWindowTextKey}" />
<Setter Property="Label.Opacity" Value="0.4" />
</Style>

<converters1:BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters2:VisibilityToBooleanConverter x:Key="VisibilityToBoolConverter" />
<converters2:GridColumnHeadersVisibilityToBooleanConverter x:Key="ColumnHeadersVisibilityToBool" />
Expand Down
180 changes: 20 additions & 160 deletions src/BuildVision.UI/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BuildVision.UI;component/Resources/CommonResources.xaml" />
<ResourceDictionary Source="/BuildVision.UI;component/Styles/ControlViewStyle.xaml" />
<ResourceDictionary Source="/BuildVision.UI;component/Resources/BuildAction.Resources.xaml" />
<ResourceDictionary Source="/BuildVision.UI;component/Resources/ValueIndicator.Resources.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -47,179 +46,40 @@
</Setter>
</Style>

<Style TargetType="{x:Type indicators:ErrorProjectsIndicator}">
<Style x:Key="ValueIndicator" TargetType="{x:Type indicators:ValueIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:ErrorProjectsIndicator}">
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<ControlTemplate TargetType="{x:Type indicators:ValueIndicator}">
<StackPanel Orientation="Vertical" ToolTipService.ShowOnDisabled="True" ToolTipService.ToolTip="{TemplateBinding Header}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource ErrorProjectsIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type indicators:WarningProjectsIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:WarningProjectsIndicator}">
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource WarningProjectsIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type indicators:SuccessProjectsIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:SuccessProjectsIndicator}">
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource SuccessProjectsIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type indicators:UpToDateProjectsIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:UpToDateProjectsIndicator}" >
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource UpToDateProjectsIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ContentControl
Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{TemplateBinding Icon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Foreground="{DynamicResource ToolWindowTextKey}" Opacity="0.4"/>

<Style TargetType="{x:Type indicators:ErrorsIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:ErrorsIndicator}">
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource ErrorsIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type indicators:WarningsIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:WarningsIndicator}">
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource WarningsIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:SuccessProjectsIndicator}" />
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:UpToDateProjectsIndicator}" />
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:WarningProjectsIndicator}" />
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:ErrorProjectsIndicator}" />

<Style TargetType="{x:Type indicators:MessagesIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type indicators:MessagesIndicator}">
<StackPanel Orientation="Vertical">
<Grid ToolTip="{TemplateBinding Description}" ToolTipService.ShowOnDisabled="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0"
Width="16"
Height="16"
SnapsToDevicePixels="True"
ClipToBounds="True"
UseLayoutRounding="False"
Template="{StaticResource MessagesIndicatorIcon}" />
<Label Grid.Column="1" Content="{TemplateBinding Value}" Style="{StaticResource ResourceKey=IndicatorLabel}" />
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:ErrorsIndicator}" />
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:WarningsIndicator}" />
<Style BasedOn="{StaticResource ValueIndicator}" TargetType="{x:Type indicators:MessagesIndicator}" />

</ResourceDictionary>

0 comments on commit 9fbfd93

Please sign in to comment.