-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSettingsManager.cs
More file actions
442 lines (390 loc) · 16 KB
/
Copy pathSettingsManager.cs
File metadata and controls
442 lines (390 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
// Modifications copyright (c) 2025 tanchekwei
// Licensed under the MIT License. See the LICENSE file in the project root for details.
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.CommandPalette.Extensions.Toolkit;
using WorkspaceLauncherForVSCode.Classes;
using WorkspaceLauncherForVSCode.Enums;
using WorkspaceLauncherForVSCode.Properties;
namespace WorkspaceLauncherForVSCode;
public class SettingsManager : JsonSettingsManager
{
private static readonly string _namespace = "vscode";
private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}";
private static readonly List<ChoiceSetSetting.Choice> _searchByChoices =
[
new ChoiceSetSetting.Choice("Both", nameof(SearchBy.Both)),
new ChoiceSetSetting.Choice("Title", nameof(SearchBy.Title)),
new ChoiceSetSetting.Choice("Path", nameof(SearchBy.Path)),
];
private static readonly List<ChoiceSetSetting.Choice> _vscodeSecondaryCommandChoices =
[
new ChoiceSetSetting.Choice("Open in Explorer", nameof(SecondaryCommand.OpenInExplorer)),
new ChoiceSetSetting.Choice("Run as Administrator", nameof(SecondaryCommand.OpenAsAdministrator)),
];
private static readonly List<ChoiceSetSetting.Choice> _vsSecondaryCommandChoices =
[
new ChoiceSetSetting.Choice("Run as Administrator", nameof(SecondaryCommand.OpenAsAdministrator)),
new ChoiceSetSetting.Choice("Open in Explorer", nameof(SecondaryCommand.OpenInExplorer)),
];
private static readonly List<ChoiceSetSetting.Choice> _sortByChoices =
[
new ChoiceSetSetting.Choice(
"Last Used, Usage Count\n" +
"- Sorted by last opened time and how many times an item has been opened.",
nameof(SortBy.Default)
),
new ChoiceSetSetting.Choice(
"Last Used\n" +
"- Sorted by last opened time.\n" +
"- Time is recorded when you open an item via the extension.",
nameof(SortBy.LastAccessed)
),
new ChoiceSetSetting.Choice(
"Usage Count\n" +
"- Sorted by how many times an item has been opened.\n" +
"- Counter increases each time you open it via the extension.",
nameof(SortBy.Frequency)
),
new ChoiceSetSetting.Choice(
"Recent from Visual Studio\n" +
"- Sorts workspaces based on Visual Studio's recent solution list.\n" +
"- Uses LastAccessed timestamps from ApplicationPrivateSettings.xml.",
nameof(SortBy.RecentFromVS)
),
new ChoiceSetSetting.Choice(
"Recent from Visual Studio Code\n" +
"- Sorts workspaces to match the order in VS Code's 'File > Open Recent' list.\n" +
"- Monitors VS Code's internal state.vscdb for real-time updates.\n" +
"- Only works when a single VS Code instance is enabled.\n" +
"- Please enable only one of: User, System, Insiders, or Custom instance.",
nameof(SortBy.RecentFromVSCode)
),
];
private static readonly List<ChoiceSetSetting.Choice> _terminalTypeChoices =
[
new ChoiceSetSetting.Choice("Windows Terminal (Default Profile)", nameof(TerminalType.WindowsTerminal)),
new ChoiceSetSetting.Choice("PowerShell", nameof(TerminalType.PowerShell)),
new ChoiceSetSetting.Choice("Command Prompt", nameof(TerminalType.Cmd)),
];
private readonly ToggleSetting _enableLogging = new(
Namespaced(nameof(EnableLogging)),
"Enable Logging",
"Enables diagnostic logging for troubleshooting.",
false);
private readonly ToggleSetting _useHelperLauncher = new(
Namespaced(nameof(UseHelperLauncher)),
"Use Helper Launcher",
"Launches Visual Studio Code via a helper executable (VisualStudioCodeForCommandPaletteLauncher.exe). Enable this if Visual Studio Code doesn't come to the foreground when opened. This workaround is needed on some PCs because Windows can prevent background processes (like this extension) from 'stealing' focus.",
false);
private readonly ToggleSetting _showTypeTag = new(
Namespaced(nameof(_showTypeTag)),
"Show by Type",
"e.g., Workspace, WSL, Codespaces, Dev Container, SSH Remote, Attached Container",
true);
private readonly ToggleSetting _showTargetTag = new(
Namespaced(nameof(_showTargetTag)),
"Show by Target IDE",
"e.g., Visual Studio 2022, VS Code, VS Code - Insiders",
false);
private readonly ToggleSetting _enableVisualStudio = new(
Namespaced(nameof(_enableVisualStudio)),
"Enable Visual Studio",
"Loads solutions/projects from Visual Studio",
true);
private readonly ToggleSetting _enableDefault = new(
Namespaced(nameof(_enableDefault)),
"Enable Visual Studio Code (User)",
"Loads folders/workspaces from the default Visual Studio Code installation",
true);
private readonly ToggleSetting _enableSystem = new(
Namespaced(nameof(_enableSystem)),
"Enable Visual Studio Code (System)",
"Loads folders/workspaces from the system-wide Visual Studio Code installation",
true);
private readonly ToggleSetting _enableInsider = new(
Namespaced(nameof(_enableInsider)),
"Enable Visual Studio Code (Insiders)",
"Loads folders/workspaces from the Visual Studio Code Insiders version",
false);
private readonly ToggleSetting _enableCustom = new(
Namespaced(nameof(_enableCustom)),
"Enable Visual Studio Code (Custom)",
"Loads folders/workspaces from custom Visual Studio Code installations found in your system PATH.",
false);
private readonly ToggleSetting _enableCustomPath = new(
Namespaced(nameof(_enableCustomPath)),
"Enable Visual Studio Code (Custom Path for Portable mode)",
"If enabled, the Custom Visual Studio Code Path below will be used.",
false);
private readonly TextSetting _customPath = new(
Namespaced(nameof(_customPath)),
"Custom Visual Studio Code Path",
"Custom Visual Studio Code Path.\nFull path to Code.exe for your Visual Studio Code installation. (e.g. D:\\VSCode-win32-x64-1.110.1\\Code.exe).",
"");
private readonly ToggleSetting _enableCursor = new(
Namespaced(nameof(_enableCursor)),
"Enable Cursor",
"Loads folders from Cursor",
false);
private readonly TextSetting _cursorPath = new(
Namespaced(nameof(CursorPath)),
"Cursor Path",
"The executable path for Cursor. Leave default if installed in the standard location.",
Path.Combine("C:", "Program Files", "cursor", "Cursor.exe"));
private readonly ToggleSetting _enableAntigravity = new(
Namespaced(nameof(_enableAntigravity)),
"Enable Google Antigravity",
"Loads folders from Google Antigravity",
false);
private readonly TextSetting _antigravityPath = new(
Namespaced(nameof(AntigravityPath)),
"Antigravity Path",
"The executable path for Google Antigravity. Leave default if installed in the standard location.",
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "antigravity", "Antigravity.exe"));
private readonly ToggleSetting _enableWindsurf = new(
Namespaced(nameof(_enableWindsurf)),
"Enable Windsurf",
"Loads folders from Windsurf",
false);
private readonly TextSetting _windsurfPath = new(
Namespaced(nameof(WindsurfPath)),
"Windsurf Path",
"The executable path for Windsurf. Leave default if installed in the standard location.",
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "Windsurf", "Windsurf.exe"));
private readonly ToggleSetting _enableVscodium = new(
Namespaced(nameof(_enableVscodium)),
"Enable VSCodium",
"Loads folders from VSCodium",
false);
private readonly TextSetting _vscodiumPath = new(
Namespaced(nameof(VscodiumPath)),
"VSCodium Path",
"The executable path for VSCodium. Leave default if installed in the standard location.",
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "VSCodium", "VSCodium.exe"));
private readonly ToggleSetting _enableWorkspaceWatcher = new(
Namespaced(nameof(EnableWorkspaceWatcher)),
"Enable Workspace Watcher",
$"Automatically refreshes the workspace list when changes are detected in {Constant.VisualStudioCodeDisplayName}'s recent list.",
true);
private readonly ChoiceSetSetting _searchBy = new(
Namespaced(nameof(SearchBy)),
"Search By",
"Search by path, title or both.",
_searchByChoices);
private readonly ChoiceSetSetting _vsSecondaryCommand = new(
Namespaced(nameof(VSSecondaryCommand)),
"Visual Studio Secondary Command",
"Configure the secondary command for Visual Studio solutions.",
_vsSecondaryCommandChoices);
private readonly ChoiceSetSetting _vscodeSecondaryCommand = new(
Namespaced(nameof(VSCodeSecondaryCommand)),
"Visual Studio Code Secondary Command",
"Configure the secondary command for Visual Studio Code workspaces.",
_vscodeSecondaryCommandChoices);
private readonly TextSetting _pageSize = new(
Namespaced(nameof(PageSize)),
Resource.setting_pageSize_label,
Resource.setting_pageSize_desc,
"16");
private readonly TextSetting _fallbackCount = new(
Namespaced(nameof(FallbackCount)),
"Fallback Count",
"Number of top-level fallback items on the main list page (set 0 to disable).\nRestart Command Palette to apply Fallback Count setting changes.",
"3");
private readonly ChoiceSetSetting _sortBy = new(
Namespaced(nameof(SortBy)),
"Sort By",
"Determines how items are sorted when no search text is entered.",
_sortByChoices);
private readonly ChoiceSetSetting _terminalType = new(
Namespaced(nameof(TerminalType)),
"Terminal Type",
"The terminal to use for the 'Open in Terminal' command.",
_terminalTypeChoices);
public TerminalType TerminalType
{
get
{
if (Enum.TryParse<TerminalType>(_terminalType.Value, out var result))
{
return result;
}
return TerminalType.WindowsTerminal;
}
}
public SortBy SortBy
{
get
{
if (Enum.TryParse<SortBy>(_sortBy.Value, out var result))
{
return result;
}
return SortBy.Default;
}
}
public bool EnableLogging => _enableLogging.Value;
public bool UseHelperLauncher => _useHelperLauncher.Value;
public bool EnableVisualStudio => _enableVisualStudio.Value;
public bool EnableWorkspaceWatcher => _enableWorkspaceWatcher.Value;
public TagType TagTypes
{
get
{
var tagType = TagType.None;
if (_showTypeTag.Value)
{
tagType |= TagType.Type;
}
if (_showTargetTag.Value)
{
tagType |= TagType.Target;
}
return tagType;
}
set
{
_showTypeTag.Value = value.HasFlag(TagType.Type);
_showTargetTag.Value = value.HasFlag(TagType.Target);
}
}
public VisualStudioCodeEdition EnabledEditions
{
get
{
var editions = VisualStudioCodeEdition.None;
if (_enableDefault.Value) editions |= VisualStudioCodeEdition.Default;
if (_enableSystem.Value) editions |= VisualStudioCodeEdition.System;
if (_enableInsider.Value) editions |= VisualStudioCodeEdition.Insider;
if (_enableCustom.Value) editions |= VisualStudioCodeEdition.Custom;
if (_enableCustomPath.Value) editions |= VisualStudioCodeEdition.CustomPath;
if (_enableCursor.Value) editions |= VisualStudioCodeEdition.Cursor;
if (_enableAntigravity.Value) editions |= VisualStudioCodeEdition.Antigravity;
if (_enableWindsurf.Value) editions |= VisualStudioCodeEdition.Windsurf;
if (_enableVscodium.Value) editions |= VisualStudioCodeEdition.Vscodium;
return editions;
}
}
public string CustomPath => _customPath.Value ?? string.Empty;
public string CursorPath => _cursorPath.Value ?? string.Empty;
public string AntigravityPath => _antigravityPath.Value ?? string.Empty;
public string WindsurfPath => _windsurfPath.Value ?? string.Empty;
public string VscodiumPath => _vscodiumPath.Value ?? string.Empty;
public SearchBy SearchBy
{
get
{
if (Enum.TryParse<SearchBy>(_searchBy.Value, out var result))
{
return result;
}
return SearchBy.Both;
}
}
public SecondaryCommand VSSecondaryCommand
{
get
{
if (Enum.TryParse<SecondaryCommand>(_vsSecondaryCommand.Value, out var result))
{
return result;
}
return SecondaryCommand.OpenAsAdministrator;
}
}
public SecondaryCommand VSCodeSecondaryCommand
{
get
{
if (Enum.TryParse<SecondaryCommand>(_vscodeSecondaryCommand.Value, out var result))
{
return result;
}
return SecondaryCommand.OpenInExplorer;
}
}
public int PageSize
{
get
{
if (int.TryParse(_pageSize.Value, out int size) && size > 0)
{
return size;
}
return 16;
}
}
public int FallbackCount
{
get
{
if (int.TryParse(_fallbackCount.Value, out int size) && size >= 0)
{
return size;
}
return 3;
}
}
internal static string SettingsJsonPath()
{
try
{
var directory = Utilities.BaseSettingsPath(Constant.AppName);
Directory.CreateDirectory(directory);
return Path.Combine(directory, "settings.json");
}
catch (Exception ex)
{
ErrorLogger.LogError(ex);
throw;
}
}
public SettingsManager()
{
try
{
FilePath = SettingsJsonPath();
Settings.Add(_showTypeTag);
Settings.Add(_showTargetTag);
Settings.Add(_enableVisualStudio);
Settings.Add(_enableDefault);
Settings.Add(_enableSystem);
Settings.Add(_enableInsider);
Settings.Add(_enableCustom);
Settings.Add(_enableCustomPath);
Settings.Add(_customPath);
Settings.Add(_enableVscodium);
Settings.Add(_vscodiumPath);
Settings.Add(_enableCursor);
Settings.Add(_cursorPath);
Settings.Add(_enableAntigravity);
Settings.Add(_antigravityPath);
Settings.Add(_enableWindsurf);
Settings.Add(_windsurfPath);
Settings.Add(_pageSize);
Settings.Add(_fallbackCount);
Settings.Add(_searchBy);
Settings.Add(_sortBy);
Settings.Add(_terminalType);
Settings.Add(_vsSecondaryCommand);
Settings.Add(_vscodeSecondaryCommand);
Settings.Add(_useHelperLauncher);
// Settings.Add(_enableWorkspaceWatcher);
#if DEBUG
Settings.Add(_enableLogging);
#endif
// Load settings from file upon initialization
LoadSettings();
Settings.SettingsChanged += (s, a) =>
{
SaveSettings();
};
}
catch (Exception ex)
{
ErrorLogger.LogError(ex);
}
}
}