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

PixelPaint: Fix crash when started with path

This change fixes the initial tool selection when pixelpaint is started
with a path. Previously an already existing editor was expected when
the default tool was initially propagated - which was not the case if
pixelpaint was launched to directly load an existing image.
This commit is contained in:
Torstennator 2024-01-01 17:29:13 +01:00 committed by Andreas Kling
parent 4e09ee1f2f
commit 82e85172e5
3 changed files with 17 additions and 8 deletions

View file

@ -55,8 +55,8 @@ void ToolboxWidget::setup_tools()
auto action = GUI::Action::create_checkable(tool->tool_name(), shortcut, Gfx::Bitmap::load_from_file(ByteString::formatted("/res/icons/pixelpaint/{}.png", icon_name)).release_value_but_fixme_should_propagate_errors(),
[this, tool = tool.ptr()](auto& action) {
if (action.is_checked()) {
on_tool_selection(tool);
m_active_tool = tool;
ensure_tool_selection();
} else {
on_tool_selection(nullptr);
}
@ -70,11 +70,11 @@ void ToolboxWidget::setup_tools()
tool->set_action(action);
m_tools.append(move(tool));
if (is_default_tool) {
VERIFY(m_active_tool == nullptr);
action->set_checked(true);
auto default_tool_index = m_tools.size() - 1;
deferred_invoke([&, default_tool_index]() {
VERIFY(m_active_tool == nullptr);
on_tool_selection(m_tools[default_tool_index]);
m_active_tool = m_tools[m_tools.size() - 1];
deferred_invoke([&]() {
ensure_tool_selection();
});
}
};
@ -100,4 +100,9 @@ void ToolboxWidget::setup_tools()
add_tool("gradients"sv, { Mod_Ctrl, Key_G }, make<GradientTool>());
}
void ToolboxWidget::ensure_tool_selection()
{
if (on_tool_selection)
on_tool_selection(m_active_tool);
}
}