Skip to content

Commit ab26bb8

Browse files
committed
refactor: re-design toolbar of Views.DiffView
1 parent 7bf6793 commit ab26bb8

File tree

7 files changed

+50
-72
lines changed

7 files changed

+50
-72
lines changed

src/Commands/Diff.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ protected override void OnReadline(string line)
4848
{
4949
if (line.StartsWith("old mode ", StringComparison.Ordinal))
5050
{
51-
_result.FileModeDiff ??= new Models.FileModeDiff();
52-
_result.FileModeDiff.Old = line.Substring(9);
51+
_result.OldMode = line.Substring(9);
5352
return;
5453
}
5554

5655
if (line.StartsWith("new mode ", StringComparison.Ordinal))
5756
{
58-
_result.FileModeDiff ??= new Models.FileModeDiff();
59-
_result.FileModeDiff.New = line.Substring(9);
57+
_result.NewMode = line.Substring(9);
6058
return;
6159
}
6260

src/Converters/PathConverters.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,5 @@ public static class PathConverters
1111

1212
public static readonly FuncValueConverter<string, string> PureDirectoryName =
1313
new FuncValueConverter<string, string>(fullpath => Path.GetDirectoryName(fullpath) ?? "");
14-
15-
public static readonly FuncValueConverter<string, string> TruncateIfTooLong =
16-
new FuncValueConverter<string, string>(fullpath =>
17-
{
18-
if (fullpath.Length <= 50)
19-
return fullpath;
20-
return fullpath.Substring(0, 20) + ".../" + Path.GetFileName(fullpath);
21-
});
2214
}
2315
}

src/Models/DiffResult.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,11 @@ public class DiffResult
586586
{
587587
public bool IsBinary { get; set; } = false;
588588
public bool IsLFS { get; set; } = false;
589+
public string OldMode { get; set; } = string.Empty;
590+
public string NewMode { get; set; } = string.Empty;
589591
public TextDiff TextDiff { get; set; } = null;
590592
public LFSDiff LFSDiff { get; set; } = null;
591-
public FileModeDiff FileModeDiff { get; set; } = null;
593+
594+
public string FileModeChange => string.IsNullOrEmpty(OldMode) ? string.Empty : $"{OldMode}{NewMode}";
592595
}
593596
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">NEW</x:String>
132132
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">OLD</x:String>
133133
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copy</x:String>
134-
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed :</x:String>
134+
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed</x:String>
135135
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJECT CHANGE</x:String>
136136
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Next Difference</x:String>
137137
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">NO CHANGES OR ONLY EOL CHANGES</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">当前大小</x:String>
132132
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">原始大小</x:String>
133133
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">复制</x:String>
134-
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化</x:String>
134+
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化</x:String>
135135
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS对象变更</x:String>
136136
<x:String x:Key="Text.Diff.Next" xml:space="preserve">下一个差异</x:String>
137137
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">没有变更或仅有换行符差异</x:String>

src/ViewModels/DiffContext.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Threading.Tasks;
44

55
using Avalonia;
6-
using Avalonia.Media;
76
using Avalonia.Media.Imaging;
87
using Avalonia.Threading;
98

@@ -28,19 +27,16 @@ public bool IsUnstaged
2827
get => _option.IsUnstaged;
2928
}
3029

31-
public string FilePath
30+
public string Title
3231
{
33-
get => _option.Path;
32+
get => _title;
33+
private set => SetProperty(ref _title, value);
3434
}
3535

36-
public bool IsOrgFilePathVisible
36+
public string FileModeChange
3737
{
38-
get => !string.IsNullOrWhiteSpace(_option.OrgPath) && _option.OrgPath != "/dev/null";
39-
}
40-
41-
public string OrgFilePath
42-
{
43-
get => _option.OrgPath;
38+
get => _fileModeChange;
39+
private set => SetProperty(ref _fileModeChange, value);
4440
}
4541

4642
public bool IsLoading
@@ -67,14 +63,6 @@ public Vector SyncScrollOffset
6763
set => SetProperty(ref _syncScrollOffset, value);
6864
}
6965

70-
public Models.FileModeDiff FileModeDiff
71-
{
72-
get => _fileModeDiff;
73-
set => SetProperty(ref _fileModeDiff, value);
74-
}
75-
76-
public TextTrimming PathTrimming { get; } = new TextLeadingPrefixTrimming("...", 20);
77-
7866
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
7967
{
8068
_repo = repo;
@@ -86,20 +74,11 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
8674
_content = previous._content;
8775
}
8876

