mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57: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))
|
if (line.StartsWith("old mode ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_result.FileModeDiff ??= new Models.FileModeDiff();
|
_result.OldMode = line.Substring(9);
|
||||||
_result.FileModeDiff.Old = line.Substring(9);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.StartsWith("new mode ", StringComparison.Ordinal))
|
if (line.StartsWith("new mode ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_result.FileModeDiff ??= new Models.FileModeDiff();
|
_result.NewMode = line.Substring(9);
|
||||||
_result.FileModeDiff.New = line.Substring(9);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,5 @@ namespace SourceGit.Converters
|
||||||
|
|
||||||
public static readonly FuncValueConverter<string, string> PureDirectoryName =
|
public static readonly FuncValueConverter<string, string> PureDirectoryName =
|
||||||
new FuncValueConverter<string, string>(fullpath => Path.GetDirectoryName(fullpath) ?? "");
|
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 IsBinary { get; set; } = false;
|
||||||
public bool IsLFS { 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 TextDiff TextDiff { get; set; } = null;
|
||||||
public LFSDiff LFSDiff { 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.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.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.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.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.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>
|
<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.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.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.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.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.Next" xml:space="preserve">下一个差异</x:String>
|
||||||
<x:String x:Key="Text.Diff.NoChange" 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 System.Threading.Tasks;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Media;
|
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
@ -28,19 +27,16 @@ namespace SourceGit.ViewModels
|
||||||
get => _option.IsUnstaged;
|
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";
|
get => _fileModeChange;
|
||||||
}
|
private set => SetProperty(ref _fileModeChange, value);
|
||||||
|
|
||||||
public string OrgFilePath
|
|
||||||
{
|
|
||||||
get => _option.OrgPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsLoading
|
public bool IsLoading
|
||||||
|
@ -67,14 +63,6 @@ namespace SourceGit.ViewModels
|
||||||
set => SetProperty(ref _syncScrollOffset, value);
|
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)
|
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
@ -86,20 +74,11 @@ namespace SourceGit.ViewModels
|
||||||
_content = previous._content;
|
_content = previous._content;
|
||||||
}
|
}
|
||||||
|
|
||||||
OnPropertyChanged(nameof(FilePath));
|
|
||||||
OnPropertyChanged(nameof(IsOrgFilePathVisible));
|
|
||||||
OnPropertyChanged(nameof(OrgFilePath));
|
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
var latest = new Commands.Diff(repo, option).Result();
|
var latest = new Commands.Diff(repo, option).Result();
|
||||||
var rs = null as object;
|
var rs = null as object;
|
||||||
|
|
||||||
if (latest.FileModeDiff != null)
|
|
||||||
{
|
|
||||||
FileModeDiff = latest.FileModeDiff;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (latest.TextDiff != null)
|
if (latest.TextDiff != null)
|
||||||
{
|
{
|
||||||
latest.TextDiff.File = _option.Path;
|
latest.TextDiff.File = _option.Path;
|
||||||
|
@ -154,6 +133,12 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(_option.OrgPath))
|
||||||
|
Title = _option.Path;
|
||||||
|
else
|
||||||
|
Title = $"{_option.OrgPath} → {_option.Path}";
|
||||||
|
|
||||||
|
FileModeChange = latest.FileModeChange;
|
||||||
Content = rs;
|
Content = rs;
|
||||||
IsTextDiff = latest.TextDiff != null;
|
IsTextDiff = latest.TextDiff != null;
|
||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
|
@ -190,10 +175,11 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
private readonly string _repo = string.Empty;
|
private readonly string _repo = string.Empty;
|
||||||
private readonly Models.DiffOption _option = null;
|
private readonly Models.DiffOption _option = null;
|
||||||
|
private string _title = string.Empty;
|
||||||
|
private string _fileModeChange = string.Empty;
|
||||||
private bool _isLoading = true;
|
private bool _isLoading = true;
|
||||||
private bool _isTextDiff = false;
|
private bool _isTextDiff = false;
|
||||||
private object _content = null;
|
private object _content = null;
|
||||||
private Vector _syncScrollOffset = Vector.Zero;
|
private Vector _syncScrollOffset = Vector.Zero;
|
||||||
private Models.FileModeDiff _fileModeDiff = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,28 +13,27 @@
|
||||||
<Grid RowDefinitions="26,*">
|
<Grid RowDefinitions="26,*">
|
||||||
<!-- Toolbar -->
|
<!-- Toolbar -->
|
||||||
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
|
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
<Grid ColumnDefinitions="Auto,Auto,*,Auto">
|
||||||
<StackPanel Grid.Column="0" Orientation="Horizontal" IsVisible="{Binding IsOrgFilePathVisible}" VerticalAlignment="Center">
|
<!-- File Icon -->
|
||||||
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
<Path Grid.Column="0" 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>
|
|
||||||
|
|
||||||
<DockPanel Grid.Column="1" VerticalAlignment="Center">
|
<!-- File Mode Change -->
|
||||||
<Path DockPanel.Dock="Left" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
<Border Grid.Column="1"
|
||||||
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath}"
|
Margin="4,0,0,0"
|
||||||
TextTrimming="{Binding PathTrimming}" TextWrapping="NoWrap" HorizontalAlignment="Stretch" ToolTip.Tip="{Binding FilePath}" FontSize="11"/>
|
Height="18"
|
||||||
<Path DockPanel.Dock="Right" Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{StaticResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
|
CornerRadius="4"
|
||||||
</DockPanel>
|
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}}">
|
<!-- Title -->
|
||||||
<TextBlock Classes="monospace" Margin="8,0,0,0" Text="{DynamicResource Text.Diff.FileModeChanged}" FontSize="11"/>
|
<TextBlock Grid.Column="2" Classes="monospace" Margin="4,0,0,0" Text="{Binding Title}" 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>
|
|
||||||
|
|
||||||
<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"
|
<ToggleButton Classes="line_path"
|
||||||
Width="32" Height="18"
|
Width="32" Height="18"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
|
|
Loading…
Reference in a new issue