From 0f56df35bca795871668ed933f3f3f63f69ce62d Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 3 Nov 2025 10:57:25 +0800 Subject: [PATCH] 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 --- src/Commands/LFS.cs | 9 ++--- src/Resources/Locales/en_US.axaml | 4 +- src/Resources/Locales/zh_CN.axaml | 2 + src/Resources/Locales/zh_TW.axaml | 2 + src/ViewModels/LFSLocks.cs | 17 ++++----- src/ViewModels/Repository.cs | 14 ------- src/Views/LFSLocks.axaml | 63 +++++++++++++++---------------- src/Views/LFSLocks.axaml.cs | 21 +++-------- 8 files changed, 53 insertions(+), 79 deletions(-) diff --git a/src/Commands/LFS.cs b/src/Commands/LFS.cs index f88fd51e..6e428335 100644 --- a/src/Commands/LFS.cs +++ b/src/Commands/LFS.cs @@ -94,19 +94,16 @@ namespace SourceGit.Commands return await ExecAsync().ConfigureAwait(false); } - public async Task UnlockAsync(string remote, List files, bool force) + public async Task UnlockMultipleAsync(string remote, List files, bool force) { var builder = new StringBuilder(); builder .Append("lfs unlock --remote=") .Append(remote) - .Append(force ? " -f " : " "); + .Append(force ? " -f" : " "); foreach (string file in files) - { - builder.Append(file.Quoted()); - builder.Append(" "); - } + builder.Append(' ').Append(file.Quoted()); Args = builder.ToString(); return await ExecAsync().ConfigureAwait(false); diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 2a7ae2c0..35475ca5 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -441,10 +441,10 @@ No Locked Files Lock Show only my locks - Are you sure you want to unlock all your locked files? - Unlock all of my locks LFS Locks Unlock + Unlock all of my locks + Are you sure you want to unlock all your locked files? Force Unlock Prune Run `git lfs prune` to delete old LFS files from local storage diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index c4dbdc05..8056fa60 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -447,6 +447,8 @@ 仅显示被我锁定的文件 LFS对象锁状态 解锁 + 解锁所有被我锁定的文件 + 确定要解锁所有被您锁定的文件吗? 强制解锁 精简本地LFS对象存储 运行`git lfs prune`命令,从本地存储中精简当前版本不需要的LFS对象 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index c46bb316..319a5454 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -447,6 +447,8 @@ 僅顯示被我鎖定的檔案 LFS 物件鎖 解鎖 + 解鎖所有由我鎖定的檔案 + 您確定要解鎖所有由您自己鎖定的檔案嗎? 強制解鎖 清理 (prune) 執行 `git lfs prune` 以從本機中清理目前版本不需要的 LFS 物件 diff --git a/src/ViewModels/LFSLocks.cs b/src/ViewModels/LFSLocks.cs index b2a41518..ee82ebd6 100644 --- a/src/ViewModels/LFSLocks.cs +++ b/src/ViewModels/LFSLocks.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; -using SourceGit.Models; namespace SourceGit.ViewModels { @@ -73,29 +72,29 @@ namespace SourceGit.ViewModels IsLoading = false; } - public async Task UnlockAllMyLocksAsync(bool force = false) + public async Task UnlockAllMyLocksAsync() { - if (_isLoading) + if (_isLoading || string.IsNullOrEmpty(_userName)) return; IsLoading = true; - List myLocks = []; - foreach (LFSLock lfsLock in _cachedLocks) + var locks = new List(); + foreach (var lfsLock in _cachedLocks) { if (lfsLock.Owner.Name.Equals(_userName, StringComparison.Ordinal)) - { - myLocks.Add(lfsLock.Path); - } + locks.Add(lfsLock.Path); } - bool succ = await _repo.UnlockLFSFilesAsync(_remote, myLocks, force, false); + var log = _repo.CreateLog("Unlock LFS Locks"); + var succ = await new Commands.LFS(_repo.FullPath).Use(log).UnlockMultipleAsync(_remote, locks, true); if (succ) { _cachedLocks.RemoveAll(lfsLock => lfsLock.Owner.Name.Equals(_userName, StringComparison.Ordinal)); UpdateVisibleLocks(); } + log.Complete(); IsLoading = false; } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 1bc369df..5ca5ca82 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -738,20 +738,6 @@ namespace SourceGit.ViewModels return succ; } - public async Task UnlockLFSFilesAsync(string remote, List paths, bool force, bool notify) - { - CommandLog log = CreateLog("Unlock LFS File"); - bool succ = await new Commands.LFS(FullPath) - .Use(log) - .UnlockAsync(remote, paths, force); - - if (succ && notify) - App.SendNotification(FullPath, $"Unlocked {paths.Count} files successfully!"); - - log.Complete(); - return succ; - } - public CommandLog CreateLog(string name) { var log = new CommandLog(name); diff --git a/src/Views/LFSLocks.axaml b/src/Views/LFSLocks.axaml index c41f9845..2d4f6ba6 100644 --- a/src/Views/LFSLocks.axaml +++ b/src/Views/LFSLocks.axaml @@ -14,7 +14,7 @@ Title="{DynamicResource Text.GitLFS.Locks.Title}" Width="600" Height="400" WindowStartupLocation="CenterOwner"> - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/Views/LFSLocks.axaml.cs b/src/Views/LFSLocks.axaml.cs index 522dcc8d..11ad3e86 100644 --- a/src/Views/LFSLocks.axaml.cs +++ b/src/Views/LFSLocks.axaml.cs @@ -29,23 +29,14 @@ namespace SourceGit.Views private async void OnUnlockAllMyLocksButtonClicked(object sender, RoutedEventArgs e) { - if (DataContext is ViewModels.LFSLocks vm) - { - Confirm dialog = new() - { - Message = - { - Text = App.Text("GitLFS.Locks.UnlockAll.Confirm") - } - }; + if (DataContext is not ViewModels.LFSLocks vm) + return; - bool result = await dialog.ShowDialog(this); - if (result) - { - await vm.UnlockAllMyLocksAsync(true); - } - } + var shouldContinue = await App.AskConfirmAsync(App.Text("GitLFS.Locks.UnlockAllMyLocks.Confirm")); + if (!shouldContinue) + return; + await vm.UnlockAllMyLocksAsync(); e.Handled = true; } }