Support for Visual Studio Code Insiders

This commit is contained in:
VNC
2020-12-28 21:12:52 +01:00
parent dc1360422f
commit e0c362856e
4 changed files with 31 additions and 7 deletions

View File

@@ -54,6 +54,9 @@ namespace FlaxEditor.Modules.SourceCodeEditing
case CodeEditorTypes.VSCode: case CodeEditorTypes.VSCode:
Name = "Visual Studio Code"; Name = "Visual Studio Code";
break; break;
case CodeEditorTypes.VSCodeInsiders:
Name = "Visual Studio Code - Insiders";
break;
default: throw new ArgumentOutOfRangeException(nameof(type), type, null); default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
} }
} }
@@ -68,7 +71,9 @@ namespace FlaxEditor.Modules.SourceCodeEditing
{ {
switch (Type) switch (Type)
{ {
case CodeEditorTypes.VSCode: return "-vscode"; case CodeEditorTypes.VSCodeInsiders:
case CodeEditorTypes.VSCode:
return "-vscode";
default: return null; default: return null;
} }
} }

View File

@@ -62,6 +62,11 @@ API_ENUM(Namespace="FlaxEditor", Attributes="HideInEditor") enum class CodeEdito
/// </summary> /// </summary>
VSCode, VSCode,
/// <summary>
/// Visual Studio Code Insiders
/// </summary>
VSCodeInsiders,
MAX MAX
}; };

View File

@@ -8,8 +8,9 @@
#include "Engine/Engine/Globals.h" #include "Engine/Engine/Globals.h"
#include "Engine/Platform/Win32/IncludeWindowsHeaders.h" #include "Engine/Platform/Win32/IncludeWindowsHeaders.h"
VisualStudioCodeEditor::VisualStudioCodeEditor(const String& execPath) VisualStudioCodeEditor::VisualStudioCodeEditor(const String& execPath, const bool isInsiders)
: _execPath(execPath) : _execPath(execPath)
, _isInsiders(isInsiders)
, _workspacePath(Globals::ProjectFolder / Editor::Project->Name + TEXT(".code-workspace")) , _workspacePath(Globals::ProjectFolder / Editor::Project->Name + TEXT(".code-workspace"))
{ {
} }
@@ -18,29 +19,40 @@ void VisualStudioCodeEditor::FindEditors(Array<CodeEditor*>* output)
{ {
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
String cmd; String cmd;
bool isInsiders = false;
if (Platform::ReadRegValue(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty()) if (Platform::ReadRegValue(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty())
{ {
if (Platform::ReadRegValue(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty()) if (Platform::ReadRegValue(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty())
{ {
return; if (Platform::ReadRegValue(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Classes\\Applications\\Code - Insiders.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty())
{
if (Platform::ReadRegValue(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Applications\\Code - Insiders.exe\\shell\\open\\command"), TEXT(""), &cmd) || cmd.IsEmpty())
{
return;
}
else
isInsiders = true;
}
else
isInsiders = true;
} }
} }
const String path = cmd.Substring(1, cmd.Length() - String(TEXT("\" \"%1\"")).Length() - 1); const String path = cmd.Substring(1, cmd.Length() - String(TEXT("\" \"%1\"")).Length() - 1);
if (FileSystem::FileExists(path)) if (FileSystem::FileExists(path))
{ {
output->Add(New<VisualStudioCodeEditor>(path)); output->Add(New<VisualStudioCodeEditor>(path, isInsiders));
} }
#endif #endif
} }
CodeEditorTypes VisualStudioCodeEditor::GetType() const CodeEditorTypes VisualStudioCodeEditor::GetType() const
{ {
return CodeEditorTypes::VSCode; return _isInsiders ? CodeEditorTypes::VSCodeInsiders : CodeEditorTypes::VSCode;
} }
String VisualStudioCodeEditor::GetName() const String VisualStudioCodeEditor::GetName() const
{ {
return TEXT("Visual Studio Code"); return _isInsiders ? TEXT("Visual Studio Code - Insiders") : TEXT("Visual Studio Code");
} }
void VisualStudioCodeEditor::OpenFile(const String& path, int32 line) void VisualStudioCodeEditor::OpenFile(const String& path, int32 line)

View File

@@ -13,6 +13,7 @@ private:
String _execPath; String _execPath;
String _workspacePath; String _workspacePath;
bool _isInsiders;
public: public:
@@ -20,7 +21,8 @@ public:
/// Initializes a new instance of the <see cref="VisualStudioEditor"/> class. /// Initializes a new instance of the <see cref="VisualStudioEditor"/> class.
/// </summary> /// </summary>
/// <param name="execPath">Executable file path</param> /// <param name="execPath">Executable file path</param>
VisualStudioCodeEditor(const String& execPath); /// <param name="isInsiders">Is insiders edition</param>
VisualStudioCodeEditor(const String& execPath, const bool isInsiders);
public: public: