// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Types.h" #include "Engine/Core/Delegate.h" #include "Engine/Core/Collections/Array.h" #include "Engine/Scripting/ScriptingType.h" /// /// Types of in-build code editors. /// API_ENUM(Namespace="FlaxEditor", Attributes="HideInEditor") enum class CodeEditorTypes { /// /// Custom/external editor /// Custom, /// /// Default program associated by the file extension on the system /// SystemDefault, /// /// Visual Studio 2008 /// VS2008, /// /// Visual Studio 2010 /// VS2010, /// /// Visual Studio 2012 /// VS2012, /// /// Visual Studio 2013 /// VS2013, /// /// Visual Studio 2015 /// VS2015, /// /// Visual Studio 2017 /// VS2017, /// /// Visual Studio 2019 /// VS2019, /// /// Visual Studio 2022 /// VS2022, /// /// Visual Studio Code /// VSCode, /// /// Visual Studio Code Insiders /// VSCodeInsiders, /// /// Rider /// Rider, MAX }; /// /// Base class for all code editors. /// class CodeEditor { public: /// /// Finalizes an instance of the class. /// virtual ~CodeEditor() = default; /// /// Gets the type of the editor (used by the in-build editors). /// /// The name virtual CodeEditorTypes GetType() const { return CodeEditorTypes::Custom; } /// /// Gets the name of the editor. /// /// The name virtual String GetName() const = 0; /// /// Opens the file. /// /// The file path. /// The target line (use 0 to not use it). virtual void OpenFile(const String& path, int32 line) = 0; /// /// Opens the solution project. /// virtual void OpenSolution() = 0; /// /// Called when source file gets added to the workspace. Can be used to automatically include new files into the project files. /// /// The path. virtual void OnFileAdded(const String& path) { } /// /// Determines whether use the asynchronous task for open solution/file. /// /// True if use async thread for open task. virtual bool UseAsyncForOpen() const { return false; } }; /// /// Editor utility to managed and use different code editors. Allows to open solution and source code files. /// API_CLASS(Static, Namespace="FlaxEditor") class CodeEditingManager { DECLARE_SCRIPTING_TYPE_NO_SPAWN(CodeEditingManager); public: /// /// Gets all found editors. /// /// The editors. Read-only. static const Array& GetEditors(); /// /// Determines whether asynchronous open action is running in a background. /// /// true if asynchronous open action is running in a background; otherwise, false. API_PROPERTY() static bool IsAsyncOpenRunning(); /// /// Gets the in-build code editor or null if not found. /// /// Type of the editor. /// The editor object or null if not found. static CodeEditor* GetCodeEditor(CodeEditorTypes editorType); /// /// Opens the file. Handles async opening. /// /// The code editor type. /// The file path. /// The target line (use 0 to not use it). API_FUNCTION() static void OpenFile(CodeEditorTypes editorType, const String& path, int32 line); /// /// Opens the file. Handles async opening. /// /// The code editor. /// The file path. /// The target line (use 0 to not use it). static void OpenFile(CodeEditor* editor, const String& path, int32 line); /// /// Opens the solution project. Handles async opening. /// /// The code editor type. API_FUNCTION() static void OpenSolution(CodeEditorTypes editorType); /// /// Called when source file gets added to the workspace. Can be used to automatically include new files into the project files. /// /// The code editor type. /// The path. API_FUNCTION() static void OnFileAdded(CodeEditorTypes editorType, const String& path); /// /// The asynchronous open begins. /// static Action AsyncOpenBegin; /// /// The asynchronous open ends. /// static Action AsyncOpenEnd; };