Skip to content

Commit 4cc8478

Browse files
committed
Merge pull request #99062 from KoBeWi/selectively_selecting_selectors
Cleanup EditorInterface selectors' code
2 parents 51d7d6b + 49dc4e0 commit 4cc8478

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

editor/editor_interface.cpp

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,10 @@ void EditorInterface::set_current_feature_profile(const String &p_profile_name)
280280
// Editor dialogs.
281281

282282
void EditorInterface::popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types, Node *p_current_value) {
283-
// TODO: Should reuse dialog instance instead of creating a fresh one, but need to rework set_valid_types first.
284-
if (node_selector) {
285-
node_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_node_selected).bind(p_callback));
286-
node_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_node_selection_canceled).bind(p_callback));
287-
get_base_control()->remove_child(node_selector);
288-
node_selector->queue_free();
283+
if (!node_selector) {
284+
node_selector = memnew(SceneTreeDialog);
285+
get_base_control()->add_child(node_selector);
289286
}
290-
node_selector = memnew(SceneTreeDialog);
291287

292288
Vector<StringName> valid_types;
293289
int length = p_valid_types.size();
@@ -296,27 +292,18 @@ void EditorInterface::popup_node_selector(const Callable &p_callback, const Type
296292
valid_types.write[i] = p_valid_types[i];
297293
}
298294
node_selector->set_valid_types(valid_types);
299-
300-
get_base_control()->add_child(node_selector);
301-
302295
node_selector->popup_scenetree_dialog(p_current_value);
303296

304-
const Callable selected_callback = callable_mp(this, &EditorInterface::_node_selected).bind(p_callback);
305-
node_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);
306-
307-
const Callable canceled_callback = callable_mp(this, &EditorInterface::_node_selection_canceled).bind(p_callback);
308-
node_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
297+
const Callable callback = callable_mp(this, &EditorInterface::_node_selected);
298+
node_selector->connect(SNAME("selected"), callback.bind(p_callback), CONNECT_DEFERRED);
299+
node_selector->connect(SNAME("canceled"), callback.bind(NodePath(), p_callback), CONNECT_DEFERRED);
309300
}
310301

311302
void EditorInterface::popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter, const String &p_current_value) {
312-
// TODO: Should reuse dialog instance instead of creating a fresh one, but need to rework set_type_filter first.
313-
if (property_selector) {
314-
property_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_property_selected).bind(p_callback));
315-
property_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_property_selection_canceled).bind(p_callback));
316-
get_base_control()->remove_child(property_selector);
317-
property_selector->queue_free();
303+
if (!property_selector) {
304+
property_selector = memnew(PropertySelector);
305+
get_base_control()->add_child(property_selector);
318306
}
319-
property_selector = memnew(PropertySelector);
320307

321308
Vector<Variant::Type> type_filter;
322309
int length = p_type_filter.size();
@@ -325,16 +312,11 @@ void EditorInterface::popup_property_selector(Object *p_object, const Callable &
325312
type_filter.write[i] = (Variant::Type)p_type_filter[i];
326313
}
327314
property_selector->set_type_filter(type_filter);
328-
329-
get_base_control()->add_child(property_selector);
330-
331315
property_selector->select_property_from_instance(p_object, p_current_value);
332316

333-
const Callable selected_callback = callable_mp(this, &EditorInterface::_property_selected).bind(p_callback);
334-
property_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);
335-
336-
const Callable canceled_callback = callable_mp(this, &EditorInterface::_property_selection_canceled).bind(p_callback);
337-
property_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
317+
const Callable callback = callable_mp(this, &EditorInterface::_property_selected);
318+
property_selector->connect(SNAME("selected"), callback.bind(p_callback), CONNECT_DEFERRED);
319+
property_selector->connect(SNAME("canceled"), callback.bind(String(), p_callback), CONNECT_DEFERRED);
338320
}
339321

340322
void EditorInterface::popup_method_selector(Object *p_object, const Callable &p_callback, const String &p_current_value) {
@@ -369,20 +351,28 @@ void EditorInterface::popup_quick_open(const Callable &p_callback, const TypedAr
369351
}
370352

371353
void EditorInterface::_node_selected(const NodePath &p_node_path, const Callable &p_callback) {
372-
const NodePath path = get_edited_scene_root()->get_path().rel_path_to(p_node_path);
373-
_call_dialog_callback(p_callback, path, "node selected");
374-
}
354+
const Callable callback = callable_mp(this, &EditorInterface::_node_selected);
355+
node_selector->disconnect(SNAME("selected"), callback);
356+
node_selector->disconnect(SNAME("canceled"), callback);
375357

376-
void EditorInterface::_node_selection_canceled(const Callable &p_callback) {
377-
_call_dialog_callback(p_callback, NodePath(), "node selection canceled");
358+
if (p_node_path.is_empty()) {
359+
_call_dialog_callback(p_callback, NodePath(), "node selection canceled");
360+
} else {
361+
const NodePath path = get_edited_scene_root()->get_path().rel_path_to(p_node_path);
362+
_call_dialog_callback(p_callback, path, "node selected");
363+
}
378364
}
379365

380366
void EditorInterface::_property_selected(const String &p_property_name, const Callable &p_callback) {
381-
_call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selected");
382-
}
367+
const Callable callback = callable_mp(this, &EditorInterface::_property_selected);
368+
property_selector->disconnect(SNAME("selected"), callback);
369+
property_selector->disconnect(SNAME("canceled"), callback);
383370

384-
void EditorInterface::_property_selection_canceled(const Callable &p_callback) {
385-
_call_dialog_callback(p_callback, NodePath(), "property selection canceled");
371+
if (p_property_name.is_empty()) {
372+
_call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selection canceled");
373+
} else {
374+
_call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selected");
375+
}
386376
}
387377

388378
void EditorInterface::_method_selected(const String &p_method_name, const Callable &p_callback) {

editor/editor_interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ class EditorInterface : public Object {
7070
SceneTreeDialog *node_selector = nullptr;
7171

7272
void _node_selected(const NodePath &p_node_paths, const Callable &p_callback);
73-
void _node_selection_canceled(const Callable &p_callback);
7473
void _property_selected(const String &p_property_name, const Callable &p_callback);
75-
void _property_selection_canceled(const Callable &p_callback);
7674
void _method_selected(const String &p_property_name, const Callable &p_callback);
7775
void _quick_open(const String &p_file_path, const Callable &p_callback);
7876
void _call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context);

0 commit comments

Comments
 (0)