From ea35725c85d97ceda9e9945e0d11960522bf7d02 Mon Sep 17 00:00:00 2001 From: Dariy Guzairov <0quokka0@gmail.com> Date: Tue, 26 Sep 2023 09:21:17 +1000 Subject: [PATCH] Fix disable delete layer button when only one layer exists (fix #3649) --- src/app/commands/cmd_remove_layer.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/app/commands/cmd_remove_layer.cpp b/src/app/commands/cmd_remove_layer.cpp index 782549ff5..2113d379b 100644 --- a/src/app/commands/cmd_remove_layer.cpp +++ b/src/app/commands/cmd_remove_layer.cpp @@ -116,9 +116,20 @@ RemoveLayerCommand::RemoveLayerCommand() bool RemoveLayerCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | - ContextFlags::HasActiveSprite | - ContextFlags::HasActiveLayer); + if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable | + ContextFlags::HasActiveSprite | + ContextFlags::HasActiveLayer)) + return false; + + const ContextReader reader(context); + const Sprite* sprite(reader.sprite()); + const Layer* layer = reader.layer(); + + return sprite && layer && + // We can remove all layers from non-root groups + ((layer->parent() != sprite->root()) || + // Check that we are not removing the last layer in the sprite + (sprite->root()->layersCount() > 1)); } void RemoveLayerCommand::onExecute(Context* context)