Skip to content

Commit 3b5fbb3

Browse files
Merge pull request #7 from JonahFintzDev/settings-integration
Add Settings Integration
2 parents ea5ce11 + 1bf2d23 commit 3b5fbb3

File tree

12 files changed

+597
-41
lines changed

12 files changed

+597
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,5 @@ MigrationBackup/
360360
.ionide/
361361

362362
# Fody - auto-generated XML schema
363-
FodyWeavers.xsd
363+
FodyWeavers.xsd
364+
.idea

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,37 @@ This project provides a command palette extension for opening Visual Studio Code
1414

1515
## Installation
1616

17+
> [!NOTE]
18+
> Because the application is first signed by the Microsoft Store, updates will take a few days to be available via WinGet or in the Command Palette.
19+
1720
### Windows Store
1821

1922
<a href="https://apps.microsoft.com/detail/9PKCGVQ05TG1?mode=direct">
2023
<img src="https://get.microsoft.com/images/en-us%20light.svg" width="300"/>
2124
</a>
2225

26+
### Via Command Palette
27+
1. Open Command Palette
28+
2. Select "Command Palette - VS Code"
29+
30+
### Via Winget
31+
1. Open Command Prompt or PowerShell
32+
2. Run the following command:
33+
```bash
34+
winget install JonahFintzDEV.CommandPalette-VSCode
35+
```
36+
2337
### Manual Installation
2438

2539
1. Make sure you use the latest version of PowerToys.
26-
2. Download the current Version and the certificate from [releases](https://github.com/JonahFintzDev/CommandPaletteVSCode/releases/).
27-
3. Install the application by double-clicking the `.msix` file.
40+
2. Install the application by double-clicking the `.msix` file.
41+
42+
## Settings
43+
44+
- **Preferred Edition**: Determines which edition (Default or Insider) is used when a folder or workspace has been opened in both editions of VS Code.
45+
- **Use Strict Search**: Enables or disables strict search for workspaces.
46+
- **Strict Search**: Matches items where the search text appears as a contiguous substring in the item's title or subtitle. For example, searching for "abc" will match "abc" or "abc123" but not "a1b2c3".
47+
- **Show Details Panel**: Toggles the visibility of the details panel in the UI.
2848

2949
## Contributing
3050

VsCode/Classes/SettingsManager.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Microsoft Corporation
2+
// The Microsoft Corporation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using CmdPalVsCode.Properties;
6+
using Microsoft.CommandPalette.Extensions.Toolkit;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
10+
namespace CmdPalVsCode;
11+
12+
public class SettingsManager : JsonSettingsManager
13+
{
14+
private static readonly string _namespace = "vscode";
15+
16+
private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}";
17+
18+
private static readonly List<ChoiceSetSetting.Choice> _choices =
19+
[
20+
new ChoiceSetSetting.Choice(Resource.setting_preferredEdition_option_default_label, "Default"),
21+
new ChoiceSetSetting.Choice(Resource.setting_preferredEdition_option_insider_label, "Insider"),
22+
];
23+
24+
25+
private readonly ToggleSetting _useStrictSearch = new(
26+
Namespaced(nameof(UseStrichtSearch)),
27+
Resource.settings_useStrictSearch_label,
28+
Resource.settings_useStrictSearch_desc,
29+
false); // TODO -- double check default value
30+
31+
private readonly ToggleSetting _showDetails = new(
32+
Namespaced(nameof(ShowDetails)),
33+
Resource.settings_showDetails_label,
34+
Resource.settings_showDetails_desc,
35+
false); // TODO -- double check default value
36+
37+
private readonly ChoiceSetSetting _preferredEdition = new(
38+
Namespaced(nameof(PreferredEdition)),
39+
Resource.setting_preferredEdition_label,
40+
Resource.setting_preferredEdition_desc,
41+
_choices);
42+
43+
public bool UseStrichtSearch => _useStrictSearch.Value;
44+
public bool ShowDetails => _showDetails.Value;
45+
46+
public string PreferredEdition => _preferredEdition.Value ?? "Default";
47+
48+
49+
internal static string SettingsJsonPath()
50+
{
51+
var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal");
52+
Directory.CreateDirectory(directory);
53+
54+
// now, the state is just next to the exe
55+
return Path.Combine(directory, "settings.json");
56+
}
57+
58+
public SettingsManager()
59+
{
60+
FilePath = SettingsJsonPath();
61+
62+
Settings.Add(_showDetails);
63+
Settings.Add(_useStrictSearch);
64+
Settings.Add(_preferredEdition);
65+
66+
// Load settings from file upon initialization
67+
LoadSettings();
68+
69+
Settings.SettingsChanged += (s, a) =>
70+
{
71+
VSCodeHandler.LoadInstances(PreferredEdition);
72+
this.SaveSettings();
73+
};
74+
}
75+
}

VsCode/Classes/VSCodeHandler.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@ internal static class VSCodeHandler
1515

