From dffd9d76760246e9eb162d9ad1fa938928f5988c Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 2 Sep 2024 17:05:43 +0800 Subject: [PATCH] feature: add context menu item to move repository node (#437) --- src/Resources/Locales/en_US.axaml | 3 + src/Resources/Locales/zh_CN.axaml | 3 + src/Resources/Locales/zh_TW.axaml | 3 + src/ViewModels/MoveRepositoryNode.cs | 72 ++++++++++++++++++++++ src/ViewModels/Welcome.cs | 12 ++++ src/Views/MoveRepositoryNode.axaml | 89 +++++++++++++++++++++++++++ src/Views/MoveRepositoryNode.axaml.cs | 14 +++++ 7 files changed, 196 insertions(+) create mode 100644 src/ViewModels/MoveRepositoryNode.cs create mode 100644 src/Views/MoveRepositoryNode.axaml create mode 100644 src/Views/MoveRepositoryNode.axaml.cs diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index ab29d6eb..a6938954 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -354,6 +354,8 @@ Into: Merge Option: Source Branch: + Move Repository Node + Select parent node for: Name: Git has NOT been configured. Please to go [Preference] and configure it first. NOTICE @@ -588,6 +590,7 @@ Delete DRAG & DROP FOLDER SUPPORTED. CUSTOM GROUPING SUPPORTED. Edit + Move to Another Group Open All Repositories Open Repository Open Terminal diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 3986e358..d25ef88e 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -357,6 +357,8 @@ 目标分支 : 合并方式 : 合并分支 : + 调整仓库分组 + 请选择目标分组: 名称 : GIT尚未配置。请打开【偏好设置】配置GIT路径。 系统提示 @@ -590,6 +592,7 @@ 删除 支持拖放目录添加。支持自定义分组。 编辑 + 调整分组 打开所有包含仓库 打开本地仓库 打开终端 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 8d7a4bf1..b63b2365 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -357,6 +357,8 @@ 目標分支: 合併方式: 合併分支: + 調整存放庫分組 + 請選擇目標分組: 名稱: 尚未設定 Git。請開啟 [偏好設定] 以設定 Git 路徑。 系統提示 @@ -591,6 +593,7 @@ 刪除 支援拖放以新增目錄與自訂群組。 編輯 + 調整存放庫分組 開啟所有包含存放庫 開啟本機存放庫 開啟終端機 diff --git a/src/ViewModels/MoveRepositoryNode.cs b/src/ViewModels/MoveRepositoryNode.cs new file mode 100644 index 00000000..e22de212 --- /dev/null +++ b/src/ViewModels/MoveRepositoryNode.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SourceGit.ViewModels +{ + public class MoveRepositoryNode : Popup + { + public RepositoryNode Target + { + get; + private set; + } = null; + + public List Rows + { + get; + private set; + } = []; + + public RepositoryNode Selected + { + get => _selected; + set => SetProperty(ref _selected, value); + } + + public MoveRepositoryNode(RepositoryNode target) + { + Target = target; + Rows.Add(new RepositoryNode() { + Name = "ROOT", + Depth = 0, + Id = Guid.NewGuid().ToString() + }); + MakeRows(Preference.Instance.RepositoryNodes, 1); + + View = new Views.MoveRepositoryNode() { DataContext = this }; + } + + public override Task Sure() + { + if (_selected != null) + { + var node = Preference.Instance.FindNode(_selected.Id); + Preference.Instance.MoveNode(Target, node, true); + Welcome.Instance.Refresh(); + } + + return null; + } + + private void MakeRows(List collection, int depth) + { + foreach (var node in collection) + { + if (node.IsRepository || node.Id == Target.Id) + continue; + + var dump = new RepositoryNode() + { + Name = node.Name, + Depth = depth, + Id = node.Id + }; + Rows.Add(dump); + MakeRows(node.SubNodes, depth + 1); + } + } + + private RepositoryNode _selected = null; + } +} diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index 420e9b03..a78faee3 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -172,6 +172,18 @@ namespace SourceGit.ViewModels }; menu.Items.Add(edit); + var move = new MenuItem(); + move.Header = App.Text("Welcome.Move"); + move.Icon = App.CreateMenuIcon("Icons.Move"); + move.Click += (_, e) => + { + if (PopupHost.CanCreatePopup()) + PopupHost.ShowPopup(new MoveRepositoryNode(node)); + + e.Handled = true; + }; + menu.Items.Add(move); + if (node.IsRepository) { var explore = new MenuItem(); diff --git a/src/Views/MoveRepositoryNode.axaml b/src/Views/MoveRepositoryNode.axaml new file mode 100644 index 00000000..7c408487 --- /dev/null +++ b/src/Views/MoveRepositoryNode.axaml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/MoveRepositoryNode.axaml.cs b/src/Views/MoveRepositoryNode.axaml.cs new file mode 100644 index 00000000..450c6924 --- /dev/null +++ b/src/Views/MoveRepositoryNode.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia.Controls; + +namespace SourceGit.Views +{ + public partial class MoveRepositoryNode : UserControl + { + public MoveRepositoryNode() + { + InitializeComponent(); + } + } +} + +