diff --git a/SourceGit/App.xaml.cs b/SourceGit/App.xaml.cs index 9f5e8de3..fed0ffda 100644 --- a/SourceGit/App.xaml.cs +++ b/SourceGit/App.xaml.cs @@ -36,14 +36,6 @@ namespace SourceGit { set; } - /// - /// Get main window. - /// - public static UI.Launcher Launcher { - get; - private set; - } - /// /// Raise error message. /// @@ -52,6 +44,26 @@ namespace SourceGit { OnError?.Invoke(message); } + /// + /// Get popup manager by repository + /// + /// + /// + public static UI.PopupManager GetPopupManager(Git.Repository repo) { + var main = Current.MainWindow as UI.Launcher; + if (main == null) return null; + if (repo == null) return (main.Tabs[0].Page as UI.Manager).popupManager; + + for (int i = 1; i < main.openedTabs.Items.Count; i++) { + var opened = main.openedTabs.Items[i] as UI.Launcher.Tab; + if (opened.Repo.Path == repo.Path) { + return (opened.Page as UI.Dashboard).popupManager; + } + } + + return null; + } + /// /// Startup event. /// @@ -100,8 +112,8 @@ namespace SourceGit { } // Show main window - Launcher = new UI.Launcher(); - Launcher.Show(); + Current.MainWindow = new UI.Launcher(); + Current.MainWindow.Show(); } /// diff --git a/SourceGit/UI/AddSubmodule.xaml.cs b/SourceGit/UI/AddSubmodule.xaml.cs index cbb210ab..ebc46cec 100644 --- a/SourceGit/UI/AddSubmodule.xaml.cs +++ b/SourceGit/UI/AddSubmodule.xaml.cs @@ -34,7 +34,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new AddSubmodule(repo)); } @@ -58,7 +58,7 @@ namespace SourceGit.UI { if (Validation.GetHasError(txtPath)) return; var recursive = chkRecursive.IsChecked == true; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.AddSubmodule(RepoURL, LocalPath, recursive, msg => { @@ -68,7 +68,7 @@ namespace SourceGit.UI { } private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } #endregion } diff --git a/SourceGit/UI/Apply.xaml.cs b/SourceGit/UI/Apply.xaml.cs index e180a07c..7d881a98 100644 --- a/SourceGit/UI/Apply.xaml.cs +++ b/SourceGit/UI/Apply.xaml.cs @@ -52,7 +52,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened) { - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(new Apply(opened)); } @@ -83,7 +83,7 @@ namespace SourceGit.UI { txtPatchFile.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtPatchFile)) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); var mode = combWhitespaceOptions.SelectedItem as WhitespaceOption; @@ -99,7 +99,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Blame.xaml.cs b/SourceGit/UI/Blame.xaml.cs index 3bf3fbeb..abf44055 100644 --- a/SourceGit/UI/Blame.xaml.cs +++ b/SourceGit/UI/Blame.xaml.cs @@ -36,7 +36,7 @@ namespace SourceGit.UI { double minWidth = content.ActualWidth; // Move to center. - var parent = App.Launcher; + var parent = App.Current.MainWindow; Left = parent.Left + (parent.Width - Width) * 0.5; Top = parent.Top + (parent.Height - Height) * 0.5; diff --git a/SourceGit/UI/CherryPick.xaml.cs b/SourceGit/UI/CherryPick.xaml.cs index f8665a1d..9491bdc2 100644 --- a/SourceGit/UI/CherryPick.xaml.cs +++ b/SourceGit/UI/CherryPick.xaml.cs @@ -29,7 +29,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Commit commit) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new CherryPick(repo, commit)); } @@ -41,7 +41,7 @@ namespace SourceGit.UI { private void Start(object sender, RoutedEventArgs e) { repo.CherryPick(commitSHA, chkCommitChanges.IsChecked != true); - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); } @@ -51,7 +51,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); } } diff --git a/SourceGit/UI/Clone.xaml.cs b/SourceGit/UI/Clone.xaml.cs index e05b1edf..fad40a03 100644 --- a/SourceGit/UI/Clone.xaml.cs +++ b/SourceGit/UI/Clone.xaml.cs @@ -42,7 +42,7 @@ namespace SourceGit.UI { /// Show clone dialog. /// public static void Show() { - var popup = App.Launcher.GetPopupManager(null); + var popup = App.GetPopupManager(null); popup?.Show(new Clone()); } @@ -92,7 +92,7 @@ namespace SourceGit.UI { rName = RemoteName; } - var popup = App.Launcher.GetPopupManager(null); + var popup = App.GetPopupManager(null); popup.Lock(); var repo = await Task.Run(() => { @@ -113,7 +113,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(null).Close(); + App.GetPopupManager(null).Close(); } } } diff --git a/SourceGit/UI/Configure.xaml.cs b/SourceGit/UI/Configure.xaml.cs index f416297d..b16c3157 100644 --- a/SourceGit/UI/Configure.xaml.cs +++ b/SourceGit/UI/Configure.xaml.cs @@ -43,7 +43,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new Configure(repo)); } @@ -64,7 +64,7 @@ namespace SourceGit.UI { } private void Close(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } #endregion } diff --git a/SourceGit/UI/CreateBranch.xaml.cs b/SourceGit/UI/CreateBranch.xaml.cs index 12fdc908..5efc18cf 100644 --- a/SourceGit/UI/CreateBranch.xaml.cs +++ b/SourceGit/UI/CreateBranch.xaml.cs @@ -59,7 +59,7 @@ namespace SourceGit.UI { if (!branch.IsLocal) dialog.txtName.Text = branch.Name.Substring(branch.Remote.Length + 1); - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(dialog); } @@ -74,7 +74,7 @@ namespace SourceGit.UI { dialog.basedOnType.Data = dialog.FindResource("Icon.Tag") as Geometry; dialog.basedOnDesc.Content = tag.Name; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(dialog); } @@ -89,7 +89,7 @@ namespace SourceGit.UI { dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry; dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}"; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(dialog); } @@ -102,7 +102,7 @@ namespace SourceGit.UI { txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtName)) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); bool checkout = chkCheckout.IsChecked == true; @@ -135,7 +135,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/CreateTag.xaml.cs b/SourceGit/UI/CreateTag.xaml.cs index 17e1d940..bf2ef238 100644 --- a/SourceGit/UI/CreateTag.xaml.cs +++ b/SourceGit/UI/CreateTag.xaml.cs @@ -52,7 +52,7 @@ namespace SourceGit.UI { dialog.basedOnType.Data = dialog.FindResource("Icon.Branch") as Geometry; dialog.basedOnDesc.Content = branch.Name; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(dialog); } @@ -67,7 +67,7 @@ namespace SourceGit.UI { dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry; dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}"; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(dialog); } @@ -82,7 +82,7 @@ namespace SourceGit.UI { Git.Tag.Add(repo, TagName, based, tagMessage.Text); - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); } @@ -92,7 +92,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Dashboard.xaml b/SourceGit/UI/Dashboard.xaml index 3763ac34..fb8446ee 100644 --- a/SourceGit/UI/Dashboard.xaml +++ b/SourceGit/UI/Dashboard.xaml @@ -7,7 +7,8 @@ xmlns:local="clr-namespace:SourceGit.UI" xmlns:converters="clr-namespace:SourceGit.Converters" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + d:DesignHeight="450" d:DesignWidth="800" + Unloaded="Cleanup"> diff --git a/SourceGit/UI/Dashboard.xaml.cs b/SourceGit/UI/Dashboard.xaml.cs index 88ebb355..8cc33b22 100644 --- a/SourceGit/UI/Dashboard.xaml.cs +++ b/SourceGit/UI/Dashboard.xaml.cs @@ -78,17 +78,6 @@ namespace SourceGit.UI { UpdateSubmodules(); } - /// - /// Cleanup all items - /// - public void Cleanup() { - localBranchTree.ItemsSource = null; - remoteBranchTree.ItemsSource = null; - tagList.ItemsSource = null; - cachedLocalBranches.Clear(); - cachedRemotes.Clear(); - } - #region DATA_UPDATE private void UpdateHistories() { Dispatcher.Invoke(() => { @@ -300,6 +289,14 @@ namespace SourceGit.UI { }); }); } + + private void Cleanup(object sender, RoutedEventArgs e) { + localBranchTree.ItemsSource = null; + remoteBranchTree.ItemsSource = null; + tagList.ItemsSource = null; + cachedLocalBranches.Clear(); + cachedRemotes.Clear(); + } #endregion #region TOOLBAR diff --git a/SourceGit/UI/DeleteBranch.xaml.cs b/SourceGit/UI/DeleteBranch.xaml.cs index 00d2fd31..d5f56321 100644 --- a/SourceGit/UI/DeleteBranch.xaml.cs +++ b/SourceGit/UI/DeleteBranch.xaml.cs @@ -28,7 +28,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened, Git.Branch branch) { - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(new DeleteBranch(opened, branch)); } @@ -38,7 +38,7 @@ namespace SourceGit.UI { /// /// private async void Sure(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => branch.Delete(repo)); popup?.Close(true); @@ -50,7 +50,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/DeleteRemote.xaml.cs b/SourceGit/UI/DeleteRemote.xaml.cs index b86bed8d..960c614c 100644 --- a/SourceGit/UI/DeleteRemote.xaml.cs +++ b/SourceGit/UI/DeleteRemote.xaml.cs @@ -29,7 +29,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened, string remote) { - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(new DeleteRemote(opened, remote)); } @@ -39,7 +39,7 @@ namespace SourceGit.UI { /// /// private async void Sure(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => Git.Remote.Delete(repo, remote)); popup?.Close(true); @@ -51,7 +51,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/DeleteTag.xaml.cs b/SourceGit/UI/DeleteTag.xaml.cs index c8b3c9dc..320c6167 100644 --- a/SourceGit/UI/DeleteTag.xaml.cs +++ b/SourceGit/UI/DeleteTag.xaml.cs @@ -30,7 +30,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Tag tag) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new DeleteTag(repo, tag)); } @@ -40,7 +40,7 @@ namespace SourceGit.UI { /// /// private async void Start(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); var push = chkWithRemote.IsChecked == true; @@ -55,7 +55,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Discard.xaml.cs b/SourceGit/UI/Discard.xaml.cs index 0f8b8ca5..794835d8 100644 --- a/SourceGit/UI/Discard.xaml.cs +++ b/SourceGit/UI/Discard.xaml.cs @@ -40,19 +40,19 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened, List targets) { - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(new Discard(opened, targets)); } private async void Sure(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.Discard(changes)); popup?.Close(true); } private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Fetch.xaml.cs b/SourceGit/UI/Fetch.xaml.cs index f5f05165..3efb3eb9 100644 --- a/SourceGit/UI/Fetch.xaml.cs +++ b/SourceGit/UI/Fetch.xaml.cs @@ -40,7 +40,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, string preferRemote = null) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new Fetch(repo, preferRemote)); } @@ -50,9 +50,9 @@ namespace SourceGit.UI { /// /// private async void Start(object sender, RoutedEventArgs e) { - bool prune = chkPrune.IsChecked == true; + bool prune = chkPrune.IsChecked == true; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); if (chkFetchAll.IsChecked == true) { @@ -71,7 +71,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/FileHistories.xaml.cs b/SourceGit/UI/FileHistories.xaml.cs index 91647601..5f72b4a2 100644 --- a/SourceGit/UI/FileHistories.xaml.cs +++ b/SourceGit/UI/FileHistories.xaml.cs @@ -29,7 +29,7 @@ namespace SourceGit.UI { InitializeComponent(); // Move to center - var parent = App.Launcher; + var parent = App.Current.MainWindow; Left = parent.Left + (parent.Width - Width) * 0.5; Top = parent.Top + (parent.Height - Height) * 0.5; diff --git a/SourceGit/UI/GitFlowFinishBranch.xaml.cs b/SourceGit/UI/GitFlowFinishBranch.xaml.cs index 973622ae..bcd48dad 100644 --- a/SourceGit/UI/GitFlowFinishBranch.xaml.cs +++ b/SourceGit/UI/GitFlowFinishBranch.xaml.cs @@ -36,7 +36,7 @@ namespace SourceGit.UI { txtBranchType.Content = "Hotfix :"; break; default: - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); return; } @@ -50,7 +50,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Branch branch) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new GitFlowFinishBranch(repo, branch)); } @@ -60,7 +60,7 @@ namespace SourceGit.UI { /// /// private async void Sure(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.FinishGitFlowBranch(branch)); popup?.Close(true); @@ -72,7 +72,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/GitFlowSetup.xaml.cs b/SourceGit/UI/GitFlowSetup.xaml.cs index 761ced41..75ac07bb 100644 --- a/SourceGit/UI/GitFlowSetup.xaml.cs +++ b/SourceGit/UI/GitFlowSetup.xaml.cs @@ -26,7 +26,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new GitFlowSetup(repo)); } @@ -36,7 +36,7 @@ namespace SourceGit.UI { /// /// private async void Sure(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); var master = txtMaster.Text; @@ -56,7 +56,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } /// diff --git a/SourceGit/UI/GitFlowStartBranch.xaml.cs b/SourceGit/UI/GitFlowStartBranch.xaml.cs index bedbe37b..5a0cc3e2 100644 --- a/SourceGit/UI/GitFlowStartBranch.xaml.cs +++ b/SourceGit/UI/GitFlowStartBranch.xaml.cs @@ -51,7 +51,7 @@ namespace SourceGit.UI { nameValidator.Prefix = hotfixPrefix; break; default: - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); return; } @@ -63,7 +63,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Branch.Type type) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new GitFlowStartBranch(repo, type)); } @@ -76,7 +76,7 @@ namespace SourceGit.UI { txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtName)) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.StartGitFlowBranch(type, SubName)); popup?.Close(true); @@ -88,7 +88,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Histories.xaml.cs b/SourceGit/UI/Histories.xaml.cs index b77ce542..b8936766 100644 --- a/SourceGit/UI/Histories.xaml.cs +++ b/SourceGit/UI/Histories.xaml.cs @@ -526,7 +526,7 @@ namespace SourceGit.UI { } var dialog = new InteractiveRebase(Repo, commit); - dialog.Owner = App.Launcher; + dialog.Owner = App.Current.MainWindow; dialog.ShowDialog(); } else { Rebase.Show(Repo, commit); diff --git a/SourceGit/UI/Init.xaml.cs b/SourceGit/UI/Init.xaml.cs index bc1964fb..d7bd449a 100644 --- a/SourceGit/UI/Init.xaml.cs +++ b/SourceGit/UI/Init.xaml.cs @@ -25,7 +25,7 @@ namespace SourceGit.UI { /// /// public static void Show(string path) { - var popup = App.Launcher.GetPopupManager(null); + var popup = App.GetPopupManager(null); popup.Show(new Init(path)); } @@ -35,7 +35,7 @@ namespace SourceGit.UI { /// /// private async void Sure(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(null); + var popup = App.GetPopupManager(null); popup.Lock(); await Task.Run(() => { @@ -59,7 +59,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(null).Close(); + App.GetPopupManager(null).Close(); } } } diff --git a/SourceGit/UI/Launcher.xaml.cs b/SourceGit/UI/Launcher.xaml.cs index c021870c..bd069bca 100644 --- a/SourceGit/UI/Launcher.xaml.cs +++ b/SourceGit/UI/Launcher.xaml.cs @@ -48,9 +48,9 @@ namespace SourceGit.UI { Git.Repository.OnOpen = repo => { Dispatcher.Invoke(() => { - foreach (var item in openedTabs.Items) { - var opened = item as Tab; - if (opened != null && opened.Repo != null && repo.Path == opened.Repo.Path) { + for (int i = 1; i < openedTabs.Items.Count; i++) { + var opened = openedTabs.Items[i] as Tab; + if (opened.Repo.Path == repo.Path) { openedTabs.SelectedItem = opened; return; } @@ -76,23 +76,6 @@ namespace SourceGit.UI { openedTabs.SelectedItem = Tabs[0]; } - /// - /// Get popup manager from given active page. - /// - /// - /// - public PopupManager GetPopupManager(Git.Repository repo) { - if (repo == null) return (Tabs[0].Page as Manager).popupManager; - - foreach (var tab in Tabs) { - if (tab.Repo != null && tab.Repo.Path == repo.Path) { - return (tab.Page as Dashboard).popupManager; - } - } - - return null; - } - #region LAYOUT_CONTENT /// /// Close repository tab. diff --git a/SourceGit/UI/Merge.xaml.cs b/SourceGit/UI/Merge.xaml.cs index 422e4a28..0d9fbeef 100644 --- a/SourceGit/UI/Merge.xaml.cs +++ b/SourceGit/UI/Merge.xaml.cs @@ -53,7 +53,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened, string source, string dest) { - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(new Merge(opened, source, dest)); } @@ -65,7 +65,7 @@ namespace SourceGit.UI { /// public static void StartDirectly(Git.Repository opened, string source, string dest) { var merge = new Merge(opened, source, dest); - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(merge); popup?.Lock(); @@ -83,7 +83,7 @@ namespace SourceGit.UI { /// /// private async void Start(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); var branch = sourceBranch.Content as string; @@ -99,7 +99,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Pull.xaml.cs b/SourceGit/UI/Pull.xaml.cs index d75e3a79..fd97ed9f 100644 --- a/SourceGit/UI/Pull.xaml.cs +++ b/SourceGit/UI/Pull.xaml.cs @@ -30,7 +30,7 @@ namespace SourceGit.UI { /// Opened repository /// Prefered remote branch public static void Show(Git.Repository opened, string preferRemoteBranch = null) { - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(new Pull(opened, preferRemoteBranch)); } @@ -77,7 +77,7 @@ namespace SourceGit.UI { if (remote == null || branch == null) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.Pull(remote, branch.Substring(branch.IndexOf('/')+1), msg => popup?.UpdateStatus(msg), rebase, autoStash)); popup?.Close(true); @@ -89,7 +89,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } /// diff --git a/SourceGit/UI/Push.xaml.cs b/SourceGit/UI/Push.xaml.cs index 352e3a76..3587e070 100644 --- a/SourceGit/UI/Push.xaml.cs +++ b/SourceGit/UI/Push.xaml.cs @@ -29,7 +29,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Branch prefer = null) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new Push(repo, prefer)); } @@ -45,7 +45,7 @@ namespace SourceGit.UI { } var push = new Push(repo, current); - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(push); popup?.Lock(); @@ -91,14 +91,14 @@ namespace SourceGit.UI { var remoteBranch = combRemoteBranches.SelectedItem as string; var track = string.IsNullOrEmpty(localBranch.Upstream); var tags = chkTags.IsChecked == true; - var force = chkForce.IsChecked == true; + var force = chkForce.IsChecked == true; remoteBranch = remoteBranch.Substring($"{remote}/".Length); if (remoteBranch.Contains(" (new)")) { remoteBranch = remoteBranch.Substring(0, remoteBranch.Length - 6); } - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.Push(remote, localBranch.Name, remoteBranch, msg => popup?.UpdateStatus(msg), tags, track, force)); popup?.Close(true); @@ -110,7 +110,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } /// diff --git a/SourceGit/UI/PushTag.xaml.cs b/SourceGit/UI/PushTag.xaml.cs index 1cc89a67..b2fc8fc0 100644 --- a/SourceGit/UI/PushTag.xaml.cs +++ b/SourceGit/UI/PushTag.xaml.cs @@ -32,7 +32,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Tag tag) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new PushTag(repo, tag)); } @@ -45,7 +45,7 @@ namespace SourceGit.UI { var remote = combRemotes.SelectedItem as Git.Remote; if (remote == null) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => Git.Tag.Push(repo, tag.Name, remote.Name)); popup?.Close(true); @@ -57,7 +57,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); } } diff --git a/SourceGit/UI/Rebase.xaml.cs b/SourceGit/UI/Rebase.xaml.cs index 577cbb14..1c583882 100644 --- a/SourceGit/UI/Rebase.xaml.cs +++ b/SourceGit/UI/Rebase.xaml.cs @@ -38,7 +38,7 @@ namespace SourceGit.UI { dialog.type.Data = dialog.FindResource("Icon.Branch") as Geometry; dialog.desc.Content = branch.Name; - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(dialog); } @@ -57,7 +57,7 @@ namespace SourceGit.UI { dialog.type.Data = dialog.FindResource("Icon.Commit") as Geometry; dialog.desc.Content = $"{commit.ShortSHA} {commit.Subject}"; - var popup = App.Launcher.GetPopupManager(opened); + var popup = App.GetPopupManager(opened); popup?.Show(dialog); } @@ -67,7 +67,7 @@ namespace SourceGit.UI { /// /// private async void Start(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); var autoStash = chkAutoStash.IsChecked == true; @@ -77,7 +77,7 @@ namespace SourceGit.UI { } private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Remote.xaml.cs b/SourceGit/UI/Remote.xaml.cs index eda0b4f3..3c6ecee9 100644 --- a/SourceGit/UI/Remote.xaml.cs +++ b/SourceGit/UI/Remote.xaml.cs @@ -44,7 +44,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened, Git.Remote editing = null) { - App.Launcher.GetPopupManager(opened)?.Show(new Remote(opened, editing)); + App.GetPopupManager(opened)?.Show(new Remote(opened, editing)); } /// @@ -59,7 +59,7 @@ namespace SourceGit.UI { txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtUrl)) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => { @@ -79,7 +79,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/RenameBranch.xaml.cs b/SourceGit/UI/RenameBranch.xaml.cs index 8886fdda..a89c30a7 100644 --- a/SourceGit/UI/RenameBranch.xaml.cs +++ b/SourceGit/UI/RenameBranch.xaml.cs @@ -38,7 +38,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository opened, Git.Branch branch) { - App.Launcher.GetPopupManager(opened)?.Show(new RenameBranch(opened, branch)); + App.GetPopupManager(opened)?.Show(new RenameBranch(opened, branch)); } /// @@ -50,7 +50,7 @@ namespace SourceGit.UI { txtNewName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtNewName)) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => branch.Rename(repo, NewName)); popup?.Close(true); @@ -62,7 +62,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Reset.xaml.cs b/SourceGit/UI/Reset.xaml.cs index 071c3f14..60cebfd7 100644 --- a/SourceGit/UI/Reset.xaml.cs +++ b/SourceGit/UI/Reset.xaml.cs @@ -59,7 +59,7 @@ namespace SourceGit.UI { var current = repo.CurrentBranch(); if (current == null) return; - App.Launcher.GetPopupManager(repo)?.Show(new Reset(repo, current, commit)); + App.GetPopupManager(repo)?.Show(new Reset(repo, current, commit)); } /// @@ -71,7 +71,7 @@ namespace SourceGit.UI { var mode = combMode.SelectedItem as Mode; if (mode == null) return; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.Reset(revision, mode.Arg)); popup?.Close(true); @@ -83,7 +83,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Revert.xaml.cs b/SourceGit/UI/Revert.xaml.cs index 58bbc0ef..7bee143e 100644 --- a/SourceGit/UI/Revert.xaml.cs +++ b/SourceGit/UI/Revert.xaml.cs @@ -30,7 +30,7 @@ namespace SourceGit.UI { /// /// public static void Show(Git.Repository repo, Git.Commit commit) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new Revert(repo, commit)); } @@ -41,7 +41,7 @@ namespace SourceGit.UI { /// private async void Sure(object sender, RoutedEventArgs e) { bool autoCommit = chkCommit.IsChecked == true; - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Lock(); await Task.Run(() => repo.Revert(sha, autoCommit)); popup?.Close(true); @@ -53,7 +53,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Close(); } } diff --git a/SourceGit/UI/Stash.xaml.cs b/SourceGit/UI/Stash.xaml.cs index 0db25dc7..1d3ba0e9 100644 --- a/SourceGit/UI/Stash.xaml.cs +++ b/SourceGit/UI/Stash.xaml.cs @@ -28,7 +28,7 @@ namespace SourceGit.UI { /// Opened repository /// Special files to stash public static void Show(Git.Repository repo, List files) { - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(new Stash(repo, files)); } @@ -42,7 +42,7 @@ namespace SourceGit.UI { string message = txtName.Text; Git.Stash.Push(repo, includeUntracked, message, files); - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } /// @@ -51,7 +51,7 @@ namespace SourceGit.UI { /// /// private void Cancel(object sender, RoutedEventArgs e) { - App.Launcher.GetPopupManager(repo)?.Close(); + App.GetPopupManager(repo)?.Close(); } } } diff --git a/SourceGit/UI/Waiting.xaml.cs b/SourceGit/UI/Waiting.xaml.cs index cfc8d9eb..27e8836d 100644 --- a/SourceGit/UI/Waiting.xaml.cs +++ b/SourceGit/UI/Waiting.xaml.cs @@ -23,7 +23,7 @@ namespace SourceGit.UI { /// public static void Show(Git.Repository repo, Action job) { var dialog = new Waiting(); - var popup = App.Launcher.GetPopupManager(repo); + var popup = App.GetPopupManager(repo); popup?.Show(dialog); popup?.Lock();