Skip to content

Commit c79d0cc

Browse files
authored
Feature: Added support for opening Git root in VS Code (#13498)
1 parent 8c67a83 commit c79d0cc

File tree

7 files changed

+79
-92
lines changed

7 files changed

+79
-92
lines changed

src/Files.App/Actions/Open/OpenInVSAction.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Files.App.Utils.Shell;
5+
6+
namespace Files.App.Actions
7+
{
8+
internal sealed class OpenRepoInVSCodeAction : ObservableObject, IAction
9+
{
10+
private readonly IContentPageContext _context;
11+
12+
private readonly bool _isVSCodeInstalled;
13+
14+
public string Label
15+
=> "OpenRepoInVSCode".GetLocalizedResource();
16+
17+
public string Description
18+
=> "OpenRepoInVSCodeDescription".GetLocalizedResource();
19+
20+
public bool IsExecutable =>
21+
_isVSCodeInstalled &&
22+
_context.Folder is not null &&
23+
_context.ShellPage!.InstanceViewModel.IsGitRepository;
24+
25+
public OpenRepoInVSCodeAction()
26+
{
27+
_context = Ioc.Default.GetRequiredService<IContentPageContext>();
28+
29+
_isVSCodeInstalled = SoftwareHelpers.IsVSCodeInstalled();
30+
if (_isVSCodeInstalled)
31+
_context.PropertyChanged += Context_PropertyChanged;
32+
}
33+
34+
public Task ExecuteAsync()
35+
{
36+
return Win32API.RunPowershellCommandAsync($"code \'{_context.ShellPage!.InstanceViewModel.GitRepositoryPath}\'", false);
37+
}
38+
39+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
40+
{
41+
if (e.PropertyName == nameof(IContentPageContext.Folder))
42+
OnPropertyChanged(nameof(IsExecutable));
43+
}
44+
}
45+
}

src/Files.App/Data/Commands/CommandCodes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public enum CommandCodes
9696
RotateRight,
9797

9898
// Open
99-
OpenInVS,
10099
OpenInVSCode,
100+
OpenRepoInVSCode,
101101
OpenProperties,
102102
OpenSettings,
103103
OpenTerminal,

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public IRichCommand this[HotKey hotKey]
9898
public IRichCommand OpenItem => commands[CommandCodes.OpenItem];
9999
public IRichCommand OpenItemWithApplicationPicker => commands[CommandCodes.OpenItemWithApplicationPicker];
100100
public IRichCommand OpenParentFolder => commands[CommandCodes.OpenParentFolder];
101-
public IRichCommand OpenInVS => commands[CommandCodes.OpenInVS];
102101
public IRichCommand OpenInVSCode => commands[CommandCodes.OpenInVSCode];
102+
public IRichCommand OpenRepoInVSCode => commands[CommandCodes.OpenRepoInVSCode];
103103
public IRichCommand OpenProperties => commands[CommandCodes.OpenProperties];
104104
public IRichCommand OpenSettings => commands[CommandCodes.OpenSettings];
105105
public IRichCommand OpenTerminal => commands[CommandCodes.OpenTerminal];
@@ -259,8 +259,8 @@ public CommandManager()
259259
[CommandCodes.OpenItem] = new OpenItemAction(),
260260
[CommandCodes.OpenItemWithApplicationPicker] = new OpenItemWithApplicationPickerAction(),
261261
[CommandCodes.OpenParentFolder] = new OpenParentFolderAction(),
262-
[CommandCodes.OpenInVS] = new OpenInVSAction(),
263262
[CommandCodes.OpenInVSCode] = new OpenInVSCodeAction(),
263+
[CommandCodes.OpenRepoInVSCode] = new OpenRepoInVSCodeAction(),
264264
[CommandCodes.OpenProperties] = new OpenPropertiesAction(),
265265
[CommandCodes.OpenSettings] = new OpenSettingsAction(),
266266
[CommandCodes.OpenTerminal] = new OpenTerminalAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public interface ICommandManager : IEnumerable<IRichCommand>
8383
IRichCommand RotateLeft { get; }
8484
IRichCommand RotateRight { get; }
8585

86-
IRichCommand OpenInVS { get; }
8786
IRichCommand OpenInVSCode { get; }
87+
IRichCommand OpenRepoInVSCode { get; }
8888
IRichCommand OpenProperties { get; }
8989
IRichCommand OpenSettings { get; }
9090
IRichCommand OpenTerminal { get; }

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,18 +3332,18 @@
33323332
<data name="CannotReachGitHubError" xml:space="preserve">
33333333
<value>Files cannot access GitHub right now.</value>
33343334
</data>
3335-
<data name="OpenInVS" xml:space="preserve">
3336-
<value>Visual Studio</value>
3337-
</data>
3338-
<data name="OpenInVSDescription" xml:space="preserve">
3339-
<value>Open the current directory in Visual Studio</value>
3340-
</data>
33413335
<data name="OpenInVSCode" xml:space="preserve">
3342-
<value>VS Code</value>
3336+
<value>Open folder in VS Code</value>
33433337
</data>
33443338
<data name="OpenInVSCodeDescription" xml:space="preserve">
33453339
<value>Open the current directory in Visual Studio Code</value>
33463340
</data>
3341+
<data name="OpenRepoInVSCode" xml:space="preserve">
3342+
<value>Open repo in VS Code</value>
3343+
</data>
3344+
<data name="OpenRepoInVSCodeDescription" xml:space="preserve">
3345+
<value>Open the root of the Git repo in Visual Studio Code</value>
3346+
</data>
33473347
<data name="CopyCode" xml:space="preserve">
33483348
<value>Copy code</value>
33493349
</data>

src/Files.App/UserControls/StatusBarControl.xaml

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -163,62 +163,48 @@
163163
Orientation="Horizontal"
164164
Spacing="4">
165165

166-
<!-- Open in VS Code Button -->
166+
<!-- Open in IDE Button -->
167167
<Button
168-
x:Name="OpenInVSCodeButton"
168+
x:Name="OpenInIDEButton"
169169
Height="24"
170170
Padding="8,0,8,0"
171171
VerticalAlignment="Center"
172-
x:Load="{x:Bind converters:MultiBooleanConverter.AndNotConvert(Commands.OpenInVSCode.IsExecutable, Commands.OpenInVS.IsExecutable), Mode=OneWay}"
172+
x:Load="{x:Bind Commands.OpenInVSCode.IsExecutable, Mode=OneWay}"
173173
Background="Transparent"
174-
BorderBrush="Transparent"
175-
Command="{x:Bind Commands.OpenInVSCode}"
176-
ToolTipService.ToolTip="{x:Bind Commands.OpenInVSCode.LabelWithHotKey, Mode=OneWay}">
174+
BorderBrush="Transparent">
177175
<Button.Content>
178176
<StackPanel Orientation="Horizontal" Spacing="8">
179177
<usercontrols:OpacityIcon
180178
Width="16"
181179
Height="16"
182180
Style="{StaticResource ColorIconOpen}" />
183-
<TextBlock Text="{x:Bind Commands.OpenInVSCode.Label, Mode=OneWay}" />
181+
<TextBlock Text="{helpers:ResourceString Name=Open}" />
184182
</StackPanel>
185183
</Button.Content>
186-
</Button>
187-
<!-- Divider -->
188-
<Border
189-
x:Name="VSCodeDivider"
190-
Width="1"
191-
Height="18"
192-
x:Load="{x:Bind converters:MultiBooleanConverter.AndNotConvert(Commands.OpenInVSCode.IsExecutable, Commands.OpenInVS.IsExecutable), Mode=OneWay}"
193-
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
194184

195-
<!-- Open in VS Button -->
196-
<Button
197-
x:Name="OpenInVSButton"
198-
Height="24"
199-
Padding="8,0,8,0"
200-
VerticalAlignment="Center"
201-
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
202-
Background="Transparent"
203-
BorderBrush="Transparent"
204-
Command="{x:Bind Commands.OpenInVS}"
205-
ToolTipService.ToolTip="{x:Bind Commands.OpenInVS.LabelWithHotKey, Mode=OneWay}">
206-
<Button.Content>
207-
<StackPanel Orientation="Horizontal" Spacing="8">
208-
<usercontrols:OpacityIcon
209-
Width="16"
210-
Height="16"
211-
Style="{StaticResource ColorIconOpen}" />
212-
<TextBlock Text="{x:Bind Commands.OpenInVS.Label, Mode=OneWay}" />
213-
</StackPanel>
214-
</Button.Content>
185+
<Button.Flyout>
186+
<MenuFlyout>
187+
<MenuFlyoutItem
188+
x:Name="OpenFolderInVSCodeButton"
189+
x:Load="{x:Bind Commands.OpenInVSCode.IsExecutable, Mode=OneWay}"
190+
Command="{x:Bind Commands.OpenInVSCode}"
191+
KeyboardAcceleratorTextOverride="{x:Bind Commands.OpenInVSCode.HotKeys, Mode=OneWay}"
192+
Text="{x:Bind Commands.OpenInVSCode.Label, Mode=OneWay}" />
193+
<MenuFlyoutItem
194+
x:Name="OpenRepoInVSCodeButton"
195+
x:Load="{x:Bind Commands.OpenRepoInVSCode.IsExecutable, Mode=OneWay}"
196+
Command="{x:Bind Commands.OpenRepoInVSCode}"
197+
KeyboardAcceleratorTextOverride="{x:Bind Commands.OpenRepoInVSCode.HotKeys, Mode=OneWay}"
198+
Text="{x:Bind Commands.OpenRepoInVSCode.Label, Mode=OneWay}" />
199+
</MenuFlyout>
200+
</Button.Flyout>
215201
</Button>
216202
<!-- Divider -->
217203
<Border
218-
x:Name="VSDivider"
204+
x:Name="VSCodeDivider"
219205
Width="1"
220206
Height="18"
221-
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
207+
x:Load="{x:Bind Commands.OpenInVSCode.IsExecutable, Mode=OneWay}"
222208
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
223209

224210
<Button

0 commit comments

Comments
 (0)