89-
OnPropertyChanged(nameof(FilePath));
90-
OnPropertyChanged(nameof(IsOrgFilePathVisible));
91-
OnPropertyChanged(nameof(OrgFilePath));
92-
9377
Task.Run(() =>
9478
{
9579
var latest = new Commands.Diff(repo, option).Result();
9680
var rs = null as object;
9781

98-
if (latest.FileModeDiff != null)
99-
{
100-
FileModeDiff = latest.FileModeDiff;
101-
}
102-
10382
if (latest.TextDiff != null)
10483
{
10584
latest.TextDiff.File = _option.Path;
@@ -154,6 +133,12 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
154133

155134
Dispatcher.UIThread.Post(() =>
156135
{
136+
if (string.IsNullOrEmpty(_option.OrgPath))
137+
Title = _option.Path;
138+
else
139+
Title = $"{_option.OrgPath}{_option.Path}";
140+
141+
FileModeChange = latest.FileModeChange;
157142
Content = rs;
158143
IsTextDiff = latest.TextDiff != null;
159144
IsLoading = false;
@@ -190,10 +175,11 @@ private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
190175

191176
private readonly string _repo = string.Empty;
192177
private readonly Models.DiffOption _option = null;
178+
private string _title = string.Empty;
179+
private string _fileModeChange = string.Empty;
193180
private bool _isLoading = true;
194181
private bool _isTextDiff = false;
195182
private object _content = null;
196183
private Vector _syncScrollOffset = Vector.Zero;
197-
private Models.FileModeDiff _fileModeDiff = null;
198184
}
199185
}

src/Views/DiffView.axaml

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,33 @@
1313
<Grid RowDefinitions="26,*">
1414
<!-- Toolbar -->
1515
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
16-
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
17-
<StackPanel Grid.Column="0" Orientation="Horizontal" IsVisible="{Binding IsOrgFilePathVisible}" VerticalAlignment="Center">
18-
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
19-
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding OrgFilePath, Converter={x:Static c:PathConverters.TruncateIfTooLong}}" FontSize="11"/>
20-
<TextBlock Margin="8,0,0,0" Text=""/>
21-
</StackPanel>
22-
23-
<DockPanel Grid.Column="1" VerticalAlignment="Center">
24-
<Path DockPanel.Dock="Left" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
25-
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath}"
26-
TextTrimming="{Binding PathTrimming}" TextWrapping="NoWrap" HorizontalAlignment="Stretch" ToolTip.Tip="{Binding FilePath}" FontSize="11"/>
27-
<Path DockPanel.Dock="Right" Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{StaticResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
28-
</DockPanel>
29-
30-
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" IsVisible="{Binding FileModeDiff, Converter={x:Static ObjectConverters.IsNotNull}}">
31-
<TextBlock Classes="monospace" Margin="8,0,0,0" Text="{DynamicResource Text.Diff.FileModeChanged}" FontSize="11"/>
32-
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.Old}" FontSize="11"/>
33-
<TextBlock Margin="4,0" Text=""/>
34-
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.New}" FontSize="11"/>
35-
</StackPanel>
36-
37-
<StackPanel Grid.Column="3" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
16+
<Grid ColumnDefinitions="Auto,Auto,*,Auto">
17+
<!-- File Icon -->
18+
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
19+
20+
<!-- File Mode Change -->
21+
<Border Grid.Column="1"
22+
Margin="4,0,0,0"
23+
Height="18"
24+
CornerRadius="4"
25+
VerticalAlignment="Center"
26+
Background="{DynamicResource Brush.Badge}"
27+
IsVisible="{Binding FileModeChange, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
28+
ToolTip.Tip="{DynamicResource Text.Diff.FileModeChanged}">
29+
<TextBlock Classes="monospace" FontSize="10" HorizontalAlignment="Center" Margin="4,0" Text="{Binding FileModeChange}"/>
30+
</Border>
31+
32+
<!-- Title -->
33+
<TextBlock Grid.Column="2" Classes="monospace" Margin="4,0,0,0" Text="{Binding Title}" FontSize="11"/>
34+
35+
<!-- Toolbar Buttons -->
36+
<StackPanel Grid.Column="3" Margin="8,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
3837
<ToggleButton Classes="line_path"
3938
Width="32" Height="18"
4039
Background="Transparent"
4140
Padding="9,6"
4241
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting, Mode=TwoWay}"
43-
IsVisible="{Binding IsTextDiff}"
42+
IsVisible="{Binding IsTextDiff}"
4443
ToolTip.Tip="{DynamicResource Text.Diff.SyntaxHighlight}">
4544
<Path Width="13" Height="13" Data="{StaticResource Icons.SyntaxHighlight}" Margin="0,3,0,0"/>
4645
</ToggleButton>
@@ -50,11 +49,11 @@
5049
Background="Transparent"
5150
Padding="9,6"
5251
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}"
53-
IsVisible="{Binding IsTextDiff}"
52+
IsVisible="{Binding IsTextDiff}"
5453
ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}">
5554
<Path Width="12" Height="12" Data="{StaticResource Icons.LayoutHorizontal}" Margin="0,2,0,0"/>
5655
</ToggleButton>
57-
56+
5857
<Button Classes="icon_button" Width="32" Command="{Binding OpenExternalMergeTool}" ToolTip.Tip="{DynamicResource Text.Diff.UseMerger}">
5958
<Path Width="12" Height="12" Stretch="Uniform" Data="{StaticResource Icons.OpenWith}"/>
6059
</Button>
@@ -135,18 +134,18 @@
135134

136135
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding NewSize}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
137136
</Grid>
138-
137+
139138
<Border Grid.Row="1" Background="{DynamicResource Brush.Window}" Effect="drop-shadow(0 0 8 #A0000000)" Margin="0,8,0,0" HorizontalAlignment="Center">
140139
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
141140
<v:ImageDiffView Alpha="{Binding #ImageDiffSlider.Value}"
142141
OldImage="{Binding Old}"
143142
NewImage="{Binding New}"
144143
RenderOptions.BitmapInterpolationMode="HighQuality"/>
145-
</Border>
144+
</Border>
146145
</Border>
147146

148-
<Slider Grid.Row="2"
149-
x:Name="ImageDiffSlider"
147+
<Slider Grid.Row="2"
148+
x:Name="ImageDiffSlider"
150149
Minimum="0" Maximum="1"
151150
VerticalAlignment="Top"
152151
TickPlacement="None"

0 commit comments

Comments
 (0)