refactor: merge ViewModels.PopupHost into ViewModels.LauncherPage

This commit is contained in:
leo 2025-01-08 21:36:49 +08:00
parent 0e34a77add
commit f06b1d5d51
No known key found for this signature in database
14 changed files with 342 additions and 344 deletions

View file

@ -53,8 +53,9 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _extraArgs, value); set => SetProperty(ref _extraArgs, value);
} }
public Clone() public Clone(string pageId)
{ {
_pageId = pageId;
View = new Views.Clone() { DataContext = this }; View = new Views.Clone() { DataContext = this };
Task.Run(async () => Task.Run(async () =>
@ -94,7 +95,7 @@ namespace SourceGit.ViewModels
return Task.Run(() => 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()) if (!cmd.Exec())
return false; return false;
@ -115,7 +116,7 @@ namespace SourceGit.ViewModels
{ {
CallUIThread(() => CallUIThread(() =>
{ {
App.RaiseException(HostPageId, $"Folder '{path}' can NOT be found"); App.RaiseException(_pageId, $"Folder '{path}' can NOT be found");
}); });
return false; return false;
} }
@ -134,7 +135,7 @@ namespace SourceGit.ViewModels
var page = null as LauncherPage; var page = null as LauncherPage;
foreach (var one in launcher.Pages) foreach (var one in launcher.Pages)
{ {
if (one.GetId() == HostPageId) if (one.Node.Id == _pageId)
{ {
page = one; page = one;
break; break;
@ -149,6 +150,7 @@ namespace SourceGit.ViewModels
}); });
} }
private string _pageId = string.Empty;
private string _remote = string.Empty; private string _remote = string.Empty;
private bool _useSSH = false; private bool _useSSH = false;
private string _sshKey = string.Empty; private string _sshKey = string.Empty;

View file

@ -209,12 +209,12 @@ namespace SourceGit.ViewModels
} }
} }
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
{ {
if (firstRemoteBranch != null) if (firstRemoteBranch != null)
PopupHost.ShowPopup(new CreateBranch(_repo, firstRemoteBranch)); _repo.ShowPopup(new CreateBranch(_repo, firstRemoteBranch));
else 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.Icon = App.CreateMenuIcon("Icons.CherryPick");
cherryPickMultiple.Click += (_, e) => cherryPickMultiple.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new CherryPick(_repo, selected)); _repo.ShowPopup(new CherryPick(_repo, selected));
e.Handled = true; e.Handled = true;
}; };
multipleMenu.Items.Add(cherryPickMultiple); multipleMenu.Items.Add(cherryPickMultiple);
@ -274,8 +274,8 @@ namespace SourceGit.ViewModels
mergeMultiple.Icon = App.CreateMenuIcon("Icons.Merge"); mergeMultiple.Icon = App.CreateMenuIcon("Icons.Merge");
mergeMultiple.Click += (_, e) => mergeMultiple.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new MergeMultiple(_repo, selected)); _repo.ShowPopup(new MergeMultiple(_repo, selected));
e.Handled = true; e.Handled = true;
}; };
multipleMenu.Items.Add(mergeMultiple); multipleMenu.Items.Add(mergeMultiple);
@ -401,8 +401,8 @@ namespace SourceGit.ViewModels
reset.Icon = App.CreateMenuIcon("Icons.Reset"); reset.Icon = App.CreateMenuIcon("Icons.Reset");
reset.Click += (_, e) => reset.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Reset(_repo, current, commit)); _repo.ShowPopup(new Reset(_repo, current, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(reset); menu.Items.Add(reset);
@ -420,8 +420,8 @@ namespace SourceGit.ViewModels
return; return;
} }
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Squash(_repo, commit, commit.SHA)); _repo.ShowPopup(new Squash(_repo, commit, commit.SHA));
e.Handled = true; e.Handled = true;
}; };
@ -441,8 +441,8 @@ namespace SourceGit.ViewModels
return; return;
} }
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Reword(_repo, commit)); _repo.ShowPopup(new Reword(_repo, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(reword); menu.Items.Add(reword);
@ -462,8 +462,8 @@ namespace SourceGit.ViewModels
if (commit.Parents.Count == 1) if (commit.Parents.Count == 1)
{ {
var parent = _commits.Find(x => x.SHA == commit.Parents[0]); var parent = _commits.Find(x => x.SHA == commit.Parents[0]);
if (parent != null && PopupHost.CanCreatePopup()) if (parent != null && _repo.CanCreatePopup())
PopupHost.ShowPopup(new Squash(_repo, parent, commit.SHA)); _repo.ShowPopup(new Squash(_repo, parent, commit.SHA));
} }
e.Handled = true; e.Handled = true;
@ -478,8 +478,8 @@ namespace SourceGit.ViewModels
rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
rebase.Click += (_, e) => rebase.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Rebase(_repo, current, commit)); _repo.ShowPopup(new Rebase(_repo, current, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(rebase); menu.Items.Add(rebase);
@ -491,8 +491,8 @@ namespace SourceGit.ViewModels
merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.Click += (_, e) => merge.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Merge(_repo, commit, current.Name)); _repo.ShowPopup(new Merge(_repo, commit, current.Name));
e.Handled = true; e.Handled = true;
}; };
@ -504,11 +504,11 @@ namespace SourceGit.ViewModels
cherryPick.Icon = App.CreateMenuIcon("Icons.CherryPick"); cherryPick.Icon = App.CreateMenuIcon("Icons.CherryPick");
cherryPick.Click += (_, e) => cherryPick.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
{ {
if (commit.Parents.Count <= 1) if (commit.Parents.Count <= 1)
{ {
PopupHost.ShowPopup(new CherryPick(_repo, [commit])); _repo.ShowPopup(new CherryPick(_repo, [commit]));
} }
else else
{ {
@ -523,7 +523,7 @@ namespace SourceGit.ViewModels
parents.Add(parent); 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.Icon = App.CreateMenuIcon("Icons.Undo");
revert.Click += (_, e) => revert.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Revert(_repo, commit)); _repo.ShowPopup(new Revert(_repo, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(revert); menu.Items.Add(revert);
@ -552,8 +552,8 @@ namespace SourceGit.ViewModels
checkoutCommit.Icon = App.CreateMenuIcon("Icons.Detached"); checkoutCommit.Icon = App.CreateMenuIcon("Icons.Detached");
checkoutCommit.Click += (_, e) => checkoutCommit.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new CheckoutCommit(_repo, commit)); _repo.ShowPopup(new CheckoutCommit(_repo, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(checkoutCommit); menu.Items.Add(checkoutCommit);
@ -630,8 +630,8 @@ namespace SourceGit.ViewModels
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (_, e) => createBranch.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new CreateBranch(_repo, commit)); _repo.ShowPopup(new CreateBranch(_repo, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(createBranch); menu.Items.Add(createBranch);
@ -641,8 +641,8 @@ namespace SourceGit.ViewModels
createTag.Header = App.Text("CreateTag"); createTag.Header = App.Text("CreateTag");
createTag.Click += (_, e) => createTag.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new CreateTag(_repo, commit)); _repo.ShowPopup(new CreateTag(_repo, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(createTag); menu.Items.Add(createTag);
@ -683,8 +683,8 @@ namespace SourceGit.ViewModels
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (_, e) => archive.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Archive(_repo, commit)); _repo.ShowPopup(new Archive(_repo, commit));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(archive); menu.Items.Add(archive);
@ -710,8 +710,8 @@ namespace SourceGit.ViewModels
item.Header = dup.Name; item.Header = dup.Name;
item.Click += (_, e) => item.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowAndStartPopup(new ExecuteCustomAction(_repo, dup, commit)); _repo.ShowAndStartPopup(new ExecuteCustomAction(_repo, dup, commit));
e.Handled = true; e.Handled = true;
}; };
@ -871,8 +871,8 @@ namespace SourceGit.ViewModels
if (b == null) if (b == null)
return; return;
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowAndStartPopup(new Merge(_repo, b, current.Name)); _repo.ShowAndStartPopup(new Merge(_repo, b, current.Name));
e.Handled = true; e.Handled = true;
}; };
@ -883,8 +883,8 @@ namespace SourceGit.ViewModels
pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.Click += (_, e) => pull.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Pull(_repo, null)); _repo.ShowPopup(new Pull(_repo, null));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(pull); submenu.Items.Add(pull);
@ -896,8 +896,8 @@ namespace SourceGit.ViewModels
push.IsEnabled = _repo.Remotes.Count > 0; push.IsEnabled = _repo.Remotes.Count > 0;
push.Click += (_, e) => push.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Push(_repo, current)); _repo.ShowPopup(new Push(_repo, current));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(push); submenu.Items.Add(push);
@ -907,8 +907,8 @@ namespace SourceGit.ViewModels
rename.Icon = App.CreateMenuIcon("Icons.Rename"); rename.Icon = App.CreateMenuIcon("Icons.Rename");
rename.Click += (_, e) => rename.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new RenameBranch(_repo, current)); _repo.ShowPopup(new RenameBranch(_repo, current));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(rename); submenu.Items.Add(rename);
@ -922,8 +922,8 @@ namespace SourceGit.ViewModels
finish.Icon = App.CreateMenuIcon("Icons.GitFlow"); finish.Icon = App.CreateMenuIcon("Icons.GitFlow");
finish.Click += (_, e) => finish.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new GitFlowFinish(_repo, current, detect.Type, detect.Prefix)); _repo.ShowPopup(new GitFlowFinish(_repo, current, detect.Type, detect.Prefix));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(finish); submenu.Items.Add(finish);
@ -967,8 +967,8 @@ namespace SourceGit.ViewModels
merge.IsEnabled = !merged; merge.IsEnabled = !merged;
merge.Click += (_, e) => merge.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Merge(_repo, branch, current.Name)); _repo.ShowPopup(new Merge(_repo, branch, current.Name));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(merge); submenu.Items.Add(merge);
@ -978,8 +978,8 @@ namespace SourceGit.ViewModels
rename.Icon = App.CreateMenuIcon("Icons.Rename"); rename.Icon = App.CreateMenuIcon("Icons.Rename");
rename.Click += (_, e) => rename.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new RenameBranch(_repo, branch)); _repo.ShowPopup(new RenameBranch(_repo, branch));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(rename); submenu.Items.Add(rename);
@ -989,8 +989,8 @@ namespace SourceGit.ViewModels
delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (_, e) => delete.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new DeleteBranch(_repo, branch)); _repo.ShowPopup(new DeleteBranch(_repo, branch));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(delete); submenu.Items.Add(delete);
@ -1004,8 +1004,8 @@ namespace SourceGit.ViewModels
finish.Icon = App.CreateMenuIcon("Icons.GitFlow"); finish.Icon = App.CreateMenuIcon("Icons.GitFlow");
finish.Click += (_, e) => finish.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new GitFlowFinish(_repo, branch, detect.Type, detect.Prefix)); _repo.ShowPopup(new GitFlowFinish(_repo, branch, detect.Type, detect.Prefix));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(finish); submenu.Items.Add(finish);
@ -1051,8 +1051,8 @@ namespace SourceGit.ViewModels
merge.IsEnabled = !merged; merge.IsEnabled = !merged;
merge.Click += (_, e) => merge.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Merge(_repo, branch, current.Name)); _repo.ShowPopup(new Merge(_repo, branch, current.Name));
e.Handled = true; e.Handled = true;
}; };
@ -1063,8 +1063,8 @@ namespace SourceGit.ViewModels
delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (_, e) => delete.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new DeleteBranch(_repo, branch)); _repo.ShowPopup(new DeleteBranch(_repo, branch));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(delete); submenu.Items.Add(delete);
@ -1098,8 +1098,8 @@ namespace SourceGit.ViewModels
push.IsEnabled = _repo.Remotes.Count > 0; push.IsEnabled = _repo.Remotes.Count > 0;
push.Click += (_, e) => push.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new PushTag(_repo, tag)); _repo.ShowPopup(new PushTag(_repo, tag));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(push); submenu.Items.Add(push);
@ -1110,8 +1110,8 @@ namespace SourceGit.ViewModels
merge.IsEnabled = !merged; merge.IsEnabled = !merged;
merge.Click += (_, e) => merge.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new Merge(_repo, tag, current.Name)); _repo.ShowPopup(new Merge(_repo, tag, current.Name));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(merge); submenu.Items.Add(merge);
@ -1121,8 +1121,8 @@ namespace SourceGit.ViewModels
delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (_, e) => delete.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new DeleteTag(_repo, tag)); _repo.ShowPopup(new DeleteTag(_repo, tag));
e.Handled = true; e.Handled = true;
}; };
submenu.Items.Add(delete); submenu.Items.Add(delete);

