BsCodeEditor.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "Utility/BsModule.h"
  6. namespace bs
  7. {
  8. /** @addtogroup CodeEditor-Internal
  9. * @{
  10. */
  11. class CodeEditor;
  12. class CodeEditorFactory;
  13. /** Contains data about a reference to a project in an external editor solution. */
  14. struct BS_ED_EXPORT CodeProjectReference
  15. {
  16. String name;
  17. Path path;
  18. };
  19. /** Contains data about a single project in an external editor solution. */
  20. struct BS_ED_EXPORT CodeProjectData
  21. {
  22. String name;
  23. Vector<Path> codeFiles;
  24. Vector<Path> nonCodeFiles;
  25. String defines;
  26. Vector<CodeProjectReference> assemblyReferences;
  27. Vector<CodeProjectReference> projectReferences;
  28. };
  29. /** Contains data about an external editor solution, including all projects contained. */
  30. struct BS_ED_EXPORT CodeSolutionData
  31. {
  32. String name;
  33. Vector<CodeProjectData> projects;
  34. };
  35. /** @} */
  36. /** @addtogroup CodeEditor
  37. * @{
  38. */
  39. /**
  40. * Handles connectivity of the editor with external code editing tools. The system provides methods for interacting with
  41. * external tools but the exact tool used depends on the currently active setting.
  42. */
  43. class BS_ED_EXPORT CodeEditorManager : public Module<CodeEditorManager>
  44. {
  45. public:
  46. CodeEditorManager();
  47. ~CodeEditorManager();
  48. /** Returns a list of all available code editors for this platform. */
  49. const Vector<CodeEditorType>& getAvailableEditors() const { return mEditors; }
  50. /**
  51. * Changes the active code editor. All further operations on this object will be executed using this editor. If the
  52. * specified editor is not valid for this platform, no change will be made.
  53. */
  54. void setActive(CodeEditorType editor);
  55. /** Returns the currently active code editor. */
  56. CodeEditorType getActive() const { return mActiveEditorType; }
  57. /**
  58. * Opens a code file in the active external editor.
  59. *
  60. * @param[in] path Path to the code file to open, can be absolute or relative to project resources folder.
  61. * The file should be part of a solution in the active editor.
  62. * @param[in] lineNumber Line number to focus on once the file is opened. Might not be supported by all editors.
  63. */
  64. void openFile(const Path& path, UINT32 lineNumber) const;
  65. /**
  66. * Synchronizes all code files and assemblies in the active project and updates the project solution for the active
  67. * editor. Each project can only have one solution per editor.
  68. */
  69. void syncSolution(const String& gameProjectName, const CodeProjectReference& engineAssemblyRef,
  70. const CodeProjectReference& editorAssemblyRef) const;
  71. /** Returns the absolute path at which the external editor solution file should be stored. */
  72. Path getSolutionPath() const;
  73. private:
  74. CodeEditor* mActiveEditor;
  75. CodeEditorType mActiveEditorType;
  76. Map<CodeEditorType, CodeEditorFactory*> mFactoryPerEditor;
  77. Vector<CodeEditorType> mEditors;
  78. Vector<CodeEditorFactory*> mFactories;
  79. };
  80. /** @} */
  81. /** @addtogroup CodeEditor-Internal
  82. * @{
  83. */
  84. /**
  85. * Interface that classes interacting with external code editors needs to implement.
  86. *
  87. * @see CodeEditorManager
  88. */
  89. class BS_ED_EXPORT CodeEditor
  90. {
  91. public:
  92. virtual ~CodeEditor() = default;
  93. /**
  94. * @copydoc CodeEditorManager::openFile
  95. *
  96. * @param[in] solutionPath Path to the solution file the file is a part of.
  97. */
  98. virtual void openFile(const Path& solutionPath, const Path& path, UINT32 lineNumber) const = 0;
  99. /**
  100. * @copydoc CodeEditorManager::syncSolution
  101. *
  102. * @param[in] data Information about the solution and the files it contains.
  103. * @param[in] outputPath Path to the file into which to output the solution.
  104. */
  105. virtual void syncSolution(const CodeSolutionData& data, const Path& outputPath) const = 0;
  106. };
  107. /**
  108. * Interface for factory that creates a specific implementation(s) of a code editor.
  109. *
  110. * @see CodeEditor
  111. */
  112. class BS_ED_EXPORT CodeEditorFactory
  113. {
  114. public:
  115. virtual ~CodeEditorFactory() { }
  116. /** Returns a list of code editors supported by this factory. */
  117. virtual const Vector<CodeEditorType>& getAvailableEditors() const = 0;
  118. /**
  119. * Creates a specific implementation of a code editor.
  120. *
  121. * @param[in] editor Type of editor to create. Make sure to provide a valid value returned by
  122. * getAvailableEditors().
  123. */
  124. virtual CodeEditor* create(CodeEditorType editor) const = 0;
  125. };
  126. /** Different versions of .csproj files, depending on which Microsoft Visual Studio version generated them. */
  127. enum class CSProjectVersion
  128. {
  129. VS2008,
  130. VS2010,
  131. VS2012,
  132. VS2013,
  133. VS2015,
  134. VS2017,
  135. MonoDevelop
  136. };
  137. /**
  138. * Contains helper functionality for the generation of .csproj files, as well as the .sln file. Those are used by C# IDE's like Visual Studio
  139. * and MonoDevelop, and build systems like msbuild or xbuild.
  140. */
  141. class CSProject
  142. {
  143. public:
  144. /**
  145. * Builds the .sln text for the provided version, using the provided solution data.
  146. *
  147. * @param[in] version Visual Studio version for which we're generating the solution file.
  148. * @param[in] data Data containing a list of projects and other information required to build the solution text.
  149. * @return Generated text of the solution file.
  150. */
  151. static String writeSolution(CSProjectVersion version, const CodeSolutionData& data);
  152. /**
  153. * Builds the .csproj text for the provided version, using the provided project data.
  154. *
  155. * @param[in] version Visual Studio version for which we're generating the project file.
  156. * @param[in] projectData Data containing a list of files, references and other information required to
  157. * build the project text.
  158. * @return Generated text of the project file.
  159. */
  160. static String writeProject(CSProjectVersion version, const CodeProjectData& projectData);
  161. private:
  162. static const String SLN_TEMPLATE; /**< Template text used for a solution file. */
  163. static const String PROJ_ENTRY_TEMPLATE; /**< Template text used for a project entry in a solution file. */
  164. static const String PROJ_PLATFORM_TEMPLATE; /**< Template text used for platform specific information for a project entry in a solution file. */
  165. static const String PROJ_TEMPLATE; /**< Template XML used for a project file. */
  166. static const String REFERENCE_ENTRY_TEMPLATE; /**< Template XML used for a reference to another assembly entry by name. */
  167. static const String REFERENCE_PROJECT_ENTRY_TEMPLATE; /**< Template XML used for a reference to another project entry. */
  168. static const String REFERENCE_PATH_ENTRY_TEMPLATE; /**< Template XML used for a reference to another assembly entry by name and path. */
  169. static const String CODE_ENTRY_TEMPLATE; /**< Template XML used for a single code file entry in a project. */
  170. static const String NON_CODE_ENTRY_TEMPLATE; /**< Template XML used for a single non-code file entry in a project. */
  171. };
  172. /** @} */
  173. }