Skip to content

Fix disable delete layer button when only one layer exists #4070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

The-Vector
Copy link
Contributor

Fixes #3649

I agree that my contributions are licensed under the Individual Contributor License Agreement V4.0 ("CLA") as stated in https://github.com/igarastudio/cla/blob/main/cla.md

I have signed the CLA following the steps given in https://github.com/igarastudio/cla#signing

@The-Vector The-Vector requested a review from dacap as a code owner September 26, 2023 08:13
@dacap dacap self-assigned this Sep 26, 2023

const ContextReader reader(context);
const Sprite* sprite(reader.sprite());
return sprite && sprite->totalFrames() > 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @The-Vector, it looks like you are asking for the number of frames here but it should be the number of layers at the root level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I don't know how I missed that.
It should be fixed now.


const ContextReader reader(context);
const Sprite* sprite(reader.sprite());
return sprite && sprite->allLayersCount() > 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @The-Vector, actually here you are counting the total number of layers (including layers in subgroups) which I think it's not the expected behavior, e.g. if you have a group with one child, that is allLayersCount=2 and enables the delete command for the group (which is the only layer at the root level).

You have to count the number of layers in the root (sprite->root()).

Also I'm seeing that the commit has 0quokka0@gmail.com as email but the CLA was signed with other email address, you should sign the CLA with the same name and email that you will use in the commit message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@The-Vector was you able to see the above comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I filled out the CLA with the correct email, and I'm just testing my code so there's no other edge cases that I missed.

@The-Vector
Copy link
Contributor Author

I believe this should work now.
The button is disabled when there is only one layer, and if you make a group with layers within it, you can delete the layers but not the group.
Unless there are other edge cases which I missed?

Copy link
Member

@dacap dacap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given some comments with suggestions. I'm a little confused by the commits (not sure if the last commit does something in particular).

In any case I'm adding some suggestion to keep the code a little more readable + with some comments.

Comment on lines 119 to 121
if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
ContextFlags::HasActiveLayer))
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can keep the same flags here:

Suggested change
if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
ContextFlags::HasActiveLayer))
return false;
if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
ContextFlags::HasActiveSprite |
ContextFlags::HasActiveLayer))
return false;

Comment on lines 127 to 128
return sprite && !((sprite->root()->layersCount() == 1) && (layer->parent() == sprite->root()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expression is confusing and I think we can simplify it checking for the true cases (intead of the inverse):

Suggested change
return sprite && !((sprite->root()->layersCount() == 1) && (layer->parent() == sprite->root()));
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));

But I saw that you wrote it originally in this way in 56726d2 and then reverted with 5b02460. Logically they do the same (by De Morgan's law). Can you explain why did you change this? Did this last commit really fix what it says it fix? (because it should work exactly the same as the previous one).

Copy link
Contributor Author

@The-Vector The-Vector Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I changed it when testing my code and I saw that checking the true cases was still allowing you to delete a group if it was the root, but I checked just now and the code is identical and works the same, so I must have done something wrong in testing, sorry.
I'll add your suggestions and push the code with comments.
Sorry again for not being as thorough with testing my code.

@dacap
Copy link
Member

dacap commented Oct 23, 2023

Merged squashed in ea35725, thanks @The-Vector 👍

@dacap dacap closed this Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable "Delete Layer" option when the sprite has only one layer
2 participants