View file

@ -16,8 +16,9 @@ namespace SourceGit.ViewModels
private set; private set;
} }
public Init(string path, RepositoryNode parent, string reason) public Init(string pageId, string path, RepositoryNode parent, string reason)
{ {
_pageId = pageId;
_targetPath = path; _targetPath = path;
_parentNode = parent; _parentNode = parent;
@ -31,7 +32,7 @@ namespace SourceGit.ViewModels
return Task.Run(() => return Task.Run(() =>
{ {
var succ = new Commands.Init(HostPageId, _targetPath).Exec(); var succ = new Commands.Init(_pageId, _targetPath).Exec();
if (!succ) if (!succ)
return false; return false;
@ -46,6 +47,7 @@ namespace SourceGit.ViewModels
}); });
} }
private string _pageId = null;
private string _targetPath = null; private string _targetPath = null;
private RepositoryNode _parentNode = null; private RepositoryNode _parentNode = null;
} }

View file

@ -36,7 +36,6 @@ namespace SourceGit.ViewModels
{ {
if (SetProperty(ref _activePage, value)) if (SetProperty(ref _activePage, value))
{ {
PopupHost.Active = value;
UpdateTitle(); UpdateTitle();
if (!_ignoreIndexChange && value is { Data: Repository repo }) if (!_ignoreIndexChange && value is { Data: Repository repo })
@ -295,7 +294,6 @@ namespace SourceGit.ViewModels
FullPath = node.Id, FullPath = node.Id,
GitDir = gitDir, GitDir = gitDir,
}; };
repo.Open(); repo.Open();
if (page == null) if (page == null)
@ -318,6 +316,8 @@ namespace SourceGit.ViewModels
page.Data = repo; page.Data = repo;
} }
repo.SetOwnerPage(page);
if (page != _activePage) if (page != _activePage)
ActivePage = page; ActivePage = page;
else else
@ -475,7 +475,7 @@ namespace SourceGit.ViewModels
{ {
foreach (var one in Pages) 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!!!"); App.RaiseException(null, "You have unfinished task(s) in opened pages. Please wait!!!");
return; return;

View file

@ -1,10 +1,10 @@
using System; using System;
using Avalonia.Collections; using Avalonia.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
{ {
public class LauncherPage : PopupHost public class LauncherPage : ObservableObject
{ {
public RepositoryNode Node public RepositoryNode Node
{ {
@ -18,6 +18,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _data, value); set => SetProperty(ref _data, value);
} }
public Popup Popup
{
get => _popup;
set => SetProperty(ref _popup, value);
}
public AvaloniaList<Models.Notification> Notifications public AvaloniaList<Models.Notification> Notifications
{ {
get; get;
@ -39,26 +45,59 @@ namespace SourceGit.ViewModels
_data = repo; _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() public void CopyPath()
{ {
if (_node.IsRepository) if (_node.IsRepository)
App.CopyText(_node.Id); 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 RepositoryNode _node = null;
private object _data = null; private object _data = null;
private Popup _popup = null;
} }
} }

View file

@ -10,12 +10,6 @@ namespace SourceGit.ViewModels
{ {
public class Popup : ObservableValidator public class Popup : ObservableValidator
{ {
public string HostPageId
{
get;
set;
}
public object View public object View
{ {
get; get;

View file

@ -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;
}
}

View file

@ -493,6 +493,7 @@ namespace SourceGit.ViewModels
public void Close() public void Close()
{ {
_page = null;
SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect
var settingsSerialized = JsonSerializer.Serialize(_settings, JsonCodeGen.Default.RepositorySettings); var settingsSerialized = JsonSerializer.Serialize(_settings, JsonCodeGen.Default.RepositorySettings);
@ -537,6 +538,26 @@ namespace SourceGit.ViewModels
SearchCommitFilterSuggestion.Clear(); 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() public void RefreshAll()
{ {
Task.Run(() => Task.Run(() =>
@ -598,7 +619,7 @@ namespace SourceGit.ViewModels
public void Fetch(bool autoStart) public void Fetch(bool autoStart)
{ {
if (!PopupHost.CanCreatePopup()) if (!CanCreatePopup())
return; return;
if (_remotes.Count == 0) if (_remotes.Count == 0)
@ -608,14 +629,14 @@ namespace SourceGit.ViewModels
} }
if (autoStart) if (autoStart)
PopupHost.ShowAndStartPopup(new Fetch(this)); ShowAndStartPopup(new Fetch(this));
else else
PopupHost.ShowPopup(new Fetch(this)); ShowPopup(new Fetch(this));
} }
public void Pull(bool autoStart) public void Pull(bool autoStart)
{ {
if (!PopupHost.CanCreatePopup()) if (!CanCreatePopup())
return; return;
if (_remotes.Count == 0) if (_remotes.Count == 0)
@ -626,14 +647,14 @@ namespace SourceGit.ViewModels
var pull = new Pull(this, null); var pull = new Pull(this, null);
if (autoStart && pull.SelectedBranch != null) if (autoStart && pull.SelectedBranch != null)
PopupHost.ShowAndStartPopup(pull); ShowAndStartPopup(pull);
else else
PopupHost.ShowPopup(pull); ShowPopup(pull);
} }
public void Push(bool autoStart) public void Push(bool autoStart)
{ {
if (!PopupHost.CanCreatePopup()) if (!CanCreatePopup())
return; return;
if (_remotes.Count == 0) if (_remotes.Count == 0)
@ -649,23 +670,23 @@ namespace SourceGit.ViewModels
} }
if (autoStart) if (autoStart)
PopupHost.ShowAndStartPopup(new Push(this, null)); ShowAndStartPopup(new Push(this, null));
else else
PopupHost.ShowPopup(new Push(this, null)); ShowPopup(new Push(this, null));
} }
public void ApplyPatch() public void ApplyPatch()
{ {
if (!PopupHost.CanCreatePopup()) if (!CanCreatePopup())
return; return;
PopupHost.ShowPopup(new Apply(this)); ShowPopup(new Apply(this));
} }
public void Cleanup() public void Cleanup()
{ {
if (!PopupHost.CanCreatePopup()) if (!CanCreatePopup())
return; return;
PopupHost.ShowAndStartPopup(new Cleanup(this)); ShowAndStartPopup(new Cleanup(this));
} }
public void ClearFilter() public void ClearFilter()
@ -1007,8 +1028,8 @@ namespace SourceGit.ViewModels
return; return;
} }
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateBranch(this, _currentBranch)); ShowPopup(new CreateBranch(this, _currentBranch));
} }
public void CheckoutBranch(Models.Branch branch) public void CheckoutBranch(Models.Branch branch)
@ -1023,15 +1044,15 @@ namespace SourceGit.ViewModels
} }
} }
if (!PopupHost.CanCreatePopup()) if (!CanCreatePopup())
return; return;
if (branch.IsLocal) if (branch.IsLocal)
{ {
if (_localChangesCount > 0) if (_localChangesCount > 0)
PopupHost.ShowPopup(new Checkout(this, branch.Name)); ShowPopup(new Checkout(this, branch.Name));
else else
PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name)); ShowAndStartPopup(new Checkout(this, branch.Name));
} }
else else
{ {
@ -1046,20 +1067,20 @@ namespace SourceGit.ViewModels
} }
} }
PopupHost.ShowPopup(new CreateBranch(this, branch)); ShowPopup(new CreateBranch(this, branch));
} }
} }
public void DeleteMultipleBranches(List<Models.Branch> branches, bool isLocal) public void DeleteMultipleBranches(List<Models.Branch> branches, bool isLocal)
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new DeleteMultipleBranches(this, branches, isLocal)); ShowPopup(new DeleteMultipleBranches(this, branches, isLocal));
} }
public void MergeMultipleBranches(List<Models.Branch> branches) public void MergeMultipleBranches(List<Models.Branch> branches)
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new MergeMultiple(this, branches)); ShowPopup(new MergeMultiple(this, branches));
} }
public void CreateNewTag() public void CreateNewTag()
@ -1070,26 +1091,26 @@ namespace SourceGit.ViewModels
return; return;
} }
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateTag(this, _currentBranch)); ShowPopup(new CreateTag(this, _currentBranch));
} }
public void AddRemote() public void AddRemote()
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new AddRemote(this)); ShowPopup(new AddRemote(this));
} }
public void AddSubmodule() public void AddSubmodule()
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new AddSubmodule(this)); ShowPopup(new AddSubmodule(this));
} }
public void UpdateSubmodules() public void UpdateSubmodules()
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new UpdateSubmodules(this)); ShowPopup(new UpdateSubmodules(this));
} }
public void OpenSubmodule(string submodule) public void OpenSubmodule(string submodule)
@ -1114,14 +1135,14 @@ namespace SourceGit.ViewModels
public void AddWorktree() public void AddWorktree()
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new AddWorktree(this)); ShowPopup(new AddWorktree(this));
} }
public void PruneWorktrees() public void PruneWorktrees()
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new PruneWorktrees(this)); ShowAndStartPopup(new PruneWorktrees(this));
} }
public void OpenWorktree(Models.Worktree worktree) public void OpenWorktree(Models.Worktree worktree)
@ -1154,8 +1175,8 @@ namespace SourceGit.ViewModels
startFeature.Icon = App.CreateMenuIcon("Icons.GitFlow.Feature"); startFeature.Icon = App.CreateMenuIcon("Icons.GitFlow.Feature");
startFeature.Click += (_, e) => startFeature.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new GitFlowStart(this, "feature")); ShowPopup(new GitFlowStart(this, "feature"));
e.Handled = true; e.Handled = true;
}; };
@ -1164,8 +1185,8 @@ namespace SourceGit.ViewModels
startRelease.Icon = App.CreateMenuIcon("Icons.GitFlow.Release"); startRelease.Icon = App.CreateMenuIcon("Icons.GitFlow.Release");
startRelease.Click += (_, e) => startRelease.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new GitFlowStart(this, "release")); ShowPopup(new GitFlowStart(this, "release"));
e.Handled = true; e.Handled = true;
}; };
@ -1174,8 +1195,8 @@ namespace SourceGit.ViewModels
startHotfix.Icon = App.CreateMenuIcon("Icons.GitFlow.Hotfix"); startHotfix.Icon = App.CreateMenuIcon("Icons.GitFlow.Hotfix");
startHotfix.Click += (_, e) => startHotfix.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new GitFlowStart(this, "hotfix")); ShowPopup(new GitFlowStart(this, "hotfix"));
e.Handled = true; e.Handled = true;
}; };
@ -1190,8 +1211,8 @@ namespace SourceGit.ViewModels
init.Icon = App.CreateMenuIcon("Icons.Init"); init.Icon = App.CreateMenuIcon("Icons.Init");
init.Click += (_, e) => init.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new InitGitFlow(this)); ShowPopup(new InitGitFlow(this));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(init); menu.Items.Add(init);
@ -1212,8 +1233,8 @@ namespace SourceGit.ViewModels
addPattern.Icon = App.CreateMenuIcon("Icons.File.Add"); addPattern.Icon = App.CreateMenuIcon("Icons.File.Add");
addPattern.Click += (_, e) => addPattern.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new LFSTrackCustomPattern(this)); ShowPopup(new LFSTrackCustomPattern(this));
e.Handled = true; e.Handled = true;
}; };
@ -1226,12 +1247,12 @@ namespace SourceGit.ViewModels
fetch.IsEnabled = _remotes.Count > 0; fetch.IsEnabled = _remotes.Count > 0;
fetch.Click += (_, e) => fetch.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
{ {
if (_remotes.Count == 1) if (_remotes.Count == 1)
PopupHost.ShowAndStartPopup(new LFSFetch(this)); ShowAndStartPopup(new LFSFetch(this));
else else
PopupHost.ShowPopup(new LFSFetch(this)); ShowPopup(new LFSFetch(this));
} }
e.Handled = true; e.Handled = true;
@ -1244,12 +1265,12 @@ namespace SourceGit.ViewModels
pull.IsEnabled = _remotes.Count > 0; pull.IsEnabled = _remotes.Count > 0;
pull.Click += (_, e) => pull.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
{ {
if (_remotes.Count == 1) if (_remotes.Count == 1)
PopupHost.ShowAndStartPopup(new LFSPull(this)); ShowAndStartPopup(new LFSPull(this));
else else
PopupHost.ShowPopup(new LFSPull(this)); ShowPopup(new LFSPull(this));
} }
e.Handled = true; e.Handled = true;
@ -1262,12 +1283,12 @@ namespace SourceGit.ViewModels
push.IsEnabled = _remotes.Count > 0; push.IsEnabled = _remotes.Count > 0;
push.Click += (_, e) => push.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
{ {
if (_remotes.Count == 1) if (_remotes.Count == 1)
PopupHost.ShowAndStartPopup(new LFSPush(this)); ShowAndStartPopup(new LFSPush(this));
else else
PopupHost.ShowPopup(new LFSPush(this)); ShowPopup(new LFSPush(this));
} }
e.Handled = true; e.Handled = true;
@ -1279,8 +1300,8 @@ namespace SourceGit.ViewModels
prune.Icon = App.CreateMenuIcon("Icons.Clean"); prune.Icon = App.CreateMenuIcon("Icons.Clean");
prune.Click += (_, e) => prune.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new LFSPrune(this)); ShowAndStartPopup(new LFSPrune(this));
e.Handled = true; e.Handled = true;
}; };
@ -1361,8 +1382,8 @@ namespace SourceGit.ViewModels
item.Header = dup.Name; item.Header = dup.Name;
item.Click += (_, e) => item.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new ExecuteCustomAction(this, dup, null)); ShowAndStartPopup(new ExecuteCustomAction(this, dup, null));
e.Handled = true; e.Handled = true;
}; };
@ -1388,8 +1409,8 @@ namespace SourceGit.ViewModels
push.IsEnabled = _remotes.Count > 0; push.IsEnabled = _remotes.Count > 0;
push.Click += (_, e) => push.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Push(this, branch)); ShowPopup(new Push(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1400,8 +1421,8 @@ namespace SourceGit.ViewModels
discard.Icon = App.CreateMenuIcon("Icons.Undo"); discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.Click += (_, e) => discard.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Discard(this)); ShowPopup(new Discard(this));
e.Handled = true; e.Handled = true;
}; };
@ -1421,8 +1442,8 @@ namespace SourceGit.ViewModels
if (b == null) if (b == null)
return; return;
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new Merge(this, b, branch.Name)); ShowAndStartPopup(new Merge(this, b, branch.Name));
e.Handled = true; e.Handled = true;
}; };
@ -1432,8 +1453,8 @@ namespace SourceGit.ViewModels
pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.Click += (_, e) => pull.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Pull(this, null)); ShowPopup(new Pull(this, null));
e.Handled = true; e.Handled = true;
}; };
@ -1473,8 +1494,8 @@ namespace SourceGit.ViewModels
fastForward.IsEnabled = branch.TrackStatus.Ahead.Count == 0; fastForward.IsEnabled = branch.TrackStatus.Ahead.Count == 0;
fastForward.Click += (_, e) => fastForward.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new FastForwardWithoutCheckout(this, branch, upstream)); ShowAndStartPopup(new FastForwardWithoutCheckout(this, branch, upstream));
e.Handled = true; e.Handled = true;
}; };
@ -1484,8 +1505,8 @@ namespace SourceGit.ViewModels
fetchInto.IsEnabled = branch.TrackStatus.Ahead.Count == 0; fetchInto.IsEnabled = branch.TrackStatus.Ahead.Count == 0;
fetchInto.Click += (_, e) => fetchInto.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new FetchInto(this, branch, upstream)); ShowAndStartPopup(new FetchInto(this, branch, upstream));
e.Handled = true; e.Handled = true;
}; };
@ -1501,8 +1522,8 @@ namespace SourceGit.ViewModels
merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.Click += (_, e) => merge.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Merge(this, branch, _currentBranch.Name)); ShowPopup(new Merge(this, branch, _currentBranch.Name));
e.Handled = true; e.Handled = true;
}; };
@ -1511,8 +1532,8 @@ namespace SourceGit.ViewModels
rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
rebase.Click += (_, e) => rebase.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Rebase(this, _currentBranch, branch)); ShowPopup(new Rebase(this, _currentBranch, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1557,8 +1578,8 @@ namespace SourceGit.ViewModels
finish.Icon = App.CreateMenuIcon("Icons.GitFlow"); finish.Icon = App.CreateMenuIcon("Icons.GitFlow");
finish.Click += (_, e) => finish.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new GitFlowFinish(this, branch, detect.Type, detect.Prefix)); ShowPopup(new GitFlowFinish(this, branch, detect.Type, detect.Prefix));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });
@ -1570,8 +1591,8 @@ namespace SourceGit.ViewModels
rename.Icon = App.CreateMenuIcon("Icons.Rename"); rename.Icon = App.CreateMenuIcon("Icons.Rename");
rename.Click += (_, e) => rename.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new RenameBranch(this, branch)); ShowPopup(new RenameBranch(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1581,8 +1602,8 @@ namespace SourceGit.ViewModels
delete.IsEnabled = !branch.IsCurrent; delete.IsEnabled = !branch.IsCurrent;
delete.Click += (_, e) => delete.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new DeleteBranch(this, branch)); ShowPopup(new DeleteBranch(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1591,8 +1612,8 @@ namespace SourceGit.ViewModels
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (_, e) => createBranch.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateBranch(this, branch)); ShowPopup(new CreateBranch(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1601,8 +1622,8 @@ namespace SourceGit.ViewModels
createTag.Header = App.Text("CreateTag"); createTag.Header = App.Text("CreateTag");
createTag.Click += (_, e) => createTag.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateTag(this, branch)); ShowPopup(new CreateTag(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1628,8 +1649,8 @@ namespace SourceGit.ViewModels
tracking.Icon = App.CreateMenuIcon("Icons.Track"); tracking.Icon = App.CreateMenuIcon("Icons.Track");
tracking.Click += (_, e) => tracking.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new SetUpstream(this, branch, remoteBranches)); ShowPopup(new SetUpstream(this, branch, remoteBranches));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(tracking); menu.Items.Add(tracking);
@ -1640,8 +1661,8 @@ namespace SourceGit.ViewModels
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (_, e) => archive.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Archive(this, branch)); ShowPopup(new Archive(this, branch));
e.Handled = true; e.Handled = true;
}; };
menu.Items.Add(archive); menu.Items.Add(archive);
@ -1684,8 +1705,8 @@ namespace SourceGit.ViewModels
fetch.Icon = App.CreateMenuIcon("Icons.Fetch"); fetch.Icon = App.CreateMenuIcon("Icons.Fetch");
fetch.Click += (_, e) => fetch.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new Fetch(this, remote)); ShowAndStartPopup(new Fetch(this, remote));
e.Handled = true; e.Handled = true;
}; };
@ -1694,8 +1715,8 @@ namespace SourceGit.ViewModels
prune.Icon = App.CreateMenuIcon("Icons.Clean"); prune.Icon = App.CreateMenuIcon("Icons.Clean");
prune.Click += (_, e) => prune.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowAndStartPopup(new PruneRemote(this, remote)); ShowAndStartPopup(new PruneRemote(this, remote));
e.Handled = true; e.Handled = true;
}; };
@ -1704,8 +1725,8 @@ namespace SourceGit.ViewModels
edit.Icon = App.CreateMenuIcon("Icons.Edit"); edit.Icon = App.CreateMenuIcon("Icons.Edit");
edit.Click += (_, e) => edit.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new EditRemote(this, remote)); ShowPopup(new EditRemote(this, remote));
e.Handled = true; e.Handled = true;
}; };
@ -1714,8 +1735,8 @@ namespace SourceGit.ViewModels
delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (_, e) => delete.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new DeleteRemote(this, remote)); ShowPopup(new DeleteRemote(this, remote));
e.Handled = true; e.Handled = true;
}; };
@ -1761,8 +1782,8 @@ namespace SourceGit.ViewModels
pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.Click += (_, e) => pull.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Pull(this, branch)); ShowPopup(new Pull(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1771,8 +1792,8 @@ namespace SourceGit.ViewModels
merge.Icon = App.CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.Click += (_, e) => merge.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Merge(this, branch, _currentBranch.Name)); ShowPopup(new Merge(this, branch, _currentBranch.Name));
e.Handled = true; e.Handled = true;
}; };
@ -1781,8 +1802,8 @@ namespace SourceGit.ViewModels
rebase.Icon = App.CreateMenuIcon("Icons.Rebase"); rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
rebase.Click += (_, e) => rebase.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Rebase(this, _currentBranch, branch)); ShowPopup(new Rebase(this, _currentBranch, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1828,8 +1849,8 @@ namespace SourceGit.ViewModels
delete.Icon = App.CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (_, e) => delete.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new DeleteBranch(this, branch)); ShowPopup(new DeleteBranch(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1838,8 +1859,8 @@ namespace SourceGit.ViewModels
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (_, e) => createBranch.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateBranch(this, branch)); ShowPopup(new CreateBranch(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1848,8 +1869,8 @@ namespace SourceGit.ViewModels
createTag.Header = App.Text("CreateTag"); createTag.Header = App.Text("CreateTag");
createTag.Click += (_, e) => createTag.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateTag(this, branch)); ShowPopup(new CreateTag(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1858,8 +1879,8 @@ namespace SourceGit.ViewModels
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (_, e) => archive.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Archive(this, branch)); ShowPopup(new Archive(this, branch));
e.Handled = true; e.Handled = true;
}; };
@ -1890,8 +1911,8 @@ namespace SourceGit.ViewModels
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (_, ev) => createBranch.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new CreateBranch(this, tag)); ShowPopup(new CreateBranch(this, tag));
ev.Handled = true; ev.Handled = true;
}; };
@ -1901,8 +1922,8 @@ namespace SourceGit.ViewModels
pushTag.IsEnabled = _remotes.Count > 0; pushTag.IsEnabled = _remotes.Count > 0;
pushTag.Click += (_, ev) => pushTag.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new PushTag(this, tag)); ShowPopup(new PushTag(this, tag));
ev.Handled = true; ev.Handled = true;
}; };
@ -1911,8 +1932,8 @@ namespace SourceGit.ViewModels
deleteTag.Icon = App.CreateMenuIcon("Icons.Clear"); deleteTag.Icon = App.CreateMenuIcon("Icons.Clear");
deleteTag.Click += (_, ev) => deleteTag.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new DeleteTag(this, tag)); ShowPopup(new DeleteTag(this, tag));
ev.Handled = true; ev.Handled = true;
}; };
@ -1921,8 +1942,8 @@ namespace SourceGit.ViewModels
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (_, ev) => archive.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new Archive(this, tag)); ShowPopup(new Archive(this, tag));
ev.Handled = true; ev.Handled = true;
}; };
@ -1983,8 +2004,8 @@ namespace SourceGit.ViewModels
rm.Icon = App.CreateMenuIcon("Icons.Clear"); rm.Icon = App.CreateMenuIcon("Icons.Clear");
rm.Click += (_, ev) => rm.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new DeleteSubmodule(this, submodule)); ShowPopup(new DeleteSubmodule(this, submodule));
ev.Handled = true; ev.Handled = true;
}; };
@ -2037,8 +2058,8 @@ namespace SourceGit.ViewModels
remove.Icon = App.CreateMenuIcon("Icons.Clear"); remove.Icon = App.CreateMenuIcon("Icons.Clear");
remove.Click += (_, ev) => remove.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (CanCreatePopup())
PopupHost.ShowPopup(new RemoveWorktree(this, worktree)); ShowPopup(new RemoveWorktree(this, worktree));
ev.Handled = true; ev.Handled = true;
}; };
menu.Items.Add(remove); menu.Items.Add(remove);
@ -2314,6 +2335,7 @@ namespace SourceGit.ViewModels
Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); Dispatcher.UIThread.Invoke(() => IsAutoFetching = false);
} }
private LauncherPage _page = null;
private string _fullpath = string.Empty; private string _fullpath = string.Empty;
private string _gitDir = string.Empty; private string _gitDir = string.Empty;
private Models.RepositorySettings _settings = null; private Models.RepositorySettings _settings = null;

