From 130b5a66ab89e8dae8d66d8f7a0b2179db5aad29 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 7 Jun 2021 11:47:16 +0800 Subject: [PATCH] feature: supports `git subtree` feature --- src/Commands/SubTree.cs | 39 +++++++++ src/Models/Repository.cs | 1 + src/Models/SubTree.cs | 10 +++ src/Models/Watcher.cs | 12 +++ src/Resources/Icons.xaml | 4 +- src/Resources/Locales/en_US.xaml | 33 ++++++- src/Resources/Locales/zh_CN.xaml | 31 ++++++- src/Views/Popups/AddSubTree.xaml | 86 +++++++++++++++++++ src/Views/Popups/AddSubTree.xaml.cs | 57 ++++++++++++ src/Views/Popups/AddSubmodule.xaml | 2 +- src/Views/Popups/EditSubTree.xaml | 54 ++++++++++++ src/Views/Popups/EditSubTree.xaml.cs | 34 ++++++++ src/Views/Popups/SubTreePull.xaml | 76 ++++++++++++++++ src/Views/Popups/SubTreePull.xaml.cs | 43 ++++++++++ src/Views/Popups/SubTreePush.xaml | 68 +++++++++++++++ src/Views/Popups/SubTreePush.xaml.cs | 41 +++++++++ src/Views/Popups/UnlinkSubTree.xaml | 40 +++++++++ src/Views/Popups/UnlinkSubTree.xaml.cs | 34 ++++++++ .../{SubmodulePath.cs => RelativePath.cs} | 5 +- src/Views/Validations/Required.cs | 13 +++ src/Views/Widgets/Dashboard.xaml | 52 ++++++++++- src/Views/Widgets/Dashboard.xaml.cs | 59 +++++++++++++ 22 files changed, 784 insertions(+), 10 deletions(-) create mode 100644 src/Commands/SubTree.cs create mode 100644 src/Models/SubTree.cs create mode 100644 src/Views/Popups/AddSubTree.xaml create mode 100644 src/Views/Popups/AddSubTree.xaml.cs create mode 100644 src/Views/Popups/EditSubTree.xaml create mode 100644 src/Views/Popups/EditSubTree.xaml.cs create mode 100644 src/Views/Popups/SubTreePull.xaml create mode 100644 src/Views/Popups/SubTreePull.xaml.cs create mode 100644 src/Views/Popups/SubTreePush.xaml create mode 100644 src/Views/Popups/SubTreePush.xaml.cs create mode 100644 src/Views/Popups/UnlinkSubTree.xaml create mode 100644 src/Views/Popups/UnlinkSubTree.xaml.cs rename src/Views/Validations/{SubmodulePath.cs => RelativePath.cs} (81%) create mode 100644 src/Views/Validations/Required.cs diff --git a/src/Commands/SubTree.cs b/src/Commands/SubTree.cs new file mode 100644 index 00000000..6c963d09 --- /dev/null +++ b/src/Commands/SubTree.cs @@ -0,0 +1,39 @@ +using System; + +namespace SourceGit.Commands { + /// + /// 子树相关操作 + /// + public class SubTree : Command { + private Action handler = null; + + public SubTree(string repo) { + Cwd = repo; + TraitErrorAsOutput = true; + } + + public override void OnReadline(string line) { + handler?.Invoke(line); + } + + public bool Add(string prefix, string source, string revision, bool squash, Action onProgress) { + handler = onProgress; + Args = $"subtree add --prefix=\"{prefix}\" {source} {revision}"; + if (squash) Args += " --squash"; + return Exec(); + } + + public void Pull(string prefix, string source, string branch, bool squash, Action onProgress) { + handler = onProgress; + Args = $"subtree pull --prefix=\"{prefix}\" {source} {branch}"; + if (squash) Args += " --squash"; + Exec(); + } + + public void Push(string prefix, string source, string branch, Action onProgress) { + handler = onProgress; + Args = $"subtree push --prefix=\"{prefix}\" {source} {branch}"; + Exec(); + } + } +} diff --git a/src/Models/Repository.cs b/src/Models/Repository.cs index d900f12e..36df309b 100644 --- a/src/Models/Repository.cs +++ b/src/Models/Repository.cs @@ -19,6 +19,7 @@ namespace SourceGit.Models { public string GitDir { get; set; } = ""; public string GroupId { get; set; } = ""; public int Bookmark { get; set; } = 0; + public List SubTrees { get; set; } = new List(); public List Filters { get; set; } = new List(); public List CommitMessages { get; set; } = new List(); #endregion diff --git a/src/Models/SubTree.cs b/src/Models/SubTree.cs new file mode 100644 index 00000000..fdbad2fe --- /dev/null +++ b/src/Models/SubTree.cs @@ -0,0 +1,10 @@ +namespace SourceGit.Models { + /// + /// 子树 + /// + public class SubTree { + public string Prefix { get; set; } + public string Remote { get; set; } + public string Branch { get; set; } = "master"; + } +} diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index d1c16927..784faa6a 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -38,6 +38,10 @@ namespace SourceGit.Models { /// 子模块变更 /// public event Action SubmoduleChanged; + /// + /// 树更新 + /// + public event Action SubTreeChanged; /// /// 打开仓库事件 @@ -119,6 +123,13 @@ namespace SourceGit.Models { WorkingCopyChanged?.Invoke(); } + /// + /// 通知更新子树列表 + /// + public void RefreshSubTrees() { + SubTreeChanged?.Invoke(); + } + private void Start(string repo, string gitDir) { wcWatcher = new FileSystemWatcher(); wcWatcher.Path = repo; @@ -163,6 +174,7 @@ namespace SourceGit.Models { TagChanged = null; StashChanged = null; SubmoduleChanged = null; + SubTreeChanged = null; } private void OnRepositoryChanged(object o, FileSystemEventArgs e) { diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index 1149947b..b23ea37e 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -2,13 +2,15 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> M1004.8 466.4 557.7 19.3c-25.7-25.8-67.5-25.8-93.3 0L360.6 123.2l78.2 78.2c12.5-6 26.6-9.4 41.4-9.4c53 0 96 43 96 96c0 14.8-3.4 28.9-9.4 41.4l128 128c12.5-6 26.6-9.4 41.4-9.4c53 0 96 43 96 96s-43 96-96 96s-96-43-96-96c0-14.8 3.4-28.9 9.4-41.4L521.5 374.6a88.8 88.8 0 01-9.4 3.9v267c37.3 13.2 64 48.7 64 90.5c0 53-43 96-96 96s-96-43-96-96c0-41.8 26.7-77.3 64-90.5V378.5c-37.3-13.2-64-48.7-64-90.5c0-14.8 3.4-28.9 9.4-41.4l-78.2-78.2L19.4 464.3c-25.8 25.8-25.8 67.5 0 93.3l447.1 447.1c25.7 25.8 67.5 25.8 93.3 0l445-445c25.8-25.8 25.8-67.6 0-93.3z M557.7 545.3 789.9 402.7c24-15 31.3-46.5 16.4-70.5c-14.8-23.8-46-31.2-70-16.7L506.5 456.6 277.1 315.4c-24.1-14.8-55.6-7.3-70.5 16.8c-14.8 24.1-7.3 55.6 16.8 70.5l231.8 142.6V819.1c0 28.3 22.9 51.2 51.2 51.2c28.3 0 51.2-22.9 51.2-51.2V545.3h.1zM506.5 0l443.4 256v511.9L506.5 1023.9 63.1 767.9v-511.9L506.5 0z + M491 256h469c13 0 21-9 21-21v-171c0-13-9-21-21-21h-469c-13 0-21 9-21 21V128H256V64c0-13-9-21-21-21h-171c-13 0-21 9-21 21v171c0 13 9 21 21 21H128v597h341v64c0 13 9 21 21 21h469c13 0 21-9 21-21v-171c0-13-9-21-21-21h-469c-13 0-21 9-21 21V811H171v-299h299v64c0 13 9 21 21 21h469c13 0 21-9 21-21v-171c0-13-9-21-21-21h-469c-13 0-21 9-21 21V469H171V256h64c13 0 21-9 21-21V171h213v64c0 13 9 21 21 21z M170 470l0 84 86 0 0-84-86 0zM86 598l0-172 852 0 0 172-852 0zM256 298l0-84-86 0 0 84 86 0zM86 170l852 0 0 172-852 0 0-172zM170 726l0 84 86 0 0-84-86 0zM86 854l0-172 852 0 0 172-852 0z M853.3 960H170.7V64h469.3l213.3 213.3zM821.3 298.7H618.7V96z M192 0l0 1024 320-320 320 320 0-1024z M888.8 0H135.2c-32.3 0-58.9 26.1-58.9 58.9v906.2c0 32.3 26.1 58.9 58.9 58.9h753.2c32.3 0 58.9-26.1 58.9-58.9v-906.2c.5-32.8-26.1-58.9-58.4-58.9zm-164.9 176.6c30.7 0 55.8 25.1 55.8 55.8s-25.1 55.8-55.8 55.8s-55.8-25.1-55.8-55.8s24.6-55.8 55.8-55.8zm-212 0c30.7 0 55.8 25.1 55.8 55.8S542.7 288.3 512 288.3s-55.8-25.1-55.8-55.8S481.3 176.6 512 176.6zm-212 0c30.7 0 55.8 25.1 55.8 55.8s-25.1 55.8-55.8 55.8s-55.8-25.1-55.8-55.8s25.1-55.8 55.8-55.8zm208.9 606.2H285.2c-24.6 0-44-20-44-44c0-24.6 20-44 44-44h223.7c24.6 0 44 20 44 44c0 24.1-19.5 44-44 44zm229.9-212H285.2c-24.6 0-44-20-44-44c0-24.6 20-44 44-44h453.1c24.6 0 44 20 44 44c.5 24.1-19.5 44-43.5 44z M490.7 85.3l42.7 0 0 853.3-42.7 0 0-853.3zM85.3 490.7l853.3 0 0 42.7-853.3 0 0-42.7z M682.7 42.7H85.3v682.7h85.3V128h512V42.7zM256 213.3l4.5 768H896V213.3H256zm554.7 682.7H341.3V298.7h469.3v597.3z - + M204 291c45-11 77-49 77-96c0-53-43-98-98-98c-53 0-98 45-98 98c0 47 34 87 77 96v91c0 13 9 21 21 21h236c2 38 32 68 70 68h372c41 0 73-32 73-73v-38c0-41-32-73-73-73h-370c-38 0-70 30-70 68H204V291zm258 74h2c0-15 13-30 30-30h372c15 0 30 13 30 30v38c0 15-13 30-30 30h-375c-15 0-30-13-30-30v-38zM183 250c-30 0-55-26-55-55s26-55 55-55s55 26 55 55s-26 55-55 55zM679 495c-134 0-244 109-244 244s109 244 244 244c134 0 244-109 244-244s-109-244-244-244zm159 268h-134v134h-50V764H521v-50h134v-134h50v134h134V764zM244 766H185c-13 0-23-11-23-23s11-23 23-23h59c13 0 23 11 23 23s-11 23-23 23zM368 766h-42c-9 0-17-8-17-17v-13c0-9 8-17 17-17h42c9 0 17 8 17 17v13c0 9-8 17-17 17zM183 766c-12 0-21-9-21-21V320c0-12 9-21 21-21c12 0 21 9 21 21v425c0 12-10 21-21 21z + M256 811h512v85H256z M922 205v614H154V205h768zm-51 51H205v512h666V256z M899 203 821 125 512 434 203 125 125 203 434 512 125 821 203 899 512 590 821 899 899 821 590 512z diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index d1365c13..977b632f 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -128,6 +128,8 @@ SUBMODULES ADD SUBMODULE UPDATE SUBMODULE + SUBTREES + ADD/LINK SUBTREE RESOLVE CONTINUE ABORT @@ -425,7 +427,33 @@ NOTICE Restart required to apply changes in preference. Restart now? - + + Add/Link SubTree + Source URL : + Branch/Commit : + Local Relative Path : + Squash commits? + + Edit SubTree + Source URL : + Local Relative Path : + + Unlink SubTree + Local Relative Path : + This will only remove links. + + Pull Changes Of SubTree + Push Changes Of SubTree + Local Relative Path : + Remote : + Branch : + Squash commits? + + Edit ... + Unlink ... + Pull ... + Push ... + Git has NOT been configured.\nPlease to go [Preference] and configure it first. Path[{0}] not exists! Can NOT locate bash.exe. Make sure bash.exe exists under the same folder with git.exe @@ -448,6 +476,7 @@ Duplicated tag name! Commit subject can NOT be empty Invalid path for patch file - Invalid path for submodules + Invalid relative path Invalid path for archive file + This field is required \ No newline at end of file diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index 5f08e071..7218c9e4 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -128,6 +128,8 @@ 子模块列表 添加子模块 更新子模块 + 子树列表 + 添加子树 解决冲突 下一步 终止冲突解决 @@ -426,6 +428,32 @@ 系统提示 本次配置变更需要在重启后生效,是否立即重启? + 添加子树 + 远程地址: + 分支或提交ID: + 本地相对路径: + 合并提交为单一提交 + + 编辑子树信息 + 远程地址: + 本地相对路径: + + 删除子树 + 本地相对路径: + 本操作仅将子树信息删除,相关文件及提交不会更改 + + 拉取子树更新 + 推送子树更新到远程 + 本地相对路径: + 远程地址: + 远程分支: + 合并提交为单一提交 + + 编辑子树 ... + 删除子树 ... + 拉取子树更新 + 推送子树变更 + GIT尚未配置。请打开【偏好设置】配置GIT路径。 路径({0})不存在或不可读取! 无法找到bash.exe,请确保其在git.exe同目录中! @@ -448,6 +476,7 @@ 标签名已存在! 提交信息未填写! 补丁文件不存在或不可访问! - 非法的子模块路径! + 非法的子路径! 非法的存档文件路径! + 内容未填写! \ No newline at end of file diff --git a/src/Views/Popups/AddSubTree.xaml b/src/Views/Popups/AddSubTree.xaml new file mode 100644 index 00000000..e416860d --- /dev/null +++ b/src/Views/Popups/AddSubTree.xaml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Popups/AddSubTree.xaml.cs b/src/Views/Popups/AddSubTree.xaml.cs new file mode 100644 index 00000000..0086a0a2 --- /dev/null +++ b/src/Views/Popups/AddSubTree.xaml.cs @@ -0,0 +1,57 @@ +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace SourceGit.Views.Popups { + + /// + /// 添加子树面板 + /// + public partial class AddSubTree : Controls.PopupWidget { + private Models.Repository repo = null; + + public string Source { get; set; } + public string Ref { get; set; } + public string Prefix { get; set; } + + public AddSubTree(Models.Repository repo) { + this.repo = repo; + InitializeComponent(); + } + + public override string GetTitle() { + return App.Text("AddSubTree"); + } + + public override Task Start() { + txtSource.GetBindingExpression(TextBox.TextProperty).UpdateSource(); + if (Validation.GetHasError(txtSource)) return null; + + txtPrefix.GetBindingExpression(TextBox.TextProperty).UpdateSource(); + if (Validation.GetHasError(txtPrefix)) return null; + + txtRef.GetBindingExpression(TextBox.TextProperty).UpdateSource(); + if (Validation.GetHasError(txtRef)) return null; + + var squash = chkSquash.IsChecked == true; + if (repo.SubTrees.FindIndex(x => x.Prefix == Prefix) >= 0) { + Models.Exception.Raise($"Subtree add failed. Prefix({Prefix}) already exists!"); + return null; + } + + return Task.Run(() => { + Models.Watcher.SetEnabled(repo.Path, false); + var succ = new Commands.SubTree(repo.Path).Add(Prefix, Source, Ref, squash, UpdateProgress); + if (succ) { + repo.SubTrees.Add(new Models.SubTree() { + Prefix = Prefix, + Remote = Source, + }); + Models.Preference.Save(); + Models.Watcher.Get(repo.Path)?.RefreshSubTrees(); + } + Models.Watcher.SetEnabled(repo.Path, true); + return succ; + }); + } + } +} diff --git a/src/Views/Popups/AddSubmodule.xaml b/src/Views/Popups/AddSubmodule.xaml index 3b50799d..1b8233e7 100644 --- a/src/Views/Popups/AddSubmodule.xaml +++ b/src/Views/Popups/AddSubmodule.xaml @@ -53,7 +53,7 @@ - + diff --git a/src/Views/Popups/EditSubTree.xaml b/src/Views/Popups/EditSubTree.xaml new file mode 100644 index 00000000..5a5c034f --- /dev/null +++ b/src/Views/Popups/EditSubTree.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Popups/EditSubTree.xaml.cs b/src/Views/Popups/EditSubTree.xaml.cs new file mode 100644 index 00000000..32e2d538 --- /dev/null +++ b/src/Views/Popups/EditSubTree.xaml.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace SourceGit.Views.Popups { + /// + /// 编辑子树 + /// + public partial class EditSubTree : Controls.PopupWidget { + private Models.Repository repo; + private Models.SubTree subtree; + + public string Source { + get { return subtree.Remote; } + set { subtree.Remote = value; } + } + + public EditSubTree(Models.Repository repo, string prefix) { + this.repo = repo; + this.subtree = repo.SubTrees.Find(x => x.Prefix == prefix); + InitializeComponent(); + txtPrefix.Text = prefix; + } + + public override string GetTitle() { + return App.Text("EditSubTree"); + } + + public override Task Start() { + txtSource.GetBindingExpression(TextBox.TextProperty).UpdateSource(); + if (Validation.GetHasError(txtSource)) return null; + return Task.Run(() => true); + } + } +} diff --git a/src/Views/Popups/SubTreePull.xaml b/src/Views/Popups/SubTreePull.xaml new file mode 100644 index 00000000..18446afa --- /dev/null +++ b/src/Views/Popups/SubTreePull.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Popups/SubTreePull.xaml.cs b/src/Views/Popups/SubTreePull.xaml.cs new file mode 100644 index 00000000..52149368 --- /dev/null +++ b/src/Views/Popups/SubTreePull.xaml.cs @@ -0,0 +1,43 @@ +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace SourceGit.Views.Popups { + /// + /// 拉取 + /// + public partial class SubTreePull : Controls.PopupWidget { + private string repo; + private Models.SubTree subtree; + + public string Branch { + get { return subtree.Branch; } + set { subtree.Branch = value; } + } + + public SubTreePull(string repo, Models.SubTree subtree) { + this.repo = repo; + this.subtree = subtree; + InitializeComponent(); + txtPrefix.Text = subtree.Prefix; + txtSource.Text = subtree.Remote; + } + + public override string GetTitle() { + return App.Text("SubTreePullOrPush.Pull"); + } + + public override Task Start() { + txtBranch.GetBindingExpression(TextBox.TextProperty).UpdateSource(); + if (Validation.GetHasError(txtBranch)) return null; + + var squash = chkSquash.IsChecked == true; + + return Task.Run(() => { + Models.Watcher.SetEnabled(repo, false); + new Commands.SubTree(repo).Pull(subtree.Prefix, subtree.Remote, Branch, squash, UpdateProgress); + Models.Watcher.SetEnabled(repo, true); + return true; + }); + } + } +} diff --git a/src/Views/Popups/SubTreePush.xaml b/src/Views/Popups/SubTreePush.xaml new file mode 100644 index 00000000..f7036261 --- /dev/null +++ b/src/Views/Popups/SubTreePush.xaml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Popups/SubTreePush.xaml.cs b/src/Views/Popups/SubTreePush.xaml.cs new file mode 100644 index 00000000..7cef2871 --- /dev/null +++ b/src/Views/Popups/SubTreePush.xaml.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace SourceGit.Views.Popups { + /// + /// 推送 + /// + public partial class SubTreePush : Controls.PopupWidget { + private string repo; + private Models.SubTree subtree; + + public string Branch { + get { return subtree.Branch; } + set { subtree.Branch = value; } + } + + public SubTreePush(string repo, Models.SubTree subtree) { + this.repo = repo; + this.subtree = subtree; + InitializeComponent(); + txtPrefix.Text = subtree.Prefix; + txtSource.Text = subtree.Remote; + } + + public override string GetTitle() { + return App.Text("SubTreePullOrPush.Push"); + } + + public override Task Start() { + txtBranch.GetBindingExpression(TextBox.TextProperty).UpdateSource(); + if (Validation.GetHasError(txtBranch)) return null; + + return Task.Run(() => { + Models.Watcher.SetEnabled(repo, false); + new Commands.SubTree(repo).Push(subtree.Prefix, subtree.Remote, Branch, UpdateProgress); + Models.Watcher.SetEnabled(repo, true); + return true; + }); + } + } +} diff --git a/src/Views/Popups/UnlinkSubTree.xaml b/src/Views/Popups/UnlinkSubTree.xaml new file mode 100644 index 00000000..4468956f --- /dev/null +++ b/src/Views/Popups/UnlinkSubTree.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Popups/UnlinkSubTree.xaml.cs b/src/Views/Popups/UnlinkSubTree.xaml.cs new file mode 100644 index 00000000..372bf305 --- /dev/null +++ b/src/Views/Popups/UnlinkSubTree.xaml.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; + +namespace SourceGit.Views.Popups { + /// + /// 删除子树 + /// + public partial class UnlinkSubTree : Controls.PopupWidget { + private Models.Repository repo; + private string prefix; + + public UnlinkSubTree(Models.Repository repo, string prefix) { + this.repo = repo; + this.prefix = prefix; + InitializeComponent(); + txtPrefix.Text = prefix; + } + + public override string GetTitle() { + return App.Text("UnlinkSubTree"); + } + + public override Task Start() { + return Task.Run(() => { + var idx = repo.SubTrees.FindIndex(x => x.Prefix == prefix); + if (idx >= 0) { + repo.SubTrees.RemoveAt(idx); + Models.Preference.Save(); + Models.Watcher.Get(repo.Path)?.RefreshSubTrees(); + } + return true; + }); + } + } +} diff --git a/src/Views/Validations/SubmodulePath.cs b/src/Views/Validations/RelativePath.cs similarity index 81% rename from src/Views/Validations/SubmodulePath.cs rename to src/Views/Validations/RelativePath.cs index 880ae4ea..4f7496a2 100644 --- a/src/Views/Validations/SubmodulePath.cs +++ b/src/Views/Validations/RelativePath.cs @@ -1,17 +1,16 @@ using System.Globalization; -using System.IO; using System.Text.RegularExpressions; using System.Windows.Controls; namespace SourceGit.Views.Validations { - public class SubmodulePath : ValidationRule { + public class RelativePath : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var path = value as string; if (string.IsNullOrEmpty(path)) return ValidationResult.ValidResult; var regex = new Regex(@"^[\w\-\._/]+$"); var succ = regex.IsMatch(path.Trim()); - return !succ ? new ValidationResult(false, App.Text("BadSubmodulePath")) : ValidationResult.ValidResult; + return !succ ? new ValidationResult(false, App.Text("BadRelativePath")) : ValidationResult.ValidResult; } } } \ No newline at end of file diff --git a/src/Views/Validations/Required.cs b/src/Views/Validations/Required.cs new file mode 100644 index 00000000..a0cdc076 --- /dev/null +++ b/src/Views/Validations/Required.cs @@ -0,0 +1,13 @@ +using System.Globalization; +using System.Windows.Controls; + +namespace SourceGit.Views.Validations { + public class Required : ValidationRule { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) { + var path = value as string; + return string.IsNullOrEmpty(path) ? + new ValidationResult(false, App.Text("Required")) : + ValidationResult.ValidResult; + } + } +} diff --git a/src/Views/Widgets/Dashboard.xaml b/src/Views/Widgets/Dashboard.xaml index c5217d22..72d900ac 100644 --- a/src/Views/Widgets/Dashboard.xaml +++ b/src/Views/Widgets/Dashboard.xaml @@ -110,6 +110,8 @@ + + @@ -326,7 +328,7 @@ Grid.Row="7" x:Name="tagList" RowHeight="24" - Height="200" + MaxHeight="200" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Visibility="{Binding ElementName=tglTags, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}" @@ -386,7 +388,7 @@ Grid.Row="9" x:Name="submoduleList" RowHeight="24" - Height="100" + MaxHeight="100" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Visibility="{Binding ElementName=tglSubmodules, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}" @@ -411,6 +413,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 5a12e642..e2e20020 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -60,6 +60,7 @@ namespace SourceGit.Views.Widgets { UpdateStashes(); UpdateTags(); UpdateSubmodules(); + UpdateSubTrees(); var watcher = Models.Watcher.Get(repo.Path); watcher.Navigate += NavigateTo; @@ -68,6 +69,7 @@ namespace SourceGit.Views.Widgets { watcher.StashChanged += UpdateStashes; watcher.TagChanged += UpdateTags; watcher.SubmoduleChanged += UpdateSubmodules; + watcher.SubTreeChanged += UpdateSubTrees; Unloaded += (o, e) => { localBranches.Clear(); @@ -257,6 +259,14 @@ namespace SourceGit.Views.Widgets { }); }); } + + private void UpdateSubTrees() { + Dispatcher.Invoke(() => { + txtSubTreeCount.Text = $"({repo.SubTrees.Count})"; + subTreeList.ItemsSource = null; + subTreeList.ItemsSource = repo.SubTrees; + }); + } #endregion #region TOOLBAR_COMMANDS @@ -909,6 +919,55 @@ namespace SourceGit.Views.Widgets { } #endregion + #region SUBTREES + private void OpenAddSubTree(object sender, RoutedEventArgs e) { + new Popups.AddSubTree(repo).Show(); + e.Handled = true; + } + + private void OnSubTreeContextMenuOpening(object sender, ContextMenuEventArgs e) { + var subtree = subTreeList.SelectedItem as Models.SubTree; + if (subtree == null) return; + + var edit = new MenuItem(); + edit.Header = App.Text("SubTree.Edit"); + edit.Click += (o, ev) => { + new Popups.EditSubTree(repo, subtree.Prefix).Show(); + ev.Handled = true; + }; + + var unlink = new MenuItem(); + unlink.Header = App.Text("SubTree.Unlink"); + unlink.Click += (o, ev) => { + new Popups.UnlinkSubTree(repo, subtree.Prefix).Show(); + ev.Handled = true; + }; + + var pull = new MenuItem(); + pull.Header = App.Text("SubTree.Pull"); + pull.Click += (o, ev) => { + new Popups.SubTreePull(repo.Path, subtree).Show(); + ev.Handled = true; + }; + + var push = new MenuItem(); + push.Header = App.Text("SubTree.Push"); + push.Click += (o, ev) => { + new Popups.SubTreePush(repo.Path, subtree).Show(); + ev.Handled = true; + }; + + var menu = new ContextMenu(); + menu.Items.Add(edit); + menu.Items.Add(unlink); + menu.Items.Add(new Separator()); + menu.Items.Add(pull); + menu.Items.Add(push); + menu.IsOpen = true; + e.Handled = true; + } + #endregion + #region FILTERS private void OnFilterChanged(object sender, RoutedEventArgs e) { var toggle = sender as ToggleButton;