From ecf8f243a6d09cd827dca6a31b6846977cf1699a Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sun, 12 Sep 2021 21:36:01 -0400 Subject: [PATCH] PixelPaint: Have `ToolboxWidget` keep track of active tool Since there's only one global toolbox, it makes sense to store the active tool in here, since we don't really have control over the deletion of an editor. --- Userland/Applications/PixelPaint/ToolboxWidget.cpp | 6 ++++-- Userland/Applications/PixelPaint/ToolboxWidget.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/PixelPaint/ToolboxWidget.cpp b/Userland/Applications/PixelPaint/ToolboxWidget.cpp index b8c4323d7a..b271e61a37 100644 --- a/Userland/Applications/PixelPaint/ToolboxWidget.cpp +++ b/Userland/Applications/PixelPaint/ToolboxWidget.cpp @@ -53,10 +53,12 @@ void ToolboxWidget::setup_tools() auto add_tool = [&](String name, StringView const& icon_name, GUI::Shortcut const& shortcut, NonnullOwnPtr tool) { auto action = GUI::Action::create_checkable(move(name), shortcut, Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/pixelpaint/{}.png", icon_name)), [this, tool = tool.ptr()](auto& action) { - if (action.is_checked()) + if (action.is_checked()) { on_tool_selection(tool); - else + m_active_tool = tool; + } else { on_tool_selection(nullptr); + } }); m_action_group.add_action(action); auto& button = m_toolbar->add_action(action); diff --git a/Userland/Applications/PixelPaint/ToolboxWidget.h b/Userland/Applications/PixelPaint/ToolboxWidget.h index c4de0ffa77..6de446ce56 100644 --- a/Userland/Applications/PixelPaint/ToolboxWidget.h +++ b/Userland/Applications/PixelPaint/ToolboxWidget.h @@ -29,6 +29,8 @@ public: callback(tool); } + Tool* active_tool() const { return m_active_tool; } + private: friend class ToolButton; @@ -38,6 +40,7 @@ private: RefPtr m_toolbar; GUI::ActionGroup m_action_group; NonnullOwnPtrVector m_tools; + Tool* m_active_tool { nullptr }; }; }