-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added open in VS/VS Code to status bar (#12645)
- Loading branch information
1 parent
d2a4a0b
commit a44bc19
Showing
12 changed files
with
276 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Contexts; | ||
using Files.App.Shell; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal sealed class OpenInVSAction : ObservableObject, IAction | ||
{ | ||
private readonly IContentPageContext _context; | ||
|
||
private readonly bool _isVSInstalled; | ||
|
||
public string Label { get; } = "OpenInVS".GetLocalizedResource(); | ||
|
||
public string Description { get; } = "OpenInVSDescription".GetLocalizedResource(); | ||
|
||
public bool IsExecutable => | ||
_isVSInstalled && | ||
!string.IsNullOrWhiteSpace(_context.SolutionFilePath); | ||
|
||
public OpenInVSAction() | ||
{ | ||
_context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
_isVSInstalled = SoftwareHelpers.IsVSInstalled(); | ||
if (_isVSInstalled ) | ||
_context.PropertyChanged += Context_PropertyChanged; | ||
} | ||
|
||
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == nameof(IContentPageContext.SolutionFilePath)) | ||
OnPropertyChanged(nameof(IsExecutable)); | ||
} | ||
|
||
public Task ExecuteAsync() | ||
{ | ||
Win32API.RunPowershellCommand($"start {_context.SolutionFilePath}", false); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Contexts; | ||
using Files.App.Shell; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal sealed class OpenInVSCodeAction : ObservableObject, IAction | ||
{ | ||
private readonly IContentPageContext _context; | ||
|
||
private readonly bool _isVSCodeInstalled; | ||
|
||
public string Label { get; } = "OpenInVSCode".GetLocalizedResource(); | ||
|
||
public string Description { get; } = "OpenInVSCodeDescription".GetLocalizedResource(); | ||
|
||
public bool IsExecutable => | ||
_isVSCodeInstalled && | ||
_context.Folder is not null; | ||
|
||
public OpenInVSCodeAction() | ||
{ | ||
_context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
_isVSCodeInstalled = SoftwareHelpers.IsVSCodeInstalled(); | ||
if (_isVSCodeInstalled) | ||
_context.PropertyChanged += Context_PropertyChanged; | ||
} | ||
|
||
public Task ExecuteAsync() | ||
{ | ||
Win32API.RunPowershellCommand($"code {_context.ShellPage?.FilesystemViewModel.WorkingDirectory}", false); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == nameof(IContentPageContext.Folder)) | ||
OnPropertyChanged(nameof(IsExecutable)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Microsoft.Win32; | ||
|
||
namespace Files.App.Helpers | ||
{ | ||
internal static class SoftwareHelpers | ||
{ | ||
public static bool IsVSCodeInstalled() | ||
{ | ||
string registryKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall"; | ||
|
||
var key = Registry.CurrentUser.OpenSubKey(registryKey); | ||
if (key is null) | ||
return false; | ||
|
||
string? displayName; | ||
|
||
foreach (var subKey in key.GetSubKeyNames().Select(key.OpenSubKey)) | ||
{ | ||
displayName = subKey?.GetValue("DisplayName") as string; | ||
if (!string.IsNullOrWhiteSpace(displayName) && displayName.StartsWith("Microsoft Visual Studio Code")) | ||
{ | ||
key.Close(); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
key.Close(); | ||
|
||
return false; | ||
} | ||
|
||
public static bool IsVSInstalled() | ||
{ | ||
string registryKey = @"SOFTWARE\Microsoft\VisualStudio"; | ||
|
||
var key = Registry.LocalMachine.OpenSubKey(registryKey); | ||
if (key is null) | ||
return false; | ||
|
||
key.Close(); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters