diff --git a/Flow.Plugin.VSCodeWorkspaces.csproj b/Flow.Plugin.VSCodeWorkspaces.csproj index f802230..fa1d655 100644 --- a/Flow.Plugin.VSCodeWorkspaces.csproj +++ b/Flow.Plugin.VSCodeWorkspaces.csproj @@ -1,6 +1,6 @@ - + - net6.0-windows + net7.0-windows {4D971245-7A70-41D5-BAA0-DDB5684CAF51} Properties Flow.Plugin.VSCodeWorkspaces @@ -44,7 +44,7 @@ - + diff --git a/Main.cs b/Main.cs index 8096813..bc44e01 100644 --- a/Main.cs +++ b/Main.cs @@ -17,7 +17,7 @@ namespace Flow.Plugin.VSCodeWorkspaces using VSCodeHelper; using WorkspacesHelper; - public class Main : IPlugin, IPluginI18n, ISettingProvider + public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu { internal static PluginInitContext _context { get; private set; } @@ -93,8 +93,8 @@ public List Query(Query query) } catch (Win32Exception) { - var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; - const string msg = "Can't Open this file"; + var name = $"{_context.CurrentPluginMetadata.Name}"; + string msg = Resources.OpenFail; _context.API.ShowMsg(name, msg, string.Empty); hide = false; } @@ -141,6 +141,13 @@ private Result CreateWorkspaceResult(VSCodeWorkspace ws) { try { + var modifierKeys = c.SpecialKeyState.ToModifierKeys(); + if (modifierKeys == System.Windows.Input.ModifierKeys.Control) + { + _context.API.OpenDirectory(SystemPath.RealPath(ws.RelativePath)); + return true; + } + var process = new ProcessStartInfo { FileName = ws.VSCodeInstance.ExecutablePath, @@ -155,8 +162,8 @@ private Result CreateWorkspaceResult(VSCodeWorkspace ws) } catch (Win32Exception) { - var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; - const string msg = "Can't Open this file"; + var name = $"{_context.CurrentPluginMetadata.Name}"; + string msg = Resources.OpenFail; _context.API.ShowMsg(name, msg, string.Empty); } return false; @@ -193,5 +200,27 @@ public string GetTranslatedPluginDescription() { return Resources.PluginDescription; } + + public List LoadContextMenus(Result selectedResult) + { + List results = new(); + if (selectedResult.ContextData is VSCodeWorkspace ws && ws.TypeWorkspace == TypeWorkspace.Local) + { + results.Add(new Result + { + Title = Resources.OpenFolder, + SubTitle = Resources.OpenFolderSubTitle, + Icon = ws.VSCodeInstance.WorkspaceIcon, + TitleToolTip = Resources.OpenFolderSubTitle, + Action = c => + { + _context.API.OpenDirectory(SystemPath.RealPath(ws.RelativePath)); + return true; + }, + ContextData = ws, + }); + } + return results; + } } } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index f76e3a8..e304058 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -132,6 +132,33 @@ public static string In { } } + /// + /// 查找类似 Can't open this workspace 的本地化字符串。 + /// + public static string OpenFail { + get { + return ResourceManager.GetString("OpenFail", resourceCulture); + } + } + + /// + /// 查找类似 Open Folder 的本地化字符串。 + /// + public static string OpenFolder { + get { + return ResourceManager.GetString("OpenFolder", resourceCulture); + } + } + + /// + /// 查找类似 Open folder in default file manager 的本地化字符串。 + /// + public static string OpenFolderSubTitle { + get { + return ResourceManager.GetString("OpenFolderSubTitle", resourceCulture); + } + } + /// /// 查找类似 Opens workspaces, remote machines (SSH or Codespaces) and containers, previously opened in VS Code. 的本地化字符串。 /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 2966271..5678ff2 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -167,4 +167,13 @@ Extra Folder URI + + Can't open this workspace + + + Open Folder + + + Open folder in default file manager + \ No newline at end of file diff --git a/Properties/Resources.zh-CN.resx b/Properties/Resources.zh-CN.resx index 05d24ca..54a6368 100644 --- a/Properties/Resources.zh-CN.resx +++ b/Properties/Resources.zh-CN.resx @@ -141,6 +141,15 @@ 位于 + + 无法打开工作区 + + + 打开文件夹 + + + 在默认文件管理器中打开文件夹 + 在 VS Code 中打开最近使用的工作区、远程计算机(SSH 或 Codespaces)和容器。 diff --git a/VSCodeHelper/VSCodeInstances.cs b/VSCodeHelper/VSCodeInstances.cs index e6871c6..64e869d 100644 --- a/VSCodeHelper/VSCodeInstances.cs +++ b/VSCodeHelper/VSCodeInstances.cs @@ -71,7 +71,7 @@ public static void LoadVSCodeInstances() _systemPath = Environment.GetEnvironmentVariable("PATH") ?? ""; var paths = _systemPath.Split(";").Where(x => x.Contains("VS Code", StringComparison.OrdinalIgnoreCase) || - x.Contains("VSCodium", StringComparison.OrdinalIgnoreCase) || + x.Contains("codium", StringComparison.OrdinalIgnoreCase) || x.Contains("vscode", StringComparison.OrdinalIgnoreCase)); foreach (var path in paths) { @@ -80,7 +80,7 @@ public static void LoadVSCodeInstances() var files = Directory.EnumerateFiles(path).Where(x => (x.Contains("code", StringComparison.OrdinalIgnoreCase) || - x.Contains("VSCodium", StringComparison.OrdinalIgnoreCase)) + x.Contains("codium", StringComparison.OrdinalIgnoreCase)) && !x.EndsWith(".cmd", StringComparison.OrdinalIgnoreCase)).ToArray(); var iconPath = Path.GetDirectoryName(path); @@ -111,6 +111,11 @@ public static void LoadVSCodeInstances() version = "Code - Exploration"; instance.VSCodeVersion = VSCodeVersion.Exploration; } + else if (file.EndsWith("codium")) + { + version = "VSCodium"; + instance.VSCodeVersion = VSCodeVersion.Stable; + } if (version == string.Empty) continue; diff --git a/plugin.json b/plugin.json index ad6eba3..dac7e0d 100644 --- a/plugin.json +++ b/plugin.json @@ -4,9 +4,9 @@ "ActionKeyword": "{", "Name": "VS Code Workspaces", "Author": "ricardosantos9521", - "Version": "1.2.2", + "Version": "1.3.0", "Language": "csharp", - "Website": "https://github.com/ricardosantos9521/PowerToys/", + "Website": "https://github.com/taooceros/Flow.Plugin.VSCodeWorkspace", "ExecuteFileName": "Flow.Plugin.VSCodeWorkspaces.dll", "IsGlobal": false, "IcoPath": "Images\\code-light.png"