Add option to sort script list by recency
Closes https://github.com/godotengine/godot-proposals/issues/8125
Added "Last Viewed" option to text_editor/script_list/sort_scripts_by. I put it after "None", which looks strange, so that it's backwards compatible.
Also added an EditorSetting called last_viewed_script_threshold. A selected script won't be moved to the top if it's already within the first N scripts on the list.
I had to change script_close_queue to reference the Control nodes directly instead of the index, because scripts are selected during the closing process, which shuffled them around and invalidated the previous indices in some cases.
This also changes help classes to not add themselves to the history when loading a project, by adding the p_grab_focus parameter to _help_class_open. This was necessary to make them not end up at the top with the recency option. The parameter defaults to false to make the request_help signal still work. To be clear, the behaviour used to be that when you loaded a project, the script history would be entirely populated by all the opened doc classes, in order. So I reckon it wasn't intended anyway :p
I also avoid sorting the script list in _update_script_names if not on an effective sorting type. So, I set lock_history to false after the loop because otherwise it'd stay true after being set in _update_history_pos. I'm not sure how _update_history_pos works or why it sets it to true, so I figured this was the safest place to set it to false.
Alright, I got around to fixing the couple issues this had, so I took it out of draft status and updated the description.
Wouldn't the term "Last Opened" be more relevant here than "Recency", especially since we use a similar name in the project manager order setting?
Wouldn't the term "Last Opened" be more relevant here than "Recency", especially since we use a similar name in the project manager order setting?
I wouldn't say this sorts by "last opened", because clicking an already-opened script also moves it to the top. I guess clicking a script is "opening the tab", but IMO it'd be confusing. Maybe "Last Accessed" or "Last Viewed" would be better?
..what I'd really love a better name for is script_recency_ignore_threshold :,)
I decided to rename "Recency" to "Last Viewed" and "script_recency_ignore_threshold" to "last_viewed_script_threshold".
thank you, this is better than godot 5
There's some additional interest for this. The PR could use a rebase. I'd also rename the option to "Last Opened".
Done, also added documentation thanks to https://github.com/godotengine/godot/pull/93427