Ah, my bad, I misunderstood what you wanted to do.
In that case you can find the ScriptCreateDialog that the editor uses and do it there. For example in a plugin:
@tool
extends EditorPlugin
var custom_buttons: Dictionary[ScriptCreateDialog, Button]
func _enter_tree() -> void:
var script_editor = EditorInterface.get_script_editor()
var create_dialogs = script_editor.find_children("*", "ScriptCreateDialog", false, false)
for dialog: ScriptCreateDialog in create_dialogs:
# Add a custom button
var custom_button = dialog.add_button("My button", true, "my_button")
custom_buttons.set(dialog, custom_button)
# And connect to the custom_action signal to process that button
if not dialog.custom_action.is_connected(_on_script_dialog_custom_action):
dialog.custom_action.connect(_on_script_dialog_custom_action)
func _exit_tree() -> void:
var script_editor = EditorInterface.get_script_editor()
var create_dialogs = script_editor.find_children("*", "ScriptCreateDialog", false, false)
for dialog: ScriptCreateDialog in create_dialogs:
# remove the custom button
var button = custom_buttons.get(dialog, null)
if button:
dialog.remove_button(button)
button.queue_free()
# And disconnect the custom_action signal
if dialog.custom_action.is_connected(_on_script_dialog_custom_action):
dialog.custom_action.disconnect(_on_script_dialog_custom_action)
func _on_script_dialog_custom_action(action: String):
print("Action %s pressed" % action)
I don’t think the script editor can have more than one ScriptCreateDialog but just in case.
Edit: I forgot to remove the button from the dialog before freeing it ![]()