feature: allow to hide tags in graph (#1109)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-18 21:40:31 +08:00
parent ae1e46b586
commit 2512d3be7a
No known key found for this signature in database
10 changed files with 48 additions and 20 deletions

View file

@ -173,8 +173,7 @@
<!-- REFS -->
<TextBlock Grid.Row="3" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Refs}" IsVisible="{Binding HasDecorators}"/>
<Border Grid.Row="3" Grid.Column="1" Margin="12,0,0,0" MinHeight="24" IsVisible="{Binding HasDecorators}">
<v:CommitRefsPresenter TagBackground="{DynamicResource Brush.DecoratorTag}"
Foreground="{DynamicResource Brush.FG1}"
<v:CommitRefsPresenter Foreground="{DynamicResource Brush.FG1}"
FontFamily="{DynamicResource Fonts.Primary}"
FontSize="11"
AllowWrap="True"

View file

@ -64,15 +64,6 @@ namespace SourceGit.Views
set => SetValue(UseGraphColorProperty, value);
}
public static readonly StyledProperty<IBrush> TagBackgroundProperty =
AvaloniaProperty.Register<CommitRefsPresenter, IBrush>(nameof(TagBackground), Brushes.White);
public IBrush TagBackground
{
get => GetValue(TagBackgroundProperty);
set => SetValue(TagBackgroundProperty, value);
}
public static readonly StyledProperty<bool> AllowWrapProperty =
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(AllowWrap));
@ -82,6 +73,15 @@ namespace SourceGit.Views
set => SetValue(AllowWrapProperty, value);
}
public static readonly StyledProperty<bool> ShowTagsProperty =
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(ShowTags), true);
public bool ShowTags
{
get => GetValue(ShowTagsProperty);
set => SetValue(ShowTagsProperty, value);
}
static CommitRefsPresenter()
{
AffectsMeasure<CommitRefsPresenter>(
@ -89,8 +89,8 @@ namespace SourceGit.Views
FontSizeProperty,
ForegroundProperty,
UseGraphColorProperty,
TagBackgroundProperty,
BackgroundProperty);
BackgroundProperty,
ShowTagsProperty);
}
public override void Render(DrawingContext context)
@ -171,15 +171,18 @@ namespace SourceGit.Views
var typefaceBold = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
var fg = Foreground;
var normalBG = UseGraphColor ? commit.Brush : Brushes.Gray;
var tagBG = UseGraphColor ? TagBackground : Brushes.Gray;
var labelSize = FontSize;
var requiredWidth = 0.0;
var requiredHeight = 16.0;
var x = 0.0;
var allowWrap = AllowWrap;
var showTags = ShowTags;
foreach (var decorator in refs)
{
if (!showTags && decorator.Type == Models.DecoratorType.Tag)
continue;
var isHead = decorator.Type == Models.DecoratorType.CurrentBranchHead ||
decorator.Type == Models.DecoratorType.CurrentCommitHead;
@ -209,7 +212,7 @@ namespace SourceGit.Views
geo = this.FindResource("Icons.Remote") as StreamGeometry;
break;
case Models.DecoratorType.Tag:
item.Brush = tagBG;
item.Brush = Brushes.Gray;
geo = this.FindResource("Icons.Tag") as StreamGeometry;
break;
default:

View file

@ -46,7 +46,6 @@
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.Commit}"/>
<v:CommitRefsPresenter Margin="8,0,0,0"
TagBackground="{DynamicResource Brush.DecoratorTag}"
Foreground="{DynamicResource Brush.FG1}"
FontFamily="{DynamicResource Fonts.Primary}"
FontSize="11"

View file

@ -140,9 +140,9 @@
<v:CommitRefsPresenter Grid.Column="1"
Background="{DynamicResource Brush.Contents}"
TagBackground="{DynamicResource Brush.DecoratorTag}"
Foreground="{DynamicResource Brush.FG1}"
FontFamily="{DynamicResource Fonts.Primary}"
ShowTags="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowTagsInGraph}"
FontSize="11"
VerticalAlignment="Center">
<v:CommitRefsPresenter.UseGraphColor>

View file

@ -447,6 +447,20 @@ namespace SourceGit.Views
ev.Handled = true;
};
var others = new MenuItem();
others.Header = App.Text("Repository.HistoriesOptions");
others.IsEnabled = false;
var showTagsInGraph = new MenuItem();
showTagsInGraph.Header = App.Text("Repository.HistoriesOptions.ShowTagsInGraph");
if (ViewModels.Preferences.Instance.ShowTagsInGraph)
showTagsInGraph.Icon = App.CreateMenuIcon("Icons.Check");
showTagsInGraph.Click += (_, ev) =>
{
ViewModels.Preferences.Instance.ShowTagsInGraph = !ViewModels.Preferences.Instance.ShowTagsInGraph;
ev.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(layout);
menu.Items.Add(horizontal);
@ -455,6 +469,9 @@ namespace SourceGit.Views
menu.Items.Add(order);
menu.Items.Add(dateOrder);
menu.Items.Add(topoOrder);
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(others);
menu.Items.Add(showTagsInGraph);
menu.Open(button);
}