BsCodeEditor.h 4.5 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 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. WString 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. WString name;
  23. Vector<Path> codeFiles;
  24. Vector<Path> nonCodeFiles;
  25. WString 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. WString 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. /** @} */
  126. }