Fix closing Theme Editor not actually closing it #97543
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #97278
The issue has uncovered a bug in editor closing logic. Folding a resource will call the editor to stop editing it, but the actual unediting code assumed that the EditorPropertyResource no longer exists (which can happen when inspector updates, e.g. when editing another object). Which means the resource wasn't actually unedited.
I wasn't sure how to solve it properly, so I just added
_should_stop_editing
internal method. It's meant for editor contexts to inform whether they are still editing the object or not. EditorPropertyResource will return true when it's folded, so folding a property now properly stops editing it.Then there is ThemeEditorPlugin, which used the self-owning mechanism added in #81523, but the method for determining whether the editor should be hidden was overly complex and assumed that the Theme is opened in the inspector. I changed it to simply stay open while it edits a valid theme. Which means that Theme Editor will keep Theme reference until you explicitly press Close button; it no longer automatically disappears. Not sure if that's expected behavior, but it's at least convenient 🤔
The remaining problem is that when you close the scene, a built-in Theme can still remain referenced, resulting in potential data loss. Not sure about a solution for this one (maybe some WeakRef?), but it's probably fine for now.Solved it withtheme_closed
signal, which will automatically close editor if it edits built-in Theme.