diff --git a/Source/Editor/Modules/SourceCodeEditing/InBuildSourceCodeEditor.cs b/Source/Editor/Modules/SourceCodeEditing/InBuildSourceCodeEditor.cs index a2a333805..87d9e3eb7 100644 --- a/Source/Editor/Modules/SourceCodeEditing/InBuildSourceCodeEditor.cs +++ b/Source/Editor/Modules/SourceCodeEditing/InBuildSourceCodeEditor.cs @@ -22,52 +22,7 @@ namespace FlaxEditor.Modules.SourceCodeEditing public InBuildSourceCodeEditor(CodeEditorTypes type) { Type = type; - switch (type) - { - case CodeEditorTypes.Custom: - Name = "Custom"; - break; - case CodeEditorTypes.SystemDefault: - Name = "System Default"; - break; - case CodeEditorTypes.VS2008: - Name = "Visual Studio 2008"; - break; - case CodeEditorTypes.VS2010: - Name = "Visual Studio 2010"; - break; - case CodeEditorTypes.VS2012: - Name = "Visual Studio 2012"; - break; - case CodeEditorTypes.VS2013: - Name = "Visual Studio 2013"; - break; - case CodeEditorTypes.VS2015: - Name = "Visual Studio 2015"; - break; - case CodeEditorTypes.VS2017: - Name = "Visual Studio 2017"; - break; - case CodeEditorTypes.VS2019: - Name = "Visual Studio 2019"; - break; - case CodeEditorTypes.VS2022: - Name = "Visual Studio 2022"; - break; - case CodeEditorTypes.VS2026: - Name = "Visual Studio 2026"; - break; - case CodeEditorTypes.VSCode: - Name = "Visual Studio Code"; - break; - case CodeEditorTypes.VSCodeInsiders: - Name = "Visual Studio Code - Insiders"; - break; - case CodeEditorTypes.Rider: - Name = "Rider"; - break; - default: throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + Name = CodeEditingManager.GetName(type); } /// diff --git a/Source/Editor/Scripting/CodeEditor.cpp b/Source/Editor/Scripting/CodeEditor.cpp index b372da189..038ec0329 100644 --- a/Source/Editor/Scripting/CodeEditor.cpp +++ b/Source/Editor/Scripting/CodeEditor.cpp @@ -139,6 +139,19 @@ CodeEditor* CodeEditingManager::GetCodeEditor(CodeEditorTypes editorType) return nullptr; } +String CodeEditingManager::GetName(CodeEditorTypes editorType) +{ + const auto editor = GetCodeEditor(editorType); + if (editor) + { + return editor->GetName(); + } + else + { + LOG(Warning, "Missing code editor type {0}", (int32)editorType); + return String::Empty; + } +} void CodeEditingManager::OpenFile(CodeEditorTypes editorType, const String& path, int32 line) { const auto editor = GetCodeEditor(editorType); diff --git a/Source/Editor/Scripting/CodeEditor.h b/Source/Editor/Scripting/CodeEditor.h index 9cc71977b..670ec51e2 100644 --- a/Source/Editor/Scripting/CodeEditor.h +++ b/Source/Editor/Scripting/CodeEditor.h @@ -109,7 +109,7 @@ public: /// /// Gets the name of the editor. /// - /// The name + /// The name. virtual String GetName() const = 0; /// @@ -169,6 +169,13 @@ public: /// The editor object or null if not found. static CodeEditor* GetCodeEditor(CodeEditorTypes editorType); + /// + /// Gets the name of the editor. + /// + /// The code editor type. + /// The name. + API_FUNCTION() static String GetName(CodeEditorTypes editorType); + /// /// Opens the file. Handles async opening. ///