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

Edit a script in the editor not emit signal "changed" #47615

Open
MikeSchulze opened this issue Apr 4, 2021 · 4 comments
Open

Edit a script in the editor not emit signal "changed" #47615

MikeSchulze opened this issue Apr 4, 2021 · 4 comments

Comments

@MikeSchulze
Copy link

MikeSchulze commented Apr 4, 2021

Godot version:
Godot Engine v3.2.4.beta4.official

OS/device including version:
Windows 10/ MacOS

Issue description:
I want to detect a script is changed via editor to handle a custom save action to save only changed scripts.
I working on a unit test api and it needs to save all changed resources before run.

For now i use a workaround to save all opend files over the menu action.

	var script_editor :ScriptEditor = _editor_interface.get_script_editor()
	script_editor._menu_option(EDITOR_ACTIONS.FILE_SAVE_ALL)

And I want to print out which file is saved, i do this for now by:

	var script_editor :ScriptEditor = _editor_interface.get_script_editor()
	for open_script in script_editor.get_open_scripts():
		prints("Save %s" % open_script.resource_path)

But it contains all opened files.
So i try to register for "changed" signal to collect a set of changed files form the editor.

func register_for_script_changes():
	var script_editor :ScriptEditor = get_editor_interface().get_script_editor()
	script_editor.connect("editor_script_changed", self, "_editor_script_changed")

func _editor_script_changed(script :Script):
	prints("editor script changed to: %s" % script.resource_path)
	
	if not script.is_connected("changed", self, "_changed"):
		script.connect("changed", self, "_changed", [script])
		script.connect("script_changed", self, "_script_changed", [script])		

func _changed(script) :
	prints("_changed", script)

func _script_changed(script) :
	prints("_script_changed", script)

But no signal changed or script_changed is emited

Steps to reproduce:

  • open the attached example project
  • open the example files to have one or more opend in the editor
  • edit a file
    No "changed" signal is emited

Minimal reproduction project:
plugin-edit-script.zip

@codecustard
Copy link
Contributor

According to the documentation: https://docs.godotengine.org/en/stable/classes/class_scripteditor.html#signals
The signal is triggered when the active script is changed to a different script. So when scriptB is active in the editor and you click on scriptA, it will trigger.

One thing you might be able to do is get the source code of the script and do a comparison to determine if it was modified or not. https://docs.godotengine.org/en/stable/classes/class_script.html#class-script-method-get-script-property-list

@MikeSchulze
Copy link
Author

MikeSchulze commented Apr 10, 2021

@codecustard i now this this is the reason why i use editor_script_changed to detect scripts opened in the editor.
I speak not about "editor_script_changed" i speak about changed and script_changed signals.

To detect source changes i need a history of the script but this is also not available.

best regards ;)

@codecustard
Copy link
Contributor

@MikeSchulze, Is there any documentation on the 'script_changed' and 'changed' signals? The only documentation I could find was the 'script_changed' signal for objects which would trigger whenever the object's script is changed, so if it has script1 attached and you attach script2, it would trigger. https://docs.godotengine.org/en/stable/classes/class_object.html#class-object

Although I could be wrong, if you have anything to point out that says otherwise.... So in that case I would think that it is functioning as intended. If that's the case you would have to create your own signal that checks the script source code for changes and trigger your custom signal that way.

This could also be an added feature (if I'm wrong that it doesn't exist) as it would definitely be beneficial, but it's uncommon to be changing scripts that I'm not sure it would be a good idea to have a signal that constantly polls the source code.

@tx350z
Copy link

tx350z commented Nov 23, 2021

Would love to have ScriptEditor emit a signal on file save with a parameter that identifies the saved file. I think that would address most of the requests I've seen where people are creating plug-ins that need to keep tract of script/file changes. Should not be a breaking change.

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

No branches or pull requests

4 participants