View file

@ -70,14 +70,16 @@ namespace SourceGit.ViewModels
public void Edit() public void Edit()
{ {
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new EditRepositoryNode(this)); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new EditRepositoryNode(this);
} }
public void AddSubFolder() public void AddSubFolder()
{ {
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new CreateGroup(this)); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new CreateGroup(this);
} }
public void OpenInFileManager() public void OpenInFileManager()
@ -96,8 +98,9 @@ namespace SourceGit.ViewModels
public void Delete() public void Delete()
{ {
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new DeleteRepositoryNode(this)); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new DeleteRepositoryNode(this);
} }
private string _id = string.Empty; private string _id = string.Empty;

View file

@ -138,8 +138,8 @@ namespace SourceGit.ViewModels
drop.Header = App.Text("StashCM.Drop"); drop.Header = App.Text("StashCM.Drop");
drop.Click += (_, ev) => drop.Click += (_, ev) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new DropStash(_repo.FullPath, stash)); _repo.ShowPopup(new DropStash(_repo.FullPath, stash));
ev.Handled = true; ev.Handled = true;
}; };
@ -221,8 +221,8 @@ namespace SourceGit.ViewModels
public void Clear() public void Clear()
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new ClearStashes(_repo)); _repo.ShowPopup(new ClearStashes(_repo));
} }
public void ClearSearchFilter() public void ClearSearchFilter()

