2
0

BsCodeEditor.h 4.2 KB

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