Skip to content

Commit

Permalink
Feature: Added support for opening Git root in VS Code (#13498)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Oct 10, 2023
1 parent 8c67a83 commit c79d0cc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 92 deletions.
44 changes: 0 additions & 44 deletions src/Files.App/Actions/Open/OpenInVSAction.cs

This file was deleted.

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));
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public enum CommandCodes
RotateRight,

// Open
OpenInVS,
OpenInVSCode,
OpenRepoInVSCode,
OpenProperties,
OpenSettings,
OpenTerminal,
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand OpenItem => commands[CommandCodes.OpenItem];
public IRichCommand OpenItemWithApplicationPicker => commands[CommandCodes.OpenItemWithApplicationPicker];
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 @@ -259,8 +259,8 @@ public CommandManager()
[CommandCodes.OpenItem] = new OpenItemAction(),
[CommandCodes.OpenItemWithApplicationPicker] = new OpenItemWithApplicationPickerAction(),
[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
2 changes: 1 addition & 1 deletion src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand RotateLeft { get; }
IRichCommand RotateRight { get; }

IRichCommand OpenInVS { get; }
IRichCommand OpenInVSCode { get; }
IRichCommand OpenRepoInVSCode { get; }
IRichCommand OpenProperties { get; }
IRichCommand OpenSettings { get; }
IRichCommand OpenTerminal { get; }
Expand Down
14 changes: 7 additions & 7 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3332,18 +3332,18 @@
<data name="CannotReachGitHubError" xml:space="preserve">
<value>Files cannot access GitHub right now.</value>
</data>
<data name="OpenInVS" xml:space="preserve">
<value>Visual Studio</value>
</data>
<data name="OpenInVSDescription" xml:space="preserve">
<value>Open the current directory 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
60 changes: 23 additions & 37 deletions src/Files.App/UserControls/StatusBarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,62 +163,48 @@
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.OpenInVSCode.IsExecutable, Mode=OneWay}"
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>
<!-- Divider -->
<Border
x:Name="VSCodeDivider"
Width="1"
Height="18"
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.Flyout>
<MenuFlyout>
<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
x:Name="VSDivider"
x:Name="VSCodeDivider"
Width="1"
Height="18"
x:Load="{x:Bind Commands.OpenInVS.IsExecutable, Mode=OneWay}"
x:Load="{x:Bind Commands.OpenInVSCode.IsExecutable, Mode=OneWay}"
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />

<Button
Expand Down

0 comments on commit c79d0cc

Please sign in to comment.