Skip to content

Commit

Permalink
Allow changing tile font color (#61)
Browse files Browse the repository at this point in the history
* Implement "Set Font Color" and "Reset Font Color" UI commands connected to work item and pull request tiles.

* Implement serialization for tile font color.
  • Loading branch information
supermem613 authored Oct 8, 2021
1 parent 857b2ac commit 610914a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 4 deletions.
22 changes: 21 additions & 1 deletion Source/TeamMate/Controls/TileCollectionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
Visibility="{Binding IsDefaultBackgroundColor, Converter={x:Static fw:Converters.InverseVisibility}}"
CommandParameter="{Binding}" />
<Separator />
<MenuItem Header="Select _Font Color"
Command="{x:Static tmr:TeamMateCommands.SelectTileFontColor}"
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
CommandParameter="{Binding}" />
<MenuItem Header="Re_set Font Color"
Command="{x:Static tmr:TeamMateCommands.ResetTileFontColor}"
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
Visibility="{Binding IsDefaultFontColor, Converter={x:Static fw:Converters.InverseVisibility}}"
CommandParameter="{Binding}" />
</ContextMenu>
</local:TileView.ContextMenu>
</local:TileView>
Expand Down Expand Up @@ -69,7 +79,17 @@
Command="{x:Static tmr:TeamMateCommands.ResetTileBackgroundColor}"
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
Visibility="{Binding IsDefaultBackgroundColor, Converter={x:Static fw:Converters.InverseVisibility}}"
CommandParameter="{Binding}" />
CommandParameter="{Binding}" />
<Separator />
<MenuItem Header="Select _Font Color"
Command="{x:Static tmr:TeamMateCommands.SelectTileFontColor}"
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
CommandParameter="{Binding}" />
<MenuItem Header="Re_set Font Color"
Command="{x:Static tmr:TeamMateCommands.ResetTileFontColor}"
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
Visibility="{Binding IsDefaultFontColor, Converter={x:Static fw:Converters.InverseVisibility}}"
CommandParameter="{Binding}" />
</ContextMenu>
</local:TileView.ContextMenu>
</local:TileView>
Expand Down
2 changes: 1 addition & 1 deletion Source/TeamMate/Controls/TileView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Margin="6"
VerticalAlignment="Top"
FontSize="18"
Foreground="White"
Foreground="{Binding TileInfo.FontColor}"
Text="{Binding TileInfo.Name}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap" />
Expand Down
5 changes: 5 additions & 0 deletions Source/TeamMate/Model/ProjectContextSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ private TileInfo ReadTile(XElement e)
throw new NotSupportedException(String.Format("Tile type {0} is not supported", tileInfo.Type));
}

tileInfo.FontColor = e.GetAttribute<string>(Schema.FontColor);

return tileInfo;
}

Expand Down Expand Up @@ -120,6 +122,8 @@ private XElement WriteTile(TileInfo tile)
throw new NotSupportedException(String.Format("Tile type {0} is not supported", tile.Type));
}

e.SetAttribute<string>(Schema.FontColor, tile.FontColor);

return e;
}

Expand Down Expand Up @@ -385,6 +389,7 @@ private static class Schema
public const string LastUpdated = "LastUpdated";
public const string OrderByFieldName = "OrderByFieldName";
public const string FilterByFieldName = "FilterByFieldName";
public const string FontColor = "FontColor";

// Work Item Stuff
public static readonly XName WorkItemQueryInfo = "WorkItemQueryInfo";
Expand Down
8 changes: 7 additions & 1 deletion Source/TeamMate/Model/TileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public BuiltInTileType BuiltInTileType
set { SetProperty(ref this.builtInTileType, value); }
}


private bool includeInItemCountSummary;

public bool IncludeInItemCountSummary
Expand Down Expand Up @@ -98,6 +97,13 @@ public string BackgroundColor
set { SetProperty(ref this.backgroundColor, value); }
}

private string fontColor;
public string FontColor
{
get { return this.fontColor; }
set { SetProperty(ref this.fontColor, value); }
}

