1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:07:36 +00:00

PixelPaint: Verify that we have an ImageEditor instead of returning

We should never be in a state where an action requiring an ImageEditor
is enabled if all tabs are closed.
This commit is contained in:
Marcus Nilsson 2022-01-09 01:15:10 +01:00 committed by Linus Groh
parent ae958d97b2
commit 876424923a

View file

@ -46,7 +46,8 @@ MainWidget::MainWidget()
m_layer_list_widget = *find_descendant_of_type_named<PixelPaint::LayerListWidget>("layer_list_widget"); m_layer_list_widget = *find_descendant_of_type_named<PixelPaint::LayerListWidget>("layer_list_widget");
m_layer_list_widget->on_layer_select = [&](auto* layer) { m_layer_list_widget->on_layer_select = [&](auto* layer) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->set_active_layer(layer); editor->set_active_layer(layer);
}; };
@ -54,7 +55,8 @@ MainWidget::MainWidget()
m_tool_properties_widget = *find_descendant_of_type_named<PixelPaint::ToolPropertiesWidget>("tool_properties_widget"); m_tool_properties_widget = *find_descendant_of_type_named<PixelPaint::ToolPropertiesWidget>("tool_properties_widget");
m_toolbox->on_tool_selection = [&](auto* tool) { m_toolbox->on_tool_selection = [&](auto* tool) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->set_active_tool(tool); editor->set_active_tool(tool);
m_tool_properties_widget->set_active_tool(tool); m_tool_properties_widget->set_active_tool(tool);
}; };
@ -136,12 +138,14 @@ void MainWidget::initialize_menubar(GUI::Window& window)
}); });
m_save_image_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { m_save_image_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->save_project_as(); editor->save_project_as();
}); });
m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) { m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->save_project(); editor->save_project();
}); });
@ -157,8 +161,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
GUI::Action::create( GUI::Action::create(
"As &BMP", [&](auto&) { "As &BMP", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto save_result = FileSystemAccessClient::Client::the().save_file(window.window_id(), "untitled", "bmp"); auto save_result = FileSystemAccessClient::Client::the().save_file(window.window_id(), "untitled", "bmp");
if (save_result.error != 0) if (save_result.error != 0)
return; return;
@ -172,6 +175,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
GUI::Action::create( GUI::Action::create(
"As &PNG", [&](auto&) { "As &PNG", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
VERIFY(editor);
auto save_result = FileSystemAccessClient::Client::the().save_file(window.window_id(), "untitled", "png"); auto save_result = FileSystemAccessClient::Client::the().save_file(window.window_id(), "untitled", "png");
if (save_result.error != 0) if (save_result.error != 0)
return; return;
@ -185,8 +189,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_close_image_action = GUI::Action::create("&Close Image", { Mod_Ctrl, Key_W }, [&](auto&) { m_close_image_action = GUI::Action::create("&Close Image", { Mod_Ctrl, Key_W }, [&](auto&) {
auto* active_widget = m_tab_widget->active_widget(); auto* active_widget = m_tab_widget->active_widget();
if (!active_widget) VERIFY(active_widget);
return;
m_tab_widget->on_tab_close_click(*active_widget); m_tab_widget->on_tab_close_click(*active_widget);
}); });
@ -201,8 +204,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_copy_action = GUI::CommonActions::make_copy_action([&](auto&) { m_copy_action = GUI::CommonActions::make_copy_action([&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
if (!editor->active_layer()) { if (!editor->active_layer()) {
dbgln("Cannot copy with no active layer selected"); dbgln("Cannot copy with no active layer selected");
return; return;
@ -219,8 +222,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
"Copy &Merged", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png").release_value_but_fixme_should_propagate_errors(), "Copy &Merged", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png").release_value_but_fixme_should_propagate_errors(),
[&](auto&) { [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto bitmap = editor->image().try_copy_bitmap(editor->selection()); auto bitmap = editor->image().try_copy_bitmap(editor->selection());
if (!bitmap) { if (!bitmap) {
dbgln("try_copy_bitmap() from Image failed"); dbgln("try_copy_bitmap() from Image failed");
@ -256,7 +259,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
}); });
m_redo_action = GUI::CommonActions::make_redo_action([&](auto&) { m_redo_action = GUI::CommonActions::make_redo_action([&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->redo(); editor->redo();
}); });
@ -269,13 +273,15 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_edit_menu->add_action(GUI::CommonActions::make_select_all_action([&](auto&) { m_edit_menu->add_action(GUI::CommonActions::make_select_all_action([&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
VERIFY(editor);
if (!editor->active_layer()) if (!editor->active_layer())
return; return;
editor->selection().merge(editor->active_layer()->relative_rect(), PixelPaint::Selection::MergeMode::Set); editor->selection().merge(editor->active_layer()->relative_rect(), PixelPaint::Selection::MergeMode::Set);
})); }));
m_edit_menu->add_action(GUI::Action::create( m_edit_menu->add_action(GUI::Action::create(
"Clear &Selection", { Mod_Ctrl | Mod_Shift, Key_A }, [&](auto&) { "Clear &Selection", { Mod_Ctrl | Mod_Shift, Key_A }, [&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->selection().clear(); editor->selection().clear();
})); }));
@ -283,18 +289,17 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_edit_menu->add_action(GUI::Action::create( m_edit_menu->add_action(GUI::Action::create(
"S&wap Colors", { Mod_None, Key_X }, [&](auto&) { "S&wap Colors", { Mod_None, Key_X }, [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto old_primary_color = editor->primary_color(); auto old_primary_color = editor->primary_color();
editor->set_primary_color(editor->secondary_color()); editor->set_primary_color(editor->secondary_color());
editor->set_secondary_color(old_primary_color); editor->set_secondary_color(old_primary_color);
})); }));
m_edit_menu->add_action(GUI::Action::create( m_edit_menu->add_action(GUI::Action::create(
"&Default Colors", { Mod_None, Key_D }, [&](auto&) { "&Default Colors", { Mod_None, Key_D }, [&](auto&) {
if (auto* editor = current_image_editor()) { auto* editor = current_image_editor();
VERIFY(editor);
editor->set_primary_color(Color::Black); editor->set_primary_color(Color::Black);
editor->set_secondary_color(Color::White); editor->set_secondary_color(Color::White);
}
})); }));
m_edit_menu->add_action(GUI::Action::create( m_edit_menu->add_action(GUI::Action::create(
"&Load Color Palette", [&](auto&) { "&Load Color Palette", [&](auto&) {
@ -325,19 +330,22 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_zoom_in_action = GUI::CommonActions::make_zoom_in_action( m_zoom_in_action = GUI::CommonActions::make_zoom_in_action(
[&](auto&) { [&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->scale_by(0.1f); editor->scale_by(0.1f);
}); });
m_zoom_out_action = GUI::CommonActions::make_zoom_out_action( m_zoom_out_action = GUI::CommonActions::make_zoom_out_action(
[&](auto&) { [&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->scale_by(-0.1f); editor->scale_by(-0.1f);
}); });
m_reset_zoom_action = GUI::CommonActions::make_reset_zoom_action( m_reset_zoom_action = GUI::CommonActions::make_reset_zoom_action(
[&](auto&) { [&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->reset_scale_and_position(); editor->reset_scale_and_position();
}); });
@ -346,21 +354,21 @@ void MainWidget::initialize_menubar(GUI::Window& window)
auto dialog = PixelPaint::EditGuideDialog::construct(&window); auto dialog = PixelPaint::EditGuideDialog::construct(&window);
if (dialog->exec() != GUI::Dialog::ExecOK) if (dialog->exec() != GUI::Dialog::ExecOK)
return; return;
if (auto* editor = current_image_editor()) { auto* editor = current_image_editor();
VERIFY(editor);
auto offset = dialog->offset_as_pixel(*editor); auto offset = dialog->offset_as_pixel(*editor);
if (!offset.has_value()) if (!offset.has_value())
return; return;
editor->add_guide(PixelPaint::Guide::construct(dialog->orientation(), offset.value())); editor->add_guide(PixelPaint::Guide::construct(dialog->orientation(), offset.value()));
}
}); });
// Save this so other methods can use it // Save this so other methods can use it
m_show_guides_action = GUI::Action::create_checkable( m_show_guides_action = GUI::Action::create_checkable(
"Show &Guides", [&](auto& action) { "Show &Guides", [&](auto& action) {
Config::write_bool("PixelPaint", "Guides", "Show", action.is_checked()); Config::write_bool("PixelPaint", "Guides", "Show", action.is_checked());
if (auto* editor = current_image_editor()) { auto* editor = current_image_editor();
VERIFY(editor);
editor->set_guide_visibility(action.is_checked()); editor->set_guide_visibility(action.is_checked());
}
}); });
m_show_guides_action->set_checked(Config::read_bool("PixelPaint", "Guides", "Show", true)); m_show_guides_action->set_checked(Config::read_bool("PixelPaint", "Guides", "Show", true));
@ -369,7 +377,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_view_menu->add_action(*m_reset_zoom_action); m_view_menu->add_action(*m_reset_zoom_action);
m_view_menu->add_action(GUI::Action::create( m_view_menu->add_action(GUI::Action::create(
"&Fit Image To View", [&](auto&) { "&Fit Image To View", [&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->fit_image_to_view(); editor->fit_image_to_view();
})); }));
m_view_menu->add_separator(); m_view_menu->add_separator();
@ -378,7 +387,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_view_menu->add_action(GUI::Action::create( m_view_menu->add_action(GUI::Action::create(
"&Clear Guides", [&](auto&) { "&Clear Guides", [&](auto&) {
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->clear_guides(); editor->clear_guides();
})); }));
m_view_menu->add_separator(); m_view_menu->add_separator();
@ -386,7 +396,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
auto show_pixel_grid_action = GUI::Action::create_checkable( auto show_pixel_grid_action = GUI::Action::create_checkable(
"Show &Pixel Grid", [&](auto& action) { "Show &Pixel Grid", [&](auto& action) {
Config::write_bool("PixelPaint", "PixelGrid", "Show", action.is_checked()); Config::write_bool("PixelPaint", "PixelGrid", "Show", action.is_checked());
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->set_pixel_grid_visibility(action.is_checked()); editor->set_pixel_grid_visibility(action.is_checked());
}); });
show_pixel_grid_action->set_checked(Config::read_bool("PixelPaint", "PixelGrid", "Show", true)); show_pixel_grid_action->set_checked(Config::read_bool("PixelPaint", "PixelGrid", "Show", true));
@ -395,9 +406,9 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_show_rulers_action = GUI::Action::create_checkable( m_show_rulers_action = GUI::Action::create_checkable(
"Show R&ulers", { Mod_Ctrl, Key_R }, [&](auto& action) { "Show R&ulers", { Mod_Ctrl, Key_R }, [&](auto& action) {
Config::write_bool("PixelPaint", "Rulers", "Show", action.is_checked()); Config::write_bool("PixelPaint", "Rulers", "Show", action.is_checked());
if (auto* editor = current_image_editor()) { auto* editor = current_image_editor();
VERIFY(editor);
editor->set_ruler_visibility(action.is_checked()); editor->set_ruler_visibility(action.is_checked());
}
}); });
m_show_rulers_action->set_checked(Config::read_bool("PixelPaint", "Rulers", "Show", true)); m_show_rulers_action->set_checked(Config::read_bool("PixelPaint", "Rulers", "Show", true));
m_view_menu->add_action(*m_show_rulers_action); m_view_menu->add_action(*m_show_rulers_action);
@ -405,7 +416,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_show_active_layer_boundary_action = GUI::Action::create_checkable( m_show_active_layer_boundary_action = GUI::Action::create_checkable(
"Show Active Layer &Boundary", [&](auto& action) { "Show Active Layer &Boundary", [&](auto& action) {
Config::write_bool("PixelPaint", "ImageEditor", "ShowActiveLayerBoundary", action.is_checked()); Config::write_bool("PixelPaint", "ImageEditor", "ShowActiveLayerBoundary", action.is_checked());
if (auto* editor = current_image_editor()) auto* editor = current_image_editor();
VERIFY(editor);
editor->set_show_active_layer_boundary(action.is_checked()); editor->set_show_active_layer_boundary(action.is_checked());
}); });
m_show_active_layer_boundary_action->set_checked(Config::read_bool("PixelPaint", "ImageEditor", "ShowActiveLayerBoundary", true)); m_show_active_layer_boundary_action->set_checked(Config::read_bool("PixelPaint", "ImageEditor", "ShowActiveLayerBoundary", true));
@ -422,15 +434,13 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_image_menu->add_action(GUI::Action::create( m_image_menu->add_action(GUI::Action::create(
"Flip &Vertically", [&](auto&) { "Flip &Vertically", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
editor->image().flip(Gfx::Orientation::Vertical); editor->image().flip(Gfx::Orientation::Vertical);
})); }));
m_image_menu->add_action(GUI::Action::create( m_image_menu->add_action(GUI::Action::create(
"Flip &Horizontally", [&](auto&) { "Flip &Horizontally", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
editor->image().flip(Gfx::Orientation::Horizontal); editor->image().flip(Gfx::Orientation::Horizontal);
})); }));
m_image_menu->add_separator(); m_image_menu->add_separator();
@ -438,24 +448,23 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_image_menu->add_action(GUI::CommonActions::make_rotate_counterclockwise_action( m_image_menu->add_action(GUI::CommonActions::make_rotate_counterclockwise_action(
[&](auto&) { [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
editor->image().rotate(Gfx::RotationDirection::CounterClockwise); editor->image().rotate(Gfx::RotationDirection::CounterClockwise);
})); }));
m_image_menu->add_action(GUI::CommonActions::make_rotate_clockwise_action( m_image_menu->add_action(GUI::CommonActions::make_rotate_clockwise_action(
[&](auto&) { [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
editor->image().rotate(Gfx::RotationDirection::Clockwise); editor->image().rotate(Gfx::RotationDirection::Clockwise);
})); }));
m_image_menu->add_separator(); m_image_menu->add_separator();
m_image_menu->add_action(GUI::Action::create( m_image_menu->add_action(GUI::Action::create(
"&Crop To Selection", [&](auto&) { "&Crop To Selection", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
VERIFY(editor);
// FIXME: disable this action if there is no selection // FIXME: disable this action if there is no selection
if (!editor || editor->selection().is_empty()) if (editor->selection().is_empty())
return; return;
auto crop_rect = editor->selection().bounding_rect(); auto crop_rect = editor->selection().bounding_rect();
editor->image().crop(crop_rect); editor->image().crop(crop_rect);
@ -466,8 +475,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"New &Layer...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new-layer.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { "New &Layer...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new-layer.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto dialog = PixelPaint::CreateNewLayerDialog::construct(editor->image().size(), &window); auto dialog = PixelPaint::CreateNewLayerDialog::construct(editor->image().size(), &window);
if (dialog->exec() == GUI::Dialog::ExecOK) { if (dialog->exec() == GUI::Dialog::ExecOK) {
auto layer_or_error = PixelPaint::Layer::try_create_with_size(editor->image(), dialog->layer_size(), dialog->layer_name()); auto layer_or_error = PixelPaint::Layer::try_create_with_size(editor->image(), dialog->layer_size(), dialog->layer_name());
@ -502,8 +510,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::CommonActions::make_move_to_front_action( m_layer_menu->add_action(GUI::CommonActions::make_move_to_front_action(
[&](auto&) { [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto active_layer = editor->active_layer(); auto active_layer = editor->active_layer();
if (!active_layer) if (!active_layer)
return; return;
@ -513,8 +520,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::CommonActions::make_move_to_back_action( m_layer_menu->add_action(GUI::CommonActions::make_move_to_back_action(
[&](auto&) { [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto active_layer = editor->active_layer(); auto active_layer = editor->active_layer();
if (!active_layer) if (!active_layer)
return; return;
@ -525,8 +531,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"Move Active Layer &Up", { Mod_Ctrl, Key_PageUp }, [&](auto&) { "Move Active Layer &Up", { Mod_Ctrl, Key_PageUp }, [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto active_layer = editor->active_layer(); auto active_layer = editor->active_layer();
if (!active_layer) if (!active_layer)
return; return;
@ -535,8 +540,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"Move Active Layer &Down", { Mod_Ctrl, Key_PageDown }, [&](auto&) { "Move Active Layer &Down", { Mod_Ctrl, Key_PageDown }, [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto active_layer = editor->active_layer(); auto active_layer = editor->active_layer();
if (!active_layer) if (!active_layer)
return; return;
@ -546,8 +550,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"&Remove Active Layer", { Mod_Ctrl, Key_D }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { "&Remove Active Layer", { Mod_Ctrl, Key_D }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto active_layer = editor->active_layer(); auto active_layer = editor->active_layer();
if (!active_layer) if (!active_layer)
return; return;
@ -573,8 +576,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"Fl&atten Image", { Mod_Ctrl, Key_F }, [&](auto&) { "Fl&atten Image", { Mod_Ctrl, Key_F }, [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
editor->image().flatten_all_layers(); editor->image().flatten_all_layers();
editor->did_complete_action(); editor->did_complete_action();
})); }));
@ -582,8 +584,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"&Merge Visible", { Mod_Ctrl, Key_M }, [&](auto&) { "&Merge Visible", { Mod_Ctrl, Key_M }, [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
editor->image().merge_visible_layers(); editor->image().merge_visible_layers();
editor->did_complete_action(); editor->did_complete_action();
})); }));
@ -591,8 +592,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_layer_menu->add_action(GUI::Action::create( m_layer_menu->add_action(GUI::Action::create(
"M&erge Active Layer Down", { Mod_Ctrl, Key_E }, [&](auto&) { "M&erge Active Layer Down", { Mod_Ctrl, Key_E }, [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto active_layer = editor->active_layer(); auto active_layer = editor->active_layer();
if (!active_layer) if (!active_layer)
return; return;
@ -604,8 +604,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_filter_menu->add_action(GUI::Action::create("Filter &Gallery", [&](auto&) { m_filter_menu->add_action(GUI::Action::create("Filter &Gallery", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
auto dialog = PixelPaint::FilterGallery::construct(&window, editor); auto dialog = PixelPaint::FilterGallery::construct(&window, editor);
if (dialog->exec() != GUI::Dialog::ExecOK) if (dialog->exec() != GUI::Dialog::ExecOK)
return; return;
@ -614,8 +613,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_filter_menu->add_separator(); m_filter_menu->add_separator();
m_filter_menu->add_action(GUI::Action::create("Generic 5x5 &Convolution", [&](auto&) { m_filter_menu->add_action(GUI::Action::create("Generic 5x5 &Convolution", [&](auto&) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (!editor) VERIFY(editor);
return;
if (auto* layer = editor->active_layer()) { if (auto* layer = editor->active_layer()) {
Gfx::GenericConvolutionFilter<5> filter; Gfx::GenericConvolutionFilter<5> filter;
if (auto parameters = PixelPaint::FilterParameters<Gfx::GenericConvolutionFilter<5>>::get(&window)) { if (auto parameters = PixelPaint::FilterParameters<Gfx::GenericConvolutionFilter<5>>::get(&window)) {
@ -647,8 +645,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
m_zoom_combobox->set_model(*GUI::ItemListModel<String>::create(s_suggested_zoom_levels)); m_zoom_combobox->set_model(*GUI::ItemListModel<String>::create(s_suggested_zoom_levels));
m_zoom_combobox->on_change = [this](String const& value, GUI::ModelIndex const& index) { m_zoom_combobox->on_change = [this](String const& value, GUI::ModelIndex const& index) {
auto* editor = current_image_editor(); auto* editor = current_image_editor();
if (editor == nullptr) VERIFY(editor);
return;
if (index.is_valid()) { if (index.is_valid()) {
switch (index.row()) { switch (index.row()) {