mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
Go to NEXT/PREV differences in DiffViewer
This commit is contained in:
parent
e9c9a98384
commit
2138ee9c33
2 changed files with 175 additions and 70 deletions
|
@ -13,18 +13,36 @@
|
|||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0" BorderBrush="{StaticResource Brush.Border2}" BorderThickness="0,0,0,1">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,4">
|
||||
<StackPanel x:Name="orgFileNamePanel" Orientation="Horizontal">
|
||||
<Grid Margin="8,4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" x:Name="orgFileNamePanel" Orientation="Horizontal">
|
||||
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.File}"/>
|
||||
<TextBlock x:Name="orgFileName" Margin="4,0,0,0" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
|
||||
<TextBlock Margin="8,0" VerticalAlignment="Center" Text="→" Foreground="{StaticResource Brush.FG}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.File}"/>
|
||||
<TextBlock x:Name="fileName" Margin="4,0" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
|
||||
<Path x:Name="loading" Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Loading}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Path x:Name="loading" Grid.Row="0" HorizontalAlignment="Left" Width="10" Height="10" Margin="8,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Loading}" Visibility="Collapsed"/>
|
||||
<StackPanel Grid.Column="2" x:Name="diffNavigation" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Width="26" Click="Go2Next" ToolTip="Next Difference" Background="Transparent">
|
||||
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.MoveDown}"/>
|
||||
</Button>
|
||||
|
||||
<Button Click="Go2Prev" ToolTip="Previous Difference" Background="Transparent">
|
||||
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.MoveUp}"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Grid x:Name="textChange" Grid.Row="1" ClipToBounds="True">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
@ -48,7 +66,8 @@
|
|||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
IsReadOnly="True"
|
||||
Margin="4,0,4,0"
|
||||
Padding="2,0"
|
||||
Margin="0"
|
||||
FontSize="13"
|
||||
HorizontalContentAlignment="Right"
|
||||
VerticalAlignment="Stretch"/>
|
||||
|
@ -103,7 +122,8 @@
|
|||
IsReadOnly="True"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
Margin="4,0,4,0"
|
||||
Padding="2,0"
|
||||
Margin="0"
|
||||
FontSize="13"
|
||||
HorizontalContentAlignment="Right"
|
||||
VerticalAlignment="Stretch"/>
|
||||
|
|
|
@ -96,18 +96,20 @@ namespace SourceGit.UI {
|
|||
Dispatcher.Invoke(() => {
|
||||
loading.Visibility = Visibility.Collapsed;
|
||||
sizeChange.Visibility = Visibility.Visible;
|
||||
diffNavigation.Visibility = Visibility.Collapsed;
|
||||
txtNewSize.Content = $"{bc.Size} Bytes";
|
||||
txtOldSize.Content = $"{bc.PreSize} Bytes";
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show no changes or only eol changes.
|
||||
/// Show no changes or only EOL changes.
|
||||
/// </summary>
|
||||
private void SetSame() {
|
||||
Dispatcher.Invoke(() => {
|
||||
loading.Visibility = Visibility.Collapsed;
|
||||
noChange.Visibility = Visibility.Visible;
|
||||
diffNavigation.Visibility = Visibility.Collapsed;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -119,6 +121,7 @@ namespace SourceGit.UI {
|
|||
Dispatcher.Invoke(() => {
|
||||
loading.Visibility = Visibility.Collapsed;
|
||||
textChange.Visibility = Visibility.Visible;
|
||||
diffNavigation.Visibility = Visibility.Visible;
|
||||
|
||||
minWidth = Math.Max(leftText.ActualWidth, rightText.ActualWidth) - 16;
|
||||
|
||||
|
@ -149,6 +152,7 @@ namespace SourceGit.UI {
|
|||
p.Background = Brushes.Transparent;
|
||||
p.Foreground = FindResource("Brush.FG") as SolidColorBrush;
|
||||
p.FontStyle = FontStyles.Normal;
|
||||
p.DataContext = b;
|
||||
|
||||
switch (b.Mode) {
|
||||
case Git.Diff.LineMode.Normal:
|
||||
|
@ -205,6 +209,7 @@ namespace SourceGit.UI {
|
|||
cp.Background = p.Background;
|
||||
cp.Foreground = p.Foreground;
|
||||
cp.FontStyle = p.FontStyle;
|
||||
cp.DataContext = b;
|
||||
rightText.Document.Blocks.Add(cp);
|
||||
|
||||
for (int i = 0; i < b.Count; i++) {
|
||||
|
@ -237,8 +242,8 @@ namespace SourceGit.UI {
|
|||
rightText.ScrollToVerticalOffset(e.VerticalOffset);
|
||||
}
|
||||
|
||||
leftLineNumber.Margin = new Thickness(4, -e.VerticalOffset, 4, 0);
|
||||
rightLineNumber.Margin = new Thickness(4, -e.VerticalOffset, 4, 0);
|
||||
leftLineNumber.Margin = new Thickness(0, -e.VerticalOffset, 0, 0);
|
||||
rightLineNumber.Margin = new Thickness(0, -e.VerticalOffset, 0, 0);
|
||||
} else {
|
||||
if (leftText.HorizontalOffset != e.HorizontalOffset) {
|
||||
leftText.ScrollToHorizontalOffset(e.HorizontalOffset);
|
||||
|
@ -315,6 +320,86 @@ namespace SourceGit.UI {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Go to next difference.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Go2Next(object sender, RoutedEventArgs e) {
|
||||
Paragraph next = null;
|
||||
double minTop = 0;
|
||||
|
||||
foreach (var p in leftText.Document.Blocks) {
|
||||
var rect = p.ContentStart.GetCharacterRect(LogicalDirection.Forward);
|
||||
var block = p.DataContext as Git.Diff.Block;
|
||||
if (rect.Top > 0 && block.IsLeftDelete) {
|
||||
next = p as Paragraph;
|
||||
minTop = rect.Top;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var p in rightText.Document.Blocks) {
|
||||
var rect = p.ContentStart.GetCharacterRect(LogicalDirection.Forward);
|
||||
var block = p.DataContext as Git.Diff.Block;
|
||||
if (rect.Top > 0 && block.IsRightAdded) {
|
||||
if (next == null || minTop > rect.Top) {
|
||||
next = p as Paragraph;
|
||||
minTop = rect.Top;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (next != null) {
|
||||
rightText.ScrollToVerticalOffset(rightText.VerticalOffset + minTop);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Go to previous difference.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Go2Prev(object sender, RoutedEventArgs e) {
|
||||
Paragraph next = null;
|
||||
double maxTop = 0;
|
||||
|
||||
var p = leftText.Document.Blocks.LastBlock as Paragraph;
|
||||
do {
|
||||
var rect = p.ContentStart.GetCharacterRect(LogicalDirection.Forward);
|
||||
var block = p.DataContext as Git.Diff.Block;
|
||||
if (rect.Top < 0 && block.IsLeftDelete) {
|
||||
next = p;
|
||||
maxTop = rect.Top;
|
||||
break;
|
||||
}
|
||||
|
||||
p = p.PreviousBlock as Paragraph;
|
||||
} while (p != null);
|
||||
|
||||
p = rightText.Document.Blocks.LastBlock as Paragraph;
|
||||
do {
|
||||
var rect = p.ContentStart.GetCharacterRect(LogicalDirection.Forward);
|
||||
var block = p.DataContext as Git.Diff.Block;
|
||||
if (rect.Top < 0 && block.IsRightAdded) {
|
||||
if (next == null || maxTop < rect.Top) {
|
||||
next = p;
|
||||
maxTop = rect.Top;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
p = p.PreviousBlock as Paragraph;
|
||||
} while (p != null);
|
||||
|
||||
if (next != null) {
|
||||
rightText.ScrollToVerticalOffset(rightText.VerticalOffset + maxTop);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue