BsCodeEditor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 Opens a code file in the active external editor.
  61. *
  62. * @param path Path to the code file to open, can be absolute or relative to project folder.
  63. * The file should be part of a solution in the active editor.
  64. * @param lineNumber Line number to focus on once the file is opened. Might not be supported by all
  65. * editors.
  66. */
  67. void openFile(const Path& path, UINT32 lineNumber) const;
  68. /**
  69. * @brief Synchronizes all code files and assemblies in the active project and updates
  70. * the project solution for the active editor. Each project can only have one solution
  71. * per editor.
  72. */
  73. void syncSolution() const;
  74. private:
  75. /**
  76. * @brief Returns the absolute path at which the external editor solution file should be stored.
  77. */
  78. Path getSolutionPath() const;
  79. CodeEditor* mActiveEditor;
  80. Map<CodeEditorType, CodeEditorFactory*> mFactoryPerEditor;
  81. Vector<CodeEditorType> mEditors;
  82. Vector<CodeEditorFactory*> mFactories;
  83. };
  84. /**
  85. * @brief 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() { }
  93. /**
  94. * @copydoc CodeEditorManager::openFile
  95. */
  96. virtual void openFile(const Path& solutionPath, const Path& path, UINT32 lineNumber) const = 0;
  97. /**
  98. * @copydoc CodeEditorManager::syncSolution
  99. */
  100. virtual void syncSolution(const CodeSolutionData& data, const Path& outputPath) const = 0;
  101. };
  102. /**
  103. * @brief Interface for factory that creates a specific implementation(s) of a code editor.
  104. *
  105. * @see CodeEditor
  106. */
  107. class BS_ED_EXPORT CodeEditorFactory
  108. {
  109. public:
  110. virtual ~CodeEditorFactory() { }
  111. /**
  112. * @brief Returns a list of code editors supported by this factory.
  113. */
  114. virtual const Vector<CodeEditorType>& getAvailableEditors() const = 0;
  115. /**
  116. * @brief Creates a specific implementation of a code editor.
  117. *
  118. * @param editor Type of editor to create. Make sure to provide a valid value
  119. * returned by "getAvailableEditors".
  120. */
  121. virtual CodeEditor* create(CodeEditorType editor) const = 0;
  122. };
  123. }