Skip to content
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

Improve editor state persistence #72277

Merged

Conversation

Geometror
Copy link
Member

@Geometror Geometror commented Jan 28, 2023

This PR is an attempt to improve the editor state preservation when restarting the editor. Strangely I couldn't find any GH issues on this topic, but I know this has been a inconvenience for quite a few users, myself included :)

The following settings are now correctly saved and loaded:

  • Active open scene
  • Bottom panel:
    • Height (split offset) offset
    • Active tab (e.g. debugger, shader editor)
    • Shader editor:
      • Open shaders (incl. VisualShader)
      • Selected(currently editing) shader
    • Active debugger tab
  • Active tab per dock
  • Active main editor plugin (2D/3D/Script/Asset/...)
  • Script editor:
    • Selected(currently editing) script
  • Selected nodes per scene
  • Some viewport specific settings which were not correctly preserved (mostly regressions)
    • Orthogonal/perspective view
    • Advanced display (debug) modes (e.g. normal buffer, GI buffer, shadow map)
    • Half resolution
  • FileSystem dock
    • selected paths
    • expanded folders

Additional misc changes (internal, not compat-breaking):

  • Rename key "use_orthogonal" to "orthogonal"
  • Rename VIEW_DISPLAY_SHADELESS to VIEW_DISPLAY_UNSHADED
  • Some renames of internal methods and variables to better describe what they do

While this PR should fix the most annoying cases where the layout/settings would be lost, there are almost certainly still some left. Please let me know if you find one that should be included in this PR :)

Somewhat related side note: I realized that after 4.0 is out we need to do some significant internal refactoring of some core editor classes/files (e.g. editor_node/node_3d_editor_plugin). There's lots of duplicated/legacy code, confusing/short variable names, etc. which make it very hard to maintain them.

And lastly, since some visual comparisons won't do any harm:


Editor before and after the restart with this PR
image

Editor after restart with beta 16 (manually switched from scene "2d_test" to "main_test")
image

Bugsquad edit: Closes godotengine/godot-proposals#4789

@Geometror Geometror added this to the 4.0 milestone Jan 28, 2023
@Geometror Geometror requested review from a team as code owners January 28, 2023 21:40
@Geometror Geometror force-pushed the improve-editor-state-preservation branch 2 times, most recently from 543f5c0 to c6d3ba5 Compare January 29, 2023 03:54
Copy link
Member

@Paulb23 Paulb23 left a comment

Choose a reason for hiding this comment

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

Strangely I couldn't find any GH issues on this topic

The ShaderEditor is tracked by #29094. Though, that would include caching the full sate i.e bookmarks, carets etc that the ScriptEditor currently does.

editor/plugins/script_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/shader_editor_plugin.cpp Show resolved Hide resolved
@Geometror Geometror force-pushed the improve-editor-state-preservation branch from c6d3ba5 to 6bd1b8d Compare February 5, 2023 23:04
@YuriSizov YuriSizov modified the milestones: 4.0, 4.x, 4.1 Feb 6, 2023
@Geometror Geometror force-pushed the improve-editor-state-preservation branch 2 times, most recently from 5e3c6d8 to 8d9cc24 Compare February 6, 2023 15:58
@Geometror
Copy link
Member Author

Updated the PR with the following changes.

  • For the current scene, selected script and selected shader the resource path is now stored instead of the tab index. (as suggested by @Paulb23)
  • Add editor setting "editors/shader_editor/behavior/files/restore_shaders_on_load" (default: true)
  • Add editor setting "text_editor/behavior/files/select_scene_root_script_on_load" (default: false) [This might require some discussion. Do you find this behavior useful?]

@Geometror Geometror force-pushed the improve-editor-state-preservation branch from 8d9cc24 to 7bc88b4 Compare February 17, 2023 15:11
@Geometror Geometror requested a review from a team as a code owner February 17, 2023 15:11
@michaelhue
Copy link

michaelhue commented Mar 26, 2023

