1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

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.
This commit is contained in:
Mustafa Quraish 2021-09-12 21:36:44 -04:00 committed by Andreas Kling
parent ecf8f243a6
commit 351dee4f8f

View file

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