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

@ -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<Models.Branch> 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<Models.Branch> 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;