// TODO: KLUDGE, don't make this public, refactor or cleanup
public void FireChanged()
{
Expand Down
2 changes: 2 additions & 0 deletions Source/TeamMate/Resources/TeamMateCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public static class TeamMateCommands
public static ICommand ModifyTile { get { return commands.Create(); } }
public static ICommand SelectTileBackgroundColor { get { return commands.Create(); } }
public static ICommand ResetTileBackgroundColor { get { return commands.Create(); } }
public static ICommand SelectTileFontColor { get { return commands.Create(); } }
public static ICommand ResetTileFontColor { get { return commands.Create(); } }
public static ICommand RetryConnectToVsts { get { return commands.Create(); } }
}
}
2 changes: 1 addition & 1 deletion Source/TeamMate/Services/WindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public PullRequestQueryInfo ShowPullRequestQueryEditorDialog(ViewModelBase owner
public string ShowColorPickerDialog(ViewModelBase ownerViewModel, string initialColor)
{
WindowsForms.ColorDialog colorPicker = new WindowsForms.ColorDialog();
// Sets the initial color select to the current tile background color.

colorPicker.Color = ColorTranslator.FromHtml(initialColor);

// If the user clicks OK, return that color, otherwise return initial color
Expand Down
21 changes: 21 additions & 0 deletions Source/TeamMate/ViewModels/HomePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public void RegisterBindings(CommandBindingCollection commands)
commands.Add<TileViewModel>(TeamMateCommands.ModifyTile, ModifyTile);
commands.Add<TileViewModel>(TeamMateCommands.SelectTileBackgroundColor, SelectBackgroundColor);
commands.Add<TileViewModel>(TeamMateCommands.ResetTileBackgroundColor, ResetBackgroundColor);
commands.Add<TileViewModel>(TeamMateCommands.SelectTileFontColor, SelectFontColor);
commands.Add<TileViewModel>(TeamMateCommands.ResetTileFontColor, ResetFontColor);
}

public Session Session
Expand Down Expand Up @@ -145,12 +147,31 @@ public void SelectBackgroundColor(TileViewModel tile)
}
}

public void SelectFontColor(TileViewModel tile)
{
Assert.ParamIsNotNull(tile, nameof(tile));

string selectedColor = this.WindowService.ShowColorPickerDialog(this, tile.TileInfo.FontColor);

// Update the text box color if the user selected a different color
if (!string.Equals(selectedColor, tile.TileInfo.FontColor, System.StringComparison.OrdinalIgnoreCase))
{
tile.FontColor = selectedColor;
}
}

public void ResetBackgroundColor(TileViewModel tile)
{
Assert.ParamIsNotNull(tile, nameof(tile));

// Assigning null will clear out any overridden background color, returning to default
tile.BackgroundColor = null;
}
public void ResetFontColor(TileViewModel tile)
{
Assert.ParamIsNotNull(tile, nameof(tile));

tile.ResetFontColor();
}
}
}
63 changes: 63 additions & 0 deletions Source/TeamMate/ViewModels/TileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public TileInfo TileInfo
this.includeInItemCountSummary = (this.TileInfo != null) ? this.tileInfo.IncludeInItemCountSummary : false;
this.backgroundColor = this.GetBackgroundColor();
this.isDefaultBackgroundColor = this.IsDefaultBackColor();
this.fontColor = this.GetFontColor();
this.tileInfo.FontColor = this.fontColor;
this.isDefaultFontColor = this.IsDefaultTextFontColor();

this.Query = (this.TileInfo != null) ? CreateQueryViewModel(this.TileInfo) : null;

Expand Down Expand Up @@ -103,6 +106,19 @@ public bool IsDefaultBackgroundColor
}
}

private bool isDefaultFontColor;
public bool IsDefaultFontColor
{
get
{
return this.isDefaultFontColor;
}
set
{
SetProperty(ref this.isDefaultFontColor, value);
}
}

private string backgroundColor;
/// <summary>
/// Holds the hex code for the background color of the tile.
Expand Down Expand Up @@ -157,6 +173,53 @@ public string GetDefaultBackgroundColor()
return DefaultBackgroundColor;
}

protected const string DefaultFontColor = "White";

private string fontColor = DefaultFontColor;
/// <summary>
/// Holds the hex code for the background color of the tile.
/// Defaults to a predefined color based on the type of the tile, if no color is explicitly selected for it.
/// </summary>
public string FontColor
{
get { return this.fontColor; }
set
{
this.TileInfo.FontColor = value;
this.TileInfo.FireChanged();

SetProperty(ref this.fontColor, this.GetFontColor());
this.IsDefaultFontColor = this.IsDefaultTextFontColor();
}
}

private string GetFontColor()
{
if (this.TileInfo != null && !string.IsNullOrEmpty(this.TileInfo.FontColor))
{
return this.TileInfo.FontColor;
}
return this.GetDefaultFontColor();
}
public void ResetFontColor()
{
this.FontColor = DefaultFontColor;
}

private bool IsDefaultTextFontColor()
{
return string.Equals(this.FontColor, this.GetDefaultFontColor(), StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Get the default foreground color for the tile based on its type
/// </summary>
/// <returns>Hex value of the default color for the tile</returns>
public string GetDefaultFontColor()
{
return DefaultFontColor;
}

public QueryViewModelBase Query
{
get { return this.query; }
Expand Down

0 comments on commit 610914a

Please sign in to comment.