From 9218b2f3ce8abfc34ae3ca2a87b4ebe88b963216 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 6 Jan 2024 09:55:46 -0500 Subject: [PATCH] LibGUI: Add a MessageBox type to reveal a file This will be used by Ladybird to open a screenshot's containing folder. --- Userland/Libraries/LibGUI/Dialog.h | 1 + Userland/Libraries/LibGUI/MessageBox.cpp | 9 ++++++++- Userland/Libraries/LibGUI/MessageBox.h | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/Dialog.h b/Userland/Libraries/LibGUI/Dialog.h index b4a1cd01e3e..b0be6fe9de0 100644 --- a/Userland/Libraries/LibGUI/Dialog.h +++ b/Userland/Libraries/LibGUI/Dialog.h @@ -21,6 +21,7 @@ public: Aborted = 2, Yes = 3, No = 4, + Reveal = 5, }; enum class ScreenPosition { diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp index 0d997e34a3e..2de30607657 100644 --- a/Userland/Libraries/LibGUI/MessageBox.cpp +++ b/Userland/Libraries/LibGUI/MessageBox.cpp @@ -130,7 +130,7 @@ ErrorOr> MessageBox::icon() 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 @@ -148,6 +148,11 @@ bool MessageBox::should_include_no_button() const return should_include_yes_button(); } +bool MessageBox::should_include_reveal_button() const +{ + return m_input_type == InputType::OKReveal; +} + ErrorOr MessageBox::build() { auto main_widget = set_main_widget(); @@ -188,6 +193,8 @@ ErrorOr MessageBox::build() m_no_button = add_button("No"_string, ExecResult::No); if (should_include_cancel_button()) 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(); return {}; diff --git a/Userland/Libraries/LibGUI/MessageBox.h b/Userland/Libraries/LibGUI/MessageBox.h index 60312440663..a31ec9a847f 100644 --- a/Userland/Libraries/LibGUI/MessageBox.h +++ b/Userland/Libraries/LibGUI/MessageBox.h @@ -32,6 +32,7 @@ public: enum class InputType { OK, OKCancel, + OKReveal, YesNo, YesNoCancel, }; @@ -58,6 +59,7 @@ private: bool should_include_cancel_button() const; bool should_include_yes_button() const; bool should_include_no_button() const; + bool should_include_reveal_button() const; ErrorOr build(); ErrorOr> icon() const; @@ -69,6 +71,7 @@ private: RefPtr m_yes_button; RefPtr m_no_button; RefPtr m_cancel_button; + RefPtr m_reveal_button; RefPtr