godot icon indicating copy to clipboard operation
godot copied to clipboard

Make the "Quick Open" dialog available via `EditorInterface`

Open ydeltastar opened this issue 1 year ago • 10 comments

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

ydeltastar avatar Sep 30 '24 05:09 ydeltastar

Needs rebase after #56772

KoBeWi avatar Oct 03 '24 13:10 KoBeWi

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?

ydeltastar avatar Oct 03 '24 16:10 ydeltastar

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.

ydeltastar avatar Oct 03 '24 18:10 ydeltastar

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.

KoBeWi avatar Oct 03 '24 20:10 KoBeWi

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.

ydeltastar avatar Oct 03 '24 21:10 ydeltastar

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.

KoBeWi avatar Oct 03 '24 21:10 KoBeWi

You could use popup_hide signal then.

Windows don't have it. Used canceled since EditorQuickOpenDialog is an AcceptDialog.

ydeltastar avatar Oct 03 '24 22:10 ydeltastar

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.

ydeltastar avatar Oct 03 '24 23:10 ydeltastar

Well after you made popup_quick_open() auto-append if empty, you can make the default empty again.

KoBeWi avatar Oct 04 '24 02:10 KoBeWi

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.

KoBeWi avatar Oct 04 '24 12:10 KoBeWi

Thanks!

akien-mga avatar Oct 04 '24 15:10 akien-mga