mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
feature: add context menu for changes in Views.CommitDetail and Views.RevisionCompare to diff with external merge tool (#53)
This commit is contained in:
parent
b5b1f0cb8d
commit
24b6e39066
5 changed files with 56 additions and 16 deletions
|
@ -137,8 +137,9 @@
|
|||
<x:String x:Key="Text.Diff.Prev" xml:space="preserve">Previous Difference</x:String>
|
||||
<x:String x:Key="Text.Diff.SideBySide" xml:space="preserve">Side-By-Side Diff</x:String>
|
||||
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">Syntax Highlighting</x:String>
|
||||
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Open With Merge Tool</x:String>
|
||||
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Open In Merge Tool</x:String>
|
||||
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">SELECT FILE TO VIEW CHANGES</x:String>
|
||||
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">Open In Merge Tool</x:String>
|
||||
<x:String x:Key="Text.Discard" xml:space="preserve">Discard Changes</x:String>
|
||||
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
|
||||
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">Changes :</x:String>
|
||||
|
|
|
@ -139,6 +139,7 @@
|
|||
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">语法高亮</x:String>
|
||||
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">使用外部合并工具查看</x:String>
|
||||
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">请选择需要对比的文件</x:String>
|
||||
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比对工具查看</x:String>
|
||||
<x:String x:Key="Text.Discard" xml:space="preserve">放弃更改确认</x:String>
|
||||
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String>
|
||||
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">需要放弃的变更 :</x:String>
|
||||
|
|
|
@ -8,6 +8,7 @@ using Avalonia.Platform.Storage;
|
|||
using Avalonia.Threading;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
|
@ -195,6 +196,28 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
var menu = new ContextMenu();
|
||||
|
||||
var diffWithMerger = new MenuItem();
|
||||
diffWithMerger.Header = App.Text("DiffWithMerger");
|
||||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.Diff");
|
||||
diffWithMerger.Click += (_, ev) =>
|
||||
{
|
||||
var opt = new Models.DiffOption(_commit, change);
|
||||
var type = Preference.Instance.ExternalMergeToolType;
|
||||
var exec = Preference.Instance.ExternalMergeToolPath;
|
||||
|
||||
var tool = Models.ExternalMergeTools.Supported.Find(x => x.Type == type);
|
||||
if (tool == null || !File.Exists(exec))
|
||||
{
|
||||
App.RaiseException(_repo, "Invalid merge tool in preference setting!");
|
||||
return;
|
||||
}
|
||||
|
||||
var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd;
|
||||
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, opt));
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(diffWithMerger);
|
||||
|
||||
if (change.Index != Models.ChangeState.Deleted)
|
||||
{
|
||||
var history = new MenuItem();
|
||||
|
@ -228,10 +251,12 @@ namespace SourceGit.ViewModels
|
|||
ev.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(new MenuItem { Header = "-" });
|
||||
menu.Items.Add(history);
|
||||
menu.Items.Add(blame);
|
||||
menu.Items.Add(explore);
|
||||
}
|
||||
menu.Items.Add(new MenuItem { Header = "-" });
|
||||
}
|
||||
|
||||
var copyPath = new MenuItem();
|
||||
copyPath.Header = App.Text("CopyPath");
|
||||
|
@ -241,8 +266,8 @@ namespace SourceGit.ViewModels
|
|||
App.CopyText(change.Path);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(copyPath);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
public async void OpenExternalMergeTool()
|
||||
public void OpenExternalMergeTool()
|
||||
{
|
||||
var type = Preference.Instance.ExternalMergeToolType;
|
||||
var exec = Preference.Instance.ExternalMergeToolPath;
|
||||
|
@ -160,7 +160,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd;
|
||||
await Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, _option));
|
||||
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, _option));
|
||||
}
|
||||
|
||||
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
|
||||
|
|
|
@ -157,33 +157,46 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
var menu = new ContextMenu();
|
||||
|
||||
var diffWithMerger = new MenuItem();
|
||||
diffWithMerger.Header = App.Text("DiffWithMerger");
|
||||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.Diff");
|
||||
diffWithMerger.Click += (_, ev) =>
|
||||
{
|
||||
var opt = new Models.DiffOption(StartPoint.SHA, EndPoint.SHA, change);
|
||||
var type = Preference.Instance.ExternalMergeToolType;
|
||||
var exec = Preference.Instance.ExternalMergeToolPath;
|
||||
|
||||
var tool = Models.ExternalMergeTools.Supported.Find(x => x.Type == type);
|
||||
if (tool == null || !File.Exists(exec))
|
||||
{
|
||||
App.RaiseException(_repo, "Invalid merge tool in preference setting!");
|
||||
return;
|
||||
}
|
||||
|
||||
var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd;
|
||||
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, opt));
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(diffWithMerger);
|
||||
|
||||
if (change.Index != Models.ChangeState.Deleted)
|
||||
{
|
||||
var history = new MenuItem();
|
||||
history.Header = App.Text("FileHistory");
|
||||
history.Click += (_, ev) =>
|
||||
{
|
||||
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
|
||||
window.Show();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var full = Path.GetFullPath(Path.Combine(_repo, change.Path));
|
||||
var explore = new MenuItem();
|
||||
explore.Header = App.Text("RevealFile");
|
||||
explore.Icon = App.CreateMenuIcon("Icons.Folder.Open");
|
||||
explore.IsEnabled = File.Exists(full);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(full, true);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(history);
|
||||
menu.Items.Add(explore);
|
||||
}
|
||||
|
||||
var copyPath = new MenuItem();
|
||||
copyPath.Header = App.Text("CopyPath");
|
||||
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
|
||||
copyPath.Click += (_, ev) =>
|
||||
{
|
||||
App.CopyText(change.Path);
|
||||
|
|
Loading…
Reference in a new issue