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.
This commit is contained in:
faxe1008 2021-11-24 20:22:12 +01:00 committed by Brian Gianforcaro
parent c74afdde26
commit 7d6058415e
2 changed files with 19 additions and 1 deletions

View file

@ -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)

View file

@ -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;
};
}