feature: supports to visit remote repository in web browser (#1265)

- combine `Open in File Manager`, `Open in Terminal` and `Open with external editor` into one dropdown menu
- add `Visit $REMOTE in Browser`

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-06 15:51:57 +08:00
parent e4e2f7b3a7
commit 93a5d7baea
No known key found for this signature in database
5 changed files with 73 additions and 36 deletions

View file

@ -626,6 +626,7 @@
<x:String x:Key="Text.Repository.Terminal" xml:space="preserve">Open in Terminal</x:String>
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">Use relative time in histories</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">View Logs</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">Visit '{0}' in Browser</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">WORKTREES</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">ADD WORKTREE</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">PRUNE</x:String>

View file

@ -630,6 +630,7 @@
<x:String x:Key="Text.Repository.Terminal" xml:space="preserve">在终端中打开</x:String>
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">在提交列表中使用相对时间</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">查看命令日志</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">访问远程仓库 '{0}'</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作树列表</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">新增工作树</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">清理</x:String>

View file

@ -630,6 +630,7 @@
<x:String x:Key="Text.Repository.Terminal" xml:space="preserve">在終端機中開啟</x:String>
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">在提交列表中使用相對時間</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">檢視 Git 指令記錄</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">檢視遠端存放庫 '{0}'</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作區列表</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">新增工作區</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">清理</x:String>

View file

@ -583,30 +583,42 @@ namespace SourceGit.ViewModels
Task.Run(RefreshStashes);
}
public void OpenInFileManager()
{
Native.OS.OpenInFileManager(_fullpath);
}
public void OpenInTerminal()
{
Native.OS.OpenTerminal(_fullpath);
}
public ContextMenu CreateContextMenuForExternalTools()
{
var tools = Native.OS.ExternalTools;
if (tools.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 tool in tools)
RenderOptions.SetBitmapInterpolationMode(menu, BitmapInterpolationMode.HighQuality);
RenderOptions.SetEdgeMode(menu, EdgeMode.Antialias);
RenderOptions.SetTextRenderingMode(menu, TextRenderingMode.Antialias);
var explore = new MenuItem();
explore.Header = App.Text("Repository.Explore");
explore.Icon = App.CreateMenuIcon("Icons.Explore");
explore.Click += (_, e) =>
{
Native.OS.OpenInFileManager(_fullpath);
e.Handled = true;
};
var terminal = new MenuItem();
terminal.Header = App.Text("Repository.Terminal");
terminal.Icon = App.CreateMenuIcon("Icons.Terminal");
terminal.Click += (_, e) =>
{
Native.OS.OpenTerminal(_fullpath);
e.Handled = true;
};
menu.Items.Add(explore);
menu.Items.Add(terminal);
var tools = Native.OS.ExternalTools;
if (tools.Count > 0)
{
menu.Items.Add(new MenuItem() { Header = "-" });
foreach (var tool in Native.OS.ExternalTools)
{
var dupTool = tool;
@ -621,6 +633,36 @@ namespace SourceGit.ViewModels
menu.Items.Add(item);
}
}
var urls = new Dictionary<string, string>();
foreach (var r in _remotes)
{
if (r.TryGetVisitURL(out var visit))
urls.Add(r.Name, visit);
}
if (urls.Count > 0)
{
menu.Items.Add(new MenuItem() { Header = "-" });
foreach (var url in urls)
{
var name = url.Key;
var addr = url.Value;
var item = new MenuItem();
item.Header = App.Text("Repository.Visit", name);
item.Icon = App.CreateMenuIcon("Icons.Remotes");
item.Click += (_, e) =>
{
Native.OS.OpenBrowser(addr);
e.Handled = true;
};
menu.Items.Add(item);
}
}
return menu;
}

View file

@ -9,16 +9,8 @@
x:DataType="vm:Repository">
<Grid ColumnDefinitions="*,Auto,*">
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="4,0,0,0">
<Button Classes="icon_button" Width="32" Command="{Binding OpenInFileManager}" ToolTip.Tip="{DynamicResource Text.Repository.Explore}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Explore}" Margin="0,2,0,0"/>
</Button>
<Button Classes="icon_button" Width="32" Click="OpenWithExternalTools" IsVisible="{Binding !IsBare}" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
</Button>
<Button Classes="icon_button" Width="32" Command="{Binding OpenInTerminal}" ToolTip.Tip="{DynamicResource Text.Repository.Terminal}">
<Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/>
<Path Width="14" Height="14" Data="{StaticResource Icons.Explore}" Margin="0,2,0,0"/>
</Button>
<Button Classes="icon_button" Width="32" Click="OpenGitLogs" ToolTip.Tip="{DynamicResource Text.Repository.ViewLogs}">