ProjectUtils.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/FileSystem.h>
  7. #include <Atomic/Graphics/Graphics.h>
  8. #include "ProjectUtils.h"
  9. #include "nfd.h"
  10. #include "../AEEditor.h"
  11. namespace AtomicEditor
  12. {
  13. ProjectUtils::ProjectUtils(Context* context) :
  14. Object(context)
  15. {
  16. }
  17. void ProjectUtils::OpenProjectFileDialog()
  18. {
  19. nfdchar_t *outPath = NULL;
  20. nfdresult_t result = NFD_OpenDialog( "atomic",
  21. NULL,
  22. &outPath);
  23. if (outPath && result == NFD_OKAY)
  24. {
  25. String fullpath = outPath;
  26. Editor* editor = GetSubsystem<Editor>();
  27. editor->LoadProject(fullpath);
  28. }
  29. GetSubsystem<Graphics>()->RaiseWindow();
  30. if (outPath)
  31. free(outPath);
  32. }
  33. String ProjectUtils::GetBuildPath(const String& defaultPath)
  34. {
  35. String buildPath;
  36. nfdchar_t *outPath = NULL;
  37. nfdresult_t result = NFD_ChooseDirectory( "Please choose the build folder",
  38. defaultPath.Length() ? defaultPath.CString() : NULL,
  39. &outPath);
  40. if (outPath && result == NFD_OKAY)
  41. {
  42. buildPath = outPath;
  43. }
  44. if (outPath)
  45. free(outPath);
  46. GetSubsystem<Graphics>()->RaiseWindow();
  47. return GetInternalPath(buildPath);
  48. }
  49. String ProjectUtils::GetAndroidSDKPath(const String& defaultPath)
  50. {
  51. String sdkPath;
  52. nfdchar_t *outPath = NULL;
  53. nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder of your Android SDK",
  54. defaultPath.Length() ? defaultPath.CString() : NULL,
  55. &outPath);
  56. if (outPath && result == NFD_OKAY)
  57. {
  58. sdkPath = outPath;
  59. }
  60. if (outPath)
  61. free(outPath);
  62. GetSubsystem<Graphics>()->RaiseWindow();
  63. return GetInternalPath(sdkPath);
  64. }
  65. String ProjectUtils::NewProjectFileDialog()
  66. {
  67. String projectPath;
  68. nfdchar_t *outPath = NULL;
  69. nfdresult_t result = NFD_ChooseDirectory( "Please create a new folder for the project",
  70. NULL,
  71. &outPath);
  72. if (outPath && result == NFD_OKAY)
  73. {
  74. projectPath = outPath;
  75. }
  76. if (outPath)
  77. free(outPath);
  78. GetSubsystem<Graphics>()->RaiseWindow();
  79. return GetInternalPath(projectPath);
  80. }
  81. void ProjectUtils::RevealInFinder(const String& fullpath)
  82. {
  83. FileSystem* fs = GetSubsystem<FileSystem>();
  84. if (fs->DirExists(fullpath))
  85. fs->SystemOpen(fullpath);
  86. else if (fs->FileExists(fullpath))
  87. fs->SystemOpen(GetPath(fullpath));
  88. }
  89. ProjectUtils::~ProjectUtils()
  90. {
  91. }
  92. }