1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

LibGUI: Add a MessageBox type to reveal a file

This will be used by Ladybird to open a screenshot's containing folder.
This commit is contained in:
Timothy Flynn 2024-01-06 09:55:46 -05:00 committed by Sam Atkins
parent cc88a2657d
commit 9218b2f3ce
3 changed files with 12 additions and 1 deletions

View file

@ -21,6 +21,7 @@ public:
Aborted = 2, Aborted = 2,
Yes = 3, Yes = 3,
No = 4, No = 4,
Reveal = 5,
}; };
enum class ScreenPosition { enum class ScreenPosition {

View file

@ -130,7 +130,7 @@ ErrorOr<RefPtr<Gfx::Bitmap>> MessageBox::icon() const
bool MessageBox::should_include_ok_button() const bool MessageBox::should_include_ok_button() const
{ {
return m_input_type == InputType::OK || m_input_type == InputType::OKCancel; return m_input_type == InputType::OK || m_input_type == InputType::OKCancel || m_input_type == InputType::OKReveal;
} }
bool MessageBox::should_include_cancel_button() const bool MessageBox::should_include_cancel_button() const
@ -148,6 +148,11 @@ bool MessageBox::should_include_no_button() const
return should_include_yes_button(); return should_include_yes_button();
} }
bool MessageBox::should_include_reveal_button() const
{
return m_input_type == InputType::OKReveal;
}
ErrorOr<void> MessageBox::build() ErrorOr<void> MessageBox::build()
{ {
auto main_widget = set_main_widget<Widget>(); auto main_widget = set_main_widget<Widget>();
@ -188,6 +193,8 @@ ErrorOr<void> MessageBox::build()
m_no_button = add_button("No"_string, ExecResult::No); m_no_button = add_button("No"_string, ExecResult::No);
if (should_include_cancel_button()) if (should_include_cancel_button())
m_cancel_button = add_button("Cancel"_string, ExecResult::Cancel); m_cancel_button = add_button("Cancel"_string, ExecResult::Cancel);
if (should_include_reveal_button())
m_reveal_button = add_button("Open folder"_string, ExecResult::Reveal);
button_container.add_spacer(); button_container.add_spacer();
return {}; return {};

View file

@ -32,6 +32,7 @@ public:
enum class InputType { enum class InputType {
OK, OK,
OKCancel, OKCancel,
OKReveal,
YesNo, YesNo,
YesNoCancel, YesNoCancel,
}; };
@ -58,6 +59,7 @@ private:
bool should_include_cancel_button() const; bool should_include_cancel_button() const;
bool should_include_yes_button() const; bool should_include_yes_button() const;
bool should_include_no_button() const; bool should_include_no_button() const;
bool should_include_reveal_button() const;
ErrorOr<void> build(); ErrorOr<void> build();
ErrorOr<RefPtr<Gfx::Bitmap>> icon() const; ErrorOr<RefPtr<Gfx::Bitmap>> icon() const;
@ -69,6 +71,7 @@ private:
RefPtr<GUI::Button> m_yes_button; RefPtr<GUI::Button> m_yes_button;
RefPtr<GUI::Button> m_no_button; RefPtr<GUI::Button> m_no_button;
RefPtr<GUI::Button> m_cancel_button; RefPtr<GUI::Button> m_cancel_button;
RefPtr<GUI::Button> m_reveal_button;
RefPtr<Label> m_text_label; RefPtr<Label> m_text_label;
}; };