Skip to content

Commit 0f56df3

Browse files
committed
code_review: PR #1890
- Re-design LFS Locks window - Unlocking multiple files is only used in `LFS Locks` window. Remove it from `ViewModels.Repository` - Use `App.AskConfirmAsync` instead of show confirm window manually - Add missing translation for Chinese Signed-off-by: leo <longshuang@msn.cn>
1 parent bdeac3e commit 0f56df3

File tree

8 files changed

+54
-80
lines changed

8 files changed

+54
-80
lines changed

src/Commands/LFS.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,16 @@ public async Task<bool> UnlockAsync(string remote, string file, bool force)
9494
return await ExecAsync().ConfigureAwait(false);
9595
}
9696

97-
public async Task<bool> UnlockAsync(string remote, List<string> files, bool force)
97+
public async Task<bool> UnlockMultipleAsync(string remote, List<string> files, bool force)
9898
{
9999
var builder = new StringBuilder();
100100
builder
101101
.Append("lfs unlock --remote=")
102102
.Append(remote)
103-
.Append(force ? " -f " : " ");
103+
.Append(force ? " -f" : " ");
104104

105105
foreach (string file in files)
106-
{
107-
builder.Append(file.Quoted());
108-
builder.Append(" ");
109-
}
106+
builder.Append(' ').Append(file.Quoted());
110107

111108
Args = builder.ToString();
112109
return await ExecAsync().ConfigureAwait(false);

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@
441441
<x:String x:Key="Text.GitLFS.Locks.Empty" xml:space="preserve">No Locked Files</x:String>
442442
<x:String x:Key="Text.GitLFS.Locks.Lock" xml:space="preserve">Lock</x:String>
443443
<x:String x:Key="Text.GitLFS.Locks.OnlyMine" xml:space="preserve">Show only my locks</x:String>
444-
<x:String x:Key="Text.GitLFS.Locks.UnlockAll.Confirm" xml:space="preserve">Are you sure you want to unlock all your locked files?</x:String>
445-
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks" xml:space="preserve">Unlock all of my locks</x:String>
446444
<x:String x:Key="Text.GitLFS.Locks.Title" xml:space="preserve">LFS Locks</x:String>
447445
<x:String x:Key="Text.GitLFS.Locks.Unlock" xml:space="preserve">Unlock</x:String>
446+
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks" xml:space="preserve">Unlock all of my locks</x:String>
447+
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks.Confirm" xml:space="preserve">Are you sure you want to unlock all your locked files?</x:String>
448448
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">Force Unlock</x:String>
449449
<x:String x:Key="Text.GitLFS.Prune" xml:space="preserve">Prune</x:String>
450450
<x:String x:Key="Text.GitLFS.Prune.Tips" xml:space="preserve">Run `git lfs prune` to delete old LFS files from local storage</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@
447447
<x:String x:Key="Text.GitLFS.Locks.OnlyMine" xml:space="preserve">仅显示被我锁定的文件</x:String>
448448
<x:String x:Key="Text.GitLFS.Locks.Title" xml:space="preserve">LFS对象锁状态</x:String>
449449
<x:String x:Key="Text.GitLFS.Locks.Unlock" xml:space="preserve">解锁</x:String>
450+
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks" xml:space="preserve">解锁所有被我锁定的文件</x:String>
451+
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks.Confirm" xml:space="preserve">确定要解锁所有被您锁定的文件吗?</x:String>
450452
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">强制解锁</x:String>
451453
<x:String x:Key="Text.GitLFS.Prune" xml:space="preserve">精简本地LFS对象存储</x:String>
452454
<x:String x:Key="Text.GitLFS.Prune.Tips" xml:space="preserve">运行`git lfs prune`命令,从本地存储中精简当前版本不需要的LFS对象</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@
447447
<x:String x:Key="Text.GitLFS.Locks.OnlyMine" xml:space="preserve">僅顯示被我鎖定的檔案</x:String>
448448
<x:String x:Key="Text.GitLFS.Locks.Title" xml:space="preserve">LFS 物件鎖</x:String>
449449
<x:String x:Key="Text.GitLFS.Locks.Unlock" xml:space="preserve">解鎖</x:String>
450+
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks" xml:space="preserve">解鎖所有由我鎖定的檔案</x:String>
451+
<x:String x:Key="Text.GitLFS.Locks.UnlockAllMyLocks.Confirm" xml:space="preserve">您確定要解鎖所有由您自己鎖定的檔案嗎?</x:String>
450452
<x:String x:Key="Text.GitLFS.Locks.UnlockForce" xml:space="preserve">強制解鎖</x:String>
451453
<x:String x:Key="Text.GitLFS.Prune" xml:space="preserve">清理 (prune)</x:String>
452454
<x:String x:Key="Text.GitLFS.Prune.Tips" xml:space="preserve">執行 `git lfs prune` 以從本機中清理目前版本不需要的 LFS 物件</x:String>

src/ViewModels/LFSLocks.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Threading.Tasks;
44
using Avalonia.Threading;
55
using CommunityToolkit.Mvvm.ComponentModel;
6-
using SourceGit.Models;
76

87
namespace SourceGit.ViewModels
98
{
@@ -73,29 +72,29 @@ public async Task UnlockAsync(Models.LFSLock lfsLock, bool force)
7372
IsLoading = false;
7473
}
7574

76-
public async Task UnlockAllMyLocksAsync(bool force = false)
75+
public async Task UnlockAllMyLocksAsync()
7776
{
78-
if (_isLoading)
77+
if (_isLoading || string.IsNullOrEmpty(_userName))
7978
return;
8079

8180
IsLoading = true;
8281

83-
List<string> myLocks = [];
84-
foreach (LFSLock lfsLock in _cachedLocks)
82+
var locks = new List<string>();
83+
foreach (var lfsLock in _cachedLocks)
8584
{
8685
if (lfsLock.Owner.Name.Equals(_userName, StringComparison.Ordinal))
87-
{
88-
myLocks.Add(lfsLock.Path);
89-
}
86+
locks.Add(lfsLock.Path);
9087
}
9188

92-
bool succ = await _repo.UnlockLFSFilesAsync(_remote, myLocks, force, false);
89+
var log = _repo.CreateLog("Unlock LFS Locks");
90+
var succ = await new Commands.LFS(_repo.FullPath).Use(log).UnlockMultipleAsync(_remote, locks, true);
9391
if (succ)
9492
{
9593
_cachedLocks.RemoveAll(lfsLock => lfsLock.Owner.Name.Equals(_userName, StringComparison.Ordinal));
9694
UpdateVisibleLocks();
9795
}
9896

97+
log.Complete();
9998
IsLoading = false;
10099
}
101100

src/ViewModels/Repository.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -738,20 +738,6 @@ public async Task<bool> UnlockLFSFileAsync(string remote, string path, bool forc
738738
return succ;
739739
}
740740

741-
public async Task<bool> UnlockLFSFilesAsync(string remote, List<string> paths, bool force, bool notify)
742-
{
743-
CommandLog log = CreateLog("Unlock LFS File");
744-
bool succ = await new Commands.LFS(FullPath)
745-
.Use(log)
746-
.UnlockAsync(remote, paths, force);
747-
748-
if (succ && notify)
749-
App.SendNotification(FullPath, $"Unlocked {paths.Count} files successfully!");
750-
751-
log.Complete();
752-
return succ;
753-
}
754-
755741
public CommandLog CreateLog(string name)
756742
{
757743
var log = new CommandLog(name);

src/Views/LFSLocks.axaml

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Title="{DynamicResource Text.GitLFS.Locks.Title}"
1515
Width="600" Height="400"
1616
WindowStartupLocation="CenterOwner">
17-
<Grid RowDefinitions="Auto,Auto,*">
17+
<Grid RowDefinitions="Auto,*,40">
1818
<!-- TitleBar -->
1919
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
2020
<Border Background="{DynamicResource Brush.TitleBar}"
@@ -37,39 +37,9 @@
3737
IsVisible="{OnPlatform True, macOS=False}"/>
3838
</Grid>
3939

40-
<!-- Filter and Unlock All -->
41-
<StackPanel Grid.Row="1"
42-
HorizontalAlignment="Left"
43-
Orientation="Horizontal">
44-
45-
<CheckBox Margin="8,0,4,0"
46-
Content="{DynamicResource Text.GitLFS.Locks.OnlyMine}"
47-
IsChecked="{Binding ShowOnlyMyLocks, Mode=TwoWay}"
48-
VerticalAlignment="Center">
49-
<CheckBox.IsEnabled>
50-
<MultiBinding Converter="{x:Static BoolConverters.And}">
51-
<Binding Path="HasValidUserName" />
52-
<Binding Path="!IsLoading" />
53-
</MultiBinding>
54-
</CheckBox.IsEnabled>
55-
</CheckBox>
56-
57-
<Button Margin="4,0,4,0"
58-
Content="{DynamicResource Text.GitLFS.Locks.UnlockAllMyLocks}"
59-
Click="OnUnlockAllMyLocksButtonClicked">
60-
<Button.IsEnabled>
61-
<MultiBinding Converter="{x:Static BoolConverters.And}">
62-
<Binding Path="HasValidUserName" />
63-
<Binding Path="!IsLoading" />
64-
</MultiBinding>
65-
</Button.IsEnabled>
66-
</Button>
67-
68-
</StackPanel>
69-
7040
<!-- Locked Files -->
71-
<Grid Grid.Row="2">
72-
<ListBox Margin="8,0,8,8"
41+
<Grid Grid.Row="1">
42+
<ListBox Margin="8,8,8,0"
7343
Background="{DynamicResource Brush.Contents}"
7444
ItemsSource="{Binding VisibleLocks}"
7545
SelectionMode="Single"
@@ -130,5 +100,32 @@
130100
HorizontalAlignment="Center" VerticalAlignment="Center"
131101
IsVisible="{Binding IsLoading}"/>
132102
</Grid>
103+
104+
<!-- Filter and Unlock All -->
105+
<Grid Grid.Row="2" ColumnDefinitions="*,Auto" Margin="8,6">
106+
<CheckBox Grid.Column="0"
107+
Content="{DynamicResource Text.GitLFS.Locks.OnlyMine}"
108+
IsChecked="{Binding ShowOnlyMyLocks, Mode=TwoWay}"
109+
VerticalAlignment="Center">
110+
<CheckBox.IsEnabled>
111+
<MultiBinding Converter="{x:Static BoolConverters.And}">
112+
<Binding Path="HasValidUserName" />
113+
<Binding Path="!IsLoading" />
114+
</MultiBinding>
115+
</CheckBox.IsEnabled>
116+
</CheckBox>
117+
118+
<Button Grid.Column="1"
119+
Classes="flat primary"
120+
Content="{DynamicResource Text.GitLFS.Locks.UnlockAllMyLocks}"
121+
Click="OnUnlockAllMyLocksButtonClicked">
122+
<Button.IsEnabled>
123+
<MultiBinding Converter="{x:Static BoolConverters.And}">
124+
<Binding Path="HasValidUserName" />
125+
<Binding Path="!IsLoading" />
126+
</MultiBinding>
127+
</Button.IsEnabled>
128+
</Button>
129+
</Grid>
133130
</Grid>
134131
</v:ChromelessWindow>

src/Views/LFSLocks.axaml.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,14 @@ private async void OnForceUnlockButtonClicked(object sender, RoutedEventArgs e)
2929

3030
private async void OnUnlockAllMyLocksButtonClicked(object sender, RoutedEventArgs e)
3131
{
32-
if (DataContext is ViewModels.LFSLocks vm)
33-
{
34-
Confirm dialog = new()
35-
{
36-
Message =
37-
{
38-
Text = App.Text("GitLFS.Locks.UnlockAll.Confirm")
39-
}
40-
};
41-
42-
bool result = await dialog.ShowDialog<bool>(this);
43-
if (result)
44-
{
45-
await vm.UnlockAllMyLocksAsync(true);
46-
}
47-
}
32+
if (DataContext is not ViewModels.LFSLocks vm)
33+
return;
4834

35+
var shouldContinue = await App.AskConfirmAsync(App.Text("GitLFS.Locks.UnlockAllMyLocks.Confirm"));
36+
if (!shouldContinue)
37+
return;
38+
39+
await vm.UnlockAllMyLocksAsync();
4940
e.Handled = true;
5041
}
5142
}

0 commit comments

Comments
 (0)