BsCodeEditor.h 4.3 KB

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