BsCodeEditor.h 6.8 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;
  70. private:
  71. /** Returns the absolute path at which the external editor solution file should be stored. */
  72. Path getSolutionPath() const;
  73. CodeEditor* mActiveEditor;
  74. CodeEditorType mActiveEditorType;
  75. Map<CodeEditorType, CodeEditorFactory*> mFactoryPerEditor;
  76. Vector<CodeEditorType> mEditors;
  77. Vector<CodeEditorFactory*> mFactories;
  78. };
  79. /** @} */
  80. /** @addtogroup CodeEditor-Internal
  81. * @{
  82. */
  83. /**
  84. * Interface that classes interacting with external code editors needs to implement.
  85. *
  86. * @see CodeEditorManager
  87. */
  88. class BS_ED_EXPORT CodeEditor
  89. {
  90. public:
  91. virtual ~CodeEditor() { }
  92. /**
  93. * @copydoc CodeEditorManager::openFile
  94. *
  95. * @param[in] solutionPath Path to the solution file the file is a part of.
  96. */
  97. virtual void openFile(const Path& solutionPath, const Path& path, UINT32 lineNumber) const = 0;
  98. /**
  99. * @copydoc CodeEditorManager::syncSolution
  100. *
  101. * @param[in] data Information about the solution and the files it contains.
  102. * @param[in] outputPath Path to the file into which to output the solution.
  103. */
  104. virtual void syncSolution(const CodeSolutionData& data, const Path& outputPath) const = 0;
  105. };
  106. /**
  107. * Interface for factory that creates a specific implementation(s) of a code editor.
  108. *
  109. * @see CodeEditor
  110. */
  111. class BS_ED_EXPORT CodeEditorFactory
  112. {
  113. public:
  114. virtual ~CodeEditorFactory() { }
  115. /** Returns a list of code editors supported by this factory. */
  116. virtual const Vector<CodeEditorType>& getAvailableEditors() const = 0;
  117. /**
  118. * Creates a specific implementation of a code editor.
  119. *
  120. * @param[in] editor Type of editor to create. Make sure to provide a valid value returned by
  121. * getAvailableEditors().
  122. */
  123. virtual CodeEditor* create(CodeEditorType editor) const = 0;
  124. };
  125. /** Different versions of .csproj files, depending on which Microsoft Visual Studio version generated them. */
  126. enum class CSProjectVersion
  127. {
  128. VS2008,
  129. VS2010,
  130. VS2012,
  131. VS2013,
  132. VS2015,
  133. VS2017,
  134. MonoDevelop
  135. };
  136. /**
  137. * 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
  138. * and MonoDevelop, and build systems like msbuild or xbuild.
  139. */
  140. class CSProject
  141. {
  142. public:
  143. /**
  144. * Builds the .sln text for the provided version, using the provided solution data.
  145. *
  146. * @param[in] version Visual Studio version for which we're generating the solution file.
  147. * @param[in] data Data containing a list of projects and other information required to build the solution text.
  148. * @return Generated text of the solution file.
  149. */
  150. static String writeSolution(CSProjectVersion version, const CodeSolutionData& data);
  151. /**
  152. * Builds the .csproj text for the provided version, using the provided project data.
  153. *
  154. * @param[in] version Visual Studio version for which we're generating the project file.
  155. * @param[in] projectData Data containing a list of files, references and other information required to
  156. * build the project text.
  157. * @return Generated text of the project file.
  158. */
  159. static String writeProject(CSProjectVersion version, const CodeProjectData& projectData);
  160. private:
  161. static const String SLN_TEMPLATE; /**< Template text used for a solution file. */
  162. static const String PROJ_ENTRY_TEMPLATE; /**< Template text used for a project entry in a solution file. */
  163. static const String PROJ_PLATFORM_TEMPLATE; /**< Template text used for platform specific information for a project entry in a solution file. */
  164. static const String PROJ_TEMPLATE; /**< Template XML used for a project file. */
  165. static const String REFERENCE_ENTRY_TEMPLATE; /**< Template XML used for a reference to another assembly entry by name. */
  166. static const String REFERENCE_PROJECT_ENTRY_TEMPLATE; /**< Template XML used for a reference to another project entry. */
  167. static const String REFERENCE_PATH_ENTRY_TEMPLATE; /**< Template XML used for a reference to another assembly entry by name and path. */
  168. static const String CODE_ENTRY_TEMPLATE; /**< Template XML used for a single code file entry in a project. */
  169. static const String NON_CODE_ENTRY_TEMPLATE; /**< Template XML used for a single non-code file entry in a project. */
  170. };
  171. /** @} */
  172. }