enhance: add file histories context menu item for staged changes and deleted files (#432)

This commit is contained in:
leo 2024-09-02 09:41:00 +08:00
parent b0b55c989a
commit a2c6afc5cc
No known key found for this signature in database
2 changed files with 37 additions and 28 deletions

View file

@ -267,44 +267,41 @@ namespace SourceGit.ViewModels
var explore = new MenuItem(); var explore = new MenuItem();
explore.Header = App.Text("RevealFile"); explore.Header = App.Text("RevealFile");
explore.Icon = App.CreateMenuIcon("Icons.Explore"); explore.Icon = App.CreateMenuIcon("Icons.Explore");
explore.IsVisible = File.Exists(fullPath); explore.IsEnabled = File.Exists(fullPath);
explore.Click += (_, ev) => explore.Click += (_, ev) =>
{ {
Native.OS.OpenInFileManager(fullPath, true); Native.OS.OpenInFileManager(fullPath, true);
ev.Handled = true; ev.Handled = true;
}; };
var history = new MenuItem();
history.Header = App.Text("FileHistory");
history.Icon = App.CreateMenuIcon("Icons.Histories");
history.Click += (_, ev) =>
{
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
window.Show();
ev.Handled = true;
};
var blame = new MenuItem();
blame.Header = App.Text("Blame");
blame.Icon = App.CreateMenuIcon("Icons.Blame");
blame.IsEnabled = change.Index != Models.ChangeState.Deleted;
blame.Click += (_, ev) =>
{
var window = new Views.Blame() { DataContext = new Blame(_repo.FullPath, change.Path, _commit.SHA) };
window.Show();
ev.Handled = true;
};
var menu = new ContextMenu(); var menu = new ContextMenu();
menu.Items.Add(diffWithMerger); menu.Items.Add(diffWithMerger);
menu.Items.Add(explore); menu.Items.Add(explore);
menu.Items.Add(new MenuItem { Header = "-" }); menu.Items.Add(new MenuItem { Header = "-" });
menu.Items.Add(history);
if (change.Index != Models.ChangeState.Deleted) menu.Items.Add(blame);
{ menu.Items.Add(new MenuItem { Header = "-" });
var history = new MenuItem();
history.Header = App.Text("FileHistory");
history.Icon = App.CreateMenuIcon("Icons.Histories");
history.Click += (_, ev) =>
{
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
window.Show();
ev.Handled = true;
};
var blame = new MenuItem();
blame.Header = App.Text("Blame");
blame.Icon = App.CreateMenuIcon("Icons.Blame");
blame.Click += (_, ev) =>
{
var window = new Views.Blame() { DataContext = new Blame(_repo.FullPath, change.Path, _commit.SHA) };
window.Show();
ev.Handled = true;
};
menu.Items.Add(history);
menu.Items.Add(blame);
menu.Items.Add(new MenuItem { Header = "-" });
}
var resetToThisRevision = new MenuItem(); var resetToThisRevision = new MenuItem();
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision"); resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");

View file

@ -952,6 +952,16 @@ namespace SourceGit.ViewModels
e.Handled = true; e.Handled = true;
}; };
var history = new MenuItem();
history.Header = App.Text("FileHistory");
history.Icon = App.CreateMenuIcon("Icons.Histories");
history.Click += (_, e) =>
{
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
window.Show();
e.Handled = true;
};
var copyPath = new MenuItem(); var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath"); copyPath.Header = App.Text("CopyPath");
copyPath.Icon = App.CreateMenuIcon("Icons.Copy"); copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
@ -977,6 +987,8 @@ namespace SourceGit.ViewModels
menu.Items.Add(stash); menu.Items.Add(stash);
menu.Items.Add(patch); menu.Items.Add(patch);
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(history);
menu.Items.Add(new MenuItem() { Header = "-" });
var lfsEnabled = new Commands.LFS(_repo.FullPath).IsEnabled(); var lfsEnabled = new Commands.LFS(_repo.FullPath).IsEnabled();
if (lfsEnabled) if (lfsEnabled)