|
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. |
| 1 | +// Modifications copyright (c) 2025 tanchekwei |
| 2 | +// Licensed under the MIT License. See the LICENSE file in the project root for details. |
4 | 3 | using System.IO; |
5 | 4 | using Microsoft.CmdPal.Ext.System.Helpers; |
6 | 5 | using Microsoft.CommandPalette.Extensions.Toolkit; |
| 6 | +using WorkspaceLauncherForVSCode.Enums; |
7 | 7 |
|
8 | 8 | namespace WorkspaceLauncherForVSCode.Commands |
9 | 9 | { |
10 | 10 | public sealed partial class OpenInExplorerCommand : InvokableCommand |
11 | 11 | { |
12 | 12 | private readonly VisualStudioCodeWorkspace? workspace; |
13 | | - private readonly VisualStudioCodePage? page; |
14 | | - public OpenInExplorerCommand(string arguments, VisualStudioCodeWorkspace? workspace, VisualStudioCodePage? page, string name = "Open in Explorer", string path = "explorer.exe", string? workingDir = null, OpenInShellHelper.ShellRunAsType runAs = OpenInShellHelper.ShellRunAsType.None, bool runWithHiddenWindow = false) |
| 13 | + private readonly string _path; |
| 14 | + private string _arguments; |
| 15 | + |
| 16 | + public OpenInExplorerCommand(string arguments, VisualStudioCodeWorkspace? workspace, string name = "Open in Explorer", string path = "explorer.exe") |
15 | 17 | { |
16 | 18 | Name = name; |
17 | 19 | _path = path; |
18 | 20 | _arguments = arguments; |
19 | | - _workingDir = workingDir; |
20 | | - _runAs = runAs; |
21 | | - _runWithHiddenWindow = runWithHiddenWindow; |
22 | 21 | Icon = Classes.Icon.FileExplorer; |
23 | 22 | this.workspace = workspace; |
24 | | - this.page = page; |
25 | 23 | } |
26 | 24 |
|
27 | 25 | public override CommandResult Invoke() |
28 | 26 | { |
29 | | - if (_arguments == null) |
| 27 | + string pathToOpen = workspace?.WindowsPath ?? _arguments; |
| 28 | + |
| 29 | + if (string.IsNullOrEmpty(pathToOpen)) |
30 | 30 | { |
31 | 31 | return CommandResult.Dismiss(); |
32 | 32 | } |
33 | | - var pathNotFoundResult = CommandHelpers.IsPathNotFound(_arguments); |
34 | | - if (pathNotFoundResult != null) |
| 33 | + if (workspace?.VsCodeRemoteType == VsCodeRemoteType.Remote) |
35 | 34 | { |
36 | | - return pathNotFoundResult; |
| 35 | + new ToastStatusMessage($"Not supported.").Show(); |
| 36 | + return CommandResult.KeepOpen(); |
37 | 37 | } |
38 | 38 | if (workspace?.WorkspaceType == Enums.WorkspaceType.Solution) |
39 | 39 | { |
40 | | - _arguments = Path.GetDirectoryName(_arguments); |
| 40 | + pathToOpen = Path.GetDirectoryName(pathToOpen) ?? string.Empty; |
| 41 | + } |
| 42 | + |
| 43 | + if (string.IsNullOrEmpty(pathToOpen)) |
| 44 | + { |
| 45 | + new ToastStatusMessage($"Path does not exist").Show(); |
| 46 | + return CommandResult.KeepOpen(); |
41 | 47 | } |
42 | | - OpenInShellHelper.OpenInShell(_path, _arguments); |
| 48 | + |
| 49 | + var pathInvalidResult = CommandHelpers.IsPathValid(pathToOpen); |
| 50 | + if (pathInvalidResult != null) |
| 51 | + { |
| 52 | + return pathInvalidResult; |
| 53 | + } |
| 54 | + |
| 55 | + OpenInShellHelper.OpenInShell(_path, pathToOpen); |
43 | 56 | return CommandResult.Dismiss(); |
44 | 57 | } |
45 | | - |
46 | | - private string _path; |
47 | | - private string? _workingDir; |
48 | | - private string? _arguments; |
49 | | - private OpenInShellHelper.ShellRunAsType _runAs; |
50 | | - private bool _runWithHiddenWindow; |
51 | 58 | } |
52 | 59 | } |
0 commit comments