diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index cc253d3c..79dce87e 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -53,8 +53,9 @@ namespace SourceGit.ViewModels set => SetProperty(ref _extraArgs, value); } - public Clone() + public Clone(string pageId) { + _pageId = pageId; View = new Views.Clone() { DataContext = this }; Task.Run(async () => @@ -94,7 +95,7 @@ namespace SourceGit.ViewModels return Task.Run(() => { - var cmd = new Commands.Clone(HostPageId, _parentFolder, _remote, _local, _useSSH ? _sshKey : "", _extraArgs, SetProgressDescription); + var cmd = new Commands.Clone(_pageId, _parentFolder, _remote, _local, _useSSH ? _sshKey : "", _extraArgs, SetProgressDescription); if (!cmd.Exec()) return false; @@ -115,7 +116,7 @@ namespace SourceGit.ViewModels { CallUIThread(() => { - App.RaiseException(HostPageId, $"Folder '{path}' can NOT be found"); + App.RaiseException(_pageId, $"Folder '{path}' can NOT be found"); }); return false; } @@ -134,7 +135,7 @@ namespace SourceGit.ViewModels var page = null as LauncherPage; foreach (var one in launcher.Pages) { - if (one.GetId() == HostPageId) + if (one.Node.Id == _pageId) { page = one; break; @@ -149,6 +150,7 @@ namespace SourceGit.ViewModels }); } + private string _pageId = string.Empty; private string _remote = string.Empty; private bool _useSSH = false; private string _sshKey = string.Empty; diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index c5cb23e9..b890b76e 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -209,12 +209,12 @@ namespace SourceGit.ViewModels } } - if (PopupHost.CanCreatePopup()) + if (_repo.CanCreatePopup()) { if (firstRemoteBranch != null) - PopupHost.ShowPopup(new CreateBranch(_repo, firstRemoteBranch)); + _repo.ShowPopup(new CreateBranch(_repo, firstRemoteBranch)); else - PopupHost.ShowPopup(new CheckoutCommit(_repo, commit)); + _repo.ShowPopup(new CheckoutCommit(_repo, commit)); } } @@ -260,8 +260,8 @@ namespace SourceGit.ViewModels cherryPickMultiple.Icon = App.CreateMenuIcon("Icons.CherryPick"); cherryPickMultiple.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CherryPick(_repo, selected)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CherryPick(_repo, selected)); e.Handled = true; }; multipleMenu.Items.Add(cherryPickMultiple); @@ -274,8 +274,8 @@ namespace SourceGit.ViewModels mergeMultiple.Icon = App.CreateMenuIcon("Icons.Merge"); mergeMultiple.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new MergeMultiple(_repo, selected)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new MergeMultiple(_repo, selected)); e.Handled = true; }; multipleMenu.Items.Add(mergeMultiple); @@ -401,8 +401,8 @@ namespace SourceGit.ViewModels reset.Icon = App.CreateMenuIcon("Icons.Reset"); reset.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Reset(_repo, current, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Reset(_repo, current, commit)); e.Handled = true; }; menu.Items.Add(reset); @@ -420,8 +420,8 @@ namespace SourceGit.ViewModels return; } - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Squash(_repo, commit, commit.SHA)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Squash(_repo, commit, commit.SHA)); e.Handled = true; }; @@ -441,8 +441,8 @@ namespace SourceGit.ViewModels return; } - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Reword(_repo, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Reword(_repo, commit)); e.Handled = true; }; menu.Items.Add(reword); @@ -462,8 +462,8 @@ namespace SourceGit.ViewModels if (commit.Parents.Count == 1) { var parent = _commits.Find(x => x.SHA == commit.Parents[0]); - if (parent != null && PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Squash(_repo, parent, commit.SHA)); + if (parent != null && _repo.CanCreatePopup()) + _repo.ShowPopup(new Squash(_repo, parent, commit.SHA)); } e.Handled = true; @@ -478,8 +478,8 @@ namespace SourceGit.ViewModels rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Rebase(_repo, current, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Rebase(_repo, current, commit)); e.Handled = true; }; menu.Items.Add(rebase); @@ -491,8 +491,8 @@ namespace SourceGit.ViewModels merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(_repo, commit, current.Name)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Merge(_repo, commit, current.Name)); e.Handled = true; }; @@ -504,11 +504,11 @@ namespace SourceGit.ViewModels cherryPick.Icon = App.CreateMenuIcon("Icons.CherryPick"); cherryPick.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) + if (_repo.CanCreatePopup()) { if (commit.Parents.Count <= 1) { - PopupHost.ShowPopup(new CherryPick(_repo, [commit])); + _repo.ShowPopup(new CherryPick(_repo, [commit])); } else { @@ -523,7 +523,7 @@ namespace SourceGit.ViewModels parents.Add(parent); } - PopupHost.ShowPopup(new CherryPick(_repo, commit, parents)); + _repo.ShowPopup(new CherryPick(_repo, commit, parents)); } } @@ -538,8 +538,8 @@ namespace SourceGit.ViewModels revert.Icon = App.CreateMenuIcon("Icons.Undo"); revert.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Revert(_repo, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Revert(_repo, commit)); e.Handled = true; }; menu.Items.Add(revert); @@ -552,8 +552,8 @@ namespace SourceGit.ViewModels checkoutCommit.Icon = App.CreateMenuIcon("Icons.Detached"); checkoutCommit.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CheckoutCommit(_repo, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CheckoutCommit(_repo, commit)); e.Handled = true; }; menu.Items.Add(checkoutCommit); @@ -630,8 +630,8 @@ namespace SourceGit.ViewModels createBranch.Header = App.Text("CreateBranch"); createBranch.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateBranch(_repo, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CreateBranch(_repo, commit)); e.Handled = true; }; menu.Items.Add(createBranch); @@ -641,8 +641,8 @@ namespace SourceGit.ViewModels createTag.Header = App.Text("CreateTag"); createTag.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateTag(_repo, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CreateTag(_repo, commit)); e.Handled = true; }; menu.Items.Add(createTag); @@ -683,8 +683,8 @@ namespace SourceGit.ViewModels archive.Header = App.Text("Archive"); archive.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Archive(_repo, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Archive(_repo, commit)); e.Handled = true; }; menu.Items.Add(archive); @@ -710,8 +710,8 @@ namespace SourceGit.ViewModels item.Header = dup.Name; item.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new ExecuteCustomAction(_repo, dup, commit)); + if (_repo.CanCreatePopup()) + _repo.ShowAndStartPopup(new ExecuteCustomAction(_repo, dup, commit)); e.Handled = true; }; @@ -871,8 +871,8 @@ namespace SourceGit.ViewModels if (b == null) return; - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new Merge(_repo, b, current.Name)); + if (_repo.CanCreatePopup()) + _repo.ShowAndStartPopup(new Merge(_repo, b, current.Name)); e.Handled = true; }; @@ -883,8 +883,8 @@ namespace SourceGit.ViewModels pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Pull(_repo, null)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Pull(_repo, null)); e.Handled = true; }; submenu.Items.Add(pull); @@ -896,8 +896,8 @@ namespace SourceGit.ViewModels push.IsEnabled = _repo.Remotes.Count > 0; push.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Push(_repo, current)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Push(_repo, current)); e.Handled = true; }; submenu.Items.Add(push); @@ -907,8 +907,8 @@ namespace SourceGit.ViewModels rename.Icon = App.CreateMenuIcon("Icons.Rename"); rename.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new RenameBranch(_repo, current)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new RenameBranch(_repo, current)); e.Handled = true; }; submenu.Items.Add(rename); @@ -922,8 +922,8 @@ namespace SourceGit.ViewModels finish.Icon = App.CreateMenuIcon("Icons.GitFlow"); finish.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new GitFlowFinish(_repo, current, detect.Type, detect.Prefix)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new GitFlowFinish(_repo, current, detect.Type, detect.Prefix)); e.Handled = true; }; submenu.Items.Add(finish); @@ -967,8 +967,8 @@ namespace SourceGit.ViewModels merge.IsEnabled = !merged; merge.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(_repo, branch, current.Name)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Merge(_repo, branch, current.Name)); e.Handled = true; }; submenu.Items.Add(merge); @@ -978,8 +978,8 @@ namespace SourceGit.ViewModels rename.Icon = App.CreateMenuIcon("Icons.Rename"); rename.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new RenameBranch(_repo, branch)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new RenameBranch(_repo, branch)); e.Handled = true; }; submenu.Items.Add(rename); @@ -989,8 +989,8 @@ namespace SourceGit.ViewModels delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteBranch(_repo, branch)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new DeleteBranch(_repo, branch)); e.Handled = true; }; submenu.Items.Add(delete); @@ -1004,8 +1004,8 @@ namespace SourceGit.ViewModels finish.Icon = App.CreateMenuIcon("Icons.GitFlow"); finish.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new GitFlowFinish(_repo, branch, detect.Type, detect.Prefix)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new GitFlowFinish(_repo, branch, detect.Type, detect.Prefix)); e.Handled = true; }; submenu.Items.Add(finish); @@ -1051,8 +1051,8 @@ namespace SourceGit.ViewModels merge.IsEnabled = !merged; merge.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(_repo, branch, current.Name)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Merge(_repo, branch, current.Name)); e.Handled = true; }; @@ -1063,8 +1063,8 @@ namespace SourceGit.ViewModels delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteBranch(_repo, branch)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new DeleteBranch(_repo, branch)); e.Handled = true; }; submenu.Items.Add(delete); @@ -1098,8 +1098,8 @@ namespace SourceGit.ViewModels push.IsEnabled = _repo.Remotes.Count > 0; push.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new PushTag(_repo, tag)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new PushTag(_repo, tag)); e.Handled = true; }; submenu.Items.Add(push); @@ -1110,8 +1110,8 @@ namespace SourceGit.ViewModels merge.IsEnabled = !merged; merge.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(_repo, tag, current.Name)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new Merge(_repo, tag, current.Name)); e.Handled = true; }; submenu.Items.Add(merge); @@ -1121,8 +1121,8 @@ namespace SourceGit.ViewModels delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteTag(_repo, tag)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new DeleteTag(_repo, tag)); e.Handled = true; }; submenu.Items.Add(delete); diff --git a/src/ViewModels/Init.cs b/src/ViewModels/Init.cs index 913127a1..06e522c0 100644 --- a/src/ViewModels/Init.cs +++ b/src/ViewModels/Init.cs @@ -16,8 +16,9 @@ namespace SourceGit.ViewModels private set; } - public Init(string path, RepositoryNode parent, string reason) + public Init(string pageId, string path, RepositoryNode parent, string reason) { + _pageId = pageId; _targetPath = path; _parentNode = parent; @@ -31,7 +32,7 @@ namespace SourceGit.ViewModels return Task.Run(() => { - var succ = new Commands.Init(HostPageId, _targetPath).Exec(); + var succ = new Commands.Init(_pageId, _targetPath).Exec(); if (!succ) return false; @@ -46,6 +47,7 @@ namespace SourceGit.ViewModels }); } + private string _pageId = null; private string _targetPath = null; private RepositoryNode _parentNode = null; } diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 02844312..e02d6d4d 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -36,7 +36,6 @@ namespace SourceGit.ViewModels { if (SetProperty(ref _activePage, value)) { - PopupHost.Active = value; UpdateTitle(); if (!_ignoreIndexChange && value is { Data: Repository repo }) @@ -295,7 +294,6 @@ namespace SourceGit.ViewModels FullPath = node.Id, GitDir = gitDir, }; - repo.Open(); if (page == null) @@ -318,6 +316,8 @@ namespace SourceGit.ViewModels page.Data = repo; } + repo.SetOwnerPage(page); + if (page != _activePage) ActivePage = page; else @@ -475,7 +475,7 @@ namespace SourceGit.ViewModels { foreach (var one in Pages) { - if (one.IsInProgress()) + if (!one.CanCreatePopup() || one.Data is Repository { IsAutoFetching: true }) { App.RaiseException(null, "You have unfinished task(s) in opened pages. Please wait!!!"); return; diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index 92114f5e..a9c6331b 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -1,10 +1,10 @@ using System; - using Avalonia.Collections; +using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.ViewModels { - public class LauncherPage : PopupHost + public class LauncherPage : ObservableObject { public RepositoryNode Node { @@ -18,6 +18,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _data, value); } + public Popup Popup + { + get => _popup; + set => SetProperty(ref _popup, value); + } + public AvaloniaList Notifications { get; @@ -39,26 +45,59 @@ namespace SourceGit.ViewModels _data = repo; } - public override string GetId() - { - return _node.Id; - } - - public override bool IsInProgress() - { - if (_data is Repository { IsAutoFetching: true }) - return true; - - return base.IsInProgress(); - } - public void CopyPath() { if (_node.IsRepository) App.CopyText(_node.Id); } + public bool CanCreatePopup() + { + return _popup == null || !_popup.InProgress; + } + + public void StartPopup(Popup popup) + { + var dumpPage = this; + dumpPage.Popup = popup; + dumpPage.ProcessPopup(); + } + + public async void ProcessPopup() + { + if (_popup != null) + { + if (!_popup.Check()) + return; + + _popup.InProgress = true; + var task = _popup.Sure(); + if (task != null) + { + var finished = await task; + _popup.InProgress = false; + if (finished) + Popup = null; + } + else + { + _popup.InProgress = false; + Popup = null; + } + } + } + + public void CancelPopup() + { + if (_popup == null) + return; + if (_popup.InProgress) + return; + Popup = null; + } + private RepositoryNode _node = null; private object _data = null; + private Popup _popup = null; } } diff --git a/src/ViewModels/Popup.cs b/src/ViewModels/Popup.cs index 1b4ff9a8..ff74df51 100644 --- a/src/ViewModels/Popup.cs +++ b/src/ViewModels/Popup.cs @@ -10,12 +10,6 @@ namespace SourceGit.ViewModels { public class Popup : ObservableValidator { - public string HostPageId - { - get; - set; - } - public object View { get; diff --git a/src/ViewModels/PopupHost.cs b/src/ViewModels/PopupHost.cs deleted file mode 100644 index 01d1158c..00000000 --- a/src/ViewModels/PopupHost.cs +++ /dev/null @@ -1,83 +0,0 @@ -using CommunityToolkit.Mvvm.ComponentModel; - -namespace SourceGit.ViewModels -{ - public class PopupHost : ObservableObject - { - public static PopupHost Active - { - get; - set; - } = null; - - public Popup Popup - { - get => _popup; - set => SetProperty(ref _popup, value); - } - - public static bool CanCreatePopup() - { - return Active?.IsInProgress() != true; - } - - public static void ShowPopup(Popup popup) - { - popup.HostPageId = Active.GetId(); - Active.Popup = popup; - } - - public static void ShowAndStartPopup(Popup popup) - { - var dumpPage = Active; - popup.HostPageId = dumpPage.GetId(); - dumpPage.Popup = popup; - dumpPage.ProcessPopup(); - } - - public virtual string GetId() - { - return string.Empty; - } - - public virtual bool IsInProgress() - { - return _popup is { InProgress: true }; - } - - public async void ProcessPopup() - { - if (_popup != null) - { - if (!_popup.Check()) - return; - - _popup.InProgress = true; - var task = _popup.Sure(); - if (task != null) - { - var finished = await task; - _popup.InProgress = false; - if (finished) - Popup = null; - } - else - { - _popup.InProgress = false; - Popup = null; - } - } - } - - public void CancelPopup() - { - if (_popup == null) - return; - if (_popup.InProgress) - return; - Popup = null; - } - - private Popup _popup = null; - } -} diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 056736c0..83d23c31 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -493,6 +493,7 @@ namespace SourceGit.ViewModels public void Close() { + _page = null; SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect var settingsSerialized = JsonSerializer.Serialize(_settings, JsonCodeGen.Default.RepositorySettings); @@ -537,6 +538,26 @@ namespace SourceGit.ViewModels SearchCommitFilterSuggestion.Clear(); } + public void SetOwnerPage(LauncherPage page) + { + _page = page; + } + + public bool CanCreatePopup() + { + return !_isAutoFetching && _page != null && _page.CanCreatePopup(); + } + + public void ShowPopup(Popup popup) + { + _page.Popup = popup; + } + + public void ShowAndStartPopup(Popup popup) + { + _page.StartPopup(popup); + } + public void RefreshAll() { Task.Run(() => @@ -598,7 +619,7 @@ namespace SourceGit.ViewModels public void Fetch(bool autoStart) { - if (!PopupHost.CanCreatePopup()) + if (!CanCreatePopup()) return; if (_remotes.Count == 0) @@ -608,14 +629,14 @@ namespace SourceGit.ViewModels } if (autoStart) - PopupHost.ShowAndStartPopup(new Fetch(this)); + ShowAndStartPopup(new Fetch(this)); else - PopupHost.ShowPopup(new Fetch(this)); + ShowPopup(new Fetch(this)); } public void Pull(bool autoStart) { - if (!PopupHost.CanCreatePopup()) + if (!CanCreatePopup()) return; if (_remotes.Count == 0) @@ -626,14 +647,14 @@ namespace SourceGit.ViewModels var pull = new Pull(this, null); if (autoStart && pull.SelectedBranch != null) - PopupHost.ShowAndStartPopup(pull); + ShowAndStartPopup(pull); else - PopupHost.ShowPopup(pull); + ShowPopup(pull); } public void Push(bool autoStart) { - if (!PopupHost.CanCreatePopup()) + if (!CanCreatePopup()) return; if (_remotes.Count == 0) @@ -649,23 +670,23 @@ namespace SourceGit.ViewModels } if (autoStart) - PopupHost.ShowAndStartPopup(new Push(this, null)); + ShowAndStartPopup(new Push(this, null)); else - PopupHost.ShowPopup(new Push(this, null)); + ShowPopup(new Push(this, null)); } public void ApplyPatch() { - if (!PopupHost.CanCreatePopup()) + if (!CanCreatePopup()) return; - PopupHost.ShowPopup(new Apply(this)); + ShowPopup(new Apply(this)); } public void Cleanup() { - if (!PopupHost.CanCreatePopup()) + if (!CanCreatePopup()) return; - PopupHost.ShowAndStartPopup(new Cleanup(this)); + ShowAndStartPopup(new Cleanup(this)); } public void ClearFilter() @@ -1007,8 +1028,8 @@ namespace SourceGit.ViewModels return; } - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateBranch(this, _currentBranch)); + if (CanCreatePopup()) + ShowPopup(new CreateBranch(this, _currentBranch)); } public void CheckoutBranch(Models.Branch branch) @@ -1023,15 +1044,15 @@ namespace SourceGit.ViewModels } } - if (!PopupHost.CanCreatePopup()) + if (!CanCreatePopup()) return; if (branch.IsLocal) { if (_localChangesCount > 0) - PopupHost.ShowPopup(new Checkout(this, branch.Name)); + ShowPopup(new Checkout(this, branch.Name)); else - PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name)); + ShowAndStartPopup(new Checkout(this, branch.Name)); } else { @@ -1046,20 +1067,20 @@ namespace SourceGit.ViewModels } } - PopupHost.ShowPopup(new CreateBranch(this, branch)); + ShowPopup(new CreateBranch(this, branch)); } } public void DeleteMultipleBranches(List branches, bool isLocal) { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteMultipleBranches(this, branches, isLocal)); + if (CanCreatePopup()) + ShowPopup(new DeleteMultipleBranches(this, branches, isLocal)); } public void MergeMultipleBranches(List branches) { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new MergeMultiple(this, branches)); + if (CanCreatePopup()) + ShowPopup(new MergeMultiple(this, branches)); } public void CreateNewTag() @@ -1070,26 +1091,26 @@ namespace SourceGit.ViewModels return; } - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateTag(this, _currentBranch)); + if (CanCreatePopup()) + ShowPopup(new CreateTag(this, _currentBranch)); } public void AddRemote() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new AddRemote(this)); + if (CanCreatePopup()) + ShowPopup(new AddRemote(this)); } public void AddSubmodule() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new AddSubmodule(this)); + if (CanCreatePopup()) + ShowPopup(new AddSubmodule(this)); } public void UpdateSubmodules() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new UpdateSubmodules(this)); + if (CanCreatePopup()) + ShowPopup(new UpdateSubmodules(this)); } public void OpenSubmodule(string submodule) @@ -1114,14 +1135,14 @@ namespace SourceGit.ViewModels public void AddWorktree() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new AddWorktree(this)); + if (CanCreatePopup()) + ShowPopup(new AddWorktree(this)); } public void PruneWorktrees() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new PruneWorktrees(this)); + if (CanCreatePopup()) + ShowAndStartPopup(new PruneWorktrees(this)); } public void OpenWorktree(Models.Worktree worktree) @@ -1154,8 +1175,8 @@ namespace SourceGit.ViewModels startFeature.Icon = App.CreateMenuIcon("Icons.GitFlow.Feature"); startFeature.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new GitFlowStart(this, "feature")); + if (CanCreatePopup()) + ShowPopup(new GitFlowStart(this, "feature")); e.Handled = true; }; @@ -1164,8 +1185,8 @@ namespace SourceGit.ViewModels startRelease.Icon = App.CreateMenuIcon("Icons.GitFlow.Release"); startRelease.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new GitFlowStart(this, "release")); + if (CanCreatePopup()) + ShowPopup(new GitFlowStart(this, "release")); e.Handled = true; }; @@ -1174,8 +1195,8 @@ namespace SourceGit.ViewModels startHotfix.Icon = App.CreateMenuIcon("Icons.GitFlow.Hotfix"); startHotfix.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new GitFlowStart(this, "hotfix")); + if (CanCreatePopup()) + ShowPopup(new GitFlowStart(this, "hotfix")); e.Handled = true; }; @@ -1190,8 +1211,8 @@ namespace SourceGit.ViewModels init.Icon = App.CreateMenuIcon("Icons.Init"); init.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new InitGitFlow(this)); + if (CanCreatePopup()) + ShowPopup(new InitGitFlow(this)); e.Handled = true; }; menu.Items.Add(init); @@ -1212,8 +1233,8 @@ namespace SourceGit.ViewModels addPattern.Icon = App.CreateMenuIcon("Icons.File.Add"); addPattern.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new LFSTrackCustomPattern(this)); + if (CanCreatePopup()) + ShowPopup(new LFSTrackCustomPattern(this)); e.Handled = true; }; @@ -1226,12 +1247,12 @@ namespace SourceGit.ViewModels fetch.IsEnabled = _remotes.Count > 0; fetch.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) + if (CanCreatePopup()) { if (_remotes.Count == 1) - PopupHost.ShowAndStartPopup(new LFSFetch(this)); + ShowAndStartPopup(new LFSFetch(this)); else - PopupHost.ShowPopup(new LFSFetch(this)); + ShowPopup(new LFSFetch(this)); } e.Handled = true; @@ -1244,12 +1265,12 @@ namespace SourceGit.ViewModels pull.IsEnabled = _remotes.Count > 0; pull.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) + if (CanCreatePopup()) { if (_remotes.Count == 1) - PopupHost.ShowAndStartPopup(new LFSPull(this)); + ShowAndStartPopup(new LFSPull(this)); else - PopupHost.ShowPopup(new LFSPull(this)); + ShowPopup(new LFSPull(this)); } e.Handled = true; @@ -1262,12 +1283,12 @@ namespace SourceGit.ViewModels push.IsEnabled = _remotes.Count > 0; push.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) + if (CanCreatePopup()) { if (_remotes.Count == 1) - PopupHost.ShowAndStartPopup(new LFSPush(this)); + ShowAndStartPopup(new LFSPush(this)); else - PopupHost.ShowPopup(new LFSPush(this)); + ShowPopup(new LFSPush(this)); } e.Handled = true; @@ -1279,8 +1300,8 @@ namespace SourceGit.ViewModels prune.Icon = App.CreateMenuIcon("Icons.Clean"); prune.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new LFSPrune(this)); + if (CanCreatePopup()) + ShowAndStartPopup(new LFSPrune(this)); e.Handled = true; }; @@ -1361,8 +1382,8 @@ namespace SourceGit.ViewModels item.Header = dup.Name; item.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new ExecuteCustomAction(this, dup, null)); + if (CanCreatePopup()) + ShowAndStartPopup(new ExecuteCustomAction(this, dup, null)); e.Handled = true; }; @@ -1388,8 +1409,8 @@ namespace SourceGit.ViewModels push.IsEnabled = _remotes.Count > 0; push.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Push(this, branch)); + if (CanCreatePopup()) + ShowPopup(new Push(this, branch)); e.Handled = true; }; @@ -1400,8 +1421,8 @@ namespace SourceGit.ViewModels discard.Icon = App.CreateMenuIcon("Icons.Undo"); discard.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Discard(this)); + if (CanCreatePopup()) + ShowPopup(new Discard(this)); e.Handled = true; }; @@ -1421,8 +1442,8 @@ namespace SourceGit.ViewModels if (b == null) return; - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new Merge(this, b, branch.Name)); + if (CanCreatePopup()) + ShowAndStartPopup(new Merge(this, b, branch.Name)); e.Handled = true; }; @@ -1432,8 +1453,8 @@ namespace SourceGit.ViewModels pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Pull(this, null)); + if (CanCreatePopup()) + ShowPopup(new Pull(this, null)); e.Handled = true; }; @@ -1473,8 +1494,8 @@ namespace SourceGit.ViewModels fastForward.IsEnabled = branch.TrackStatus.Ahead.Count == 0; fastForward.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new FastForwardWithoutCheckout(this, branch, upstream)); + if (CanCreatePopup()) + ShowAndStartPopup(new FastForwardWithoutCheckout(this, branch, upstream)); e.Handled = true; }; @@ -1484,8 +1505,8 @@ namespace SourceGit.ViewModels fetchInto.IsEnabled = branch.TrackStatus.Ahead.Count == 0; fetchInto.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new FetchInto(this, branch, upstream)); + if (CanCreatePopup()) + ShowAndStartPopup(new FetchInto(this, branch, upstream)); e.Handled = true; }; @@ -1501,8 +1522,8 @@ namespace SourceGit.ViewModels merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(this, branch, _currentBranch.Name)); + if (CanCreatePopup()) + ShowPopup(new Merge(this, branch, _currentBranch.Name)); e.Handled = true; }; @@ -1511,8 +1532,8 @@ namespace SourceGit.ViewModels rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Rebase(this, _currentBranch, branch)); + if (CanCreatePopup()) + ShowPopup(new Rebase(this, _currentBranch, branch)); e.Handled = true; }; @@ -1557,8 +1578,8 @@ namespace SourceGit.ViewModels finish.Icon = App.CreateMenuIcon("Icons.GitFlow"); finish.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new GitFlowFinish(this, branch, detect.Type, detect.Prefix)); + if (CanCreatePopup()) + ShowPopup(new GitFlowFinish(this, branch, detect.Type, detect.Prefix)); e.Handled = true; }; menu.Items.Add(new MenuItem() { Header = "-" }); @@ -1570,8 +1591,8 @@ namespace SourceGit.ViewModels rename.Icon = App.CreateMenuIcon("Icons.Rename"); rename.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new RenameBranch(this, branch)); + if (CanCreatePopup()) + ShowPopup(new RenameBranch(this, branch)); e.Handled = true; }; @@ -1581,8 +1602,8 @@ namespace SourceGit.ViewModels delete.IsEnabled = !branch.IsCurrent; delete.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteBranch(this, branch)); + if (CanCreatePopup()) + ShowPopup(new DeleteBranch(this, branch)); e.Handled = true; }; @@ -1591,8 +1612,8 @@ namespace SourceGit.ViewModels createBranch.Header = App.Text("CreateBranch"); createBranch.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateBranch(this, branch)); + if (CanCreatePopup()) + ShowPopup(new CreateBranch(this, branch)); e.Handled = true; }; @@ -1601,8 +1622,8 @@ namespace SourceGit.ViewModels createTag.Header = App.Text("CreateTag"); createTag.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateTag(this, branch)); + if (CanCreatePopup()) + ShowPopup(new CreateTag(this, branch)); e.Handled = true; }; @@ -1628,8 +1649,8 @@ namespace SourceGit.ViewModels tracking.Icon = App.CreateMenuIcon("Icons.Track"); tracking.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new SetUpstream(this, branch, remoteBranches)); + if (CanCreatePopup()) + ShowPopup(new SetUpstream(this, branch, remoteBranches)); e.Handled = true; }; menu.Items.Add(tracking); @@ -1640,8 +1661,8 @@ namespace SourceGit.ViewModels archive.Header = App.Text("Archive"); archive.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Archive(this, branch)); + if (CanCreatePopup()) + ShowPopup(new Archive(this, branch)); e.Handled = true; }; menu.Items.Add(archive); @@ -1684,8 +1705,8 @@ namespace SourceGit.ViewModels fetch.Icon = App.CreateMenuIcon("Icons.Fetch"); fetch.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new Fetch(this, remote)); + if (CanCreatePopup()) + ShowAndStartPopup(new Fetch(this, remote)); e.Handled = true; }; @@ -1694,8 +1715,8 @@ namespace SourceGit.ViewModels prune.Icon = App.CreateMenuIcon("Icons.Clean"); prune.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new PruneRemote(this, remote)); + if (CanCreatePopup()) + ShowAndStartPopup(new PruneRemote(this, remote)); e.Handled = true; }; @@ -1704,8 +1725,8 @@ namespace SourceGit.ViewModels edit.Icon = App.CreateMenuIcon("Icons.Edit"); edit.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new EditRemote(this, remote)); + if (CanCreatePopup()) + ShowPopup(new EditRemote(this, remote)); e.Handled = true; }; @@ -1714,8 +1735,8 @@ namespace SourceGit.ViewModels delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteRemote(this, remote)); + if (CanCreatePopup()) + ShowPopup(new DeleteRemote(this, remote)); e.Handled = true; }; @@ -1761,8 +1782,8 @@ namespace SourceGit.ViewModels pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Pull(this, branch)); + if (CanCreatePopup()) + ShowPopup(new Pull(this, branch)); e.Handled = true; }; @@ -1771,8 +1792,8 @@ namespace SourceGit.ViewModels merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Merge(this, branch, _currentBranch.Name)); + if (CanCreatePopup()) + ShowPopup(new Merge(this, branch, _currentBranch.Name)); e.Handled = true; }; @@ -1781,8 +1802,8 @@ namespace SourceGit.ViewModels rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Rebase(this, _currentBranch, branch)); + if (CanCreatePopup()) + ShowPopup(new Rebase(this, _currentBranch, branch)); e.Handled = true; }; @@ -1828,8 +1849,8 @@ namespace SourceGit.ViewModels delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteBranch(this, branch)); + if (CanCreatePopup()) + ShowPopup(new DeleteBranch(this, branch)); e.Handled = true; }; @@ -1838,8 +1859,8 @@ namespace SourceGit.ViewModels createBranch.Header = App.Text("CreateBranch"); createBranch.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateBranch(this, branch)); + if (CanCreatePopup()) + ShowPopup(new CreateBranch(this, branch)); e.Handled = true; }; @@ -1848,8 +1869,8 @@ namespace SourceGit.ViewModels createTag.Header = App.Text("CreateTag"); createTag.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateTag(this, branch)); + if (CanCreatePopup()) + ShowPopup(new CreateTag(this, branch)); e.Handled = true; }; @@ -1858,8 +1879,8 @@ namespace SourceGit.ViewModels archive.Header = App.Text("Archive"); archive.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Archive(this, branch)); + if (CanCreatePopup()) + ShowPopup(new Archive(this, branch)); e.Handled = true; }; @@ -1890,8 +1911,8 @@ namespace SourceGit.ViewModels createBranch.Header = App.Text("CreateBranch"); createBranch.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateBranch(this, tag)); + if (CanCreatePopup()) + ShowPopup(new CreateBranch(this, tag)); ev.Handled = true; }; @@ -1901,8 +1922,8 @@ namespace SourceGit.ViewModels pushTag.IsEnabled = _remotes.Count > 0; pushTag.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new PushTag(this, tag)); + if (CanCreatePopup()) + ShowPopup(new PushTag(this, tag)); ev.Handled = true; }; @@ -1911,8 +1932,8 @@ namespace SourceGit.ViewModels deleteTag.Icon = App.CreateMenuIcon("Icons.Clear"); deleteTag.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteTag(this, tag)); + if (CanCreatePopup()) + ShowPopup(new DeleteTag(this, tag)); ev.Handled = true; }; @@ -1921,8 +1942,8 @@ namespace SourceGit.ViewModels archive.Header = App.Text("Archive"); archive.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Archive(this, tag)); + if (CanCreatePopup()) + ShowPopup(new Archive(this, tag)); ev.Handled = true; }; @@ -1983,8 +2004,8 @@ namespace SourceGit.ViewModels rm.Icon = App.CreateMenuIcon("Icons.Clear"); rm.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteSubmodule(this, submodule)); + if (CanCreatePopup()) + ShowPopup(new DeleteSubmodule(this, submodule)); ev.Handled = true; }; @@ -2037,8 +2058,8 @@ namespace SourceGit.ViewModels remove.Icon = App.CreateMenuIcon("Icons.Clear"); remove.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new RemoveWorktree(this, worktree)); + if (CanCreatePopup()) + ShowPopup(new RemoveWorktree(this, worktree)); ev.Handled = true; }; menu.Items.Add(remove); @@ -2314,6 +2335,7 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); } + private LauncherPage _page = null; private string _fullpath = string.Empty; private string _gitDir = string.Empty; private Models.RepositorySettings _settings = null; diff --git a/src/ViewModels/RepositoryNode.cs b/src/ViewModels/RepositoryNode.cs index 7e121b36..cd79c06e 100644 --- a/src/ViewModels/RepositoryNode.cs +++ b/src/ViewModels/RepositoryNode.cs @@ -70,14 +70,16 @@ namespace SourceGit.ViewModels public void Edit() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new EditRepositoryNode(this)); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new EditRepositoryNode(this); } public void AddSubFolder() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateGroup(this)); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new CreateGroup(this); } public void OpenInFileManager() @@ -96,8 +98,9 @@ namespace SourceGit.ViewModels public void Delete() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DeleteRepositoryNode(this)); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new DeleteRepositoryNode(this); } private string _id = string.Empty; diff --git a/src/ViewModels/StashesPage.cs b/src/ViewModels/StashesPage.cs index 1e35d647..44223b6e 100644 --- a/src/ViewModels/StashesPage.cs +++ b/src/ViewModels/StashesPage.cs @@ -138,8 +138,8 @@ namespace SourceGit.ViewModels drop.Header = App.Text("StashCM.Drop"); drop.Click += (_, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new DropStash(_repo.FullPath, stash)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new DropStash(_repo.FullPath, stash)); ev.Handled = true; }; @@ -221,8 +221,8 @@ namespace SourceGit.ViewModels public void Clear() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new ClearStashes(_repo)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new ClearStashes(_repo)); } public void ClearSearchFilter() diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index 3645744f..08d81d44 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -87,12 +87,13 @@ namespace SourceGit.ViewModels { if (!Preference.Instance.IsGitConfigured()) { - App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured")); + App.RaiseException(string.Empty, App.Text("NotConfigured")); return; } - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Init(path, parent, reason)); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new Init(activePage.Node.Id, path, parent, reason); } public void Clone() @@ -103,14 +104,15 @@ namespace SourceGit.ViewModels return; } - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Clone()); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new Clone(activePage.Node.Id); } public void OpenTerminal() { if (!Preference.Instance.IsGitConfigured()) - App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured")); + App.RaiseException(string.Empty, App.Text("NotConfigured")); else Native.OS.OpenTerminal(null); } @@ -119,11 +121,20 @@ namespace SourceGit.ViewModels { var defaultCloneDir = Preference.Instance.GitDefaultCloneDir; if (string.IsNullOrEmpty(defaultCloneDir)) - App.RaiseException(PopupHost.Active.GetId(), "The default clone dir hasn't been configured!"); - else if (!Directory.Exists(defaultCloneDir)) - App.RaiseException(PopupHost.Active.GetId(), $"The default clone dir '{defaultCloneDir}' does not exist!"); - else if (PopupHost.CanCreatePopup()) - PopupHost.ShowAndStartPopup(new ScanRepositories(defaultCloneDir)); + { + App.RaiseException(string.Empty, "The default clone directory hasn't been configured!"); + return; + } + + if (!Directory.Exists(defaultCloneDir)) + { + App.RaiseException(string.Empty, $"The default clone directory '{defaultCloneDir}' does not exist!"); + return; + } + + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.StartPopup(new ScanRepositories(defaultCloneDir)); } public void ClearSearchFilter() @@ -133,8 +144,9 @@ namespace SourceGit.ViewModels public void AddRootNode() { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new CreateGroup(null)); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new CreateGroup(null); } public void MoveNode(RepositoryNode from, RepositoryNode to) @@ -224,8 +236,9 @@ namespace SourceGit.ViewModels move.Icon = App.CreateMenuIcon("Icons.MoveToAnotherGroup"); move.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new MoveRepositoryNode(node)); + var activePage = App.GetLauncer().ActivePage; + if (activePage != null && activePage.CanCreatePopup()) + activePage.Popup = new MoveRepositoryNode(node); e.Handled = true; }; diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index a1230715..bbefd77f 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -314,13 +314,13 @@ namespace SourceGit.ViewModels public void StashAll(bool autoStart) { - if (!PopupHost.CanCreatePopup()) + if (!_repo.CanCreatePopup()) return; if (autoStart) - PopupHost.ShowAndStartPopup(new StashChanges(_repo, _cached, false)); + _repo.ShowAndStartPopup(new StashChanges(_repo, _cached, false)); else - PopupHost.ShowPopup(new StashChanges(_repo, _cached, false)); + _repo.ShowPopup(new StashChanges(_repo, _cached, false)); } public void StageSelected(Models.Change next) @@ -405,12 +405,12 @@ namespace SourceGit.ViewModels public void Discard(List changes) { - if (PopupHost.CanCreatePopup()) + if (_repo.CanCreatePopup()) { if (changes.Count == _unstaged.Count && _staged.Count == 0) - PopupHost.ShowPopup(new Discard(_repo)); + _repo.ShowPopup(new Discard(_repo)); else - PopupHost.ShowPopup(new Discard(_repo, changes)); + _repo.ShowPopup(new Discard(_repo, changes)); } } @@ -666,8 +666,8 @@ namespace SourceGit.ViewModels stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true)); e.Handled = true; }; @@ -1008,8 +1008,8 @@ namespace SourceGit.ViewModels stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true)); e.Handled = true; }; @@ -1131,8 +1131,8 @@ namespace SourceGit.ViewModels stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new StashChanges(_repo, _selectedStaged, true)); e.Handled = true; }; @@ -1306,8 +1306,8 @@ namespace SourceGit.ViewModels stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Click += (_, e) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true)); + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new StashChanges(_repo, _selectedStaged, true)); e.Handled = true; }; @@ -1514,7 +1514,7 @@ namespace SourceGit.ViewModels private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty) { - if (!PopupHost.CanCreatePopup()) + if (!_repo.CanCreatePopup()) { App.RaiseException(_repo.FullPath, "Repository has unfinished job! Please wait!"); return; @@ -1560,7 +1560,7 @@ namespace SourceGit.ViewModels UseAmend = false; if (autoPush) - PopupHost.ShowAndStartPopup(new Push(_repo, null)); + _repo.ShowAndStartPopup(new Push(_repo, null)); } _repo.MarkBranchesDirtyManually(); diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 28cef62b..8b5142ad 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -845,12 +845,17 @@ namespace SourceGit.Views // CTRL/COMMAND + B -> shows Create Branch pop-up at selected commit. if (e.Key == Key.B) { - if (selected.Count == 1 && - selected[0] is Models.Commit commit && - DataContext is ViewModels.Histories histories && - ViewModels.PopupHost.CanCreatePopup()) + var repoView = this.FindAncestorOfType(); + if (repoView == null) + return; + + var repo = repoView.DataContext as ViewModels.Repository; + if (repo == null || !repo.CanCreatePopup()) + return; + + if (selected.Count == 1 && selected[0] is Models.Commit commit) { - ViewModels.PopupHost.ShowPopup(new ViewModels.CreateBranch(histories.Repo, commit)); + repo.ShowPopup(new ViewModels.CreateBranch(repo, commit)); e.Handled = true; } } diff --git a/src/Views/WelcomeToolbar.axaml.cs b/src/Views/WelcomeToolbar.axaml.cs index fc36e050..0a9e4822 100644 --- a/src/Views/WelcomeToolbar.axaml.cs +++ b/src/Views/WelcomeToolbar.axaml.cs @@ -17,7 +17,8 @@ namespace SourceGit.Views private async void OpenLocalRepository(object _1, RoutedEventArgs e) { - if (!ViewModels.PopupHost.CanCreatePopup()) + var activePage = App.GetLauncer().ActivePage; + if (activePage == null || !activePage.CanCreatePopup()) return; var topLevel = TopLevel.GetTopLevel(this);