1616
/// <summary>
1717
/// Loads all available VS Code instances (default and insiders, user and system installations).
18-
/// </summary>
19-
public static void LoadInstances()
18+
/// </summary>
19+
public static void LoadInstances(string preferredEdition)
2020
{
2121
var appdataProgramFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
2222
var programsFolderPathBase = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
2323
var defaultStoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Code", "User", "globalStorage");
2424
var insiderStoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Code - Insiders", "User", "globalStorage");
2525

26+
Instances.Clear();
2627

2728
AddInstance("VS Code", Path.Combine(appdataProgramFilesPath, "Programs", "Microsoft VS Code", "Code.exe"), defaultStoragePath, VSCodeInstallationType.User, VSCodeType.Default);
2829
AddInstance("VS Code [System]", Path.Combine(programsFolderPathBase, "Microsoft VS Code", "Code.exe"), defaultStoragePath, VSCodeInstallationType.System, VSCodeType.Default);
2930
AddInstance("VS Code - Insiders", Path.Combine(appdataProgramFilesPath, "Programs", "Microsoft VS Code Insiders", "Code - Insiders.exe"), insiderStoragePath, VSCodeInstallationType.User, VSCodeType.Insider);
3031
AddInstance("VS Code - Insiders [System]", Path.Combine(programsFolderPathBase, "Microsoft VS Code Insiders", "Code - Insiders.exe"), insiderStoragePath, VSCodeInstallationType.System, VSCodeType.Insider);
32+
33+
34+
if (preferredEdition == "Insider")
35+
{
36+
// Reverse the order of the instances
37+
Instances.Reverse();
38+
}
3139
}
3240

3341
/// <summary>

VsCode/Classes/VSCodeWorkspace.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
namespace CmdPalVsCode;
1+
using CmdPalVsCode.Properties;
2+
using Microsoft.CommandPalette.Extensions.Toolkit;
3+
using System;
4+
using System.Collections.Generic;
5+
6+
namespace CmdPalVsCode;
27

38
/// <summary>
49
/// Enum for type of Visual Studio Code.
@@ -97,4 +102,36 @@ public string GetWorkspaceType()
97102
return "Unknown Type";
98103
}
99104
}
105+
106+
107+
/// <summary>
108+
/// Gets the details of the workspace.
109+
/// </summary>
110+
/// <returns>An array of details elements containing information about the workspace.</returns>
111+
public DetailsElement[] GetMetadata()
112+
{
113+
var typeTags = new List<Tag>() { new Tag(GetWorkspaceType()) };
114+
if (GetVSType() != "")
115+
{
116+
typeTags.Add(new Tag(GetVSType()));
117+
}
118+
119+
return new List<DetailsElement>(){
120+
new DetailsElement()
121+
{
122+
Key = Resource.item_details_target,
123+
Data = new DetailsTags() { Tags = new List<Tag>() { new Tag(Instance.Name) }.ToArray() }
124+
},
125+
new DetailsElement()
126+
{
127+
Key = Resource.item_details_type,
128+
Data = new DetailsTags() { Tags = typeTags.ToArray() }
129+
},
130+
new DetailsElement()
131+
{
132+
Key = Resource.item_details_path,
133+
Data = new DetailsLink() { Text = Uri.UnescapeDataString(Path) },
134+
}
135+
}.ToArray();
136+
}
100137
}

VsCode/CmdPalVsCode.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
<PackageReference Include="System.Text.Json" />
6060
<PackageReference Include="Shmuelie.WinRTServer" />
6161
</ItemGroup>
62+
<ItemGroup>
63+
<Compile Update="Properties\Resource.Designer.cs">
64+
<DesignTime>True</DesignTime>
65+
<AutoGen>True</AutoGen>
66+
<DependentUpon>Resource.resx</DependentUpon>
67+
</Compile>
68+
</ItemGroup>
6269
<ItemGroup>
6370
<Content Update="Assets\VsCodeIcon.png">
6471
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -153,6 +160,12 @@
153160
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
154161
</Content>
155162
</ItemGroup>
163+
<ItemGroup>
164+
<EmbeddedResource Update="Properties\Resource.resx">
165+
<Generator>ResXFileCodeGenerator</Generator>
166+
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
167+
</EmbeddedResource>
168+
</ItemGroup>
156169

157170
<!--
158171
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
@@ -182,7 +195,7 @@
182195
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
183196
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
184197
<GenerateTemporaryStoreCertificate>True</GenerateTemporaryStoreCertificate>
185-
<AppxPackageDir>C:\Users\jonah\Documents\Visual Studio 2022\Projects\VsCode\AppPackages\</AppxPackageDir>
198+
<AppxPackageDir>I:\Freelancer\RiderProjects\CommandPaletteVSCode\AppPackages\</AppxPackageDir>
186199
</PropertyGroup>
187200

188201
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

VsCode/CmdPalVsCodeCommandsProvider.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,27 @@ namespace CmdPalVsCode;
66
public partial class CmdPalVsCodeCommandsProvider : CommandProvider
77
{
88
private readonly ICommandItem[] _commands;
9-
9+
private readonly SettingsManager _settingsManager = new();
1010
public CmdPalVsCodeCommandsProvider()
1111
{
1212
DisplayName = "VS Code";
1313
Icon = IconHelpers.FromRelativePath("Assets\\VsCodeIcon.png");
14+
15+
Settings = _settingsManager.Settings;
1416
_commands = [
15-
new CommandItem(new VSCodePage()) { Title = DisplayName },
17+
new CommandItem(new VSCodePage(_settingsManager)) {
18+
Title = DisplayName,
19+
MoreCommands = [
20+
new CommandContextItem(Settings.SettingsPage),
21+
],
22+
},
1623
];
1724

18-
VSCodeHandler.LoadInstances();
25+
VSCodeHandler.LoadInstances(_settingsManager.PreferredEdition);
26+
1927
}
2028

29+
2130
public override ICommandItem[] TopLevelCommands()
2231
{
2332
return _commands;

VsCode/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Identity
1313
Name="JonahFintzDEV.602808C55E867"
1414
Publisher="CN=240FD63B-E96D-4F79-A6D2-BFC6E6AD6C10"
15-
Version="1.1.2.0" />
15+
Version="1.2.0.0" />
1616

1717

1818
<Properties>

0 commit comments

Comments
 (0)