From 7d6058415e371561d9dbfa7b68081680a0a3e4c1 Mon Sep 17 00:00:00 2001 From: faxe1008 Date: Wed, 24 Nov 2021 20:22:12 +0100 Subject: [PATCH] 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. --- Userland/Services/Taskbar/QuickLaunchWidget.cpp | 15 +++++++++++++++ Userland/Services/Taskbar/QuickLaunchWidget.h | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 #include #include +#include #include 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(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); + RefPtr m_context_menu; + RefPtr m_context_menu_default_action; + String m_context_menu_app_name; }; }