file_dialog.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_FILE_DIALOG_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_FILE_DIALOG_H_
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "base/files/file_path.h"
  10. #include "base/memory/raw_ptr_exclusion.h"
  11. #include "shell/common/gin_helper/dictionary.h"
  12. #include "shell/common/gin_helper/promise.h"
  13. namespace electron {
  14. class NativeWindow;
  15. }
  16. namespace file_dialog {
  17. // <description, extensions>
  18. typedef std::pair<std::string, std::vector<std::string>> Filter;
  19. typedef std::vector<Filter> Filters;
  20. enum OpenFileDialogProperty {
  21. OPEN_DIALOG_OPEN_FILE = 1 << 0,
  22. OPEN_DIALOG_OPEN_DIRECTORY = 1 << 1,
  23. OPEN_DIALOG_MULTI_SELECTIONS = 1 << 2,
  24. OPEN_DIALOG_CREATE_DIRECTORY = 1 << 3, // macOS
  25. OPEN_DIALOG_SHOW_HIDDEN_FILES = 1 << 4,
  26. OPEN_DIALOG_PROMPT_TO_CREATE = 1 << 5, // Windows
  27. OPEN_DIALOG_NO_RESOLVE_ALIASES = 1 << 6, // macOS
  28. OPEN_DIALOG_TREAT_PACKAGE_APP_AS_DIRECTORY = 1 << 7, // macOS
  29. FILE_DIALOG_DONT_ADD_TO_RECENT = 1 << 8, // Windows
  30. };
  31. enum SaveFileDialogProperty {
  32. SAVE_DIALOG_CREATE_DIRECTORY = 1 << 0,
  33. SAVE_DIALOG_SHOW_HIDDEN_FILES = 1 << 1,
  34. SAVE_DIALOG_TREAT_PACKAGE_APP_AS_DIRECTORY = 1 << 2, // macOS
  35. SAVE_DIALOG_SHOW_OVERWRITE_CONFIRMATION = 1 << 3, // Linux
  36. SAVE_DIALOG_DONT_ADD_TO_RECENT = 1 << 4, // Windows
  37. };
  38. struct DialogSettings {
  39. RAW_PTR_EXCLUSION electron::NativeWindow* parent_window = nullptr;
  40. std::string title;
  41. std::string message;
  42. std::string button_label;
  43. std::string name_field_label;
  44. base::FilePath default_path;
  45. Filters filters;
  46. int properties = 0;
  47. bool shows_tag_field = true;
  48. bool force_detached = false;
  49. bool security_scoped_bookmarks = false;
  50. DialogSettings();
  51. DialogSettings(const DialogSettings&);
  52. ~DialogSettings();
  53. };
  54. bool ShowOpenDialogSync(const DialogSettings& settings,
  55. std::vector<base::FilePath>* paths);
  56. void ShowOpenDialog(const DialogSettings& settings,
  57. gin_helper::Promise<gin_helper::Dictionary> promise);
  58. bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
  59. void ShowSaveDialog(const DialogSettings& settings,
  60. gin_helper::Promise<gin_helper::Dictionary> promise);
  61. } // namespace file_dialog
  62. #endif // ELECTRON_SHELL_BROWSER_UI_FILE_DIALOG_H_