Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added support for opening Git root in VS Code #13498

Merged
merged 13 commits into from
Oct 10, 2023
45 changes: 45 additions & 0 deletions src/Files.App/Actions/Open/OpenRepoInVSCodeAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.Shell;

namespace Files.App.Actions
{
internal sealed class OpenRepoInVSCodeAction : ObservableObject, IAction
{
private readonly IContentPageContext _context;

private readonly bool _isVSCodeInstalled;

public string Label
=> "OpenRepoInVSCode".GetLocalizedResource();

public string Description
=> "OpenRepoInVSCodeDescription".GetLocalizedResource();

public bool IsExecutable =>
_isVSCodeInstalled &&
_context.Folder is not null &&
_context.ShellPage!.InstanceViewModel.IsGitRepository;

public OpenRepoInVSCodeAction()
{
_context = Ioc.Default.GetRequiredService<IContentPageContext>();

_isVSCodeInstalled = SoftwareHelpers.IsVSCodeInstalled();
if (_isVSCodeInstalled)
_context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
{
return Win32API.RunPowershellCommandAsync($"code \'{_context.ShellPage!.InstanceViewModel.GitRepositoryPath}\'", false);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(IContentPageContext.Folder))
OnPropertyChanged(nameof(IsExecutable));
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public enum CommandCodes
// Open
OpenInVS,
OpenInVSCode,
OpenRepoInVSCode,
OpenProperties,
OpenSettings,
OpenTerminal,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand OpenParentFolder => commands[CommandCodes.OpenParentFolder];
public IRichCommand OpenInVS => commands[CommandCodes.OpenInVS];
public IRichCommand OpenInVSCode => commands[CommandCodes.OpenInVSCode];
public IRichCommand OpenRepoInVSCode => commands[CommandCodes.OpenRepoInVSCode];
public IRichCommand OpenProperties => commands[CommandCodes.OpenProperties];
public IRichCommand OpenSettings => commands[CommandCodes.OpenSettings];
public IRichCommand OpenTerminal => commands[CommandCodes.OpenTerminal];
Expand Down Expand Up @@ -261,6 +262,7 @@ public CommandManager()
[CommandCodes.OpenParentFolder] = new OpenParentFolderAction(),
[CommandCodes.OpenInVS] = new OpenInVSAction(),
[CommandCodes.OpenInVSCode] = new OpenInVSCodeAction(),
[CommandCodes.OpenRepoInVSCode] = new OpenRepoInVSCodeAction(),
[CommandCodes.OpenProperties] = new OpenPropertiesAction(),
[CommandCodes.OpenSettings] = new OpenSettingsAction(),
[CommandCodes.OpenTerminal] = new OpenTerminalAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand OpenInVS { get; }
IRichCommand OpenInVSCode { get; }
IRichCommand OpenRepoInVSCode { get; }
IRichCommand OpenProperties { get; }
IRichCommand OpenSettings { get; }
IRichCommand OpenTerminal { get; }
Expand Down
12 changes: 9 additions & 3 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3333,17 +3333,23 @@
<value>Files cannot access GitHub right now.</value>
</data>
<data name="OpenInVS" xml:space="preserve">
<value>Visual Studio</value>
<value>Open solution file in Visual Studio</value>
</data>
<data name="OpenInVSDescription" xml:space="preserve">
<value>Open the current directory in Visual Studio</value>
<value>Open the solution file in Visual Studio</value>
</data>
<data name="OpenInVSCode" xml:space="preserve">
<value>VS Code</value>
<value>Open folder in VS Code</value>
</data>
<data name="OpenInVSCodeDescription" xml:space="preserve">
<value>Open the current directory in Visual Studio Code</value>
</data>
<data name="OpenRepoInVSCode" xml:space="preserve">
<value>Open repo in VS Code</value>
</data>
<data name="OpenRepoInVSCodeDescription" xml:space="preserve">
<value>Open the root of the Git repo in Visual Studio Code</value>
</data>
<data name="CopyCode" xml:space="preserve">
<value>Copy code</value>
</data>
Expand Down
64 changes: 28 additions & 36 deletions src/Files.App/UserControls/StatusBarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,47 @@
Orientation="Horizontal"
Spacing="4">

<!-- Open in VS Code Button -->
<!-- Open in IDE Button -->
<Button
x:Name="OpenInVSCodeButton"
x:Name="OpenInIDEButton"
Height="24"
Padding="8,0,8,0"
VerticalAlignment="Center"
x:Load="{x:Bind converters:MultiBooleanConverter.AndNotConvert(Commands.OpenInVSCode.IsExecutable, Commands.OpenInVS.IsExecutable), Mode=OneWay}"
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
Background="Transparent"
BorderBrush="Transparent"
Command="{x:Bind Commands.OpenInVSCode}"
ToolTipService.ToolTip="{x:Bind Commands.OpenInVSCode.LabelWithHotKey, Mode=OneWay}">
BorderBrush="Transparent">
<Button.Content>
<StackPanel Orientation="Horizontal" Spacing="8">
<usercontrols:OpacityIcon
Width="16"
Height="16"
Style="{StaticResource ColorIconOpen}" />
<TextBlock Text="{x:Bind Commands.OpenInVSCode.Label, Mode=OneWay}" />
<TextBlock Text="{helpers:ResourceString Name=Open}" />
</StackPanel>
</Button.Content>

<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem
x:Name="OpenInVSButton"
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
Command="{x:Bind Commands.OpenInVS}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.OpenInVS.HotKeys, Mode=OneWay}"
Text="{x:Bind Commands.OpenInVS.Label, Mode=OneWay}" />
<MenuFlyoutItem
x:Name="OpenFolderInVSCodeButton"
x:Load="{x:Bind Commands.OpenInVSCode.IsExecutable, Mode=OneWay}"
Command="{x:Bind Commands.OpenInVSCode}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.OpenInVSCode.HotKeys, Mode=OneWay}"
Text="{x:Bind Commands.OpenInVSCode.Label, Mode=OneWay}" />
<MenuFlyoutItem
x:Name="OpenRepoInVSCodeButton"
x:Load="{x:Bind Commands.OpenRepoInVSCode.IsExecutable, Mode=OneWay}"
Command="{x:Bind Commands.OpenRepoInVSCode}"
KeyboardAcceleratorTextOverride="{x:Bind Commands.OpenRepoInVSCode.HotKeys, Mode=OneWay}"
Text="{x:Bind Commands.OpenRepoInVSCode.Label, Mode=OneWay}" />
</MenuFlyout>
</Button.Flyout>
</Button>
<!-- Divider -->
<Border
Expand All @@ -192,35 +213,6 @@
x:Load="{x:Bind converters:MultiBooleanConverter.AndNotConvert(Commands.OpenInVSCode.IsExecutable, Commands.OpenInVS.IsExecutable), Mode=OneWay}"
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />

<!-- Open in VS Button -->
<Button
x:Name="OpenInVSButton"
Height="24"
Padding="8,0,8,0"
VerticalAlignment="Center"
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
Background="Transparent"
BorderBrush="Transparent"
Command="{x:Bind Commands.OpenInVS}"
ToolTipService.ToolTip="{x:Bind Commands.OpenInVS.LabelWithHotKey, Mode=OneWay}">
<Button.Content>
<StackPanel Orientation="Horizontal" Spacing="8">
<usercontrols:OpacityIcon
Width="16"
Height="16"
Style="{StaticResource ColorIconOpen}" />
<TextBlock Text="{x:Bind Commands.OpenInVS.Label, Mode=OneWay}" />
</StackPanel>
</Button.Content>
</Button>
<!-- Divider -->
<Border
x:Name="VSDivider"
Width="1"
Height="18"
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />

<Button
x:Name="GitNetworkActions"
Height="24"
Expand Down