file_dialog.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 ATOM_BROWSER_UI_FILE_DIALOG_H_
  5. #define ATOM_BROWSER_UI_FILE_DIALOG_H_
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "base/callback_forward.h"
  10. #include "base/files/file_path.h"
  11. namespace atom {
  12. class NativeWindow;
  13. }
  14. namespace file_dialog {
  15. // <description, extensions>
  16. typedef std::pair<std::string, std::vector<std::string>> Filter;
  17. typedef std::vector<Filter> Filters;
  18. enum FileDialogProperty {
  19. FILE_DIALOG_OPEN_FILE = 1 << 0,
  20. FILE_DIALOG_OPEN_DIRECTORY = 1 << 1,
  21. FILE_DIALOG_MULTI_SELECTIONS = 1 << 2,
  22. FILE_DIALOG_CREATE_DIRECTORY = 1 << 3,
  23. FILE_DIALOG_SHOW_HIDDEN_FILES = 1 << 4,
  24. FILE_DIALOG_PROMPT_TO_CREATE = 1 << 5,
  25. FILE_DIALOG_NO_RESOLVE_ALIASES = 1 << 6,
  26. FILE_DIALOG_TREAT_PACKAGE_APP_AS_DIRECTORY = 1 << 7,
  27. };
  28. #if defined(MAS_BUILD)
  29. typedef base::Callback<void(bool result,
  30. const std::vector<base::FilePath>& paths,
  31. const std::vector<std::string>& bookmarkData)>
  32. OpenDialogCallback;
  33. typedef base::Callback<void(bool result,
  34. const base::FilePath& path,
  35. const std::string& bookmarkData)>
  36. SaveDialogCallback;
  37. #else
  38. typedef base::Callback<void(bool result,
  39. const std::vector<base::FilePath>& paths)>
  40. OpenDialogCallback;
  41. typedef base::Callback<void(bool result, const base::FilePath& path)>
  42. SaveDialogCallback;
  43. #endif
  44. struct DialogSettings {
  45. atom::NativeWindow* parent_window = nullptr;
  46. std::string title;
  47. std::string message;
  48. std::string button_label;
  49. std::string name_field_label;
  50. base::FilePath default_path;
  51. Filters filters;
  52. int properties = 0;
  53. bool shows_tag_field = true;
  54. bool force_detached = false;
  55. bool security_scoped_bookmarks = false;
  56. DialogSettings();
  57. ~DialogSettings();
  58. };
  59. bool ShowOpenDialog(const DialogSettings& settings,
  60. std::vector<base::FilePath>* paths);
  61. void ShowOpenDialog(const DialogSettings& settings,
  62. const OpenDialogCallback& callback);
  63. bool ShowSaveDialog(const DialogSettings& settings, base::FilePath* path);
  64. void ShowSaveDialog(const DialogSettings& settings,
  65. const SaveDialogCallback& callback);
  66. } // namespace file_dialog
  67. #endif // ATOM_BROWSER_UI_FILE_DIALOG_H_