Make the "Quick Open" dialog available via `EditorInterface`
Allows to use the "Quick Open" dialog in tool scripts via the EditorInterface without exposing internal classes. Works the same as other editor popups added in https://github.com/godotengine/godot/pull/81655.
@tool
extends EditorScript
func _run():
EditorInterface.popup_quick_open(_on_selected, "Texture2D", true, false, "Select Textures")
static func _on_selected(paths: PackedStringArray):
print("Paths: %s" % paths)
- Closes: https://github.com/godotengine/godot-proposals/issues/3745
Needs rebase after #56772
It is a close-on-selection dialogue now. Support for multi-selection was removed. Will it be re-added or should I go with what it is now?
I changed the arguments to match the new implementation. Also, there was no way to tell if the dialog was canceled since the new implementation uses a callback instead of signals and it doesn't call when canceled. I made changes so it calls with an empty string when canceled.
editor/gui/editor_quick_open_dialog.cpp:94 - Condition "p_base_types.is_empty()" is true.
error when using default second argument. You can make it default to ["Resource"].
I made changes so it calls with an empty string when canceled.
Is it a problem that canceled dialog doesn't call the callback?
Will it be re-added or should I go with what it is now?
Opening multiple files with the dialog is rather rare, so it was removed to allow opening the file faster.
error when using default second argument. You can make it default to
["Resource"].
Not sure if that's possible with the binding API, I couldn't find any example. I made it a required argument with an error check.
Is it a problem that canceled dialog doesn't call the callback?
Not for the editor's current behavior. But for addons the user may want a way to know. The other popups call it when canceled as well.
You could use popup_hide signal then.
Not sure if that's possible with the binding API, I couldn't find any example.
You can make a TypedArray variable, append default and put it in DEFVAL.
You could use
popup_hidesignal then.
Windows don't have it. Used canceled since EditorQuickOpenDialog is an AcceptDialog.
You can make a TypedArray variable, append default and put it in DEFVAL.
Although it works fine CI is failing because the test suite doesn't support appended values for TypedArrays.
godot\tests/core/object/test_class_db.h(453): ERROR: CHECK_FALSE( !arg_defval_valid_data ) is NOT correct!
values: CHECK_FALSE( true )
logged: Invalid default value for parameter 'base_types' of method 'EditorInterface.popup_quick_open'. Must be zero.
Well after you made popup_quick_open() auto-append if empty, you can make the default empty again.
Looks good now. One last thing that would be nice is checking for supported types. QuickOpen dialog only supports Resource types, if you use e.g. Node or some non-existent type, the dialog will be empty with no proper feedback.
You can check valid types like this:
for (const StringName &type : p_base_types) {
ERR_FAIL_COND_MSG(!ClassDB::is_parent_class(type, "Resource"), "Only Resource-deriving types are supported in QuickOpen.");
}
It should also be documented in the method's description.
Thanks!