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

Expose ScriptEditor.reload_scripts() #8111

Open
KANAjetzt opened this issue Oct 14, 2023 · 0 comments · May be fixed by godotengine/godot#83267
Open

Expose ScriptEditor.reload_scripts() #8111

KANAjetzt opened this issue Oct 14, 2023 · 0 comments · May be fixed by godotengine/godot#83267

Comments

@KANAjetzt
Copy link

KANAjetzt commented Oct 14, 2023

Describe the project you are working on

I'm working on a plugin that assists with mod development. Part of that involves generating code that is added to a specific script file.

Describe the problem or limitation you are having in your project

After porting from 3.5 to 4.1.2, I am missing the ScriptEditor.reload_scripts() method, which we used to reload the script editor after adding code.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Expose the ScriptEditor.reload_scripts() method again, to match the state of 3.5

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

EditorInterface.get_script_editor().reload_scripts()

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can be worked around (sort of):
Edit: I partially take that back. It's dangerous to do it this way. The content of the script editor is replaced, and if, for whatever reason, the wrong script is open in the editor, the wrong content is displayed.

static func reload_script(text_edit: TextEdit, source_code: String) -> void:
	var column := text_edit.get_caret_column()
	var row := text_edit.get_caret_line()
	var scroll_position_h := text_edit.get_h_scroll_bar().value
	var scroll_position_v := text_edit.get_v_scroll_bar().value

	text_edit.text = source_code
	text_edit.set_caret_column(column)
	text_edit.set_caret_line(row)
	text_edit.scroll_horizontal = scroll_position_h
	text_edit.scroll_vertical = scroll_position_v

	text_edit.tag_saved_version()

And setting the text_editor/behavior/files/auto_reload_scripts_on_external_change setting to true, to prevent the "newer on disk" popup from appearing.

I imagine code generation plugins are not a total exotic thing. A bit of research reveals that:

  • Searching for "Godot plugin reload scripts" leads people to this Q&A post (Godot version 3.4.4) pointing to _reload_scripts.
  • There is one other plugin on GitHub currently using .reload_scripts().

I think using the above script as a workaround is fine, but because it is not a full replacement, I would love to see the reload_scripts() method being exposed again or something to hide the "newer on disk" popup. This is because the mentioned setting will hide the popup for all external code changes, and the user will have to set the setting.

Is there a reason why this should be core and not an add-on in the asset library?

There seems to be no way to hide the "newer on disk" popup via script, so it cannot be achieved through an add-on.

KANAjetzt added a commit to KANAjetzt/godot that referenced this issue Sep 8, 2024
Expose the reload_scripts method to match the current state of the 3.x branch.
Bind it as `reload_open_files` in contrast to `reload_scripts` in 3.x to more accurately reflect its function.

closes godotengine/godot-proposals#8111

clarifies the description of the method's internals

Co-authored-by: Chris Cranford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants