Added Preference and ToggleButton for diff navigation style

This commit is contained in:
goran-w 2024-11-16 18:39:04 +01:00
parent 2f2579772f
commit 908b982170
5 changed files with 79 additions and 22 deletions

View file

@ -133,6 +133,14 @@ namespace SourceGit.ViewModels
LoadDiffContent(); LoadDiffContent();
} }
public void ToggleHighlightedDiffNavigation()
{
Preference.Instance.EnableChangeBlocks = !Preference.Instance.EnableChangeBlocks;
if (_content is Models.TextDiff textDiff)
textDiff.CurrentChangeBlockIdx = -1;
RefreshChangeBlockIndicator();
}
public void IncrUnified() public void IncrUnified()
{ {
UnifiedLines = _unifiedLines + 1; UnifiedLines = _unifiedLines + 1;
@ -145,6 +153,12 @@ namespace SourceGit.ViewModels
LoadDiffContent(); LoadDiffContent();
} }
public void ToggleTwoSideDiff()
{
Preference.Instance.UseSideBySideDiff = !Preference.Instance.UseSideBySideDiff;
RefreshChangeBlockIndicator();
}
public void OpenExternalMergeTool() public void OpenExternalMergeTool()
{ {
var toolType = Preference.Instance.ExternalMergeToolType; var toolType = Preference.Instance.ExternalMergeToolType;

View file

@ -206,6 +206,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _useFullTextDiff, value); set => SetProperty(ref _useFullTextDiff, value);
} }
public bool EnableChangeBlocks
{
get => _enableChangeBlocks;
set => SetProperty(ref _enableChangeBlocks, value);
}
public Models.ChangeViewMode UnstagedChangeViewMode public Models.ChangeViewMode UnstagedChangeViewMode
{ {
get => _unstagedChangeViewMode; get => _unstagedChangeViewMode;
@ -614,6 +620,7 @@ namespace SourceGit.ViewModels
private bool _enableDiffViewWordWrap = false; private bool _enableDiffViewWordWrap = false;
private bool _showHiddenSymbolsInDiffView = false; private bool _showHiddenSymbolsInDiffView = false;
private bool _useFullTextDiff = false; private bool _useFullTextDiff = false;
private bool _enableChangeBlocks = false;
private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List; private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List;
private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List; private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List;

View file

@ -34,6 +34,15 @@
<!-- Toolbar Buttons --> <!-- Toolbar Buttons -->
<StackPanel Grid.Column="3" Margin="8,0,0,0" Orientation="Horizontal" VerticalAlignment="Center"> <StackPanel Grid.Column="3" Margin="8,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
<ToggleButton Classes="line_path"
Width="28"
Command="{Binding ToggleHighlightedDiffNavigation}"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableChangeBlocks, Mode=OneWay}"
IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.HighlightedDiffNavigation}">
<Path Width="13" Height="13" Data="{StaticResource Icons.Highlight}" Margin="0,3,0,0"/>
</ToggleButton>
<Button Classes="icon_button" <Button Classes="icon_button"
Width="28" Width="28"
Click="OnGotoPrevChange" Click="OnGotoPrevChange"
@ -42,12 +51,17 @@
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/> <Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
</Button> </Button>
<TextBlock Classes="primary" <TextBlock Classes="primary"
Margin="0,0,0,0" Margin="0,0,0,0"
Text="{Binding ChangeBlockIndicator}" Text="{Binding ChangeBlockIndicator}"
FontSize="11" FontSize="11">
TextTrimming="CharacterEllipsis" <TextBlock.IsVisible>
IsVisible="{Binding IsTextDiff}"/> <MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="IsTextDiff"/>
<Binding Source="{x:Static vm:Preference.Instance}" Path="EnableChangeBlocks" Mode="OneWay"/>
</MultiBinding>
</TextBlock.IsVisible>
</TextBlock>
<Button Classes="icon_button" <Button Classes="icon_button"
Width="28" Width="28"
@ -131,7 +145,8 @@
<ToggleButton Classes="line_path" <ToggleButton Classes="line_path"
Width="28" Height="18" Width="28" Height="18"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}" Command="{Binding ToggleTwoSideDiff}"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"
IsVisible="{Binding IsTextDiff}" IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}"> 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.LayoutHorizontal}" Margin="0,2,0,0"/>

View file

@ -13,28 +13,44 @@ namespace SourceGit.Views
private void OnGotoPrevChange(object _, RoutedEventArgs e) private void OnGotoPrevChange(object _, RoutedEventArgs e)
{ {
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>(); if (ViewModels.Preference.Instance.EnableChangeBlocks)
if (textDiff == null) {
return; if (DataContext is ViewModels.DiffContext diffCtx)
diffCtx.PrevChange();
}
else
{
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>();
if (textDiff == null)
return;
textDiff.GotoPrevChange(); textDiff.GotoPrevChange();
if (textDiff is SingleSideTextDiffPresenter presenter) if (textDiff is SingleSideTextDiffPresenter presenter)
presenter.ForceSyncScrollOffset(); presenter.ForceSyncScrollOffset();
e.Handled = true; e.Handled = true;
}
} }
private void OnGotoNextChange(object _, RoutedEventArgs e) private void OnGotoNextChange(object _, RoutedEventArgs e)
{ {
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>(); if (ViewModels.Preference.Instance.EnableChangeBlocks)
if (textDiff == null) {
return; if (DataContext is ViewModels.DiffContext diffCtx)
diffCtx.NextChange();
}
else
{
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>();
if (textDiff == null)
return;
textDiff.GotoNextChange(); textDiff.GotoNextChange();
if (textDiff is SingleSideTextDiffPresenter presenter) if (textDiff is SingleSideTextDiffPresenter presenter)
presenter.ForceSyncScrollOffset(); presenter.ForceSyncScrollOffset();
e.Handled = true; e.Handled = true;
}
} }
} }
} }

View file

@ -635,6 +635,7 @@ namespace SourceGit.Views
//TextArea.Caret.BringCaretToView(); // NOTE: Brings caret line (barely) into view. //TextArea.Caret.BringCaretToView(); // NOTE: Brings caret line (barely) into view.
ScrollToLine(changeBlock.StartLine); // NOTE: Brings specified line into center of view. ScrollToLine(changeBlock.StartLine); // NOTE: Brings specified line into center of view.
} }
TextArea.TextView.Redraw();
} }
public override void Render(DrawingContext context) public override void Render(DrawingContext context)
@ -712,6 +713,10 @@ namespace SourceGit.Views
{ {
InvalidateVisual(); InvalidateVisual();
} }
else if (change.Property == CurrentChangeBlockIdxProperty)
{
InvalidateVisual();
}
} }
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e) private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
@ -1587,7 +1592,7 @@ namespace SourceGit.Views
CurrentChangeBlockIdxProperty.Changed.AddClassHandler<TextDiffView>((v, e) => CurrentChangeBlockIdxProperty.Changed.AddClassHandler<TextDiffView>((v, e) =>
{ {
if ((int)e.NewValue >= 0 && v.Editor.Presenter != null) if (v.Editor.Presenter != null)
{ {
foreach (var p in v.Editor.Presenter.GetVisualDescendants().OfType<ThemedTextDiffPresenter>()) foreach (var p in v.Editor.Presenter.GetVisualDescendants().OfType<ThemedTextDiffPresenter>())
{ {