mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +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:
parent
4e09ee1f2f
commit
82e85172e5
3 changed files with 17 additions and 8 deletions
|
@ -61,9 +61,11 @@ MainWidget::MainWidget()
|
||||||
|
|
||||||
m_toolbox->on_tool_selection = [&](auto* tool) {
|
m_toolbox->on_tool_selection = [&](auto* tool) {
|
||||||
auto* editor = current_image_editor();
|
auto* editor = current_image_editor();
|
||||||
VERIFY(editor);
|
// Ignore tool selection changes if we don't have an editor yet, e.g. if PixelPaint is started with a path argument.
|
||||||
editor->set_active_tool(tool);
|
if (editor) {
|
||||||
m_tool_properties_widget->set_active_tool(tool);
|
editor->set_active_tool(tool);
|
||||||
|
m_tool_properties_widget->set_active_tool(tool);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_tab_widget->on_middle_click = [&](auto& widget) {
|
m_tab_widget->on_middle_click = [&](auto& widget) {
|
||||||
|
@ -1298,6 +1300,7 @@ void MainWidget::open_image(FileSystemAccessClient::File file)
|
||||||
editor.set_path(file.filename().to_byte_string());
|
editor.set_path(file.filename().to_byte_string());
|
||||||
editor.set_unmodified();
|
editor.set_unmodified();
|
||||||
m_layer_list_widget->set_image(&image);
|
m_layer_list_widget->set_image(&image);
|
||||||
|
m_toolbox->ensure_tool_selection();
|
||||||
GUI::Application::the()->set_most_recently_open_file(file.filename());
|
GUI::Application::the()->set_most_recently_open_file(file.filename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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(),
|
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) {
|
[this, tool = tool.ptr()](auto& action) {
|
||||||
if (action.is_checked()) {
|
if (action.is_checked()) {
|
||||||
on_tool_selection(tool);
|
|
||||||
m_active_tool = tool;
|
m_active_tool = tool;
|
||||||
|
ensure_tool_selection();
|
||||||
} else {
|
} else {
|
||||||
on_tool_selection(nullptr);
|
on_tool_selection(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,11 @@ void ToolboxWidget::setup_tools()
|
||||||
tool->set_action(action);
|
tool->set_action(action);
|
||||||
m_tools.append(move(tool));
|
m_tools.append(move(tool));
|
||||||
if (is_default_tool) {
|
if (is_default_tool) {
|
||||||
|
VERIFY(m_active_tool == nullptr);
|
||||||
action->set_checked(true);
|
action->set_checked(true);
|
||||||
auto default_tool_index = m_tools.size() - 1;
|
m_active_tool = m_tools[m_tools.size() - 1];
|
||||||
deferred_invoke([&, default_tool_index]() {
|
deferred_invoke([&]() {
|
||||||
VERIFY(m_active_tool == nullptr);
|
ensure_tool_selection();
|
||||||
on_tool_selection(m_tools[default_tool_index]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -100,4 +100,9 @@ void ToolboxWidget::setup_tools()
|
||||||
add_tool("gradients"sv, { Mod_Ctrl, Key_G }, make<GradientTool>());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Tool* active_tool() const { return m_active_tool; }
|
Tool* active_tool() const { return m_active_tool; }
|
||||||
|
void ensure_tool_selection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ToolButton;
|
friend class ToolButton;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue