2
0

BsCodeEditor.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "BsCodeEditor.h"
  2. #if BS_PLATFORM == BS_PLATFORM_WIN32
  3. #include "Win32/BsVSCodeEditor.h"
  4. #else
  5. static_assert("Make sure to add implementations for other platforms.");
  6. #endif
  7. namespace BansheeEngine
  8. {
  9. CodeEditorManager::CodeEditorManager()
  10. :mActiveEditor(nullptr)
  11. {
  12. #if BS_PLATFORM == BS_PLATFORM_WIN32
  13. VSCodeEditorFactory* vsCodeEditorFactory = bs_new<VSCodeEditorFactory>();
  14. Vector<WString> vsEditors = vsCodeEditorFactory->getAvailableEditors();
  15. for(auto& editor : vsEditors)
  16. {
  17. mFactoryPerEditor[editor] = vsCodeEditorFactory;
  18. mEditors.push_back(editor);
  19. }
  20. mFactories.push_back(vsCodeEditorFactory);
  21. #else
  22. static_assert("Make sure to add implementations for other platforms.");
  23. #endif
  24. }
  25. CodeEditorManager::~CodeEditorManager()
  26. {
  27. for (auto& factory : mFactories)
  28. bs_delete(factory);
  29. if (mActiveEditor != nullptr)
  30. bs_delete(mActiveEditor);
  31. }
  32. void CodeEditorManager::setActive(const WString& editor)
  33. {
  34. if (mActiveEditor != nullptr)
  35. {
  36. bs_delete(mActiveEditor);
  37. mActiveEditor = nullptr;
  38. }
  39. auto findIter = mFactoryPerEditor.find(editor);
  40. if (findIter == mFactoryPerEditor.end())
  41. return;
  42. mActiveEditor = findIter->second->create(editor);
  43. }
  44. void CodeEditorManager::openFile(const Path& path, UINT32 lineNumber) const
  45. {
  46. if (mActiveEditor != nullptr)
  47. mActiveEditor->openFile(path, lineNumber);
  48. }
  49. void CodeEditorManager::syncSolution(const CodeSolutionData& data, const Path& outputPath) const
  50. {
  51. if (mActiveEditor != nullptr)
  52. mActiveEditor->syncSolution(data, outputPath);
  53. }
  54. }