diff options
author | faxe1008 <fabianblatz@gmail.com> | 2021-11-24 20:22:12 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-28 00:57:48 -0800 |
commit | 7d6058415e371561d9dbfa7b68081680a0a3e4c1 (patch) | |
tree | df551fe3ceb25994d3c9eaa3285ece89778bdeee | |
parent | c74afdde26d4cbb8e158e2da6cf6c6f091e3eb3f (diff) | |
download | serenity-7d6058415e371561d9dbfa7b68081680a0a3e4c1.zip |
Taskbar: Add context menu to remove quicklaunch items
This change adds a context menu for each app button to remove items
from the quicklaunch section of the Taskbar.
-rw-r--r-- | Userland/Services/Taskbar/QuickLaunchWidget.cpp | 15 | ||||
-rw-r--r-- | Userland/Services/Taskbar/QuickLaunchWidget.h | 5 |
2 files changed, 19 insertions, 1 deletions
diff --git a/Userland/Services/Taskbar/QuickLaunchWidget.cpp b/Userland/Services/Taskbar/QuickLaunchWidget.cpp index b74e9ff551..f968a27786 100644 --- a/Userland/Services/Taskbar/QuickLaunchWidget.cpp +++ b/Userland/Services/Taskbar/QuickLaunchWidget.cpp @@ -8,6 +8,7 @@ #include <LibConfig/Client.h> #include <LibCore/MimeData.h> #include <LibGUI/BoxLayout.h> +#include <LibGUI/Menu.h> #include <serenity.h> namespace Taskbar { @@ -23,6 +24,16 @@ QuickLaunchWidget::QuickLaunchWidget() set_frame_thickness(0); set_fixed_height(24); + m_context_menu = GUI::Menu::construct(); + m_context_menu_default_action = GUI::Action::create("&Remove", [this](auto&) { + Config::remove_key("Taskbar", quick_launch, m_context_menu_app_name); + auto button = find_child_of_type_named<GUI::Button>(m_context_menu_app_name); + if (button) { + remove_child(*button); + } + }); + m_context_menu->add_action(*m_context_menu_default_action); + auto keys = Config::list_keys("Taskbar", quick_launch); for (auto& name : keys) { auto af_name = Config::read_string("Taskbar", quick_launch, name); @@ -71,6 +82,10 @@ void QuickLaunchWidget::add_or_adjust_button(String const& button_name, NonnullR perror("disown"); } }; + button->on_context_menu_request = [this, button_name](auto& context_menu_event) { + m_context_menu_app_name = button_name; + m_context_menu->popup(context_menu_event.screen_position(), m_context_menu_default_action); + }; } void QuickLaunchWidget::config_key_was_removed(String const& domain, String const& group, String const& key) diff --git a/Userland/Services/Taskbar/QuickLaunchWidget.h b/Userland/Services/Taskbar/QuickLaunchWidget.h index 9e444ca4b1..6f90c67c2f 100644 --- a/Userland/Services/Taskbar/QuickLaunchWidget.h +++ b/Userland/Services/Taskbar/QuickLaunchWidget.h @@ -23,11 +23,14 @@ public: virtual void config_key_was_removed(String const&, String const&, String const&) override; virtual void config_string_did_change(String const&, String const&, String const&, String const&) override; - virtual void drop_event(GUI::DropEvent&); + virtual void drop_event(GUI::DropEvent&) override; private: QuickLaunchWidget(); void add_or_adjust_button(String const&, NonnullRefPtr<Desktop::AppFile>); + RefPtr<GUI::Menu> m_context_menu; + RefPtr<GUI::Action> m_context_menu_default_action; + String m_context_menu_app_name; }; } |