View file

@ -87,12 +87,13 @@ namespace SourceGit.ViewModels
{ {
if (!Preference.Instance.IsGitConfigured()) if (!Preference.Instance.IsGitConfigured())
{ {
App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured")); App.RaiseException(string.Empty, App.Text("NotConfigured"));
return; return;
} }
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new Init(path, parent, reason)); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new Init(activePage.Node.Id, path, parent, reason);
} }
public void Clone() public void Clone()
@ -103,14 +104,15 @@ namespace SourceGit.ViewModels
return; return;
} }
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new Clone()); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new Clone(activePage.Node.Id);
} }
public void OpenTerminal() public void OpenTerminal()
{ {
if (!Preference.Instance.IsGitConfigured()) if (!Preference.Instance.IsGitConfigured())
App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured")); App.RaiseException(string.Empty, App.Text("NotConfigured"));
else else
Native.OS.OpenTerminal(null); Native.OS.OpenTerminal(null);
} }
@ -119,11 +121,20 @@ namespace SourceGit.ViewModels
{ {
var defaultCloneDir = Preference.Instance.GitDefaultCloneDir; var defaultCloneDir = Preference.Instance.GitDefaultCloneDir;
if (string.IsNullOrEmpty(defaultCloneDir)) if (string.IsNullOrEmpty(defaultCloneDir))
App.RaiseException(PopupHost.Active.GetId(), "The default clone dir hasn't been configured!"); {
else if (!Directory.Exists(defaultCloneDir)) App.RaiseException(string.Empty, "The default clone directory hasn't been configured!");
App.RaiseException(PopupHost.Active.GetId(), $"The default clone dir '{defaultCloneDir}' does not exist!"); return;
else if (PopupHost.CanCreatePopup()) }
PopupHost.ShowAndStartPopup(new ScanRepositories(defaultCloneDir));
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() public void ClearSearchFilter()
@ -133,8 +144,9 @@ namespace SourceGit.ViewModels
public void AddRootNode() public void AddRootNode()
{ {
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new CreateGroup(null)); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new CreateGroup(null);
} }
public void MoveNode(RepositoryNode from, RepositoryNode to) public void MoveNode(RepositoryNode from, RepositoryNode to)
@ -224,8 +236,9 @@ namespace SourceGit.ViewModels
move.Icon = App.CreateMenuIcon("Icons.MoveToAnotherGroup"); move.Icon = App.CreateMenuIcon("Icons.MoveToAnotherGroup");
move.Click += (_, e) => move.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
PopupHost.ShowPopup(new MoveRepositoryNode(node)); if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new MoveRepositoryNode(node);
e.Handled = true; e.Handled = true;
}; };

