diff --git a/README.md b/README.md index 1b1b3b41af..896c5b2bd2 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ This app supports open repository in external tools listed in the table below. | VSCodium | YES | YES | YES | | Cursor | YES | YES | YES | | Sublime Text | YES | YES | YES | +| Kate | YES | YES | YES | | Zed | YES | YES | YES | | Visual Studio | YES | NO | NO | diff --git a/THIRD-PARTY-LICENSES.md b/THIRD-PARTY-LICENSES.md index 1cd779a8e3..3f71f1b780 100644 --- a/THIRD-PARTY-LICENSES.md +++ b/THIRD-PARTY-LICENSES.md @@ -67,6 +67,14 @@ The project uses the following third-party libraries or assets - **Version**: 2.30.15 - **License**: Public Domain +## Icons + +### Kate + +- **Author**: Tyson Tan for the Kate project +- **Source**: [Kate's 32×32 application icon](https://github.com/KDE/kate/blob/master/apps/kate/icons/unix/32-apps-kate.png), included unchanged +- **License**: [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/), as offered by the [Kate project](https://kate-editor.org/post/2020/2020-01-25-new-kate-icon/) + ## Fonts ### JetBrainsMono diff --git a/src/Models/ExternalTool.cs b/src/Models/ExternalTool.cs index 04dc2acd4b..97d44780bf 100644 --- a/src/Models/ExternalTool.cs +++ b/src/Models/ExternalTool.cs @@ -28,6 +28,7 @@ public LaunchOption(string title, string args) public string ExecFile { get; } public Bitmap IconImage { get; } public bool SupportOpenFolder { get; } + public bool SupportOpenUnrealProject { get; init; } public ExternalTool(string name, string icon, string execFile, Func> optionsGenerator, bool supportOpenFolder) { @@ -54,6 +55,22 @@ public List MakeLaunchOptions(string repo) return _optionsGenerator?.Invoke(repo); } + public List MakeUnrealProjectLaunchOptions(string repo) + { + if (!SupportOpenUnrealProject) + return null; + + var root = new DirectoryInfo(repo); + var options = new List(); + root.WalkFiles(file => + { + if (file.EndsWith(".uproject", StringComparison.OrdinalIgnoreCase)) + options.Add(new(Path.GetRelativePath(root.FullName, file), file.Quoted())); + }, maxDepth: 1); + options.Sort((left, right) => StringComparer.Ordinal.Compare(left.Title, right.Title)); + return options; + } + public void Launch(string args) { if (File.Exists(ExecFile)) @@ -175,6 +192,11 @@ public void SublimeText(Func platformFinder) TryAdd("Sublime Text", "sublime_text", platformFinder); } + public void Kate(Func platformFinder) + { + TryAdd("Kate", "kate", platformFinder); + } + public void Zed(Func platformFinder) { TryAdd("Zed", "zed", platformFinder); @@ -205,7 +227,10 @@ public void FindJetBrainsFromToolbox(Func platformFinder) $"JetBrains/{tool.ProductCode}", Path.Combine(tool.InstallLocation, tool.LaunchCommand), null, - true)); + true) + { + SupportOpenUnrealProject = tool.ProductCode == "RD", + }); } } catch diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index 1744cf913e..ce65d5d081 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -113,6 +113,7 @@ public string FindTerminal(Models.ShellOrTerminal shell) finder.Cursor(() => FindExecutable("cursor")); finder.FindJetBrainsFromToolbox(() => Path.Combine(localAppDataDir, "JetBrains/Toolbox")); finder.SublimeText(() => FindExecutable("subl")); + finder.Kate(() => FindExecutable("kate")); finder.Zed(() => { var exec = FindExecutable("zeditor"); diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index a02a90751a..ff10727d3a 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -102,6 +102,15 @@ public string FindTerminal(Models.ShellOrTerminal shell) finder.Cursor(() => "/Applications/Cursor.app/Contents/Resources/app/bin/cursor"); finder.FindJetBrainsFromToolbox(() => Path.Combine(home, "Library/Application Support/JetBrains/Toolbox")); finder.SublimeText(() => "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"); + finder.Kate(() => + { + const string bundleExecutable = "kate.app/Contents/MacOS/kate"; + var executable = "/Applications/" + bundleExecutable; + if (File.Exists(executable)) + return executable; + + return string.IsNullOrEmpty(home) ? string.Empty : Path.Combine(home, "Applications", bundleExecutable); + }); finder.Zed(() => File.Exists("/usr/local/bin/zed") ? "/usr/local/bin/zed" : "/Applications/Zed.app/Contents/MacOS/cli"); return finder.Tools; } diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index a2d3f496c1..83ce6fd1f5 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -12,6 +12,8 @@ using Avalonia.Platform; using Avalonia.Threading; +using Microsoft.Win32; + namespace SourceGit.Native { [SupportedOSPlatform("windows")] @@ -157,6 +159,7 @@ public string FindTerminal(Models.ShellOrTerminal shell) finder.Cursor(() => Path.Combine(localAppDataDir, @"Programs\Cursor\Cursor.exe")); finder.FindJetBrainsFromToolbox(() => Path.Combine(localAppDataDir, @"JetBrains\Toolbox")); finder.SublimeText(FindSublimeText); + finder.Kate(FindKate); finder.Zed(FindZed); return finder.Tools; } @@ -410,6 +413,31 @@ private void FindVisualStudio(Models.ExternalToolsFinder finder) } } + private string FindKate() + { + var registryLocations = new[] + { + (RegistryHive.CurrentUser, RegistryView.Default), + (RegistryHive.LocalMachine, RegistryView.Registry64), + (RegistryHive.LocalMachine, RegistryView.Registry32), + }; + + foreach (var (hive, view) in registryLocations) + { + using var baseKey = RegistryKey.OpenBaseKey(hive, view); + using var kate = baseKey.OpenSubKey(@"SOFTWARE\KDE\Kate"); + if (kate?.GetValue("Install_Dir") is not string installDir || !Path.IsPathFullyQualified(installDir)) + continue; + + var executable = Path.Combine(installDir, "bin", "kate.exe"); + if (File.Exists(executable)) + return executable; + } + + var findInPath = new StringBuilder("kate.exe", 512); + return PathFindOnPath(findInPath, null) ? findInPath.ToString() : string.Empty; + } + private string FindZed() { var currentUser = Microsoft.Win32.RegistryKey.OpenBaseKey( diff --git a/src/Resources/Images/ExternalToolIcons/kate.png b/src/Resources/Images/ExternalToolIcons/kate.png new file mode 100644 index 0000000000..e4b89a47d9 Binary files /dev/null and b/src/Resources/Images/ExternalToolIcons/kate.png differ diff --git a/src/Views/RepositoryToolbar.axaml.cs b/src/Views/RepositoryToolbar.axaml.cs index c5ba572cad..0ee6e3c416 100644 --- a/src/Views/RepositoryToolbar.axaml.cs +++ b/src/Views/RepositoryToolbar.axaml.cs @@ -117,6 +117,9 @@ private void OpenWithExternalTools(object sender, RoutedEventArgs ev) } menu.Items.Add(item); + + if (CreateUnrealProjectMenuItem(dupTool, fullpath) is { } unrealProjectItem) + menu.Items.Add(unrealProjectItem); } } @@ -153,6 +156,35 @@ private void OpenWithExternalTools(object sender, RoutedEventArgs ev) } } + private static MenuItem CreateUnrealProjectMenuItem(Models.ExternalTool tool, string repositoryPath) + { + var projects = tool.MakeUnrealProjectLaunchOptions(repositoryPath); + if (projects == null || projects.Count == 0) + return null; + + var item = new MenuItem(); + item.Header = App.Text("Repository.OpenIn", $"{tool.Name} (uproject)"); + item.Icon = new Image { Width = 16, Height = 16, Source = tool.IconImage }; + + foreach (var project in projects) + { + var target = item; + if (projects.Count > 1) + { + target = new MenuItem { Header = project.Title }; + item.Items.Add(target); + } + + target.Click += (_, e) => + { + tool.Launch(project.Args); + e.Handled = true; + }; + } + + return item; + } + private async void OpenStatistics(object _, RoutedEventArgs e) { if (DataContext is ViewModels.Repository repo)