Skip to content

Commit

Permalink
Merge pull request #9 from VictoriousRaptor/main
Browse files Browse the repository at this point in the history
Update and bugfixes
  • Loading branch information
taooceros authored May 25, 2023
2 parents 5e4e1c5 + 4f7b971 commit df8d300
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Flow.Plugin.VSCodeWorkspaces.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<ProjectGuid>{4D971245-7A70-41D5-BAA0-DDB5684CAF51}</ProjectGuid>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Flow.Plugin.VSCodeWorkspaces</RootNamespace>
Expand Down Expand Up @@ -44,7 +44,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Plugin" Version="3.0.0" />
<PackageReference Include="Flow.Launcher.Plugin" Version="4.0.1" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.1" />
Expand Down
39 changes: 34 additions & 5 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -93,8 +93,8 @@ public List<Result> 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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -193,5 +200,27 @@ public string GetTranslatedPluginDescription()
{
return Resources.PluginDescription;
}

public List<Result> LoadContextMenus(Result selectedResult)
{
List<Result> 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;
}
}
}
27 changes: 27 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,13 @@
<data name="ExtraFolderUri" xml:space="preserve">
<value>Extra Folder URI</value>
</data>
<data name="OpenFail" xml:space="preserve">
<value>Can't open this workspace</value>
</data>
<data name="OpenFolder" xml:space="preserve">
<value>Open Folder</value>
</data>
<data name="OpenFolderSubTitle" xml:space="preserve">
<value>Open folder in default file manager</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@
<data name="In" xml:space="preserve">
<value>位于</value>
</data>
<data name="OpenFail" xml:space="preserve">
<value>无法打开工作区</value>
</data>
<data name="OpenFolder" xml:space="preserve">
<value>打开文件夹</value>
</data>
<data name="OpenFolderSubTitle" xml:space="preserve">
<value>在默认文件管理器中打开文件夹</value>
</data>
<data name="PluginDescription" xml:space="preserve">
<value>在 VS Code 中打开最近使用的工作区、远程计算机(SSH 或 Codespaces)和容器。</value>
</data>
Expand Down
9 changes: 7 additions & 2 deletions VSCodeHelper/VSCodeInstances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit df8d300

Please sign in to comment.