From 351dee4f8f9edd1f362b1949db6cf04f466796eb Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sun, 12 Sep 2021 21:36:44 -0400 Subject: [PATCH] PixelPaint: Properly transfer active tool to editor on tab close Previously the code assumed that the active tool had a reference to the old editor, which is the only way we had to check if it is active without having a reference to the editor. However, when a tab in PixelPaint is closed, the editor is destroyed, so the `WeakPtr` in a tool referencing the old editor is no longer valid. This made it so that if you closed a tab, the tool would appear to be selected in the ToolBox, but the editor would not know about it at all. --- Userland/Applications/PixelPaint/MainWidget.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 2d4f0f7766..4beef916e1 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -73,13 +73,8 @@ MainWidget::MainWidget() m_palette_widget->set_image_editor(image_editor); m_layer_list_widget->set_image(&image_editor.image()); m_layer_properties_widget->set_layer(image_editor.active_layer()); - // FIXME: This is badly factored. It transfers tools from the previously active editor to the new one. - m_toolbox->template for_each_tool([&](auto& tool) { - if (tool.editor()) { - tool.editor()->set_active_tool(nullptr); - image_editor.set_active_tool(&tool); - } - }); + if (auto* active_tool = m_toolbox->active_tool()) + image_editor.set_active_tool(active_tool); m_show_guides_action->set_checked(image_editor.guide_visibility()); m_show_rulers_action->set_checked(image_editor.ruler_visibility()); };