|
32 | 32 | #include "editor_interface.compat.inc"
|
33 | 33 |
|
34 | 34 | #include "core/config/project_settings.h"
|
| 35 | +#include "editor/create_dialog.h" |
35 | 36 | #include "editor/editor_command_palette.h"
|
36 | 37 | #include "editor/editor_feature_profile.h"
|
37 | 38 | #include "editor/editor_main_screen.h"
|
@@ -512,6 +513,45 @@ void EditorInterface::popup_quick_open(const Callable &p_callback, const TypedAr
|
512 | 513 | quick_open->popup_dialog(base_types, callable_mp(this, &EditorInterface::_quick_open).bind(p_callback));
|
513 | 514 | }
|
514 | 515 |
|
| 516 | +void EditorInterface::popup_create_dialog(const Callable &p_callback, const StringName &p_base_type, const String &p_current_type, const String &p_dialog_title, const TypedArray<StringName> &p_custom_type_blocklist, const Dictionary &p_custom_suffix) { |
| 517 | + if (!create_dialog) { |
| 518 | + create_dialog = memnew(CreateDialog); |
| 519 | + get_base_control()->add_child(create_dialog); |
| 520 | + } |
| 521 | + |
| 522 | + HashSet<StringName> blocklist; |
| 523 | + for (const Variant &E : p_custom_type_blocklist) { |
| 524 | + blocklist.insert(E); |
| 525 | + } |
| 526 | + create_dialog->set_type_blocklist(blocklist); |
| 527 | + |
| 528 | + HashMap<StringName, String> suffix_map; |
| 529 | + List<Variant> keys; |
| 530 | + p_custom_suffix.get_key_list(&keys); |
| 531 | + for (Variant &k : keys) { |
| 532 | + const StringName key = k; |
| 533 | + if (key.is_empty()) { |
| 534 | + continue; |
| 535 | + } |
| 536 | + suffix_map.insert(key, p_custom_suffix[key]); |
| 537 | + } |
| 538 | + create_dialog->set_type_suffixes(suffix_map); |
| 539 | + |
| 540 | + String safe_base_type = p_base_type; |
| 541 | + if (p_base_type.is_empty() || (!ClassDB::class_exists(p_base_type) && !ScriptServer::is_global_class(p_base_type))) { |
| 542 | + ERR_PRINT(vformat("Invalid base type '%s'. The base type has fallen back to 'Object'.", p_base_type)); |
| 543 | + safe_base_type = "Object"; |
| 544 | + } |
| 545 | + |
| 546 | + create_dialog->set_base_type(safe_base_type); |
| 547 | + create_dialog->popup_create(false, true, p_current_type, ""); |
| 548 | + create_dialog->set_title(p_dialog_title.is_empty() ? vformat(TTR("Create New %s"), p_base_type) : p_dialog_title); |
| 549 | + |
| 550 | + const Callable callback = callable_mp(this, &EditorInterface::_create_dialog_item_selected); |
| 551 | + create_dialog->connect(SNAME("create"), callback.bind(false, p_callback), CONNECT_DEFERRED); |
| 552 | + create_dialog->connect(SNAME("canceled"), callback.bind(true, p_callback), CONNECT_DEFERRED); |
| 553 | +} |
| 554 | + |
515 | 555 | void EditorInterface::_node_selected(const NodePath &p_node_path, const Callable &p_callback) {
|
516 | 556 | const Callable callback = callable_mp(this, &EditorInterface::_node_selected);
|
517 | 557 | node_selector->disconnect(SNAME("selected"), callback);
|
@@ -555,6 +595,13 @@ void EditorInterface::_quick_open(const String &p_file_path, const Callable &p_c
|
555 | 595 | _call_dialog_callback(p_callback, p_file_path, "quick open");
|
556 | 596 | }
|
557 | 597 |
|
| 598 | +void EditorInterface::_create_dialog_item_selected(bool p_is_canceled, const Callable &p_callback) { |
| 599 | + const Callable callback = callable_mp(this, &EditorInterface::_create_dialog_item_selected); |
| 600 | + create_dialog->disconnect(SNAME("create"), callback); |
| 601 | + create_dialog->disconnect(SNAME("canceled"), callback); |
| 602 | + _call_dialog_callback(p_callback, p_is_canceled ? "" : create_dialog->get_selected_type(), "create dialog"); |
| 603 | +} |
| 604 | + |
558 | 605 | void EditorInterface::_call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context) {
|
559 | 606 | Callable::CallError ce;
|
560 | 607 | Variant ret;
|
@@ -773,6 +820,7 @@ void EditorInterface::_bind_methods() {
|
773 | 820 | ClassDB::bind_method(D_METHOD("popup_property_selector", "object", "callback", "type_filter", "current_value"), &EditorInterface::popup_property_selector, DEFVAL(PackedInt32Array()), DEFVAL(String()));
|
774 | 821 | ClassDB::bind_method(D_METHOD("popup_method_selector", "object", "callback", "current_value"), &EditorInterface::popup_method_selector, DEFVAL(String()));
|
775 | 822 | ClassDB::bind_method(D_METHOD("popup_quick_open", "callback", "base_types"), &EditorInterface::popup_quick_open, DEFVAL(TypedArray<StringName>()));
|
| 823 | + ClassDB::bind_method(D_METHOD("popup_create_dialog", "callback", "base_type", "current_type", "dialog_title", "type_blocklist", "type_suffixes"), &EditorInterface::popup_create_dialog, DEFVAL(""), DEFVAL(""), DEFVAL(""), DEFVAL(TypedArray<StringName>()), DEFVAL(Dictionary())); |
776 | 824 |
|
777 | 825 | // Editor docks.
|
778 | 826 |
|
|
0 commit comments