AEExternalTooling.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/Core/Context.h>
  6. #include <Atomic/IO/Log.h>
  7. #include <Atomic/IO/FileSystem.h>
  8. #include "AEEvents.h"
  9. #include "AEExternalTooling.h"
  10. #include "AtomicTiled.h"
  11. namespace AtomicEditor
  12. {
  13. ExternalTooling::ExternalTooling(Context* context) :
  14. Object(context)
  15. {
  16. SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(ExternalTooling, HandleEditorShutdown));
  17. }
  18. ExternalTooling::~ExternalTooling()
  19. {
  20. }
  21. void ExternalTooling::LaunchOrOpen(const String& name, const String& fullpath)
  22. {
  23. if (tools_.Contains(name))
  24. {
  25. // TODO: open
  26. return;
  27. }
  28. if (name == "AtomicTiled")
  29. {
  30. SharedPtr<ExternalTool> tiled(new AtomicTiled(context_));
  31. if (tiled->Launch(fullpath))
  32. {
  33. tools_[name] = tiled;
  34. }
  35. }
  36. }
  37. void ExternalTooling::ToolExited(const String& name)
  38. {
  39. if (!tools_.Contains(name))
  40. return;
  41. tools_.Erase(name);
  42. }
  43. String ExternalTooling::GetToolApplicationPath()
  44. {
  45. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  46. String appDir = fileSystem->GetProgramDir();
  47. #ifdef ATOMIC_PLATFORM_WINDOWS
  48. appDir += "/Applications/";
  49. #else
  50. unsigned p = appDir.Find("/Contents/MacOS");
  51. if (p != String::NPOS)
  52. {
  53. appDir.Erase(p, appDir.Length() - p);
  54. appDir += "/Contents/Applications/";
  55. }
  56. #endif
  57. return appDir;
  58. }
  59. void ExternalTooling::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
  60. {
  61. context_->RemoveSubsystem(GetType());
  62. }
  63. }