Populate custom dropdown export in tool script

Godot Version

v4.4.stable.arch_linux

Question

So following my problem from last year:

I had a similar idea again, but now have a bit more of an idea how to go about it.
I instantiate the foreign scene and go through its children and populate a dropdown with the potential paths to choose from.

This is what I got so far:

@tool
class_name MapConnectionMarker
extends Marker2D


@export_file("*.tscn") var map_path: String: set = set_map_path
@export_custom(PROPERTY_HINT_ENUM, "") var connection: String
@export_tool_button("Regenerate List", "Marker2D") var regenerate_list_action = regenerate_list


func set_map_path(value: String) -> void:
	map_path = value
	regenerate_list()


func regenerate_list() -> void:
	if not map_path:
		return # TODO: clear list
	
	var map: Map = load(map_path).instantiate()
	for child in map.find_children("*", "MapConnectionMarker"):
		child.get_path()
		# TODO: where to add the paths to so they appear in the dropdown?

It at least looks like what I had in mind,

but I can’t figure out where to add the node paths to, so they appear in the dropdown.

Okay finally managed to do it.

I had to use _get_property_list to effectively populate a custom enum export per code.

This is my working solution:

@tool
class_name MapConnectionMarker
extends Marker2D


@export_file("*.tscn") var map_path: String
var connection: String


func _get_property_list() -> Array[Dictionary]:
	var list: Array[Dictionary] = []
	
	if map_path:
		var map: Map = load(map_path).instantiate()
		
		var paths := []
		for child in map.find_children("*", "MapConnectionMarker"):
			paths.append(map.get_path_to(child))
		
		list.append({
			"name": "connection",
			"type": TYPE_STRING,
			"hint": PROPERTY_HINT_ENUM,
			"hint_string": ",".join(paths)
		})
	
	return list