Skip to content

Commit

Permalink
simplified the code and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazy-Rabbit-2001 committed Dec 12, 2024
1 parent 5c72cc1 commit 12e948b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
<description>
Pops up an editor dialog for creating an object.
The [param callback] must take a single argument of type [StringName] which will contain the type name of the selected object or be empty if no item is selected.
The [param base_type] specifies the base type of objects to display. If you set this to "Resource", all items shown in the create dialog are derived from [Resource].
The [param base_type] specifies the base type of objects to display. For example, if you set this to "Resource", all types derived from [Resource] will display in the create dialog.
The [param current_type] will be passed in the search box of the create dialog, and the specified type can be immediately selected when the dialog pops up. If the [param current_type] is not derived from [param base_type], there will be no result of the type in the dialog.
The [param dialog_title] allows you to define a custom title for the dialog. This is useful if you want to accurately hint the usage of the dialog. If the [param dialog_title] is an empty string, the dialog will use "Create New 'Base Type'" as the default title.
The [param type_blocklist] contains a list of type names, and the types in the blocklist will be hidden from the create dialog.
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,11 @@ void EditorInterface::popup_create_dialog(const Callable &p_callback, const Stri
}
create_dialog->set_type_suffixes(suffix_map);

const bool is_type_valid = ClassDB::class_exists(p_base_type) || ScriptServer::is_global_class(p_base_type);
if (!is_type_valid) {
String safe_base_type = p_base_type;
if (p_base_type.is_empty() || (!ClassDB::class_exists(p_base_type) && !ScriptServer::is_global_class(p_base_type))) {
ERR_PRINT(vformat("Invalid base type '%s'. The base type has fallen back to 'Object'.", p_base_type));
safe_base_type = "Object";
}
const String safe_base_type = !p_base_type.is_empty() && is_type_valid ? p_base_type : "Object";

create_dialog->set_base_type(safe_base_type);
create_dialog->popup_create(false, true, p_current_type, "");
Expand Down

0 comments on commit 12e948b

Please sign in to comment.