FileUtils.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include <Poco/File.h>
  2. #include "AtomicEditor.h"
  3. #include <Atomic/Core/Context.h>
  4. #include <Atomic/Core/StringUtils.h>
  5. #include <Atomic/IO/FileSystem.h>
  6. #include <Atomic/Graphics/Graphics.h>
  7. #include "FileUtils.h"
  8. #include "nfd.h"
  9. namespace AtomicEditor
  10. {
  11. FileUtils::FileUtils(Context* context) :
  12. Object(context)
  13. {
  14. }
  15. FileUtils::~FileUtils()
  16. {
  17. }
  18. void FileUtils::OpenProjectFileDialog()
  19. {
  20. nfdchar_t *outPath = NULL;
  21. nfdresult_t result = NFD_OpenDialog( "atomic",
  22. NULL,
  23. &outPath);
  24. if (outPath && result == NFD_OKAY)
  25. {
  26. String fullpath = outPath;
  27. //Editor* editor = GetSubsystem<Editor>();
  28. //editor->LoadProject(fullpath);
  29. }
  30. GetSubsystem<Graphics>()->RaiseWindow();
  31. if (outPath)
  32. free(outPath);
  33. }
  34. bool FileUtils::CreateDirs(const String& folder)
  35. {
  36. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  37. Poco::File dirs(folder.CString());
  38. dirs.createDirectories();
  39. return fileSystem->DirExists(folder);
  40. }
  41. String FileUtils::NewProjectFileDialog()
  42. {
  43. String projectPath;
  44. nfdchar_t *outPath = NULL;
  45. nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder for your project",
  46. NULL,
  47. &outPath);
  48. if (outPath && result == NFD_OKAY)
  49. {
  50. projectPath = outPath;
  51. }
  52. GetSubsystem<Graphics>()->RaiseWindow();
  53. if (outPath)
  54. free(outPath);
  55. return projectPath;
  56. }
  57. void FileUtils::RevealInFinder(const String& fullpath)
  58. {
  59. FileSystem* fs = GetSubsystem<FileSystem>();
  60. if (fs->DirExists(fullpath))
  61. fs->SystemOpen(fullpath);
  62. else if (fs->FileExists(fullpath))
  63. fs->SystemOpen(GetPath(fullpath));
  64. }
  65. }