mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
refactor: re-design toolbar of Views.DiffView
This commit is contained in:
parent
7bf6793a11
commit
ab26bb83e9
7 changed files with 47 additions and 69 deletions
|
@ -48,15 +48,13 @@ namespace SourceGit.Commands
|
|||
{
|
||||
if (line.StartsWith("old mode ", StringComparison.Ordinal))
|
||||
{
|
||||
_result.FileModeDiff ??= new Models.FileModeDiff();
|
||||
_result.FileModeDiff.Old = line.Substring(9);
|
||||
_result.OldMode = line.Substring(9);
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.StartsWith("new mode ", StringComparison.Ordinal))
|
||||
{
|
||||
_result.FileModeDiff ??= new Models.FileModeDiff();
|
||||
_result.FileModeDiff.New = line.Substring(9);
|
||||
_result.NewMode = line.Substring(9);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,5 @@ namespace SourceGit.Converters
|
|||
|
||||
public static readonly FuncValueConverter<string, string> PureDirectoryName =
|
||||
new FuncValueConverter<string, string>(fullpath => Path.GetDirectoryName(fullpath) ?? "");
|
||||
|
||||
public static readonly FuncValueConverter<string, string> TruncateIfTooLong =
|
||||
new FuncValueConverter<string, string>(fullpath =>
|
||||
{
|
||||
if (fullpath.Length <= 50)
|
||||
return fullpath;
|
||||
return fullpath.Substring(0, 20) + ".../" + Path.GetFileName(fullpath);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -586,8 +586,11 @@ namespace SourceGit.Models
|
|||
{
|
||||
public bool IsBinary { get; set; } = false;
|
||||
public bool IsLFS { get; set; } = false;
|
||||
public string OldMode { get; set; } = string.Empty;
|
||||
public string NewMode { get; set; } = string.Empty;
|
||||
public TextDiff TextDiff { get; set; } = null;
|
||||
public LFSDiff LFSDiff { get; set; } = null;
|
||||
public FileModeDiff FileModeDiff { get; set; } = null;
|
||||
|
||||
public string FileModeChange => string.IsNullOrEmpty(OldMode) ? string.Empty : $"{OldMode} → {NewMode}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">NEW</x:String>
|
||||
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">OLD</x:String>
|
||||
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copy</x:String>
|
||||
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed :</x:String>
|
||||
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed</x:String>
|
||||
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJECT CHANGE</x:String>
|
||||
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Next Difference</x:String>
|
||||
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">NO CHANGES OR ONLY EOL CHANGES</x:String>
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">当前大小</x:String>
|
||||
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">原始大小</x:String>
|
||||
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">复制</x:String>
|
||||
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化 :</x:String>
|
||||
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化</x:String>
|
||||
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS对象变更</x:String>
|
||||
<x:String x:Key="Text.Diff.Next" xml:space="preserve">下一个差异</x:String>
|
||||
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">没有变更或仅有换行符差异</x:String>
|
||||
|
|
|
@ -3,7 +3,6 @@ using System.IO;
|
|||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
|
||||
|
@ -28,19 +27,16 @@ namespace SourceGit.ViewModels
|
|||
get => _option.IsUnstaged;
|
||||
}
|
||||
|
||||
public string FilePath
|
||||
public string Title
|
||||
{
|
||||
get => _option.Path;
|
||||
get => _title;
|
||||
private set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
public bool IsOrgFilePathVisible
|
||||
public string FileModeChange
|
||||
{
|
||||
get => !string.IsNullOrWhiteSpace(_option.OrgPath) && _option.OrgPath != "/dev/null";
|
||||
}
|
||||
|
||||
public string OrgFilePath
|
||||
{
|
||||
get => _option.OrgPath;
|
||||
get => _fileModeChange;
|
||||
private set => SetProperty(ref _fileModeChange, value);
|
||||
}
|
||||
|
||||
public bool IsLoading
|
||||
|
@ -67,14 +63,6 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _syncScrollOffset, value);
|
||||
}
|
||||
|
||||
public Models.FileModeDiff FileModeDiff
|
||||
{
|
||||
get => _fileModeDiff;
|
||||
set => SetProperty(ref _fileModeDiff, value);
|
||||
}
|
||||
|
||||
public TextTrimming PathTrimming { get; } = new TextLeadingPrefixTrimming("...", 20);
|
||||
|
||||
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
|
||||
{
|
||||
_repo = repo;
|
||||
|
@ -86,20 +74,11 @@ namespace SourceGit.ViewModels
|
|||
_content = previous._content;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(FilePath));
|
||||
OnPropertyChanged(nameof(IsOrgFilePathVisible));
|
||||
OnPropertyChanged(nameof(OrgFilePath));
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var latest = new Commands.Diff(repo, option).Result();
|
||||
var rs = null as object;
|
||||
|
||||
if (latest.FileModeDiff != null)
|
||||
{
|
||||
FileModeDiff = latest.FileModeDiff;
|
||||
}
|
||||
|
||||
if (latest.TextDiff != null)
|
||||
{
|
||||
latest.TextDiff.File = _option.Path;
|
||||
|
@ -154,6 +133,12 @@ namespace SourceGit.ViewModels
|
|||
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(_option.OrgPath))
|
||||
Title = _option.Path;
|
||||
else
|
||||
Title = $"{_option.OrgPath} → {_option.Path}";
|
||||
|
||||
FileModeChange = latest.FileModeChange;
|
||||
Content = rs;
|
||||
IsTextDiff = latest.TextDiff != null;
|
||||
IsLoading = false;
|
||||
|
@ -190,10 +175,11 @@ namespace SourceGit.ViewModels
|
|||
|
||||
private readonly string _repo = string.Empty;
|
||||
private readonly Models.DiffOption _option = null;
|
||||
private string _title = string.Empty;
|
||||
private string _fileModeChange = string.Empty;
|
||||
private bool _isLoading = true;
|
||||
private bool _isTextDiff = false;
|
||||
private object _content = null;
|
||||
private Vector _syncScrollOffset = Vector.Zero;
|
||||
private Models.FileModeDiff _fileModeDiff = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,34 +13,33 @@
|
|||
<Grid RowDefinitions="26,*">
|
||||
<!-- Toolbar -->
|
||||
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" IsVisible="{Binding IsOrgFilePathVisible}" VerticalAlignment="Center">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
||||
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding OrgFilePath, Converter={x:Static c:PathConverters.TruncateIfTooLong}}" FontSize="11"/>
|
||||
<TextBlock Margin="8,0,0,0" Text="→"/>
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="Auto,Auto,*,Auto">
|
||||
<!-- File Icon -->
|
||||
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
||||
|
||||
<DockPanel Grid.Column="1" VerticalAlignment="Center">
|
||||
<Path DockPanel.Dock="Left" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
||||
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath}"
|
||||
TextTrimming="{Binding PathTrimming}" TextWrapping="NoWrap" HorizontalAlignment="Stretch" ToolTip.Tip="{Binding FilePath}" FontSize="11"/>
|
||||
<Path DockPanel.Dock="Right" Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{StaticResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
|
||||
</DockPanel>
|
||||
<!-- File Mode Change -->
|
||||
<Border Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Height="18"
|
||||
CornerRadius="4"
|
||||
VerticalAlignment="Center"
|
||||
Background="{DynamicResource Brush.Badge}"
|
||||
IsVisible="{Binding FileModeChange, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.FileModeChanged}">
|
||||
<TextBlock Classes="monospace" FontSize="10" HorizontalAlignment="Center" Margin="4,0" Text="{Binding FileModeChange}"/>
|
||||
</Border>
|
||||
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" IsVisible="{Binding FileModeDiff, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<TextBlock Classes="monospace" Margin="8,0,0,0" Text="{DynamicResource Text.Diff.FileModeChanged}" FontSize="11"/>
|
||||
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.Old}" FontSize="11"/>
|
||||
<TextBlock Margin="4,0" Text="→"/>
|
||||
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.New}" FontSize="11"/>
|
||||
</StackPanel>
|
||||
<!-- Title -->
|
||||
<TextBlock Grid.Column="2" Classes="monospace" Margin="4,0,0,0" Text="{Binding Title}" FontSize="11"/>
|
||||
|
||||
<StackPanel Grid.Column="3" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<!-- Toolbar Buttons -->
|
||||
<StackPanel Grid.Column="3" Margin="8,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ToggleButton Classes="line_path"
|
||||
Width="32" Height="18"
|
||||
Background="Transparent"
|
||||
Padding="9,6"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.SyntaxHighlight}">
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.SyntaxHighlight}" Margin="0,3,0,0"/>
|
||||
</ToggleButton>
|
||||
|
@ -50,11 +49,11 @@
|
|||
Background="Transparent"
|
||||
Padding="9,6"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.LayoutHorizontal}" Margin="0,2,0,0"/>
|
||||
</ToggleButton>
|
||||
|
||||
|
||||
<Button Classes="icon_button" Width="32" Command="{Binding OpenExternalMergeTool}" ToolTip.Tip="{DynamicResource Text.Diff.UseMerger}">
|
||||
<Path Width="12" Height="12" Stretch="Uniform" Data="{StaticResource Icons.OpenWith}"/>
|
||||
</Button>
|
||||
|
@ -135,18 +134,18 @@
|
|||
|
||||
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding NewSize}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
|
||||
</Grid>
|
||||
|
||||
|
||||
<Border Grid.Row="1" Background="{DynamicResource Brush.Window}" Effect="drop-shadow(0 0 8 #A0000000)" Margin="0,8,0,0" HorizontalAlignment="Center">
|
||||
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
|
||||
<v:ImageDiffView Alpha="{Binding #ImageDiffSlider.Value}"
|
||||
OldImage="{Binding Old}"
|
||||
NewImage="{Binding New}"
|
||||
RenderOptions.BitmapInterpolationMode="HighQuality"/>
|
||||
</Border>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
<Slider Grid.Row="2"
|
||||
x:Name="ImageDiffSlider"
|
||||
<Slider Grid.Row="2"
|
||||
x:Name="ImageDiffSlider"
|
||||
Minimum="0" Maximum="1"
|
||||
VerticalAlignment="Top"
|
||||
TickPlacement="None"
|
||||
|
|
Loading…
Reference in a new issue