From 40a72883ff94eab589ddcb21c427eb46ce9a6fdf Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 May 2020 22:12:14 +0200 Subject: [PATCH] PaintBrush: Add "Delete layer" action to move tool context menu --- Applications/PaintBrush/Image.cpp | 7 +++++++ Applications/PaintBrush/Image.h | 1 + Applications/PaintBrush/MoveTool.cpp | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Applications/PaintBrush/Image.cpp b/Applications/PaintBrush/Image.cpp index a2739c1ada..6cb92d039e 100644 --- a/Applications/PaintBrush/Image.cpp +++ b/Applications/PaintBrush/Image.cpp @@ -104,4 +104,11 @@ void Image::move_layer_to_front(Layer& layer) m_layers.append(layer); } +void Image::remove_layer(Layer& layer) +{ + NonnullRefPtr protector(layer); + auto index = index_of(layer); + m_layers.remove(index); +} + } diff --git a/Applications/PaintBrush/Image.h b/Applications/PaintBrush/Image.h index 6b832df594..9526f0efe4 100644 --- a/Applications/PaintBrush/Image.h +++ b/Applications/PaintBrush/Image.h @@ -57,6 +57,7 @@ public: void move_layer_to_front(Layer&); void move_layer_to_back(Layer&); + void remove_layer(Layer&); private: explicit Image(const Gfx::Size&); diff --git a/Applications/PaintBrush/MoveTool.cpp b/Applications/PaintBrush/MoveTool.cpp index 1c87e3e79d..8a73e6d37f 100644 --- a/Applications/PaintBrush/MoveTool.cpp +++ b/Applications/PaintBrush/MoveTool.cpp @@ -111,11 +111,19 @@ void MoveTool::on_context_menu(Layer& layer, GUI::ContextMenuEvent& event) m_context_menu->add_action(GUI::CommonActions::make_move_to_front_action([this](auto&) { m_editor->image()->move_layer_to_front(*m_context_menu_layer); m_editor->layers_did_change(); - })); + }, m_editor)); m_context_menu->add_action(GUI::CommonActions::make_move_to_back_action([this](auto&) { m_editor->image()->move_layer_to_back(*m_context_menu_layer); m_editor->layers_did_change(); - })); + }, m_editor)); + m_context_menu->add_separator(); + m_context_menu->add_action(GUI::Action::create("Delete layer", Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png"), [this](auto&) { + m_editor->image()->remove_layer(*m_context_menu_layer); + // FIXME: This should not be done imperatively here. Perhaps a Image::Client interface that ImageEditor can implement? + if (m_editor->active_layer() == m_context_menu_layer) + m_editor->set_active_layer(nullptr); + m_editor->layers_did_change(); + }, m_editor)); } m_context_menu_layer = layer; m_context_menu->popup(event.screen_position());