View file

@ -314,13 +314,13 @@ namespace SourceGit.ViewModels
public void StashAll(bool autoStart) public void StashAll(bool autoStart)
{ {
if (!PopupHost.CanCreatePopup()) if (!_repo.CanCreatePopup())
return; return;
if (autoStart) if (autoStart)
PopupHost.ShowAndStartPopup(new StashChanges(_repo, _cached, false)); _repo.ShowAndStartPopup(new StashChanges(_repo, _cached, false));
else else
PopupHost.ShowPopup(new StashChanges(_repo, _cached, false)); _repo.ShowPopup(new StashChanges(_repo, _cached, false));
} }
public void StageSelected(Models.Change next) public void StageSelected(Models.Change next)
@ -405,12 +405,12 @@ namespace SourceGit.ViewModels
public void Discard(List<Models.Change> changes) public void Discard(List<Models.Change> changes)
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
{ {
if (changes.Count == _unstaged.Count && _staged.Count == 0) if (changes.Count == _unstaged.Count && _staged.Count == 0)
PopupHost.ShowPopup(new Discard(_repo)); _repo.ShowPopup(new Discard(_repo));
else 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.Icon = App.CreateMenuIcon("Icons.Stashes.Add");
stash.Click += (_, e) => stash.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true)); _repo.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true));
e.Handled = true; e.Handled = true;
}; };
@ -1008,8 +1008,8 @@ namespace SourceGit.ViewModels
stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add");
stash.Click += (_, e) => stash.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true)); _repo.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true));
e.Handled = true; e.Handled = true;
}; };
@ -1131,8 +1131,8 @@ namespace SourceGit.ViewModels
stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add");
stash.Click += (_, e) => stash.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true)); _repo.ShowPopup(new StashChanges(_repo, _selectedStaged, true));
e.Handled = true; e.Handled = true;
}; };
@ -1306,8 +1306,8 @@ namespace SourceGit.ViewModels
stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add"); stash.Icon = App.CreateMenuIcon("Icons.Stashes.Add");
stash.Click += (_, e) => stash.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (_repo.CanCreatePopup())
PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true)); _repo.ShowPopup(new StashChanges(_repo, _selectedStaged, true));
e.Handled = true; e.Handled = true;
}; };
@ -1514,7 +1514,7 @@ namespace SourceGit.ViewModels
private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty) 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!"); App.RaiseException(_repo.FullPath, "Repository has unfinished job! Please wait!");
return; return;
@ -1560,7 +1560,7 @@ namespace SourceGit.ViewModels
UseAmend = false; UseAmend = false;
if (autoPush) if (autoPush)
PopupHost.ShowAndStartPopup(new Push(_repo, null)); _repo.ShowAndStartPopup(new Push(_repo, null));
} }
_repo.MarkBranchesDirtyManually(); _repo.MarkBranchesDirtyManually();

View file

@ -845,12 +845,17 @@ namespace SourceGit.Views
// CTRL/COMMAND + B -> shows Create Branch pop-up at selected commit. // CTRL/COMMAND + B -> shows Create Branch pop-up at selected commit.
if (e.Key == Key.B) if (e.Key == Key.B)
{ {
if (selected.Count == 1 && var repoView = this.FindAncestorOfType<Repository>();
selected[0] is Models.Commit commit && if (repoView == null)
DataContext is ViewModels.Histories histories && return;
ViewModels.PopupHost.CanCreatePopup())
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; e.Handled = true;
} }
} }

View file

@ -17,7 +17,8 @@ namespace SourceGit.Views
private async void OpenLocalRepository(object _1, RoutedEventArgs e) private async void OpenLocalRepository(object _1, RoutedEventArgs e)
{ {
if (!ViewModels.PopupHost.CanCreatePopup()) var activePage = App.GetLauncer().ActivePage;
if (activePage == null || !activePage.CanCreatePopup())
return; return;
var topLevel = TopLevel.GetTopLevel(this); var topLevel = TopLevel.GetTopLevel(this);