file_dialog.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. namespace electron {
  12. class NativeWindow;
  13. }
  14. namespace gin_helper {
  15. class Dictionary;
  16. template <typename T>
  17. class Promise;
  18. } // namespace gin_helper
  19. namespace file_dialog {
  20. // <description, extensions>
  21. typedef std::pair<std::string, std::vector<std::string>> Filter;
  22. typedef std::vector<Filter> Filters;
  23. enum OpenFileDialogProperty {
  24. OPEN_DIALOG_OPEN_FILE = 1 << 0,
  25. OPEN_DIALOG_OPEN_DIRECTORY = 1 << 1,
  26. OPEN_DIALOG_MULTI_SELECTIONS = 1 << 2,
  27. OPEN_DIALOG_CREATE_DIRECTORY = 1 << 3, // macOS
  28. OPEN_DIALOG_SHOW_HIDDEN_FILES = 1 << 4,
  29. OPEN_DIALOG_PROMPT_TO_CREATE = 1 << 5, // Windows
  30. OPEN_DIALOG_NO_RESOLVE_ALIASES = 1 << 6, // macOS
  31. OPEN_DIALOG_TREAT_PACKAGE_APP_AS_DIRECTORY = 1 << 7, // macOS
  32. FILE_DIALOG_DONT_ADD_TO_RECENT = 1 << 8, // Windows
  33. };
  34. enum SaveFileDialogProperty {
  35. SAVE_DIALOG_CREATE_DIRECTORY = 1 << 0,
  36. SAVE_DIALOG_SHOW_HIDDEN_FILES = 1 << 1,
  37. SAVE_DIALOG_TREAT_PACKAGE_APP_AS_DIRECTORY = 1 << 2, // macOS
  38. SAVE_DIALOG_SHOW_OVERWRITE_CONFIRMATION = 1 << 3, // Linux
  39. SAVE_DIALOG_DONT_ADD_TO_RECENT = 1 << 4, // Windows
  40. };
  41. struct DialogSettings {
  42. RAW_PTR_EXCLUSION electron::NativeWindow* parent_window = nullptr;
  43. std::string title;
  44. std::string message;
  45. std::string button_label;
  46. std::string name_field_label;
  47. base::FilePath default_path;
  48. Filters filters;
  49. int properties = 0;
  50. bool shows_tag_field = true;
  51. bool force_detached = false;
  52. bool security_scoped_bookmarks = false;
  53. DialogSettings();
  54. DialogSettings(const DialogSettings&);
  55. ~DialogSettings();
  56. };
  57. bool ShowOpenDialogSync(const DialogSettings& settings,
  58. std::vector<base::FilePath>* paths);
  59. void ShowOpenDialog(const DialogSettings& settings,
  60. gin_helper::Promise<gin_helper::Dictionary> promise);
  61. bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path);
  62. void ShowSaveDialog(const DialogSettings& settings,
  63. gin_helper::Promise<gin_helper::Dictionary> promise);
  64. } // namespace file_dialog
  65. #endif // ELECTRON_SHELL_BROWSER_UI_FILE_DIALOG_H_