mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
refactor: rewrite external editor supports
* supported editors can be different on different platforms. * display founded editors only
This commit is contained in:
parent
bcb83af576
commit
111bf2966a
20 changed files with 417 additions and 220 deletions
|
@ -6,6 +6,9 @@ using System.Threading.Tasks;
|
|||
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Threading;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
@ -279,21 +282,43 @@ namespace SourceGit.ViewModels
|
|||
Native.OS.OpenInFileManager(_fullpath);
|
||||
}
|
||||
|
||||
public void OpenInVSCode()
|
||||
{
|
||||
Native.OS.OpenInVSCode(_fullpath);
|
||||
}
|
||||
|
||||
public void OpenInFleet()
|
||||
{
|
||||
Native.OS.OpenInFleet(_fullpath);
|
||||
}
|
||||
|
||||
public void OpenInTerminal()
|
||||
{
|
||||
Native.OS.OpenTerminal(_fullpath);
|
||||
}
|
||||
|
||||
public ContextMenu CreateContextMenuForExternalEditors()
|
||||
{
|
||||
var editors = Native.OS.ExternalEditors;
|
||||
if (editors.Count == 0)
|
||||
{
|
||||
App.RaiseException(_fullpath, "No available external editors found!");
|
||||
return null;
|
||||
}
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
|
||||
RenderOptions.SetBitmapInterpolationMode(menu, BitmapInterpolationMode.HighQuality);
|
||||
|
||||
foreach (var editor in editors)
|
||||
{
|
||||
var dupEditor = editor;
|
||||
var icon = AssetLoader.Open(dupEditor.Icon);
|
||||
var item = new MenuItem();
|
||||
item.Header = App.Text("Repository.OpenIn", dupEditor.Name);
|
||||
item.Icon = new Image { Width = 16, Height = 16, Source = new Bitmap(icon) };
|
||||
item.Click += (o, e) =>
|
||||
{
|
||||
dupEditor.Open(_fullpath);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(item);
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void Fetch()
|
||||
{
|
||||
if (!PopupHost.CanCreatePopup())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue