/* * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include namespace GUI { namespace CommonActions { NonnullRefPtr make_about_action(String const& app_name, Icon const& app_icon, Window* parent = nullptr); NonnullRefPtr make_open_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_save_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_save_as_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_undo_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_redo_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_cut_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_copy_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_paste_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_delete_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_move_to_front_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_move_to_back_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_fullscreen_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_quit_action(Function); NonnullRefPtr make_help_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_go_back_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_go_forward_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_go_home_action(Function callback, Core::Object* parent = nullptr); NonnullRefPtr make_close_tab_action(Function callback, Core::Object* parent = nullptr); NonnullRefPtr make_reload_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_select_all_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_rename_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_properties_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_zoom_in_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_zoom_out_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_reset_zoom_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_rotate_clockwise_action(Function, Core::Object* parent = nullptr); NonnullRefPtr make_rotate_counterclockwise_action(Function, Core::Object* parent = nullptr); }; class Action final : public Core::Object { C_OBJECT(Action) public: enum class ShortcutScope { None, WidgetLocal, WindowLocal, ApplicationGlobal, }; static NonnullRefPtr create(String text, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create(String text, RefPtr icon, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create(String text, Shortcut const& shortcut, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create(String text, Shortcut const& shortcut, Shortcut const& alternate_shortcut, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create(String text, Shortcut const& shortcut, RefPtr icon, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create(String text, Shortcut const& shortcut, Shortcut const& alternate_shortcut, RefPtr icon, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create_checkable(String text, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create_checkable(String text, RefPtr icon, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create_checkable(String text, Shortcut const& shortcut, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create_checkable(String text, Shortcut const& shortcut, RefPtr icon, Function callback, Core::Object* parent = nullptr); virtual ~Action() override; String text() const { return m_text; } void set_text(String); String const& status_tip() const { return m_status_tip; } void set_status_tip(String status_tip) { m_status_tip = move(status_tip); } Shortcut const& shortcut() const { return m_shortcut; } Shortcut const& alternate_shortcut() const { return m_alternate_shortcut; } Gfx::Bitmap const* icon() const { return m_icon.ptr(); } void set_icon(Gfx::Bitmap const*); Core::Object const* activator() const { return m_activator.ptr(); } Core::Object* activator() { return m_activator.ptr(); } Function on_activation; void activate(Core::Object* activator = nullptr); void flash_menubar_menu(GUI::Window& window); bool is_enabled() const { return m_enabled; } void set_enabled(bool); bool is_checkable() const { return m_checkable; } void set_checkable(bool checkable) { m_checkable = checkable; } bool is_checked() const { VERIFY(is_checkable()); return m_checked; } void set_checked(bool); bool swallow_key_event_when_disabled() const { return m_swallow_key_event_when_disabled; } void set_swallow_key_event_when_disabled(bool swallow) { m_swallow_key_event_when_disabled = swallow; } void register_button(Badge