summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-04 23:31:08 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-04 23:31:42 +0100
commitda536c8d2271efda24d3d0275bcbea3ac1ca8073 (patch)
treeb81817503738a3ca308c342a1791244845ef1c2f /Libraries
parent6bfcb9c2b0c098731e54908408c2403d4da6b32f (diff)
downloadserenity-da536c8d2271efda24d3d0275bcbea3ac1ca8073.zip
LibGUI: Add CommonActions::make_about_action()
This creates an "About" menu action given the app name and icon. It takes care of showing the about dialog for you.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/Action.cpp10
-rw-r--r--Libraries/LibGUI/Action.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Action.cpp b/Libraries/LibGUI/Action.cpp
index f71354fc5d..5a9743df7e 100644
--- a/Libraries/LibGUI/Action.cpp
+++ b/Libraries/LibGUI/Action.cpp
@@ -24,10 +24,12 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <LibGUI/AboutDialog.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
#include <LibGUI/Button.h>
+#include <LibGUI/Icon.h>
#include <LibGUI/MenuItem.h>
#include <LibGUI/Window.h>
@@ -35,6 +37,14 @@ namespace GUI {
namespace CommonActions {
+NonnullRefPtr<Action> make_about_action(const String& app_name, const Icon& app_icon, Window* parent)
+{
+ WeakPtr<Window> weak_parent = parent ? parent->make_weak_ptr<Window>() : nullptr;
+ return Action::create(String::formatted("About {}", app_name), app_icon.bitmap_for_size(16), [=](auto&) {
+ AboutDialog::show(app_name, app_icon.bitmap_for_size(32), weak_parent.ptr());
+ });
+}
+
NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent)
{
return Action::create("Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), parent);
diff --git a/Libraries/LibGUI/Action.h b/Libraries/LibGUI/Action.h
index 486aa6b999..9b006031bb 100644
--- a/Libraries/LibGUI/Action.h
+++ b/Libraries/LibGUI/Action.h
@@ -42,6 +42,7 @@
namespace GUI {
namespace CommonActions {
+NonnullRefPtr<Action> make_about_action(const String& app_name, const Icon& app_icon, Window* parent = nullptr);
NonnullRefPtr<Action> make_open_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_save_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_save_as_action(Function<void(Action&)>, Core::Object* parent = nullptr);