message_box.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_MESSAGE_BOX_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_MESSAGE_BOX_H_
  6. #include <optional>
  7. #include <string>
  8. #include <vector>
  9. #include "base/functional/callback_forward.h"
  10. #include "base/memory/raw_ptr_exclusion.h"
  11. #include "ui/gfx/image/image_skia.h"
  12. namespace electron {
  13. class NativeWindow;
  14. enum class MessageBoxType {
  15. kNone = 0,
  16. kInformation,
  17. kWarning,
  18. kError,
  19. kQuestion,
  20. };
  21. struct MessageBoxSettings {
  22. RAW_PTR_EXCLUSION electron::NativeWindow* parent_window = nullptr;
  23. MessageBoxType type = electron::MessageBoxType::kNone;
  24. std::vector<std::string> buttons;
  25. std::optional<int> id;
  26. int default_id;
  27. int cancel_id;
  28. bool no_link = false;
  29. std::string title;
  30. std::string message;
  31. std::string detail;
  32. std::string checkbox_label;
  33. bool checkbox_checked = false;
  34. gfx::ImageSkia icon;
  35. int text_width = 0;
  36. MessageBoxSettings();
  37. MessageBoxSettings(const MessageBoxSettings&);
  38. ~MessageBoxSettings();
  39. };
  40. int ShowMessageBoxSync(const MessageBoxSettings& settings);
  41. typedef base::OnceCallback<void(int code, bool checkbox_checked)>
  42. MessageBoxCallback;
  43. void ShowMessageBox(const MessageBoxSettings& settings,
  44. MessageBoxCallback callback);
  45. void CloseMessageBox(int id);
  46. // Like ShowMessageBox with simplest settings, but safe to call at very early
  47. // stage of application.
  48. void ShowErrorBox(const std::u16string& title, const std::u16string& content);
  49. } // namespace electron
  50. #endif // ELECTRON_SHELL_BROWSER_UI_MESSAGE_BOX_H_