optimize<*>: add a static method CreateMenuIcon to App. Restore working copy changes' selection state after refreshed

This commit is contained in:
leo 2024-02-27 18:26:05 +08:00
parent 9c3294c285
commit 2aacec75b4
7 changed files with 217 additions and 292 deletions

View file

@ -120,6 +120,15 @@ namespace SourceGit {
return string.Format(fmt, args); return string.Format(fmt, args);
} }
public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
icon.Stretch = Stretch.Uniform;
icon.Data = Current.FindResource(key) as StreamGeometry;
return icon;
}
public static TopLevel GetTopLevel() { public static TopLevel GetTopLevel() {
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
return desktop.MainWindow; return desktop.MainWindow;

View file

@ -1,6 +1,4 @@
using Avalonia; using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -151,7 +149,7 @@ namespace SourceGit.ViewModels {
if (change.Index != Models.ChangeState.Deleted) { if (change.Index != Models.ChangeState.Deleted) {
var history = new MenuItem(); var history = new MenuItem();
history.Header = App.Text("FileHistory"); history.Header = App.Text("FileHistory");
history.Icon = CreateMenuIcon("Icons.Histories"); history.Icon = App.CreateMenuIcon("Icons.Histories");
history.Click += (_, ev) => { history.Click += (_, ev) => {
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) }; var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
window.Show(); window.Show();
@ -160,7 +158,7 @@ namespace SourceGit.ViewModels {
var blame = new MenuItem(); var blame = new MenuItem();
blame.Header = App.Text("Blame"); blame.Header = App.Text("Blame");
blame.Icon = CreateMenuIcon("Icons.Blame"); blame.Icon = App.CreateMenuIcon("Icons.Blame");
blame.Click += (o, ev) => { blame.Click += (o, ev) => {
var window = new Views.Blame() { DataContext = new Blame(_repo, change.Path, _commit.SHA) }; var window = new Views.Blame() { DataContext = new Blame(_repo, change.Path, _commit.SHA) };
window.Show(); window.Show();
@ -170,7 +168,7 @@ namespace SourceGit.ViewModels {
var full = Path.GetFullPath(Path.Combine(_repo, change.Path)); var full = Path.GetFullPath(Path.Combine(_repo, change.Path));
var explore = new MenuItem(); var explore = new MenuItem();
explore.Header = App.Text("RevealFile"); explore.Header = App.Text("RevealFile");
explore.Icon = CreateMenuIcon("Icons.Folder.Open"); explore.Icon = App.CreateMenuIcon("Icons.Folder.Open");
explore.IsEnabled = File.Exists(full); explore.IsEnabled = File.Exists(full);
explore.Click += (_, ev) => { explore.Click += (_, ev) => {
Native.OS.OpenInFileManager(full, true); Native.OS.OpenInFileManager(full, true);
@ -184,7 +182,7 @@ namespace SourceGit.ViewModels {
var copyPath = new MenuItem(); var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath"); copyPath.Header = App.Text("CopyPath");
copyPath.Icon = CreateMenuIcon("Icons.Copy"); copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyPath.Click += (_, ev) => { copyPath.Click += (_, ev) => {
App.CopyText(change.Path); App.CopyText(change.Path);
ev.Handled = true; ev.Handled = true;
@ -197,7 +195,7 @@ namespace SourceGit.ViewModels {
public ContextMenu CreateRevisionFileContextMenu(Models.Object file) { public ContextMenu CreateRevisionFileContextMenu(Models.Object file) {
var history = new MenuItem(); var history = new MenuItem();
history.Header = App.Text("FileHistory"); history.Header = App.Text("FileHistory");
history.Icon = CreateMenuIcon("Icons.Histories"); history.Icon = App.CreateMenuIcon("Icons.Histories");
history.Click += (_, ev) => { history.Click += (_, ev) => {
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, file.Path) }; var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, file.Path) };
window.Show(); window.Show();
@ -206,7 +204,7 @@ namespace SourceGit.ViewModels {
var blame = new MenuItem(); var blame = new MenuItem();
blame.Header = App.Text("Blame"); blame.Header = App.Text("Blame");
blame.Icon = CreateMenuIcon("Icons.Blame"); blame.Icon = App.CreateMenuIcon("Icons.Blame");
blame.Click += (o, ev) => { blame.Click += (o, ev) => {
var window = new Views.Blame() { DataContext = new Blame(_repo, file.Path, _commit.SHA) }; var window = new Views.Blame() { DataContext = new Blame(_repo, file.Path, _commit.SHA) };
window.Show(); window.Show();
@ -216,7 +214,7 @@ namespace SourceGit.ViewModels {
var full = Path.GetFullPath(Path.Combine(_repo, file.Path)); var full = Path.GetFullPath(Path.Combine(_repo, file.Path));
var explore = new MenuItem(); var explore = new MenuItem();
explore.Header = App.Text("RevealFile"); explore.Header = App.Text("RevealFile");
explore.Icon = CreateMenuIcon("Icons.Folder.Open"); explore.Icon = App.CreateMenuIcon("Icons.Folder.Open");
explore.Click += (_, ev) => { explore.Click += (_, ev) => {
Native.OS.OpenInFileManager(full, file.Type == Models.ObjectType.Blob); Native.OS.OpenInFileManager(full, file.Type == Models.ObjectType.Blob);
ev.Handled = true; ev.Handled = true;
@ -224,7 +222,7 @@ namespace SourceGit.ViewModels {
var saveAs = new MenuItem(); var saveAs = new MenuItem();
saveAs.Header = App.Text("SaveAs"); saveAs.Header = App.Text("SaveAs");
saveAs.Icon = CreateMenuIcon("Icons.Save"); saveAs.Icon = App.CreateMenuIcon("Icons.Save");
saveAs.IsEnabled = file.Type == Models.ObjectType.Blob; saveAs.IsEnabled = file.Type == Models.ObjectType.Blob;
saveAs.Click += async (_, ev) => { saveAs.Click += async (_, ev) => {
var topLevel = App.GetTopLevel(); var topLevel = App.GetTopLevel();
@ -242,7 +240,7 @@ namespace SourceGit.ViewModels {
var copyPath = new MenuItem(); var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath"); copyPath.Header = App.Text("CopyPath");
copyPath.Icon = CreateMenuIcon("Icons.Copy"); copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyPath.Click += (_, ev) => { copyPath.Click += (_, ev) => {
App.CopyText(file.Path); App.CopyText(file.Path);
ev.Handled = true; ev.Handled = true;
@ -397,15 +395,6 @@ namespace SourceGit.ViewModels {
} }
} }
private Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
icon.Stretch = Stretch.Uniform;
icon.Data = App.Current?.FindResource(key) as StreamGeometry;
return icon;
}
private string _repo = string.Empty; private string _repo = string.Empty;
private int _activePageIndex = 0; private int _activePageIndex = 0;
private Models.Commit _commit = null; private Models.Commit _commit = null;

View file

@ -1,5 +1,4 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -148,7 +147,7 @@ namespace SourceGit.ViewModels {
if (current.Head != commit.SHA) { if (current.Head != commit.SHA) {
var reset = new MenuItem(); var reset = new MenuItem();
reset.Header = CreateHighlightLabel("CommitCM.Reset", current.Name); reset.Header = CreateHighlightLabel("CommitCM.Reset", current.Name);
reset.Icon = CreateMenuIcon("Icons.Reset"); reset.Icon = App.CreateMenuIcon("Icons.Reset");
reset.Click += (o, e) => { reset.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reset(_repo, current, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reset(_repo, current, commit));
e.Handled = true; e.Handled = true;
@ -157,7 +156,7 @@ namespace SourceGit.ViewModels {
} else { } else {
var reword = new MenuItem(); var reword = new MenuItem();
reword.Header = App.Text("CommitCM.Reword"); reword.Header = App.Text("CommitCM.Reword");
reword.Icon = CreateMenuIcon("Icons.Edit"); reword.Icon = App.CreateMenuIcon("Icons.Edit");
reword.Click += (o, e) => { reword.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reword(_repo, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reword(_repo, commit));
e.Handled = true; e.Handled = true;
@ -166,7 +165,7 @@ namespace SourceGit.ViewModels {
var squash = new MenuItem(); var squash = new MenuItem();
squash.Header = App.Text("CommitCM.Squash"); squash.Header = App.Text("CommitCM.Squash");
squash.Icon = CreateMenuIcon("Icons.SquashIntoParent"); squash.Icon = App.CreateMenuIcon("Icons.SquashIntoParent");
squash.IsEnabled = commit.Parents.Count == 1; squash.IsEnabled = commit.Parents.Count == 1;
squash.Click += (o, e) => { squash.Click += (o, e) => {
if (commit.Parents.Count == 1) { if (commit.Parents.Count == 1) {
@ -182,7 +181,7 @@ namespace SourceGit.ViewModels {
if (!commit.IsMerged) { if (!commit.IsMerged) {
var rebase = new MenuItem(); var rebase = new MenuItem();
rebase.Header = CreateHighlightLabel("CommitCM.Rebase", current.Name); rebase.Header = CreateHighlightLabel("CommitCM.Rebase", current.Name);
rebase.Icon = CreateMenuIcon("Icons.Rebase"); rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
rebase.Click += (o, e) => { rebase.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(_repo, current, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(_repo, current, commit));
e.Handled = true; e.Handled = true;
@ -191,7 +190,7 @@ namespace SourceGit.ViewModels {
var cherryPick = new MenuItem(); var cherryPick = new MenuItem();
cherryPick.Header = App.Text("CommitCM.CherryPick"); cherryPick.Header = App.Text("CommitCM.CherryPick");
cherryPick.Icon = CreateMenuIcon("Icons.CherryPick"); cherryPick.Icon = App.CreateMenuIcon("Icons.CherryPick");
cherryPick.Click += (o, e) => { cherryPick.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CherryPick(_repo, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CherryPick(_repo, commit));
e.Handled = true; e.Handled = true;
@ -200,7 +199,7 @@ namespace SourceGit.ViewModels {
} else { } else {
var revert = new MenuItem(); var revert = new MenuItem();
revert.Header = App.Text("CommitCM.Revert"); revert.Header = App.Text("CommitCM.Revert");
revert.Icon = CreateMenuIcon("Icons.Undo"); revert.Icon = App.CreateMenuIcon("Icons.Undo");
revert.Click += (o, e) => { revert.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Revert(_repo, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Revert(_repo, commit));
e.Handled = true; e.Handled = true;
@ -211,7 +210,7 @@ namespace SourceGit.ViewModels {
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });
var createBranch = new MenuItem(); var createBranch = new MenuItem();
createBranch.Icon = CreateMenuIcon("Icons.Branch.Add"); createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (o, e) => { createBranch.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(_repo, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(_repo, commit));
@ -220,7 +219,7 @@ namespace SourceGit.ViewModels {
menu.Items.Add(createBranch); menu.Items.Add(createBranch);
var createTag = new MenuItem(); var createTag = new MenuItem();
createTag.Icon = CreateMenuIcon("Icons.Tag.Add"); createTag.Icon = App.CreateMenuIcon("Icons.Tag.Add");
createTag.Header = App.Text("CreateTag"); createTag.Header = App.Text("CreateTag");
createTag.Click += (o, e) => { createTag.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(_repo, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(_repo, commit));
@ -230,7 +229,7 @@ namespace SourceGit.ViewModels {
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });
var saveToPatch = new MenuItem(); var saveToPatch = new MenuItem();
saveToPatch.Icon = CreateMenuIcon("Icons.Diff"); saveToPatch.Icon = App.CreateMenuIcon("Icons.Diff");
saveToPatch.Header = App.Text("CommitCM.SaveAsPatch"); saveToPatch.Header = App.Text("CommitCM.SaveAsPatch");
saveToPatch.Click += async (_, e) => { saveToPatch.Click += async (_, e) => {
var topLevel = App.GetTopLevel(); var topLevel = App.GetTopLevel();
@ -248,7 +247,7 @@ namespace SourceGit.ViewModels {
menu.Items.Add(saveToPatch); menu.Items.Add(saveToPatch);
var archive = new MenuItem(); var archive = new MenuItem();
archive.Icon = CreateMenuIcon("Icons.Archive"); archive.Icon = App.CreateMenuIcon("Icons.Archive");
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (o, e) => { archive.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(_repo, commit)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(_repo, commit));
@ -259,7 +258,7 @@ namespace SourceGit.ViewModels {
var copySHA = new MenuItem(); var copySHA = new MenuItem();
copySHA.Header = App.Text("CommitCM.CopySHA"); copySHA.Header = App.Text("CommitCM.CopySHA");
copySHA.Icon = CreateMenuIcon("Icons.Copy"); copySHA.Icon = App.CreateMenuIcon("Icons.Copy");
copySHA.Click += (o, e) => { copySHA.Click += (o, e) => {
App.CopyText(commit.SHA); App.CopyText(commit.SHA);
e.Handled = true; e.Handled = true;
@ -270,7 +269,7 @@ namespace SourceGit.ViewModels {
private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) { private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) {
var submenu = new MenuItem(); var submenu = new MenuItem();
submenu.Icon = CreateMenuIcon("Icons.Branch"); submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = current.Name; submenu.Header = current.Name;
var dirty = !string.IsNullOrEmpty(current.UpstreamTrackStatus); var dirty = !string.IsNullOrEmpty(current.UpstreamTrackStatus);
@ -279,7 +278,7 @@ namespace SourceGit.ViewModels {
var fastForward = new MenuItem(); var fastForward = new MenuItem();
fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", upstream); fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", upstream);
fastForward.Icon = CreateMenuIcon("Icons.FastForward"); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
fastForward.IsEnabled = dirty; fastForward.IsEnabled = dirty;
fastForward.Click += (o, e) => { fastForward.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name));
@ -289,7 +288,7 @@ namespace SourceGit.ViewModels {
var pull = new MenuItem(); var pull = new MenuItem();
pull.Header = CreateHighlightLabel("BranchCM.Pull", upstream); pull.Header = CreateHighlightLabel("BranchCM.Pull", upstream);
pull.Icon = CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.IsEnabled = dirty; pull.IsEnabled = dirty;
pull.Click += (o, e) => { pull.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(_repo, null)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(_repo, null));
@ -300,7 +299,7 @@ namespace SourceGit.ViewModels {
var push = new MenuItem(); var push = new MenuItem();
push.Header = CreateHighlightLabel("BranchCM.Push", current.Name); push.Header = CreateHighlightLabel("BranchCM.Push", current.Name);
push.Icon = CreateMenuIcon("Icons.Push"); push.Icon = App.CreateMenuIcon("Icons.Push");
push.IsEnabled = _repo.Remotes.Count > 0 && dirty; push.IsEnabled = _repo.Remotes.Count > 0 && dirty;
push.Click += (o, e) => { push.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(_repo, current)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(_repo, current));
@ -313,7 +312,7 @@ namespace SourceGit.ViewModels {
if (type != Models.GitFlowBranchType.None) { if (type != Models.GitFlowBranchType.None) {
var finish = new MenuItem(); var finish = new MenuItem();
finish.Header = CreateHighlightLabel("BranchCM.Finish", current.Name); finish.Header = CreateHighlightLabel("BranchCM.Finish", current.Name);
finish.Icon = CreateMenuIcon("Icons.Flow"); finish.Icon = App.CreateMenuIcon("Icons.Flow");
finish.Click += (o, e) => { finish.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(_repo, current, type)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(_repo, current, type));
e.Handled = true; e.Handled = true;
@ -324,7 +323,7 @@ namespace SourceGit.ViewModels {
var rename = new MenuItem(); var rename = new MenuItem();
rename.Header = CreateHighlightLabel("BranchCM.Rename", current.Name); rename.Header = CreateHighlightLabel("BranchCM.Rename", current.Name);
rename.Icon = CreateMenuIcon("Icons.Rename"); rename.Icon = App.CreateMenuIcon("Icons.Rename");
rename.Click += (o, e) => { rename.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(_repo, current)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(_repo, current));
e.Handled = true; e.Handled = true;
@ -336,12 +335,12 @@ namespace SourceGit.ViewModels {
private void FillOtherLocalBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged) { private void FillOtherLocalBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged) {
var submenu = new MenuItem(); var submenu = new MenuItem();
submenu.Icon = CreateMenuIcon("Icons.Branch"); submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = branch.Name; submenu.Header = branch.Name;
var checkout = new MenuItem(); var checkout = new MenuItem();
checkout.Header = CreateHighlightLabel("BranchCM.Checkout", branch.Name); checkout.Header = CreateHighlightLabel("BranchCM.Checkout", branch.Name);
checkout.Icon = CreateMenuIcon("Icons.Check"); checkout.Icon = App.CreateMenuIcon("Icons.Check");
checkout.Click += (o, e) => { checkout.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Checkout(_repo, branch.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Checkout(_repo, branch.Name));
e.Handled = true; e.Handled = true;
@ -350,7 +349,7 @@ namespace SourceGit.ViewModels {
var merge = new MenuItem(); var merge = new MenuItem();
merge.Header = CreateHighlightLabel("BranchCM.Merge", branch.Name, current.Name); merge.Header = CreateHighlightLabel("BranchCM.Merge", branch.Name, current.Name);
merge.Icon = CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.IsEnabled = !merged; merge.IsEnabled = !merged;
merge.Click += (o, e) => { merge.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(_repo, branch.Name, current.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(_repo, branch.Name, current.Name));
@ -363,7 +362,7 @@ namespace SourceGit.ViewModels {
if (type != Models.GitFlowBranchType.None) { if (type != Models.GitFlowBranchType.None) {
var finish = new MenuItem(); var finish = new MenuItem();
finish.Header = CreateHighlightLabel("BranchCM.Finish", branch.Name); finish.Header = CreateHighlightLabel("BranchCM.Finish", branch.Name);
finish.Icon = CreateMenuIcon("Icons.Flow"); finish.Icon = App.CreateMenuIcon("Icons.Flow");
finish.Click += (o, e) => { finish.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(_repo, branch, type)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(_repo, branch, type));
e.Handled = true; e.Handled = true;
@ -374,7 +373,7 @@ namespace SourceGit.ViewModels {
var rename = new MenuItem(); var rename = new MenuItem();
rename.Header = CreateHighlightLabel("BranchCM.Rename", branch.Name); rename.Header = CreateHighlightLabel("BranchCM.Rename", branch.Name);
rename.Icon = CreateMenuIcon("Icons.Rename"); rename.Icon = App.CreateMenuIcon("Icons.Rename");
rename.Click += (o, e) => { rename.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(_repo, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(_repo, branch));
e.Handled = true; e.Handled = true;
@ -383,7 +382,7 @@ namespace SourceGit.ViewModels {
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = CreateHighlightLabel("BranchCM.Delete", branch.Name); delete.Header = CreateHighlightLabel("BranchCM.Delete", branch.Name);
delete.Icon = CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (o, e) => { delete.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(_repo, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(_repo, branch));
e.Handled = true; e.Handled = true;
@ -397,12 +396,12 @@ namespace SourceGit.ViewModels {
var name = $"{branch.Remote}/{branch.Name}"; var name = $"{branch.Remote}/{branch.Name}";
var submenu = new MenuItem(); var submenu = new MenuItem();
submenu.Icon = CreateMenuIcon("Icons.Branch"); submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = name; submenu.Header = name;
var checkout = new MenuItem(); var checkout = new MenuItem();
checkout.Header = CreateHighlightLabel("BranchCM.Checkout", name); checkout.Header = CreateHighlightLabel("BranchCM.Checkout", name);
checkout.Icon = CreateMenuIcon("Icons.Check"); checkout.Icon = App.CreateMenuIcon("Icons.Check");
checkout.Click += (o, e) => { checkout.Click += (o, e) => {
foreach (var b in _repo.Branches) { foreach (var b in _repo.Branches) {
if (b.IsLocal && b.Upstream == branch.FullName) { if (b.IsLocal && b.Upstream == branch.FullName) {
@ -419,7 +418,7 @@ namespace SourceGit.ViewModels {
var merge = new MenuItem(); var merge = new MenuItem();
merge.Header = CreateHighlightLabel("BranchCM.Merge", name, current.Name); merge.Header = CreateHighlightLabel("BranchCM.Merge", name, current.Name);
merge.Icon = CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.IsEnabled = !merged; merge.IsEnabled = !merged;
merge.Click += (o, e) => { merge.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(_repo, name, current.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(_repo, name, current.Name));
@ -431,7 +430,7 @@ namespace SourceGit.ViewModels {
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = CreateHighlightLabel("BranchCM.Delete", name); delete.Header = CreateHighlightLabel("BranchCM.Delete", name);
delete.Icon = CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (o, e) => { delete.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(_repo, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(_repo, branch));
e.Handled = true; e.Handled = true;
@ -444,12 +443,12 @@ namespace SourceGit.ViewModels {
private void FillTagMenu(ContextMenu menu, Models.Tag tag) { private void FillTagMenu(ContextMenu menu, Models.Tag tag) {
var submenu = new MenuItem(); var submenu = new MenuItem();
submenu.Header = tag.Name; submenu.Header = tag.Name;
submenu.Icon = CreateMenuIcon("Icons.Tag"); submenu.Icon = App.CreateMenuIcon("Icons.Tag");
submenu.MinWidth = 200; submenu.MinWidth = 200;
var push = new MenuItem(); var push = new MenuItem();
push.Header = CreateHighlightLabel("TagCM.Push", tag.Name); push.Header = CreateHighlightLabel("TagCM.Push", tag.Name);
push.Icon = CreateMenuIcon("Icons.Push"); push.Icon = App.CreateMenuIcon("Icons.Push");
push.IsEnabled = _repo.Remotes.Count > 0; push.IsEnabled = _repo.Remotes.Count > 0;
push.Click += (o, e) => { push.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new PushTag(_repo, tag)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new PushTag(_repo, tag));
@ -459,7 +458,7 @@ namespace SourceGit.ViewModels {
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = CreateHighlightLabel("TagCM.Delete", tag.Name); delete.Header = CreateHighlightLabel("TagCM.Delete", tag.Name);
delete.Icon = CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (o, e) => { delete.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteTag(_repo, tag)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteTag(_repo, tag));
e.Handled = true; e.Handled = true;
@ -476,15 +475,6 @@ namespace SourceGit.ViewModels {
return label; return label;
} }
private Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
icon.Stretch = Stretch.Uniform;
icon.Data = App.Current?.FindResource(key) as StreamGeometry;
return icon;
}
private Repository _repo = null; private Repository _repo = null;
private double _dataGridRowHeight = 28; private double _dataGridRowHeight = 28;
private bool _isLoading = true; private bool _isLoading = true;

View file

@ -1,6 +1,5 @@
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using System; using System;
@ -580,7 +579,7 @@ namespace SourceGit.ViewModels {
var push = new MenuItem(); var push = new MenuItem();
push.Header = CreateHighlightLabel("BranchCM.Push", branch.Name); push.Header = CreateHighlightLabel("BranchCM.Push", branch.Name);
push.Icon = CreateMenuIcon("Icons.Push"); push.Icon = App.CreateMenuIcon("Icons.Push");
push.IsEnabled = Remotes.Count > 0; push.IsEnabled = Remotes.Count > 0;
push.Click += (_, e) => { push.Click += (_, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(this, branch));
@ -590,7 +589,7 @@ namespace SourceGit.ViewModels {
if (branch.IsCurrent) { if (branch.IsCurrent) {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("BranchCM.DiscardAll"); discard.Header = App.Text("BranchCM.DiscardAll");
discard.Icon = CreateMenuIcon("Icons.Undo"); discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.Click += (o, e) => { discard.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Discard(this)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Discard(this));
e.Handled = true; e.Handled = true;
@ -603,7 +602,7 @@ namespace SourceGit.ViewModels {
var upstream = branch.Upstream.Substring(13); var upstream = branch.Upstream.Substring(13);
var fastForward = new MenuItem(); var fastForward = new MenuItem();
fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", upstream); fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", upstream);
fastForward.Icon = CreateMenuIcon("Icons.FastForward"); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0; fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0;
fastForward.Click += (o, e) => { fastForward.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(this, upstream, branch.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(this, upstream, branch.Name));
@ -612,7 +611,7 @@ namespace SourceGit.ViewModels {
var pull = new MenuItem(); var pull = new MenuItem();
pull.Header = CreateHighlightLabel("BranchCM.Pull", upstream); pull.Header = CreateHighlightLabel("BranchCM.Pull", upstream);
pull.Icon = CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus); pull.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus);
pull.Click += (o, e) => { pull.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, null)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, null));
@ -629,7 +628,7 @@ namespace SourceGit.ViewModels {
var checkout = new MenuItem(); var checkout = new MenuItem();
checkout.Header = CreateHighlightLabel("BranchCM.Checkout", branch.Name); checkout.Header = CreateHighlightLabel("BranchCM.Checkout", branch.Name);
checkout.Icon = CreateMenuIcon("Icons.Check"); checkout.Icon = App.CreateMenuIcon("Icons.Check");
checkout.Click += (o, e) => { checkout.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name));
e.Handled = true; e.Handled = true;
@ -640,7 +639,7 @@ namespace SourceGit.ViewModels {
if (upstream != null) { if (upstream != null) {
var fastForward = new MenuItem(); var fastForward = new MenuItem();
fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", $"{upstream.Remote}/{upstream.Name}"); fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", $"{upstream.Remote}/{upstream.Name}");
fastForward.Icon = CreateMenuIcon("Icons.FastForward"); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0; fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0;
fastForward.Click += (o, e) => { fastForward.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new FastForwardWithoutCheckout(this, branch, upstream)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new FastForwardWithoutCheckout(this, branch, upstream));
@ -656,7 +655,7 @@ namespace SourceGit.ViewModels {
var merge = new MenuItem(); var merge = new MenuItem();
merge.Header = CreateHighlightLabel("BranchCM.Merge", branch.Name, current.Name); merge.Header = CreateHighlightLabel("BranchCM.Merge", branch.Name, current.Name);
merge.Icon = CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.Click += (o, e) => { merge.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(this, branch.Name, current.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(this, branch.Name, current.Name));
e.Handled = true; e.Handled = true;
@ -664,7 +663,7 @@ namespace SourceGit.ViewModels {
var rebase = new MenuItem(); var rebase = new MenuItem();
rebase.Header = CreateHighlightLabel("BranchCM.Rebase", current.Name, branch.Name); rebase.Header = CreateHighlightLabel("BranchCM.Rebase", current.Name, branch.Name);
rebase.Icon = CreateMenuIcon("Icons.Rebase"); rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
rebase.Click += (o, e) => { rebase.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(this, current, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(this, current, branch));
e.Handled = true; e.Handled = true;
@ -678,7 +677,7 @@ namespace SourceGit.ViewModels {
if (type != Models.GitFlowBranchType.None) { if (type != Models.GitFlowBranchType.None) {
var finish = new MenuItem(); var finish = new MenuItem();
finish.Header = CreateHighlightLabel("BranchCM.Finish", branch.Name); finish.Header = CreateHighlightLabel("BranchCM.Finish", branch.Name);
finish.Icon = CreateMenuIcon("Icons.Flow"); finish.Icon = App.CreateMenuIcon("Icons.Flow");
finish.Click += (o, e) => { finish.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(this, branch, type)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(this, branch, type));
e.Handled = true; e.Handled = true;
@ -689,7 +688,7 @@ namespace SourceGit.ViewModels {
var rename = new MenuItem(); var rename = new MenuItem();
rename.Header = CreateHighlightLabel("BranchCM.Rename", branch.Name); rename.Header = CreateHighlightLabel("BranchCM.Rename", branch.Name);
rename.Icon = CreateMenuIcon("Icons.Rename"); rename.Icon = App.CreateMenuIcon("Icons.Rename");
rename.Click += (o, e) => { rename.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(this, branch));
e.Handled = true; e.Handled = true;
@ -697,7 +696,7 @@ namespace SourceGit.ViewModels {
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = CreateHighlightLabel("BranchCM.Delete", branch.Name); delete.Header = CreateHighlightLabel("BranchCM.Delete", branch.Name);
delete.Icon = CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.IsEnabled = !branch.IsCurrent; delete.IsEnabled = !branch.IsCurrent;
delete.Click += (o, e) => { delete.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(this, branch));
@ -705,7 +704,7 @@ namespace SourceGit.ViewModels {
}; };
var createBranch = new MenuItem(); var createBranch = new MenuItem();
createBranch.Icon = CreateMenuIcon("Icons.Branch.Add"); createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (o, e) => { createBranch.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(this, branch));
@ -713,7 +712,7 @@ namespace SourceGit.ViewModels {
}; };
var createTag = new MenuItem(); var createTag = new MenuItem();
createTag.Icon = CreateMenuIcon("Icons.Tag.Add"); createTag.Icon = App.CreateMenuIcon("Icons.Tag.Add");
createTag.Header = App.Text("CreateTag"); createTag.Header = App.Text("CreateTag");
createTag.Click += (o, e) => { createTag.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(this, branch));
@ -736,13 +735,13 @@ namespace SourceGit.ViewModels {
if (remoteBranches.Count > 0) { if (remoteBranches.Count > 0) {
var tracking = new MenuItem(); var tracking = new MenuItem();
tracking.Header = App.Text("BranchCM.Tracking"); tracking.Header = App.Text("BranchCM.Tracking");
tracking.Icon = CreateMenuIcon("Icons.Branch"); tracking.Icon = App.CreateMenuIcon("Icons.Branch");
foreach (var b in remoteBranches) { foreach (var b in remoteBranches) {
var upstream = b.FullName.Replace("refs/remotes/", ""); var upstream = b.FullName.Replace("refs/remotes/", "");
var target = new MenuItem(); var target = new MenuItem();
target.Header = upstream; target.Header = upstream;
if (branch.Upstream == b.FullName) target.Icon = CreateMenuIcon("Icons.Check"); if (branch.Upstream == b.FullName) target.Icon = App.CreateMenuIcon("Icons.Check");
target.Click += (o, e) => { target.Click += (o, e) => {
if (Commands.Branch.SetUpstream(_fullpath, branch.Name, upstream)) { if (Commands.Branch.SetUpstream(_fullpath, branch.Name, upstream)) {
@ -769,7 +768,7 @@ namespace SourceGit.ViewModels {
} }
var archive = new MenuItem(); var archive = new MenuItem();
archive.Icon = CreateMenuIcon("Icons.Archive"); archive.Icon = App.CreateMenuIcon("Icons.Archive");
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (o, e) => { archive.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(this, branch));
@ -780,7 +779,7 @@ namespace SourceGit.ViewModels {
var copy = new MenuItem(); var copy = new MenuItem();
copy.Header = App.Text("BranchCM.CopyName"); copy.Header = App.Text("BranchCM.CopyName");
copy.Icon = CreateMenuIcon("Icons.Copy"); copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (o, e) => { copy.Click += (o, e) => {
App.CopyText(branch.Name); App.CopyText(branch.Name);
e.Handled = true; e.Handled = true;
@ -795,7 +794,7 @@ namespace SourceGit.ViewModels {
var fetch = new MenuItem(); var fetch = new MenuItem();
fetch.Header = App.Text("RemoteCM.Fetch"); fetch.Header = App.Text("RemoteCM.Fetch");
fetch.Icon = CreateMenuIcon("Icons.Fetch"); fetch.Icon = App.CreateMenuIcon("Icons.Fetch");
fetch.Click += (o, e) => { fetch.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Fetch(this, remote)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Fetch(this, remote));
e.Handled = true; e.Handled = true;
@ -803,7 +802,7 @@ namespace SourceGit.ViewModels {
var prune = new MenuItem(); var prune = new MenuItem();
prune.Header = App.Text("RemoteCM.Prune"); prune.Header = App.Text("RemoteCM.Prune");
prune.Icon = CreateMenuIcon("Icons.Clear2"); prune.Icon = App.CreateMenuIcon("Icons.Clear2");
prune.Click += (o, e) => { prune.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new PruneRemote(this, remote)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new PruneRemote(this, remote));
e.Handled = true; e.Handled = true;
@ -811,7 +810,7 @@ namespace SourceGit.ViewModels {
var edit = new MenuItem(); var edit = new MenuItem();
edit.Header = App.Text("RemoteCM.Edit"); edit.Header = App.Text("RemoteCM.Edit");
edit.Icon = CreateMenuIcon("Icons.Edit"); edit.Icon = App.CreateMenuIcon("Icons.Edit");
edit.Click += (o, e) => { edit.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new EditRemote(this, remote)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new EditRemote(this, remote));
e.Handled = true; e.Handled = true;
@ -819,7 +818,7 @@ namespace SourceGit.ViewModels {
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = App.Text("RemoteCM.Delete"); delete.Header = App.Text("RemoteCM.Delete");
delete.Icon = CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (o, e) => { delete.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteRemote(this, remote)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteRemote(this, remote));
e.Handled = true; e.Handled = true;
@ -827,7 +826,7 @@ namespace SourceGit.ViewModels {
var copy = new MenuItem(); var copy = new MenuItem();
copy.Header = App.Text("RemoteCM.CopyURL"); copy.Header = App.Text("RemoteCM.CopyURL");
copy.Icon = CreateMenuIcon("Icons.Copy"); copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (o, e) => { copy.Click += (o, e) => {
App.CopyText(remote.URL); App.CopyText(remote.URL);
e.Handled = true; e.Handled = true;
@ -849,7 +848,7 @@ namespace SourceGit.ViewModels {
var checkout = new MenuItem(); var checkout = new MenuItem();
checkout.Header = CreateHighlightLabel("BranchCM.Checkout", $"{branch.Remote}/{branch.Name}"); checkout.Header = CreateHighlightLabel("BranchCM.Checkout", $"{branch.Remote}/{branch.Name}");
checkout.Icon = CreateMenuIcon("Icons.Check"); checkout.Icon = App.CreateMenuIcon("Icons.Check");
checkout.Click += (o, e) => { checkout.Click += (o, e) => {
foreach (var b in Branches) { foreach (var b in Branches) {
if (b.IsLocal && b.Upstream == branch.FullName) { if (b.IsLocal && b.Upstream == branch.FullName) {
@ -868,7 +867,7 @@ namespace SourceGit.ViewModels {
if (current != null) { if (current != null) {
var pull = new MenuItem(); var pull = new MenuItem();
pull.Header = CreateHighlightLabel("BranchCM.PullInto", $"{branch.Remote}/{branch.Name}", current.Name); pull.Header = CreateHighlightLabel("BranchCM.PullInto", $"{branch.Remote}/{branch.Name}", current.Name);
pull.Icon = CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.Click += (o, e) => { pull.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, branch));
e.Handled = true; e.Handled = true;
@ -876,7 +875,7 @@ namespace SourceGit.ViewModels {
var merge = new MenuItem(); var merge = new MenuItem();
merge.Header = CreateHighlightLabel("BranchCM.Merge", $"{branch.Remote}/{branch.Name}", current.Name); merge.Header = CreateHighlightLabel("BranchCM.Merge", $"{branch.Remote}/{branch.Name}", current.Name);
merge.Icon = CreateMenuIcon("Icons.Merge"); merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.Click += (o, e) => { merge.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(this, $"{branch.Remote}/{branch.Name}", current.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(this, $"{branch.Remote}/{branch.Name}", current.Name));
e.Handled = true; e.Handled = true;
@ -884,7 +883,7 @@ namespace SourceGit.ViewModels {
var rebase = new MenuItem(); var rebase = new MenuItem();
rebase.Header = CreateHighlightLabel("BranchCM.Rebase", current.Name, $"{branch.Remote}/{branch.Name}"); rebase.Header = CreateHighlightLabel("BranchCM.Rebase", current.Name, $"{branch.Remote}/{branch.Name}");
rebase.Icon = CreateMenuIcon("Icons.Rebase"); rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
rebase.Click += (o, e) => { rebase.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(this, current, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(this, current, branch));
e.Handled = true; e.Handled = true;
@ -898,14 +897,14 @@ namespace SourceGit.ViewModels {
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = CreateHighlightLabel("BranchCM.Delete", $"{branch.Remote}/{branch.Name}"); delete.Header = CreateHighlightLabel("BranchCM.Delete", $"{branch.Remote}/{branch.Name}");
delete.Icon = CreateMenuIcon("Icons.Clear"); delete.Icon = App.CreateMenuIcon("Icons.Clear");
delete.Click += (o, e) => { delete.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(this, branch));
e.Handled = true; e.Handled = true;
}; };
var createBranch = new MenuItem(); var createBranch = new MenuItem();
createBranch.Icon = CreateMenuIcon("Icons.Branch.Add"); createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (o, e) => { createBranch.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(this, branch));
@ -913,7 +912,7 @@ namespace SourceGit.ViewModels {
}; };
var createTag = new MenuItem(); var createTag = new MenuItem();
createTag.Icon = CreateMenuIcon("Icons.Tag.Add"); createTag.Icon = App.CreateMenuIcon("Icons.Tag.Add");
createTag.Header = App.Text("CreateTag"); createTag.Header = App.Text("CreateTag");
createTag.Click += (o, e) => { createTag.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(this, branch));
@ -921,7 +920,7 @@ namespace SourceGit.ViewModels {
}; };
var archive = new MenuItem(); var archive = new MenuItem();
archive.Icon = CreateMenuIcon("Icons.Archive"); archive.Icon = App.CreateMenuIcon("Icons.Archive");
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (o, e) => { archive.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(this, branch)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(this, branch));
@ -930,7 +929,7 @@ namespace SourceGit.ViewModels {
var copy = new MenuItem(); var copy = new MenuItem();
copy.Header = App.Text("BranchCM.CopyName"); copy.Header = App.Text("BranchCM.CopyName");
copy.Icon = CreateMenuIcon("Icons.Copy"); copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (o, e) => { copy.Click += (o, e) => {
App.CopyText(branch.Remote + "/" + branch.Name); App.CopyText(branch.Remote + "/" + branch.Name);
e.Handled = true; e.Handled = true;
@ -949,7 +948,7 @@ namespace SourceGit.ViewModels {
public ContextMenu CreateContextMenuForTag(Models.Tag tag) { public ContextMenu CreateContextMenuForTag(Models.Tag tag) {
var createBranch = new MenuItem(); var createBranch = new MenuItem();
createBranch.Icon = CreateMenuIcon("Icons.Branch.Add"); createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
createBranch.Header = App.Text("CreateBranch"); createBranch.Header = App.Text("CreateBranch");
createBranch.Click += (o, ev) => { createBranch.Click += (o, ev) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(this, tag)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(this, tag));
@ -958,7 +957,7 @@ namespace SourceGit.ViewModels {
var pushTag = new MenuItem(); var pushTag = new MenuItem();
pushTag.Header = CreateHighlightLabel("TagCM.Push", tag.Name); pushTag.Header = CreateHighlightLabel("TagCM.Push", tag.Name);
pushTag.Icon = CreateMenuIcon("Icons.Push"); pushTag.Icon = App.CreateMenuIcon("Icons.Push");
pushTag.IsEnabled = Remotes.Count > 0; pushTag.IsEnabled = Remotes.Count > 0;
pushTag.Click += (o, ev) => { pushTag.Click += (o, ev) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new PushTag(this, tag)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new PushTag(this, tag));
@ -967,14 +966,14 @@ namespace SourceGit.ViewModels {
var deleteTag = new MenuItem(); var deleteTag = new MenuItem();
deleteTag.Header = CreateHighlightLabel("TagCM.Delete", tag.Name); deleteTag.Header = CreateHighlightLabel("TagCM.Delete", tag.Name);
deleteTag.Icon = CreateMenuIcon("Icons.Clear"); deleteTag.Icon = App.CreateMenuIcon("Icons.Clear");
deleteTag.Click += (o, ev) => { deleteTag.Click += (o, ev) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteTag(this, tag)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteTag(this, tag));
ev.Handled = true; ev.Handled = true;
}; };
var archive = new MenuItem(); var archive = new MenuItem();
archive.Icon = CreateMenuIcon("Icons.Archive"); archive.Icon = App.CreateMenuIcon("Icons.Archive");
archive.Header = App.Text("Archive"); archive.Header = App.Text("Archive");
archive.Click += (o, ev) => { archive.Click += (o, ev) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(this, tag)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(this, tag));
@ -983,7 +982,7 @@ namespace SourceGit.ViewModels {
var copy = new MenuItem(); var copy = new MenuItem();
copy.Header = App.Text("TagCM.Copy"); copy.Header = App.Text("TagCM.Copy");
copy.Icon = CreateMenuIcon("Icons.Copy"); copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (o, ev) => { copy.Click += (o, ev) => {
App.CopyText(tag.Name); App.CopyText(tag.Name);
ev.Handled = true; ev.Handled = true;
@ -1004,7 +1003,7 @@ namespace SourceGit.ViewModels {
public ContextMenu CreateContextMenuForSubmodule(string submodule) { public ContextMenu CreateContextMenuForSubmodule(string submodule) {
var open = new MenuItem(); var open = new MenuItem();
open.Header = App.Text("Submodule.Open"); open.Header = App.Text("Submodule.Open");
open.Icon = CreateMenuIcon("Icons.Folder.Open"); open.Icon = App.CreateMenuIcon("Icons.Folder.Open");
open.Click += (o, ev) => { open.Click += (o, ev) => {
var root = Path.GetFullPath(Path.Combine(_fullpath, submodule)); var root = Path.GetFullPath(Path.Combine(_fullpath, submodule));
var gitDir = new Commands.QueryGitDir(root).Result(); var gitDir = new Commands.QueryGitDir(root).Result();
@ -1026,7 +1025,7 @@ namespace SourceGit.ViewModels {
var copy = new MenuItem(); var copy = new MenuItem();
copy.Header = App.Text("Submodule.CopyPath"); copy.Header = App.Text("Submodule.CopyPath");
copy.Icon = CreateMenuIcon("Icons.Copy"); copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (o, ev) => { copy.Click += (o, ev) => {
App.CopyText(submodule); App.CopyText(submodule);
ev.Handled = true; ev.Handled = true;
@ -1034,7 +1033,7 @@ namespace SourceGit.ViewModels {
var rm = new MenuItem(); var rm = new MenuItem();
rm.Header = App.Text("Submodule.Remove"); rm.Header = App.Text("Submodule.Remove");
rm.Icon = CreateMenuIcon("Icons.Clear"); rm.Icon = App.CreateMenuIcon("Icons.Clear");
rm.Click += (o, ev) => { rm.Click += (o, ev) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteSubmodule(this, submodule)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteSubmodule(this, submodule));
ev.Handled = true; ev.Handled = true;
@ -1054,15 +1053,6 @@ namespace SourceGit.ViewModels {
return label; return label;
} }
private Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
icon.Stretch = Stretch.Uniform;
icon.Data = App.Current?.FindResource(key) as StreamGeometry;
return icon;
}
private string _fullpath = string.Empty; private string _fullpath = string.Empty;
private string _gitDir = string.Empty; private string _gitDir = string.Empty;
private Models.GitFlow _gitflow = new Models.GitFlow(); private Models.GitFlow _gitflow = new Models.GitFlow();

View file

@ -1,6 +1,4 @@
using Avalonia; using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -14,11 +12,6 @@ namespace SourceGit.ViewModels {
public Models.Change Change { get; set; } public Models.Change Change { get; set; }
} }
public class ViewChangeDetailContext {
public string FilePath { get; set; } = string.Empty;
public bool IsUnstaged { get; set; } = false;
}
public class WorkingCopy : ObservableObject { public class WorkingCopy : ObservableObject {
public bool IsStaging { public bool IsStaging {
get => _isStaging; get => _isStaging;
@ -54,6 +47,28 @@ namespace SourceGit.ViewModels {
get => _count; get => _count;
} }
public Models.Change SelectedUnstagedChange {
get => _selectedUnstagedChange;
set {
if (SetProperty(ref _selectedUnstagedChange, value) && value != null) {
SelectedStagedChange = null;
SelectedStagedTreeNode = null;
SetDetail(value, true);
}
}
}
public Models.Change SelectedStagedChange {
get => _selectedStagedChange;
set {
if (SetProperty(ref _selectedStagedChange, value) && value != null) {
SelectedUnstagedChange = null;
SelectedUnstagedTreeNode = null;
SetDetail(value, false);
}
}
}
public List<FileTreeNode> UnstagedTree { public List<FileTreeNode> UnstagedTree {
get => _unstagedTree; get => _unstagedTree;
private set => SetProperty(ref _unstagedTree, value); private set => SetProperty(ref _unstagedTree, value);
@ -64,6 +79,44 @@ namespace SourceGit.ViewModels {
private set => SetProperty(ref _stagedTree, value); private set => SetProperty(ref _stagedTree, value);
} }
public FileTreeNode SelectedUnstagedTreeNode {
get => _selectedUnstagedTreeNode;
set {
if (SetProperty(ref _selectedUnstagedTreeNode, value)) {
if (value == null) {
SelectedUnstagedChange = null;
} else {
SelectedUnstagedChange = value.Backend as Models.Change;
SelectedStagedTreeNode = null;
SelectedStagedChange = null;
if (value.IsFolder) {
SetDetail(null, true);
}
}
}
}
}
public FileTreeNode SelectedStagedTreeNode {
get => _selectedStagedTreeNode;
set {
if (SetProperty(ref _selectedStagedTreeNode, value)) {
if (value == null) {
SelectedStagedChange = null;
} else {
SelectedStagedChange = value.Backend as Models.Change;
SelectedUnstagedTreeNode = null;
SelectedUnstagedChange = null;
if (value.IsFolder) {
SetDetail(null, false);
}
}
}
}
}
public object DetailContext { public object DetailContext {
get => _detailContext; get => _detailContext;
private set => SetProperty(ref _detailContext, value); private set => SetProperty(ref _detailContext, value);
@ -84,7 +137,10 @@ namespace SourceGit.ViewModels {
if (_staged != null) _staged.Clear(); if (_staged != null) _staged.Clear();
if (_unstagedTree != null) _unstagedTree.Clear(); if (_unstagedTree != null) _unstagedTree.Clear();
if (_stagedTree != null) _stagedTree.Clear(); if (_stagedTree != null) _stagedTree.Clear();
_lastViewChange = null; _selectedUnstagedChange = null;
_selectedStagedChange = null;
_selectedUnstagedTreeNode = null;
_selectedStagedTreeNode = null;
_detailContext = null; _detailContext = null;
_commitMessage = string.Empty; _commitMessage = string.Empty;
} }
@ -93,24 +149,34 @@ namespace SourceGit.ViewModels {
var unstaged = new List<Models.Change>(); var unstaged = new List<Models.Change>();
var staged = new List<Models.Change>(); var staged = new List<Models.Change>();
var viewFile = _lastViewChange == null ? string.Empty : _lastViewChange.FilePath; var viewFile = string.Empty;
var lastSelectedIsUnstaged = false;
if (_selectedUnstagedChange != null) {
viewFile = _selectedUnstagedChange.Path;
lastSelectedIsUnstaged = true;
} else if (_selectedStagedChange != null) {
viewFile = _selectedStagedChange.Path;
}
var viewChange = null as Models.Change; var viewChange = null as Models.Change;
var hasConflict = false; var hasConflict = false;
foreach (var c in changes) { foreach (var c in changes) {
if (c.Path == viewFile) {
viewChange = c;
}
if (c.Index == Models.ChangeState.Modified if (c.Index == Models.ChangeState.Modified
|| c.Index == Models.ChangeState.Added || c.Index == Models.ChangeState.Added
|| c.Index == Models.ChangeState.Deleted || c.Index == Models.ChangeState.Deleted
|| c.Index == Models.ChangeState.Renamed) { || c.Index == Models.ChangeState.Renamed) {
staged.Add(c); staged.Add(c);
if (!lastSelectedIsUnstaged && c.Path == viewFile) {
viewChange = c;
}
} }
if (c.WorkTree != Models.ChangeState.None) { if (c.WorkTree != Models.ChangeState.None) {
unstaged.Add(c); unstaged.Add(c);
hasConflict |= c.IsConflit; hasConflict |= c.IsConflit;
if (lastSelectedIsUnstaged && c.Path == viewFile) {
viewChange = c;
}
} }
} }
@ -125,7 +191,23 @@ namespace SourceGit.ViewModels {
UnstagedTree = unstagedTree; UnstagedTree = unstagedTree;
StagedTree = stagedTree; StagedTree = stagedTree;
_isLoadingData = false; _isLoadingData = false;
SetDetail(viewChange, _lastViewChange == null || _lastViewChange.IsUnstaged);
// Restore last selection states.
if (viewChange != null) {
if (lastSelectedIsUnstaged) {
SelectedUnstagedChange = viewChange;
SelectedUnstagedTreeNode = FileTreeNode.SelectByPath(_unstagedTree, viewFile);
} else {
SelectedStagedChange = viewChange;
SelectedStagedTreeNode = FileTreeNode.SelectByPath(_stagedTree, viewFile);
}
} else {
SelectedUnstagedChange = null;
SelectedUnstagedTreeNode = null;
SelectedStagedChange = null;
SelectedStagedTreeNode = null;
SetDetail(null, false);
}
}); });
return hasConflict; return hasConflict;
@ -135,13 +217,10 @@ namespace SourceGit.ViewModels {
if (_isLoadingData) return; if (_isLoadingData) return;
if (change == null) { if (change == null) {
_lastViewChange = null;
DetailContext = null; DetailContext = null;
} else if (change.IsConflit) { } else if (change.IsConflit) {
_lastViewChange = new ViewChangeDetailContext() { FilePath = change.Path, IsUnstaged = isUnstaged };
DetailContext = new ConflictContext() { Change = change }; DetailContext = new ConflictContext() { Change = change };
} else { } else {
_lastViewChange = new ViewChangeDetailContext() { FilePath = change.Path, IsUnstaged = isUnstaged };
DetailContext = new DiffContext(_repo.FullPath, new Models.DiffOption(change, isUnstaged)); DetailContext = new DiffContext(_repo.FullPath, new Models.DiffOption(change, isUnstaged));
} }
} }
@ -284,7 +363,7 @@ namespace SourceGit.ViewModels {
var explore = new MenuItem(); var explore = new MenuItem();
explore.Header = App.Text("RevealFile"); explore.Header = App.Text("RevealFile");
explore.Icon = CreateMenuIcon("Icons.Folder.Open"); explore.Icon = App.CreateMenuIcon("Icons.Folder.Open");
explore.IsEnabled = File.Exists(path) || Directory.Exists(path); explore.IsEnabled = File.Exists(path) || Directory.Exists(path);
explore.Click += (_, e) => { explore.Click += (_, e) => {
Native.OS.OpenInFileManager(path, true); Native.OS.OpenInFileManager(path, true);
@ -293,7 +372,7 @@ namespace SourceGit.ViewModels {
var openWith = new MenuItem(); var openWith = new MenuItem();
openWith.Header = App.Text("OpenWith"); openWith.Header = App.Text("OpenWith");
openWith.Icon = CreateMenuIcon("Icons.OpenWith"); openWith.Icon = App.CreateMenuIcon("Icons.OpenWith");
openWith.IsEnabled = File.Exists(path); openWith.IsEnabled = File.Exists(path);
openWith.Click += (_, e) => { openWith.Click += (_, e) => {
Native.OS.OpenWithDefaultEditor(path); Native.OS.OpenWithDefaultEditor(path);
@ -302,7 +381,7 @@ namespace SourceGit.ViewModels {
var stage = new MenuItem(); var stage = new MenuItem();
stage.Header = App.Text("FileCM.Stage"); stage.Header = App.Text("FileCM.Stage");
stage.Icon = CreateMenuIcon("Icons.File.Add"); stage.Icon = App.CreateMenuIcon("Icons.File.Add");
stage.Click += (_, e) => { stage.Click += (_, e) => {
StageChanges(changes); StageChanges(changes);
e.Handled = true; e.Handled = true;
@ -310,7 +389,7 @@ namespace SourceGit.ViewModels {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("FileCM.Discard"); discard.Header = App.Text("FileCM.Discard");
discard.Icon = CreateMenuIcon("Icons.Undo"); discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.Click += (_, e) => { discard.Click += (_, e) => {
Discard(changes); Discard(changes);
e.Handled = true; e.Handled = true;
@ -318,7 +397,7 @@ namespace SourceGit.ViewModels {
var stash = new MenuItem(); var stash = new MenuItem();
stash.Header = App.Text("FileCM.Stash"); stash.Header = App.Text("FileCM.Stash");
stash.Icon = CreateMenuIcon("Icons.Stashes"); stash.Icon = App.CreateMenuIcon("Icons.Stashes");
stash.Click += (_, e) => { stash.Click += (_, e) => {
if (PopupHost.CanCreatePopup()) { if (PopupHost.CanCreatePopup()) {
PopupHost.ShowPopup(new StashChanges(_repo, changes, false)); PopupHost.ShowPopup(new StashChanges(_repo, changes, false));
@ -328,7 +407,7 @@ namespace SourceGit.ViewModels {
var patch = new MenuItem(); var patch = new MenuItem();
patch.Header = App.Text("FileCM.SaveAsPatch"); patch.Header = App.Text("FileCM.SaveAsPatch");
patch.Icon = CreateMenuIcon("Icons.Diff"); patch.Icon = App.CreateMenuIcon("Icons.Diff");
patch.Click += async (_, e) => { patch.Click += async (_, e) => {
var topLevel = App.GetTopLevel(); var topLevel = App.GetTopLevel();
if (topLevel == null) return; if (topLevel == null) return;
@ -349,7 +428,7 @@ namespace SourceGit.ViewModels {
var history = new MenuItem(); var history = new MenuItem();
history.Header = App.Text("FileHistory"); history.Header = App.Text("FileHistory");
history.Icon = CreateMenuIcon("Icons.Histories"); history.Icon = App.CreateMenuIcon("Icons.Histories");
history.Click += (_, e) => { history.Click += (_, e) => {
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo.FullPath, change.Path) }; var window = new Views.FileHistories() { DataContext = new FileHistories(_repo.FullPath, change.Path) };
window.Show(); window.Show();
@ -358,7 +437,7 @@ namespace SourceGit.ViewModels {
var assumeUnchanged = new MenuItem(); var assumeUnchanged = new MenuItem();
assumeUnchanged.Header = App.Text("FileCM.AssumeUnchanged"); assumeUnchanged.Header = App.Text("FileCM.AssumeUnchanged");
assumeUnchanged.Icon = CreateMenuIcon("Icons.File.Ignore"); assumeUnchanged.Icon = App.CreateMenuIcon("Icons.File.Ignore");
assumeUnchanged.IsEnabled = change.WorkTree != Models.ChangeState.Untracked; assumeUnchanged.IsEnabled = change.WorkTree != Models.ChangeState.Untracked;
assumeUnchanged.Click += (_, e) => { assumeUnchanged.Click += (_, e) => {
new Commands.AssumeUnchanged(_repo.FullPath).Add(change.Path); new Commands.AssumeUnchanged(_repo.FullPath).Add(change.Path);
@ -367,7 +446,7 @@ namespace SourceGit.ViewModels {
var copy = new MenuItem(); var copy = new MenuItem();
copy.Header = App.Text("CopyPath"); copy.Header = App.Text("CopyPath");
copy.Icon = CreateMenuIcon("Icons.Copy"); copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (_, e) => { copy.Click += (_, e) => {
App.CopyText(change.Path); App.CopyText(change.Path);
e.Handled = true; e.Handled = true;
@ -388,7 +467,7 @@ namespace SourceGit.ViewModels {
} else { } else {
var stage = new MenuItem(); var stage = new MenuItem();
stage.Header = App.Text("FileCM.StageMulti", changes.Count); stage.Header = App.Text("FileCM.StageMulti", changes.Count);
stage.Icon = CreateMenuIcon("Icons.File.Add"); stage.Icon = App.CreateMenuIcon("Icons.File.Add");
stage.Click += (_, e) => { stage.Click += (_, e) => {
StageChanges(changes); StageChanges(changes);
e.Handled = true; e.Handled = true;
@ -396,7 +475,7 @@ namespace SourceGit.ViewModels {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("FileCM.DiscardMulti", changes.Count); discard.Header = App.Text("FileCM.DiscardMulti", changes.Count);
discard.Icon = CreateMenuIcon("Icons.Undo"); discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.Click += (_, e) => { discard.Click += (_, e) => {
Discard(changes); Discard(changes);
e.Handled = true; e.Handled = true;
@ -404,7 +483,7 @@ namespace SourceGit.ViewModels {
var stash = new MenuItem(); var stash = new MenuItem();
stash.Header = App.Text("FileCM.StashMulti", changes.Count); stash.Header = App.Text("FileCM.StashMulti", changes.Count);
stash.Icon = CreateMenuIcon("Icons.Stashes"); stash.Icon = App.CreateMenuIcon("Icons.Stashes");
stash.Click += (_, e) => { stash.Click += (_, e) => {
if (PopupHost.CanCreatePopup()) { if (PopupHost.CanCreatePopup()) {
PopupHost.ShowPopup(new StashChanges(_repo, changes, false)); PopupHost.ShowPopup(new StashChanges(_repo, changes, false));
@ -414,7 +493,7 @@ namespace SourceGit.ViewModels {
var patch = new MenuItem(); var patch = new MenuItem();
patch.Header = App.Text("FileCM.SaveAsPatch"); patch.Header = App.Text("FileCM.SaveAsPatch");
patch.Icon = CreateMenuIcon("Icons.Diff"); patch.Icon = App.CreateMenuIcon("Icons.Diff");
patch.Click += async (o, e) => { patch.Click += async (o, e) => {
var topLevel = App.GetTopLevel(); var topLevel = App.GetTopLevel();
if (topLevel == null) return; if (topLevel == null) return;
@ -453,7 +532,7 @@ namespace SourceGit.ViewModels {
var explore = new MenuItem(); var explore = new MenuItem();
explore.IsEnabled = File.Exists(path) || Directory.Exists(path); explore.IsEnabled = File.Exists(path) || Directory.Exists(path);
explore.Header = App.Text("RevealFile"); explore.Header = App.Text("RevealFile");
explore.Icon = CreateMenuIcon("Icons.Folder.Open"); explore.Icon = App.CreateMenuIcon("Icons.Folder.Open");
explore.Click += (o, e) => { explore.Click += (o, e) => {
Native.OS.OpenInFileManager(path, true); Native.OS.OpenInFileManager(path, true);
e.Handled = true; e.Handled = true;
@ -461,7 +540,7 @@ namespace SourceGit.ViewModels {
var openWith = new MenuItem(); var openWith = new MenuItem();
openWith.Header = App.Text("OpenWith"); openWith.Header = App.Text("OpenWith");
openWith.Icon = CreateMenuIcon("Icons.OpenWith"); openWith.Icon = App.CreateMenuIcon("Icons.OpenWith");
openWith.IsEnabled = File.Exists(path); openWith.IsEnabled = File.Exists(path);
openWith.Click += (_, e) => { openWith.Click += (_, e) => {
Native.OS.OpenWithDefaultEditor(path); Native.OS.OpenWithDefaultEditor(path);
@ -470,7 +549,7 @@ namespace SourceGit.ViewModels {
var unstage = new MenuItem(); var unstage = new MenuItem();
unstage.Header = App.Text("FileCM.Unstage"); unstage.Header = App.Text("FileCM.Unstage");
unstage.Icon = CreateMenuIcon("Icons.File.Remove"); unstage.Icon = App.CreateMenuIcon("Icons.File.Remove");
unstage.Click += (o, e) => { unstage.Click += (o, e) => {
UnstageChanges(changes); UnstageChanges(changes);
e.Handled = true; e.Handled = true;
@ -478,7 +557,7 @@ namespace SourceGit.ViewModels {
var stash = new MenuItem(); var stash = new MenuItem();
stash.Header = App.Text("FileCM.Stash"); stash.Header = App.Text("FileCM.Stash");
stash.Icon = CreateMenuIcon("Icons.Stashes"); stash.Icon = App.CreateMenuIcon("Icons.Stashes");
stash.Click += (_, e) => { stash.Click += (_, e) => {
if (PopupHost.CanCreatePopup()) { if (PopupHost.CanCreatePopup()) {
PopupHost.ShowPopup(new StashChanges(_repo, changes, false)); PopupHost.ShowPopup(new StashChanges(_repo, changes, false));
@ -488,7 +567,7 @@ namespace SourceGit.ViewModels {
var patch = new MenuItem(); var patch = new MenuItem();
patch.Header = App.Text("FileCM.SaveAsPatch"); patch.Header = App.Text("FileCM.SaveAsPatch");
patch.Icon = CreateMenuIcon("Icons.Diff"); patch.Icon = App.CreateMenuIcon("Icons.Diff");
patch.Click += async (o, e) => { patch.Click += async (o, e) => {
var topLevel = App.GetTopLevel(); var topLevel = App.GetTopLevel();
if (topLevel == null) return; if (topLevel == null) return;
@ -509,7 +588,7 @@ namespace SourceGit.ViewModels {
var copyPath = new MenuItem(); var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath"); copyPath.Header = App.Text("CopyPath");
copyPath.Icon = CreateMenuIcon("Icons.Copy"); copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyPath.Click += (o, e) => { copyPath.Click += (o, e) => {
App.CopyText(change.Path); App.CopyText(change.Path);
e.Handled = true; e.Handled = true;
@ -526,7 +605,7 @@ namespace SourceGit.ViewModels {
} else { } else {
var unstage = new MenuItem(); var unstage = new MenuItem();
unstage.Header = App.Text("FileCM.UnstageMulti", changes.Count); unstage.Header = App.Text("FileCM.UnstageMulti", changes.Count);
unstage.Icon = CreateMenuIcon("Icons.File.Remove"); unstage.Icon = App.CreateMenuIcon("Icons.File.Remove");
unstage.Click += (o, e) => { unstage.Click += (o, e) => {
UnstageChanges(changes); UnstageChanges(changes);
e.Handled = true; e.Handled = true;
@ -534,7 +613,7 @@ namespace SourceGit.ViewModels {
var stash = new MenuItem(); var stash = new MenuItem();
stash.Header = App.Text("FileCM.StashMulti", changes.Count); stash.Header = App.Text("FileCM.StashMulti", changes.Count);
stash.Icon = CreateMenuIcon("Icons.Stashes"); stash.Icon = App.CreateMenuIcon("Icons.Stashes");
stash.Click += (_, e) => { stash.Click += (_, e) => {
if (PopupHost.CanCreatePopup()) { if (PopupHost.CanCreatePopup()) {
PopupHost.ShowPopup(new StashChanges(_repo, changes, false)); PopupHost.ShowPopup(new StashChanges(_repo, changes, false));
@ -544,7 +623,7 @@ namespace SourceGit.ViewModels {
var patch = new MenuItem(); var patch = new MenuItem();
patch.Header = App.Text("FileCM.SaveAsPatch"); patch.Header = App.Text("FileCM.SaveAsPatch");
patch.Icon = CreateMenuIcon("Icons.Diff"); patch.Icon = App.CreateMenuIcon("Icons.Diff");
patch.Click += async (_, e) => { patch.Click += async (_, e) => {
var topLevel = App.GetTopLevel(); var topLevel = App.GetTopLevel();
if (topLevel == null) return; if (topLevel == null) return;
@ -603,15 +682,6 @@ namespace SourceGit.ViewModels {
return menu; return menu;
} }
private Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
icon.Stretch = Stretch.Uniform;
icon.Data = App.Current?.FindResource(key) as StreamGeometry;
return icon;
}
private void PushCommitMessage() { private void PushCommitMessage() {
var existIdx = _repo.CommitMessages.IndexOf(CommitMessage); var existIdx = _repo.CommitMessages.IndexOf(CommitMessage);
if (existIdx == 0) { if (existIdx == 0) {
@ -636,10 +706,13 @@ namespace SourceGit.ViewModels {
private bool _useAmend = false; private bool _useAmend = false;
private List<Models.Change> _unstaged = null; private List<Models.Change> _unstaged = null;
private List<Models.Change> _staged = null; private List<Models.Change> _staged = null;
private Models.Change _selectedUnstagedChange = null;
private Models.Change _selectedStagedChange = null;
private int _count = 0; private int _count = 0;
private List<FileTreeNode> _unstagedTree = null; private List<FileTreeNode> _unstagedTree = null;
private List<FileTreeNode> _stagedTree = null; private List<FileTreeNode> _stagedTree = null;
private ViewChangeDetailContext _lastViewChange = null; private FileTreeNode _selectedUnstagedTreeNode = null;
private FileTreeNode _selectedStagedTreeNode = null;
private object _detailContext = null; private object _detailContext = null;
private string _commitMessage = string.Empty; private string _commitMessage = string.Empty;
} }

View file

@ -60,6 +60,7 @@
<DataGrid x:Name="unstagedList" <DataGrid x:Name="unstagedList"
Background="Transparent" Background="Transparent"
ItemsSource="{Binding Unstaged}" ItemsSource="{Binding Unstaged}"
SelectedItem="{Binding SelectedUnstagedChange, Mode=TwoWay}"
SelectionMode="Extended" SelectionMode="Extended"
CanUserReorderColumns="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeColumns="False"
@ -70,7 +71,6 @@
RowHeight="26" RowHeight="26"
HorizontalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
SelectionChanged="OnUnstagedListSelectionChanged"
KeyDown="OnUnstagedListKeyDown" KeyDown="OnUnstagedListKeyDown"
ContextRequested="OnUnstagedListContextRequested" ContextRequested="OnUnstagedListContextRequested"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsList}}"> IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsList}}">
@ -96,6 +96,7 @@
<DataGrid x:Name="unstagedGrid" <DataGrid x:Name="unstagedGrid"
Background="Transparent" Background="Transparent"
ItemsSource="{Binding Unstaged}" ItemsSource="{Binding Unstaged}"
SelectedItem="{Binding SelectedUnstagedChange, Mode=TwoWay}"
SelectionMode="Extended" SelectionMode="Extended"
CanUserReorderColumns="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeColumns="False"
@ -106,7 +107,6 @@
RowHeight="26" RowHeight="26"
HorizontalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
SelectionChanged="OnUnstagedListSelectionChanged"
KeyDown="OnUnstagedListKeyDown" KeyDown="OnUnstagedListKeyDown"
ContextRequested="OnUnstagedListContextRequested" ContextRequested="OnUnstagedListContextRequested"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsGrid}}"> IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsGrid}}">
@ -139,11 +139,11 @@
<TreeView x:Name="unstagedTree" <TreeView x:Name="unstagedTree"
ItemsSource="{Binding UnstagedTree}" ItemsSource="{Binding UnstagedTree}"
SelectedItem="{Binding SelectedUnstagedTreeNode, Mode=TwoWay}"
SelectionMode="Multiple" SelectionMode="Multiple"
AutoScrollToSelectedItem="True" AutoScrollToSelectedItem="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionChanged="OnUnstagedTreeViewSelectionChanged"
KeyDown="OnUnstagedTreeViewKeyDown" KeyDown="OnUnstagedTreeViewKeyDown"
ContextRequested="OnUnstagedTreeViewContextRequested" ContextRequested="OnUnstagedTreeViewContextRequested"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsTree}}"> IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsTree}}">
@ -185,6 +185,7 @@
<DataGrid x:Name="stagedList" <DataGrid x:Name="stagedList"
Background="Transparent" Background="Transparent"
ItemsSource="{Binding Staged}" ItemsSource="{Binding Staged}"
SelectedItem="{Binding SelectedStagedChange, Mode=TwoWay}"
SelectionMode="Extended" SelectionMode="Extended"
CanUserReorderColumns="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeColumns="False"
@ -195,7 +196,6 @@
RowHeight="26" RowHeight="26"
HorizontalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
SelectionChanged="OnStagedListSelectionChanged"
KeyDown="OnStagedListKeyDown" KeyDown="OnStagedListKeyDown"
ContextRequested="OnStagedListContextRequested" ContextRequested="OnStagedListContextRequested"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsList}}"> IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsList}}">
@ -221,6 +221,7 @@
<DataGrid x:Name="stagedGrid" <DataGrid x:Name="stagedGrid"
Background="Transparent" Background="Transparent"
ItemsSource="{Binding Staged}" ItemsSource="{Binding Staged}"
SelectedItem="{Binding SelectedStagedChange, Mode=TwoWay}"
SelectionMode="Extended" SelectionMode="Extended"
CanUserReorderColumns="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeColumns="False"
@ -231,7 +232,6 @@
RowHeight="26" RowHeight="26"
HorizontalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
SelectionChanged="OnStagedListSelectionChanged"
KeyDown="OnStagedListKeyDown" KeyDown="OnStagedListKeyDown"
ContextRequested="OnStagedListContextRequested" ContextRequested="OnStagedListContextRequested"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsGrid}}"> IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsGrid}}">
@ -264,11 +264,11 @@
<TreeView x:Name="stagedTree" <TreeView x:Name="stagedTree"
ItemsSource="{Binding StagedTree}" ItemsSource="{Binding StagedTree}"
SelectedItem="{Binding SelectedStagedTreeNode, Mode=TwoWay}"
SelectionMode="Multiple" SelectionMode="Multiple"
AutoScrollToSelectedItem="True" AutoScrollToSelectedItem="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionChanged="OnStagedTreeViewSelectionChanged"
KeyDown="OnStagedTreeViewKeyDown" KeyDown="OnStagedTreeViewKeyDown"
ContextRequested="OnStagedTreeViewContextRequested" ContextRequested="OnStagedTreeViewContextRequested"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsTree}}"> IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Converter={x:Static c:ChangeViewModeConverters.IsTree}}">

View file

@ -19,132 +19,6 @@ namespace SourceGit.Views {
GC.Collect(); GC.Collect();
} }
private void OnUnstagedListSelectionChanged(object sender, SelectionChangedEventArgs e) {
var vm = DataContext as ViewModels.WorkingCopy;
if (vm == null) return;
var datagrid = sender as DataGrid;
if (datagrid.SelectedItems.Count == 0) {
if (stagedList.SelectedItem == null &&
stagedGrid.SelectedItem == null &&
stagedTree.SelectedItem == null) {
vm.SetDetail(null, true);
}
e.Handled = true;
return;
}
stagedList.SelectedItems.Clear();
stagedGrid.SelectedItems.Clear();
stagedTree.SelectedItems.Clear();
if (datagrid.SelectedItems.Count == 1) {
vm.SetDetail(datagrid.SelectedItem as Models.Change, true);
} else {
vm.SetDetail(null, true);
}
e.Handled = true;
}
private void OnUnstagedTreeViewSelectionChanged(object sender, SelectionChangedEventArgs e) {
var vm = DataContext as ViewModels.WorkingCopy;
if (vm == null) return;
var tree = sender as TreeView;
if (tree.SelectedItems.Count == 0) {
if (stagedList.SelectedItem == null &&
stagedGrid.SelectedItem == null &&
stagedTree.SelectedItem == null) {
vm.SetDetail(null, true);
}
e.Handled = true;
return;
}
stagedList.SelectedItems.Clear();
stagedGrid.SelectedItems.Clear();
stagedTree.SelectedItems.Clear();
if (tree.SelectedItems.Count == 1) {
var node = tree.SelectedItem as ViewModels.FileTreeNode;
if (node != null && !node.IsFolder) {
vm.SetDetail(node.Backend as Models.Change, true);
} else {
vm.SetDetail(null, true);
}
} else {
vm.SetDetail(null, true);
}
e.Handled = true;
}
private void OnStagedListSelectionChanged(object sender, SelectionChangedEventArgs e) {
var vm = DataContext as ViewModels.WorkingCopy;
if (vm == null) return;
var datagrid = sender as DataGrid;
if (datagrid.SelectedItems.Count == 0) {
if (unstagedList.SelectedItem == null &&
unstagedGrid.SelectedItem == null &&
unstagedTree.SelectedItem == null) {
vm.SetDetail(null, false);
}
e.Handled = true;
return;
}
unstagedList.SelectedItems.Clear();
unstagedGrid.SelectedItems.Clear();
unstagedTree.SelectedItems.Clear();
if (datagrid.SelectedItems.Count == 1) {
vm.SetDetail(datagrid.SelectedItem as Models.Change, false);
} else {
vm.SetDetail(null, false);
}
e.Handled = true;
}
private void OnStagedTreeViewSelectionChanged(object sender, SelectionChangedEventArgs e) {
var vm = DataContext as ViewModels.WorkingCopy;
if (vm == null) return;
var tree = sender as TreeView;
if (tree.SelectedItems.Count == 0) {
if (unstagedList.SelectedItem == null &&
unstagedGrid.SelectedItem == null &&
unstagedTree.SelectedItem == null) {
vm.SetDetail(null, false);
}
e.Handled = true;
return;
}
unstagedList.SelectedItems.Clear();
unstagedGrid.SelectedItems.Clear();
unstagedTree.SelectedItems.Clear();
if (tree.SelectedItems.Count == 1) {
var node = tree.SelectedItem as ViewModels.FileTreeNode;
if (node != null && !node.IsFolder) {
vm.SetDetail(node.Backend as Models.Change, false);
} else {
vm.SetDetail(null, false);
}
} else {
vm.SetDetail(null, false);
}
e.Handled = true;
}
private void ViewAssumeUnchanged(object sender, RoutedEventArgs e) { private void ViewAssumeUnchanged(object sender, RoutedEventArgs e) {
var repoPage = this.FindAncestorOfType<Repository>(); var repoPage = this.FindAncestorOfType<Repository>();
if (repoPage != null) { if (repoPage != null) {