From 73fcaaeda461be3dcae4cb8d2bece12db5fac84b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 20 Sep 2022 10:22:10 -0400 Subject: [PATCH] Taskbar: Add a context menu to open clock settings from the clock widget --- Userland/Services/Taskbar/ClockWidget.cpp | 19 +++++++++++++++++++ Userland/Services/Taskbar/ClockWidget.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Userland/Services/Taskbar/ClockWidget.cpp b/Userland/Services/Taskbar/ClockWidget.cpp index 1089b87b1e..539e728cc2 100644 --- a/Userland/Services/Taskbar/ClockWidget.cpp +++ b/Userland/Services/Taskbar/ClockWidget.cpp @@ -6,10 +6,13 @@ #include "ClockWidget.h" #include +#include +#include #include #include #include #include +#include #include #include @@ -196,6 +199,22 @@ void ClockWidget::mousedown_event(GUI::MouseEvent& event) } } +void ClockWidget::context_menu_event(GUI::ContextMenuEvent& event) +{ + if (!m_context_menu) { + m_context_menu = GUI::Menu::construct(); + + auto settings_icon = MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"sv)); + auto open_clock_settings_action = GUI::Action::create("Clock &Settings", *settings_icon, [this](auto&) { + GUI::Process::spawn_or_show_error(window(), "/bin/ClockSettings"sv, Array { "--open-tab", "clock" }); + }); + + m_context_menu->add_action(open_clock_settings_action); + } + + m_context_menu->popup(event.screen_position()); +} + void ClockWidget::open() { jump_to_current_date(); diff --git a/Userland/Services/Taskbar/ClockWidget.h b/Userland/Services/Taskbar/ClockWidget.h index 420d02a61a..a07971cb0f 100644 --- a/Userland/Services/Taskbar/ClockWidget.h +++ b/Userland/Services/Taskbar/ClockWidget.h @@ -31,6 +31,7 @@ private: virtual void paint_event(GUI::PaintEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void context_menu_event(GUI::ContextMenuEvent&) override; void tick_clock() { @@ -52,6 +53,7 @@ private: RefPtr m_selected_calendar_button; RefPtr m_jump_to_button; RefPtr m_calendar_launcher; + RefPtr m_context_menu; RefPtr m_timer; int m_time_width { 0 }; Gfx::IntSize m_window_size { 158, 186 };