mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-30 00:24:59 +00:00
feature: add option to only highlight current branch in commit graph (#848)
- add a toggle button to only highlight current branch in commit graph - re-order buttons in histories toolbar - remove unused icons and styles
This commit is contained in:
parent
65e820e4d5
commit
26ebd5ae7e
20 changed files with 194 additions and 120 deletions
|
@ -88,9 +88,8 @@ namespace SourceGit.Views
|
|||
FontFamilyProperty,
|
||||
FontSizeProperty,
|
||||
ForegroundProperty,
|
||||
TagBackgroundProperty);
|
||||
|
||||
AffectsRender<CommitRefsPresenter>(
|
||||
UseGraphColorProperty,
|
||||
TagBackgroundProperty,
|
||||
BackgroundProperty);
|
||||
}
|
||||
|
||||
|
@ -172,7 +171,7 @@ namespace SourceGit.Views
|
|||
var typefaceBold = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
|
||||
var fg = Foreground;
|
||||
var normalBG = UseGraphColor ? commit.Brush : Brushes.Gray;
|
||||
var tagBG = TagBackground;
|
||||
var tagBG = UseGraphColor ? TagBackground : Brushes.Gray;
|
||||
var labelSize = FontSize;
|
||||
var requiredWidth = 0.0;
|
||||
var requiredHeight = 16.0;
|
||||
|
|
|
@ -146,7 +146,7 @@
|
|||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.LayoutHorizontal}" Margin="0,2,0,0"/>
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Layout}" Margin="0,2,0,0"/>
|
||||
</ToggleButton>
|
||||
|
||||
<Button Classes="icon_button" Width="28" Command="{Binding OpenExternalMergeTool}" ToolTip.Tip="{DynamicResource Text.Diff.UseMerger}">
|
||||
|
|
|
@ -48,9 +48,6 @@
|
|||
<TextBlock Classes="table_header" Text="{DynamicResource Text.Histories.Header.SHA}" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
<StackPanel Grid.Column="4" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<ToggleButton Classes="time_display_mode"
|
||||
Width="10" Height="10"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=DisplayTimeAsPeriodInHistories, Mode=TwoWay}"/>
|
||||
<TextBlock Classes="table_header"
|
||||
Margin="6,0,0,0"
|
||||
Text="{DynamicResource Text.Histories.Header.Time}"
|
||||
|
@ -143,8 +140,14 @@
|
|||
Foreground="{DynamicResource Brush.FG1}"
|
||||
FontFamily="{DynamicResource Fonts.Primary}"
|
||||
FontSize="11"
|
||||
VerticalAlignment="Center"
|
||||
UseGraphColor="True"/>
|
||||
VerticalAlignment="Center">
|
||||
<v:CommitRefsPresenter.UseGraphColor>
|
||||
<MultiBinding Converter="{x:Static BoolConverters.Or}">
|
||||
<Binding Path="IsMerged"/>
|
||||
<Binding Path="$parent[v:Histories].OnlyHighlightCurrentBranch" Converter="{x:Static BoolConverters.Not}"/>
|
||||
</MultiBinding>
|
||||
</v:CommitRefsPresenter.UseGraphColor>
|
||||
</v:CommitRefsPresenter>
|
||||
|
||||
<v:CommitSubjectPresenter Grid.Column="2"
|
||||
Classes="primary"
|
||||
|
@ -202,6 +205,7 @@
|
|||
<v:CommitGraph x:Name="CommitGraph"
|
||||
Graph="{Binding Graph}"
|
||||
DotBrush="{DynamicResource Brush.Contents}"
|
||||
OnlyHighlightCurrentBranch="{Binding $parent[v:Histories].OnlyHighlightCurrentBranch}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
IsHitTestVisible="False"
|
||||
ClipToBounds="True"/>
|
||||
|
|
|
@ -506,9 +506,18 @@ namespace SourceGit.Views
|
|||
set => SetValue(DotBrushProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> OnlyHighlightCurrentBranchProperty =
|
||||
AvaloniaProperty.Register<CommitGraph, bool>(nameof(OnlyHighlightCurrentBranch), true);
|
||||
|
||||
public bool OnlyHighlightCurrentBranch
|
||||
{
|
||||
get => GetValue(OnlyHighlightCurrentBranchProperty);
|
||||
set => SetValue(OnlyHighlightCurrentBranchProperty, value);
|
||||
}
|
||||
|
||||
static CommitGraph()
|
||||
{
|
||||
AffectsRender<CommitGraph>(GraphProperty, DotBrushProperty);
|
||||
AffectsRender<CommitGraph>(GraphProperty, DotBrushProperty, OnlyHighlightCurrentBranchProperty);
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
|
@ -545,6 +554,31 @@ namespace SourceGit.Views
|
|||
|
||||
private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double top, double bottom)
|
||||
{
|
||||
var grayedPen = new Pen(Brushes.Gray, Models.CommitGraph.Pens[0].Thickness);
|
||||
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
|
||||
|
||||
if (onlyHighlightCurrentBranch)
|
||||
{
|
||||
foreach (var link in graph.Links)
|
||||
{
|
||||
if (link.IsMerged)
|
||||
continue;
|
||||
if (link.End.Y < top)
|
||||
continue;
|
||||
if (link.Start.Y > bottom)
|
||||
break;
|
||||
|
||||
var geo = new StreamGeometry();
|
||||
using (var ctx = geo.Open())
|
||||
{
|
||||
ctx.BeginFigure(link.Start, false);
|
||||
ctx.QuadraticBezierTo(link.Control, link.End);
|
||||
}
|
||||
|
||||
context.DrawGeometry(null, grayedPen, geo);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var line in graph.Paths)
|
||||
{
|
||||
var last = line.Points[0];
|
||||
|
@ -610,11 +644,16 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
context.DrawGeometry(null, pen, geo);
|
||||
if (!line.IsMerged && onlyHighlightCurrentBranch)
|
||||
context.DrawGeometry(null, grayedPen, geo);
|
||||
else
|
||||
context.DrawGeometry(null, pen, geo);
|
||||
}
|
||||
|
||||
foreach (var link in graph.Links)
|
||||
{
|
||||
if (onlyHighlightCurrentBranch && !link.IsMerged)
|
||||
continue;
|
||||
if (link.End.Y < top)
|
||||
continue;
|
||||
if (link.Start.Y > bottom)
|
||||
|
@ -633,8 +672,10 @@ namespace SourceGit.Views
|
|||
|
||||
private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, double top, double bottom)
|
||||
{
|
||||
IBrush dotFill = DotBrush;
|
||||
Pen dotFillPen = new Pen(dotFill, 2);
|
||||
var dotFill = DotBrush;
|
||||
var dotFillPen = new Pen(dotFill, 2);
|
||||
var grayedPen = new Pen(Brushes.Gray, Models.CommitGraph.Pens[0].Thickness);
|
||||
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
|
||||
|
||||
foreach (var dot in graph.Dots)
|
||||
{
|
||||
|
@ -644,6 +685,9 @@ namespace SourceGit.Views
|
|||
break;
|
||||
|
||||
var pen = Models.CommitGraph.Pens[dot.Color];
|
||||
if (!dot.IsMerged && onlyHighlightCurrentBranch)
|
||||
pen = grayedPen;
|
||||
|
||||
switch (dot.Type)
|
||||
{
|
||||
case Models.CommitGraph.DotType.Head:
|
||||
|
@ -692,6 +736,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(IssueTrackerRulesProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> OnlyHighlightCurrentBranchProperty =
|
||||
AvaloniaProperty.Register<Histories, bool>(nameof(OnlyHighlightCurrentBranch), true);
|
||||
|
||||
public bool OnlyHighlightCurrentBranch
|
||||
{
|
||||
get => GetValue(OnlyHighlightCurrentBranchProperty);
|
||||
set => SetValue(OnlyHighlightCurrentBranchProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<long> NavigationIdProperty =
|
||||
AvaloniaProperty.Register<Histories, long>(nameof(NavigationId));
|
||||
|
||||
|
|
|
@ -83,15 +83,11 @@
|
|||
</ListBox.ItemsPanel>
|
||||
|
||||
<ListBoxItem>
|
||||
<Grid Classes="view_mode" ColumnDefinitions="Auto,*,Auto,Auto,Auto,Auto">
|
||||
<Grid Classes="view_mode" ColumnDefinitions="Auto,*,Auto,Auto,Auto,Auto,Auto">
|
||||
<Path Grid.Column="0" Classes="icon" Data="{StaticResource Icons.Histories}"/>
|
||||
<TextBlock Grid.Column="1" Classes="header" Text="{DynamicResource Text.Histories}"/>
|
||||
|
||||
<ToggleButton Grid.Column="2"
|
||||
Classes="layout_direction"
|
||||
Width="28" Height="26"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseTwoColumnsLayoutInHistories, Mode=TwoWay}"
|
||||
ToolTip.Tip="{DynamicResource Text.Histories.DisplayMode}"/>
|
||||
<ToggleButton Grid.Column="3"
|
||||
Classes="line_path"
|
||||
Width="28" Height="26"
|
||||
Background="Transparent"
|
||||
|
@ -99,7 +95,7 @@
|
|||
ToolTip.Tip="{DynamicResource Text.Repository.EnableReflog}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Reference}"/>
|
||||
</ToggleButton>
|
||||
<ToggleButton Grid.Column="4"
|
||||
<ToggleButton Grid.Column="3"
|
||||
Classes="line_path"
|
||||
Width="28" Height="26"
|
||||
Background="Transparent"
|
||||
|
@ -107,12 +103,27 @@
|
|||
ToolTip.Tip="{DynamicResource Text.Repository.FirstParentFilterToggle}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.FirstParentFilter}"/>
|
||||
</ToggleButton>
|
||||
<Button Grid.Column="5"
|
||||
<ToggleButton Grid.Column="4"
|
||||
Classes="line_path"
|
||||
Width="28" Height="26"
|
||||
Background="Transparent"
|
||||
IsChecked="{Binding OnlyHighlightCurrentBranchInHistories, Mode=TwoWay}"
|
||||
ToolTip.Tip="{DynamicResource Text.Repository.OnlyHighlightCurrentBranchInHistories}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.LightOn}"/>
|
||||
</ToggleButton>
|
||||
<ToggleButton Grid.Column="5"
|
||||
Classes="line_path"
|
||||
Width="28" Height="26"
|
||||
Background="Transparent"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=DisplayTimeAsPeriodInHistories, Mode=TwoWay}"
|
||||
ToolTip.Tip="{DynamicResource Text.Repository.UseRelativeTimeInHistories}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Stopwatch}"/>
|
||||
</ToggleButton>
|
||||
<Button Grid.Column="6"
|
||||
Classes="icon_button"
|
||||
Width="28" Height="26"
|
||||
Click="OnSwitchHistoriesOrderClicked"
|
||||
ToolTip.Tip="{DynamicResource Text.Repository.HistoriesOrder}">
|
||||
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Order}"/>
|
||||
Click="OnOpenAdvancedHistoriesOption">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.More}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
</ListBoxItem>
|
||||
|
@ -677,6 +688,7 @@
|
|||
<v:Histories CurrentBranch="{Binding Repo.CurrentBranch}"
|
||||
AuthorNameColumnWidth="{Binding Source={x:Static vm:Preference.Instance}, Path=Layout.HistoriesAuthorColumnWidth, Mode=TwoWay}"
|
||||
IssueTrackerRules="{Binding Repo.Settings.IssueTrackerRules}"
|
||||
OnlyHighlightCurrentBranch="{Binding Repo.OnlyHighlightCurrentBranchInHistories}"
|
||||
NavigationId="{Binding NavigationId}"/>
|
||||
</DataTemplate>
|
||||
|
||||
|
|
|
@ -396,15 +396,35 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnSwitchHistoriesOrderClicked(object sender, RoutedEventArgs e)
|
||||
private void OnOpenAdvancedHistoriesOption(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button button && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
var checkIcon = App.CreateMenuIcon("Icons.Check");
|
||||
var isHorizontal = ViewModels.Preference.Instance.UseTwoColumnsLayoutInHistories;
|
||||
var horizontal = new MenuItem();
|
||||
horizontal.Header = App.Text("Repository.HistoriesLayout.Horizontal");
|
||||
if (isHorizontal)
|
||||
horizontal.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
horizontal.Click += (_, ev) =>
|
||||
{
|
||||
ViewModels.Preference.Instance.UseTwoColumnsLayoutInHistories = true;
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var vertical = new MenuItem();
|
||||
vertical.Header = App.Text("Repository.HistoriesLayout.Vertical");
|
||||
if (!isHorizontal)
|
||||
vertical.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
vertical.Click += (_, ev) =>
|
||||
{
|
||||
ViewModels.Preference.Instance.UseTwoColumnsLayoutInHistories = false;
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var dateOrder = new MenuItem();
|
||||
dateOrder.Header = App.Text("Repository.HistoriesOrder.ByDate");
|
||||
dateOrder.Icon = repo.EnableTopoOrderInHistories ? null : checkIcon;
|
||||
if (!repo.EnableTopoOrderInHistories)
|
||||
dateOrder.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
dateOrder.Click += (_, ev) =>
|
||||
{
|
||||
repo.EnableTopoOrderInHistories = false;
|
||||
|
@ -413,7 +433,8 @@ namespace SourceGit.Views
|
|||
|
||||
var topoOrder = new MenuItem();
|
||||
topoOrder.Header = App.Text("Repository.HistoriesOrder.Topo");
|
||||
topoOrder.Icon = repo.EnableTopoOrderInHistories ? checkIcon : null;
|
||||
if (repo.EnableTopoOrderInHistories)
|
||||
topoOrder.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
topoOrder.Click += (_, ev) =>
|
||||
{
|
||||
repo.EnableTopoOrderInHistories = true;
|
||||
|
@ -421,6 +442,9 @@ namespace SourceGit.Views
|
|||
};
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(horizontal);
|
||||
menu.Items.Add(vertical);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
menu.Items.Add(dateOrder);
|
||||
menu.Items.Add(topoOrder);
|
||||
menu.Open(button);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue