summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-23 19:53:48 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-23 19:53:48 +0200
commit7973f767905abd64942bf538a53e385ab207bd6e (patch)
tree4de2bf9367b9333970f0dacfade8e83316b81337 /Applications
parent4392413cd1520b11a5c9314dd2a291e8ca92a75d (diff)
downloadserenity-7973f767905abd64942bf538a53e385ab207bd6e.zip
PixelPaint: Scope tool actions to the containing window
We achieve this by deferring the construction of the tool buttons until the toolbox widget has been added to a window.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/PixelPaint/ToolboxWidget.cpp30
-rw-r--r--Applications/PixelPaint/ToolboxWidget.h2
2 files changed, 22 insertions, 10 deletions
diff --git a/Applications/PixelPaint/ToolboxWidget.cpp b/Applications/PixelPaint/ToolboxWidget.cpp
index ee4cd0a88e..c6e6399282 100644
--- a/Applications/PixelPaint/ToolboxWidget.cpp
+++ b/Applications/PixelPaint/ToolboxWidget.cpp
@@ -38,6 +38,7 @@
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
+#include <LibGUI/Window.h>
namespace PixelPaint {
@@ -55,12 +56,14 @@ public:
builder.append(")");
set_tooltip(builder.to_string());
- m_action = GUI::Action::create_checkable(name, shortcut, [this](auto& action) {
- if (action.is_checked())
- m_toolbox.on_tool_selection(m_tool);
- else
- m_toolbox.on_tool_selection(nullptr);
- });
+ m_action = GUI::Action::create_checkable(
+ name, shortcut, [this](auto& action) {
+ if (action.is_checked())
+ m_toolbox.on_tool_selection(m_tool);
+ else
+ m_toolbox.on_tool_selection(nullptr);
+ },
+ toolbox.window());
m_tool->set_action(m_action);
set_action(*m_action);
@@ -101,6 +104,17 @@ ToolboxWidget::ToolboxWidget()
m_action_group.set_exclusive(true);
m_action_group.set_unchecking_allowed(false);
+ deferred_invoke([this](auto&) {
+ setup_tools();
+ });
+}
+
+ToolboxWidget::~ToolboxWidget()
+{
+}
+
+void ToolboxWidget::setup_tools()
+{
auto add_tool = [&](const StringView& name, const StringView& icon_name, const GUI::Shortcut& shortcut, NonnullOwnPtr<Tool> tool) -> ToolButton& {
m_tools.append(tool.ptr());
auto& button = add<ToolButton>(*this, name, shortcut, move(tool));
@@ -122,8 +136,4 @@ ToolboxWidget::ToolboxWidget()
add_tool("Ellipse", "circle", { Mod_Ctrl | Mod_Shift, Key_E }, make<EllipseTool>());
}
-ToolboxWidget::~ToolboxWidget()
-{
-}
-
}
diff --git a/Applications/PixelPaint/ToolboxWidget.h b/Applications/PixelPaint/ToolboxWidget.h
index 93a5b70552..23794179f6 100644
--- a/Applications/PixelPaint/ToolboxWidget.h
+++ b/Applications/PixelPaint/ToolboxWidget.h
@@ -50,6 +50,8 @@ public:
private:
friend class ToolButton;
+ void setup_tools();
+
explicit ToolboxWidget();
GUI::ActionGroup m_action_group;
Vector<Tool*> m_tools;