mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 21:24:59 +00:00
feature: add context menu for both branch and commit to compare selected with current HEAD
This commit is contained in:
parent
de6375da7c
commit
4249653ed6
8 changed files with 254 additions and 10 deletions
|
@ -69,7 +69,7 @@ namespace SourceGit.ViewModels
|
|||
public Models.Commit AutoSelectedCommit
|
||||
{
|
||||
get => _autoSelectedCommit;
|
||||
private set => SetProperty(ref _autoSelectedCommit, value);
|
||||
set => SetProperty(ref _autoSelectedCommit, value);
|
||||
}
|
||||
|
||||
public long NavigationId
|
||||
|
@ -81,7 +81,7 @@ namespace SourceGit.ViewModels
|
|||
public object DetailContext
|
||||
{
|
||||
get => _detailContext;
|
||||
private set => SetProperty(ref _detailContext, value);
|
||||
set => SetProperty(ref _detailContext, value);
|
||||
}
|
||||
|
||||
public Histories(Repository repo)
|
||||
|
@ -171,17 +171,16 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public ContextMenu MakeContextMenu()
|
||||
public ContextMenu MakeContextMenu(DataGrid datagrid)
|
||||
{
|
||||
var detail = _detailContext as CommitDetail;
|
||||
if (detail == null)
|
||||
if (datagrid.SelectedItems.Count != 1)
|
||||
return null;
|
||||
|
||||
var current = _repo.Branches.Find(x => x.IsCurrent);
|
||||
if (current == null)
|
||||
return null;
|
||||
|
||||
var commit = detail.Commit;
|
||||
var commit = datagrid.SelectedItem as Models.Commit;
|
||||
var menu = new ContextMenu();
|
||||
var tags = new List<Models.Tag>();
|
||||
|
||||
|
@ -317,6 +316,33 @@ namespace SourceGit.ViewModels
|
|||
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
|
||||
if (current.Head != commit.SHA)
|
||||
{
|
||||
var compare = new MenuItem();
|
||||
compare.Header = App.Text("CommitCM.CompareWithHead");
|
||||
compare.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compare.Click += (o, e) =>
|
||||
{
|
||||
var head = _commits.Find(x => x.SHA == current.Head);
|
||||
if (head == null)
|
||||
{
|
||||
_repo.SearchResultSelectedCommit = null;
|
||||
head = new Commands.QuerySingleCommit(_repo.FullPath, current.Head).Result();
|
||||
if (head != null)
|
||||
DetailContext = new RevisionCompare(_repo.FullPath, commit, head);
|
||||
}
|
||||
else
|
||||
{
|
||||
datagrid.SelectedItems.Add(head);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(compare);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
|
||||
var createBranch = new MenuItem();
|
||||
createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
|
||||
createBranch.Header = App.Text("CreateBranch");
|
||||
|
|
|
@ -928,6 +928,27 @@ namespace SourceGit.ViewModels
|
|||
|
||||
menu.Items.Add(merge);
|
||||
menu.Items.Add(rebase);
|
||||
|
||||
var compare = new MenuItem();
|
||||
compare.Header = App.Text("BranchCM.CompareWithHead");
|
||||
compare.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compare.Click += (o, e) =>
|
||||
{
|
||||
SearchResultSelectedCommit = null;
|
||||
|
||||
if (_histories != null)
|
||||
{
|
||||
var target = new Commands.QuerySingleCommit(FullPath, branch.Head).Result();
|
||||
var head = new Commands.QuerySingleCommit(FullPath, current.Head).Result();
|
||||
_histories.AutoSelectedCommit = null;
|
||||
_histories.DetailContext = new RevisionCompare(FullPath, target, head);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
menu.Items.Add(compare);
|
||||
}
|
||||
|
||||
var type = GitFlow.GetBranchType(branch.Name);
|
||||
|
@ -1197,6 +1218,30 @@ namespace SourceGit.ViewModels
|
|||
menu.Items.Add(merge);
|
||||
menu.Items.Add(rebase);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
|
||||
if (current.Head != branch.Head)
|
||||
{
|
||||
var compare = new MenuItem();
|
||||
compare.Header = App.Text("BranchCM.CompareWithHead");
|
||||
compare.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compare.Click += (o, e) =>
|
||||
{
|
||||
SearchResultSelectedCommit = null;
|
||||
|
||||
if (_histories != null)
|
||||
{
|
||||
var target = new Commands.QuerySingleCommit(FullPath, branch.Head).Result();
|
||||
var head = new Commands.QuerySingleCommit(FullPath, current.Head).Result();
|
||||
_histories.AutoSelectedCommit = null;
|
||||
_histories.DetailContext = new RevisionCompare(FullPath, target, head);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(compare);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
}
|
||||
|
||||
var delete = new MenuItem();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue