Przeglądaj źródła

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.
Mustafa Quraish 3 lat temu
rodzic
commit
351dee4f8f
1 zmienionych plików z 2 dodań i 7 usunięć
  1. 2 7
      Userland/Applications/PixelPaint/MainWidget.cpp

+ 2 - 7
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());
     };