BsCodeEditor.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. class CodeEditor;
  7. class CodeEditorFactory;
  8. /**
  9. * @brief Contains data about a reference to a
  10. * project in an external editor solution.
  11. */
  12. struct BS_ED_EXPORT CodeProjectReference
  13. {
  14. WString name;
  15. Path path;
  16. };
  17. /**
  18. * @brief Contains data about a single project
  19. * in an external editor solution.
  20. */
  21. struct BS_ED_EXPORT CodeProjectData
  22. {
  23. WString name;
  24. Vector<Path> codeFiles;
  25. Vector<Path> nonCodeFiles;
  26. WString defines;
  27. Vector<CodeProjectReference> assemblyReferences;
  28. Vector<CodeProjectReference> projectReferences;
  29. };
  30. /**
  31. * @brief Contains data about an external editor solution,
  32. * including all projects contained.
  33. */
  34. struct BS_ED_EXPORT CodeSolutionData
  35. {
  36. WString name;
  37. Vector<CodeProjectData> projects;
  38. };
  39. /**
  40. * @brief Handles connectivity of the editor with external code editing tools.
  41. * The system provides methods for interacting with external tools but
  42. * the exact tool used depends on the currently active setting.
  43. */
  44. class BS_ED_EXPORT CodeEditorManager : public Module<CodeEditorManager>
  45. {
  46. public:
  47. CodeEditorManager();
  48. ~CodeEditorManager();
  49. /**
  50. * @brief Returns a list of all available code editors for this platform.
  51. */
  52. const Vector<CodeEditorType>& getAvailableEditors() const { return mEditors; }
  53. /**
  54. * @brief Changes the active code editor. All further operations on this object will
  55. * be executed using this editor. If the specified editor is not valid for this
  56. * platform, no change will be made.
  57. */
  58. void setActive(CodeEditorType editor);
  59. /**
  60. * @brief Returns the currently active code editor.
  61. */
  62. CodeEditorType getActive() const { return mActiveEditorType; }
  63. /**
  64. * @brief Opens a code file in the active external editor.
  65. *
  66. * @param path Path to the code file to open, can be absolute or relative to project resources folder.
  67. * The file should be part of a solution in the active editor.
  68. * @param lineNumber Line number to focus on once the file is opened. Might not be supported by all
  69. * editors.
  70. */
  71. void openFile(const Path& path, UINT32 lineNumber) const;
  72. /**
  73. * @brief Synchronizes all code files and assemblies in the active project and updates
  74. * the project solution for the active editor. Each project can only have one solution
  75. * per editor.
  76. */
  77. void syncSolution() const;
  78. private:
  79. /**
  80. * @brief Returns the absolute path at which the external editor solution file should be stored.
  81. */
  82. Path getSolutionPath() const;
  83. CodeEditor* mActiveEditor;
  84. CodeEditorType mActiveEditorType;
  85. Map<CodeEditorType, CodeEditorFactory*> mFactoryPerEditor;
  86. Vector<CodeEditorType> mEditors;
  87. Vector<CodeEditorFactory*> mFactories;
  88. };
  89. /**
  90. * @brief Interface that classes interacting with external code editors needs to implement.
  91. *
  92. * @see CodeEditorManager
  93. */
  94. class BS_ED_EXPORT CodeEditor
  95. {
  96. public:
  97. virtual ~CodeEditor() { }
  98. /**
  99. * @copydoc CodeEditorManager::openFile
  100. */
  101. virtual void openFile(const Path& solutionPath, const Path& path, UINT32 lineNumber) const = 0;
  102. /**
  103. * @copydoc CodeEditorManager::syncSolution
  104. */
  105. virtual void syncSolution(const CodeSolutionData& data, const Path& outputPath) const = 0;
  106. };
  107. /**
  108. * @brief 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. /**
  117. * @brief Returns a list of code editors supported by this factory.
  118. */
  119. virtual const Vector<CodeEditorType>& getAvailableEditors() const = 0;
  120. /**
  121. * @brief Creates a specific implementation of a code editor.
  122. *
  123. * @param editor Type of editor to create. Make sure to provide a valid value
  124. * returned by "getAvailableEditors".
  125. */
  126. virtual CodeEditor* create(CodeEditorType editor) const = 0;
  127. };
  128. }