From 10d8d3b2efedfcaf358aa9b29b444ae25d460024 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 13 Jan 2025 14:42:07 +0800 Subject: [PATCH] refactor: branch compare --- src/Resources/Locales/de_DE.axaml | 1 - src/Resources/Locales/en_US.axaml | 1 - src/Resources/Locales/es_ES.axaml | 1 - src/Resources/Locales/fr_FR.axaml | 1 - src/Resources/Locales/it_IT.axaml | 1 - src/Resources/Locales/pt_BR.axaml | 1 - src/Resources/Locales/ru_RU.axaml | 1 - src/Resources/Locales/zh_CN.axaml | 1 - src/Resources/Locales/zh_TW.axaml | 1 - src/ViewModels/Repository.cs | 89 ++++++++++--------------------- 10 files changed, 27 insertions(+), 71 deletions(-) diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 96dced8d..db4fee87 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -50,7 +50,6 @@ Blame BLAME WIRD BEI DIESER DATEI NICHT UNTERSTÜTZT!!! Auschecken von ${0}$... - Mit Branch vergleichen Mit HEAD vergleichen Mit Worktree vergleichen Branch-Namen kopieren diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 1b0059a5..d06f438d 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -47,7 +47,6 @@ Blame BLAME ON THIS FILE IS NOT SUPPORTED!!! Checkout ${0}$... - Compare with Branch Compare with HEAD Compare with Worktree Copy Branch Name diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml index 7f6bad97..74b2f224 100644 --- a/src/Resources/Locales/es_ES.axaml +++ b/src/Resources/Locales/es_ES.axaml @@ -50,7 +50,6 @@ Blame ¡BLAME EN ESTE ARCHIVO NO SOPORTADO! Checkout ${0}$... - Comparar con Rama Comparar con HEAD Comparar con Worktree Copiar Nombre de Rama diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 1bfd5284..e4bb9c26 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -50,7 +50,6 @@ Blâme LE BLÂME SUR CE FICHIER N'EST PAS SUPPORTÉ!!! Récupérer ${0}$... - Comparer avec la branche Comparer avec HEAD Comparer avec le worktree Copier le nom de la branche diff --git a/src/Resources/Locales/it_IT.axaml b/src/Resources/Locales/it_IT.axaml index e63a4737..72e2aa28 100644 --- a/src/Resources/Locales/it_IT.axaml +++ b/src/Resources/Locales/it_IT.axaml @@ -50,7 +50,6 @@ Attribuisci L'ATTRIBUZIONE SU QUESTO FILE NON È SUPPORTATA!!! Checkout ${0}$... - Confronta con Branch Confronta con HEAD Confronta con Worktree Copia Nome Branch diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 5d29caca..8b17bdaf 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -75,7 +75,6 @@ Blame BLAME NESTE ARQUIVO NÃO É SUPORTADO!!! Checkout ${0}$... - Comparar com Branch Comparar com HEAD Comparar com Worktree Copiar Nome do Branch diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index 725f378c..75650a28 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -50,7 +50,6 @@ Расследование РАССЛЕДОВАНИЕ В ЭТОМ ФАЙЛЕ НЕ ПОДДЕРЖИВАЕТСЯ!!! Проверить ${0}$... - Сравнить с веткой Сравнить с ГОЛОВОЙ (HEAD) Сравнить с рабочим каталогом Копировать имя ветки diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 81d0d80f..b5541376 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -50,7 +50,6 @@ 逐行追溯(blame) 选中文件不支持该操作!!! 检出(checkout) ${0}$... - 与其他分支对比 与当前HEAD比较 与本地工作树比较 复制分支名 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 4fb4f375..d2395e58 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -50,7 +50,6 @@ 逐行溯源 (blame) 所選擇的檔案不支援該操作! 簽出 (checkout) ${0}$... - 與其他分支比較 與目前 HEAD 比較 與本機工作區比較 複製分支名稱 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index c317c2b8..209c66e1 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.Intrinsics.Arm; using System.Text; using System.Text.Json; using System.Threading; @@ -1463,13 +1464,6 @@ namespace SourceGit.ViewModels } menu.Items.Add(push); - - var compareWithBranch = CreateMenuItemToCompareBranches(branch); - if (compareWithBranch != null) - { - menu.Items.Add(new MenuItem() { Header = "-" }); - menu.Items.Add(compareWithBranch); - } } else { @@ -1540,6 +1534,19 @@ namespace SourceGit.ViewModels menu.Items.Add(merge); menu.Items.Add(rebase); + var compareWithHead = new MenuItem(); + compareWithHead.Header = App.Text("BranchCM.CompareWithHead"); + compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare"); + compareWithHead.Click += (_, _) => + { + App.OpenDialog(new Views.BranchCompare() + { + DataContext = new BranchCompare(_fullpath, branch, _currentBranch) + }); + }; + menu.Items.Add(new MenuItem() { Header = "-" }); + menu.Items.Add(compareWithHead); + if (_localChangesCount > 0) { var compareWithWorktree = new MenuItem(); @@ -1556,18 +1563,8 @@ namespace SourceGit.ViewModels _histories.DetailContext = new RevisionCompare(_fullpath, target, null); } }; - menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(compareWithWorktree); } - - var compareWithBranch = CreateMenuItemToCompareBranches(branch); - if (compareWithBranch != null) - { - if (_localChangesCount == 0) - menu.Items.Add(new MenuItem() { Header = "-" }); - - menu.Items.Add(compareWithBranch); - } } var detect = Commands.GitFlow.DetectType(_fullpath, _branches, branch.Name); @@ -1813,7 +1810,19 @@ namespace SourceGit.ViewModels menu.Items.Add(new MenuItem() { Header = "-" }); } - var hasCompare = false; + var compareWithHead = new MenuItem(); + compareWithHead.Header = App.Text("BranchCM.CompareWithHead"); + compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare"); + compareWithHead.Click += (_, _) => + { + App.OpenDialog(new Views.BranchCompare() + { + DataContext = new BranchCompare(_fullpath, branch, _currentBranch) + }); + }; + menu.Items.Add(new MenuItem() { Header = "-" }); + menu.Items.Add(compareWithHead); + if (_localChangesCount > 0) { var compareWithWorktree = new MenuItem(); @@ -1831,19 +1840,8 @@ namespace SourceGit.ViewModels } }; menu.Items.Add(compareWithWorktree); - hasCompare = true; } - var compareWithBranch = CreateMenuItemToCompareBranches(branch); - if (compareWithBranch != null) - { - menu.Items.Add(compareWithBranch); - hasCompare = true; - } - - if (hasCompare) - menu.Items.Add(new MenuItem() { Header = "-" }); - var delete = new MenuItem(); delete.Header = new Views.NameHighlightedTextBlock("BranchCM.Delete", name); delete.Icon = App.CreateMenuIcon("Icons.Clear"); @@ -2078,39 +2076,6 @@ namespace SourceGit.ViewModels return menu; } - private MenuItem CreateMenuItemToCompareBranches(Models.Branch branch) - { - if (_branches.Count == 1) - return null; - - var compare = new MenuItem(); - compare.Header = App.Text("BranchCM.CompareWithBranch"); - compare.Icon = App.CreateMenuIcon("Icons.Compare"); - - foreach (var b in _branches) - { - if (b.FullName != branch.FullName) - { - var dup = b; - var target = new MenuItem(); - target.Header = b.FriendlyName; - target.Icon = App.CreateMenuIcon(b.IsCurrent ? "Icons.Check" : "Icons.Branch"); - target.Click += (_, e) => - { - App.OpenDialog(new Views.BranchCompare() - { - DataContext = new BranchCompare(_fullpath, branch, dup) - }); - e.Handled = true; - }; - - compare.Items.Add(target); - } - } - - return compare; - } - private LauncherPage GetOwnerPage() { var launcher = App.GetLauncer();