It would be great if the FileSystem panel could preserve expanded folders.

@Geometror Geometror force-pushed the improve-editor-state-preservation branch from 7bc88b4 to 5e33dcd Compare May 3, 2023 01:32
@Geometror Geometror requested review from a team as code owners May 3, 2023 01:32
@Geometror
Copy link
Member Author

Rebased and updated:

  • Fixed a crash
  • Improved state preservation for the FileSystemDock
    • selected paths
    • expanded folders (as suggested by @michaelhue)

@Geometror Geometror force-pushed the improve-editor-state-preservation branch from 5e33dcd to 111b54c Compare May 6, 2023 02:48
@Geometror
Copy link
Member Author

  • Fixed a bug that caused the selected nodes not to be restored when the scene's root node was a canvas item.
  • Some internal renames of unclearly named methods

@KoBeWi
Copy link
Member

KoBeWi commented May 8, 2023

There's one more bug with filesystem dock. It stores <null> in uncollapsed paths (probably from res://).

EDIT:
It's not res://, because when I collapse it the null is still there 🤔
Another thing is that if you have uncollapsed directory, which is a child of a collapsed one, it's not stored.
Also, probably not that important, but if you select a file and then collapse the parent directory, it will be uncollapsed on launch, because it navigates to the selected file.

@Geometror Geometror force-pushed the improve-editor-state-preservation branch 2 times, most recently from 064d09d to d626d00 Compare May 9, 2023 20:54
@Geometror
Copy link
Member Author

Geometror commented May 9, 2023

Okay, rewrote a few things.
@KoBeWi All problems you mentioned regarding the FileSystemDock should be gone now.
I also fixed a bug where an uncollapsed directory, which is a child of a collapsed directory, got collapsed when you saved the scene (and the Tree is rebuilt).

FileSystemDock::_compute_uncollapsed_paths() is renamed to FileSystemDock::get_uncollapsed_paths() const , made public (so it can be used in EditorNode) and uses the new BFS algorithm (which does not include non-directory paths and fixes the bug described above).

In addition, I introduced get_prev_in_tree(bool p_wrap) and get_next_in_tree(bool p_wrap) (together with some minor internal refactoring).
These were necessary because the TreeItem API lacked a method like get_next_visible for iterating over the tree via a DFS, which includes all items, not just the visible. get_next just returns a TreeItem's sibling.

(As an alternative approach, we could add two parameters (default: false) to get_next, one for changing the mode to DFS and another for wrapping)

@Geometror Geometror force-pushed the improve-editor-state-preservation branch from d626d00 to 33ea232 Compare May 10, 2023 01:58
@KoBeWi
Copy link
Member

KoBeWi commented May 10, 2023

Needs rebase 🙃

@Geometror Geometror force-pushed the improve-editor-state-preservation branch from 33ea232 to d3a7e49 Compare May 10, 2023 15:23
editor/editor_node.cpp Outdated Show resolved Hide resolved
@KoBeWi

This comment was marked as resolved.

editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
doc/classes/TreeItem.xml Outdated Show resolved Hide resolved
doc/classes/TreeItem.xml Outdated Show resolved Hide resolved
editor/filesystem_dock.h Outdated Show resolved Hide resolved
editor/filesystem_dock.h Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
@Geometror Geometror force-pushed the improve-editor-state-preservation branch from d3a7e49 to 8514ced Compare May 10, 2023 21:57
@Geometror
Copy link
Member Author

Floating docks should now be restored correctly again, somehow a small code section got automatically removed during the rebase. Addressed all other review comments too.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

There's one last documentation comment left, but other than that I think it's fine now.

@Geometror Geometror force-pushed the improve-editor-state-preservation branch from 8514ced to dc46163 Compare May 11, 2023 02:17
@akien-mga akien-mga merged commit f7070a6 into godotengine:master May 11, 2023
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remember directory folding state across restarts in the FileSystem dock
7 participants