enhance: add first/last buttons for block-nav, no wrapping (#1015) (#1016)

Added 2 new buttons (only visible in block-nav mode), with new icons and new (en_US) strings (First/Last Difference).
Implemented these new buttons, and disabled the automatic wrap-around for the prev/next buttons in block-nav mode.
This commit is contained in:
Göran W 2025-02-24 02:32:19 +01:00 committed by GitHub
parent 9ab602788a
commit fa4caa2186
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 127 additions and 3 deletions

View file

@ -34,6 +34,20 @@
<!-- Toolbar Buttons -->
<StackPanel Grid.Column="3" Margin="8,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
<Button Classes="icon_button"
Width="28"
Click="OnGotoFirstChange"
IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.First}">
<Button.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsTextDiff"/>
<Binding Source="{x:Static vm:Preferences.Instance}" Path="UseBlockNavigationInDiffView" Mode="OneWay"/>
</MultiBinding>
</Button.IsVisible>
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Top}"/>
</Button>
<Button Classes="icon_button"
Width="28"
Click="OnGotoPrevChange"
@ -61,6 +75,20 @@
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Down}"/>
</Button>
<Button Classes="icon_button"
Width="28"
Click="OnGotoLastChange"
IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.Last}">
<Button.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsTextDiff"/>
<Binding Source="{x:Static vm:Preferences.Instance}" Path="UseBlockNavigationInDiffView" Mode="OneWay"/>
</MultiBinding>
</Button.IsVisible>
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Bottom}"/>
</Button>
<ToggleButton Classes="line_path"
Width="28"
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseBlockNavigationInDiffView, Mode=TwoWay}"

View file

@ -11,6 +11,13 @@ namespace SourceGit.Views
InitializeComponent();
}
private void OnGotoFirstChange(object _, RoutedEventArgs e)
{
var textDiff = this.FindDescendantOfType<TextDiffView>();
textDiff?.GotoFirstChange();
e.Handled = true;
}
private void OnGotoPrevChange(object _, RoutedEventArgs e)
{
var textDiff = this.FindDescendantOfType<TextDiffView>();
@ -24,5 +31,12 @@ namespace SourceGit.Views
textDiff?.GotoNextChange();
e.Handled = true;
}
private void OnGotoLastChange(object _, RoutedEventArgs e)
{
var textDiff = this.FindDescendantOfType<TextDiffView>();
textDiff?.GotoLastChange();
e.Handled = true;
}
}
}

View file

@ -543,6 +543,21 @@ namespace SourceGit.Views
{
}
public void GotoFirstChange()
{
var blockNavigation = BlockNavigation;
if (blockNavigation != null)
{
var prev = blockNavigation.GotoFirst();
if (prev != null)
{
TextArea.Caret.Line = prev.Start;
ScrollToLine(prev.Start);
}
}
// NOTE: Not implemented (button hidden) for non-block navigation.
}
public void GotoPrevChange()
{
var blockNavigation = BlockNavigation;
@ -641,6 +656,21 @@ namespace SourceGit.Views
}
}
public void GotoLastChange()
{
var blockNavigation = BlockNavigation;
if (blockNavigation != null)
{
var next = blockNavigation.GotoLast();
if (next != null)
{
TextArea.Caret.Line = next.Start;
ScrollToLine(next.Start);
}
}
// NOTE: Not implemented (button hidden) for non-block navigation.
}
public override void Render(DrawingContext context)
{
base.Render(context);
@ -1682,6 +1712,19 @@ namespace SourceGit.Views
InitializeComponent();
}
public void GotoFirstChange()
{
var presenter = this.FindDescendantOfType<ThemedTextDiffPresenter>();
if (presenter == null)
return;
presenter.GotoFirstChange();
if (presenter is SingleSideTextDiffPresenter singleSide)
singleSide.ForceSyncScrollOffset();
BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
}
public void GotoPrevChange()
{
var presenter = this.FindDescendantOfType<ThemedTextDiffPresenter>();
@ -1708,6 +1751,19 @@ namespace SourceGit.Views
BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
}
public void GotoLastChange()
{
var presenter = this.FindDescendantOfType<ThemedTextDiffPresenter>();
if (presenter == null)
return;
presenter.GotoLastChange();
if (presenter is SingleSideTextDiffPresenter singleSide)
singleSide.ForceSyncScrollOffset();
BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);