From 4600d463280f18eefcb4367bada1fbc3af9a5c8b Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 17 Dec 2020 21:28:09 +0800 Subject: [PATCH] fix: refresh home page when successfully clone/init a repository --- src/UI/Clone.xaml.cs | 9 +++++++-- src/UI/Init.xaml.cs | 14 ++++++++++---- src/UI/Manager.xaml.cs | 17 ++++++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/UI/Clone.xaml.cs b/src/UI/Clone.xaml.cs index 36b712aa..8293853b 100644 --- a/src/UI/Clone.xaml.cs +++ b/src/UI/Clone.xaml.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Threading.Tasks; using System.Windows; @@ -10,6 +11,7 @@ namespace SourceGit.UI { /// public partial class Clone : UserControl { private PopupManager popup = null; + private Action cb = null; /// /// Remote repository @@ -34,9 +36,10 @@ namespace SourceGit.UI { /// /// Constructor. /// - public Clone(PopupManager mgr) { + public Clone(PopupManager mgr, Action success) { ParentFolder = App.Setting.Tools.GitDefaultCloneDir; popup = mgr; + cb = success; InitializeComponent(); } @@ -90,7 +93,9 @@ namespace SourceGit.UI { if (succ) { var path = new DirectoryInfo(ParentFolder + "/" + repoName).FullName; var repo = App.Setting.AddRepository(path, ""); - repo.Open(); + App.Open(repo); + cb?.Invoke(); + popup.Close(true); } else { popup.Unlock(); } diff --git a/src/UI/Init.xaml.cs b/src/UI/Init.xaml.cs index f0acae3f..d6d534e2 100644 --- a/src/UI/Init.xaml.cs +++ b/src/UI/Init.xaml.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -10,15 +11,17 @@ namespace SourceGit.UI { public partial class Init : UserControl { private PopupManager popup = null; private string workingDir = null; + private Action onSuccess = null; /// /// Constructor. /// /// /// - public Init(PopupManager mgr, string path) { + public Init(PopupManager mgr, string path, Action success) { popup = mgr; workingDir = path; + onSuccess = success; InitializeComponent(); txtPath.Content = path; } @@ -40,10 +43,13 @@ namespace SourceGit.UI { } }); - popup.Close(true); - var repo = App.Setting.FindRepository(workingDir); - if (repo != null) repo.Open(); + if (repo != null) { + App.Open(repo); + onSuccess?.Invoke(); + } + + popup.Close(true); } /// diff --git a/src/UI/Manager.xaml.cs b/src/UI/Manager.xaml.cs index b9ce3513..225a93a3 100644 --- a/src/UI/Manager.xaml.cs +++ b/src/UI/Manager.xaml.cs @@ -57,7 +57,12 @@ namespace SourceGit.UI { /// /// private void CloneRepo(object sender, RoutedEventArgs e) { - if (MakeSureReady()) popupManager.Show(new Clone(popupManager)); + if (MakeSureReady()) { + popupManager.Show(new Clone(popupManager, () => { + UpdateRecentOpened(); + UpdateTree(); + })); + } } #endregion @@ -401,7 +406,10 @@ namespace SourceGit.UI { private void ShowBrief(Git.Repository repo) { if (repo == null || !Git.Repository.IsValid(repo.Path)) { if (Directory.Exists(repo.Path)) { - popupManager.Show(new Init(popupManager, repo.Path)); + popupManager.Show(new Init(popupManager, repo.Path, () => { + UpdateRecentOpened(); + UpdateTree(); + })); } else { App.RaiseError("Path is NOT valid git repository or has been removed."); App.Setting.RemoveRepository(repo.Path); @@ -477,7 +485,10 @@ namespace SourceGit.UI { if (!Git.Repository.IsValid(path)) { if (Directory.Exists(path)) { - popupManager.Show(new Init(popupManager, path)); + popupManager.Show(new Init(popupManager, path, () => { + UpdateRecentOpened(); + UpdateTree(); + })); return; }