file_dialog.h 2.3 KB

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