file_dialog.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. };
  27. typedef base::Callback<void(
  28. bool result, const std::vector<base::FilePath>& paths)> OpenDialogCallback;
  29. typedef base::Callback<void(
  30. bool result, const base::FilePath& path)> SaveDialogCallback;
  31. struct DialogSettings {
  32. atom::NativeWindow* parent_window = nullptr;
  33. std::string title;
  34. std::string message;
  35. std::string button_label;
  36. std::string name_field_label;
  37. base::FilePath default_path;
  38. Filters filters;
  39. int properties = 0;
  40. bool shows_tag_field = true;
  41. };
  42. bool ShowOpenDialog(const DialogSettings& settings,
  43. std::vector<base::FilePath>* paths);
  44. void ShowOpenDialog(const DialogSettings& settings,
  45. const OpenDialogCallback& callback);
  46. bool ShowSaveDialog(const DialogSettings& settings,
  47. base::FilePath* path);
  48. void ShowSaveDialog(const DialogSettings& settings,
  49. const SaveDialogCallback& callback);
  50. } // namespace file_dialog
  51. #endif // ATOM_BROWSER_UI_FILE_DIALOG_H_