Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);

TreeItem *item = search_options->create_item(parent);
item->set_text(0, p_type);
if (cpp_type) {
item->set_text(0, p_type);
item->set_tooltip(0, DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description));
} else {
item->set_tooltip(0, ScriptServer::get_global_class_path(p_type));
item->add_button(0, EditorNode::get_singleton()->get_class_icon("Script"));
item->set_metadata(0, p_type);
item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
}
if (!can_instance) {
item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
Expand Down Expand Up @@ -244,9 +246,6 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
item->set_collapsed(collapse);
}

const String &description = DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description);
item->set_tooltip(0, description);

String icon_fallback = has_icon(base_type, "EditorIcons") ? base_type : "Object";
item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback));

Expand Down Expand Up @@ -555,25 +554,32 @@ void CreateDialog::_item_selected() {
favorite->set_disabled(false);
favorite->set_pressed(favorite_list.find(name) != -1);

if (!EditorHelp::get_doc_data()->class_list.has(name)) {
return;
}

const String brief_desc = DTR(EditorHelp::get_doc_data()->class_list[name].brief_description);
if (!brief_desc.empty()) {
// Display both class name and description, since the help bit may be displayed
// far away from the location (especially if the dialog was resized to be taller).
help_bit->set_text(vformat("[b]%s[/b]: %s", name, brief_desc));
help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 1));
const String brief_desc = item->get_tooltip(0);
if (EditorHelp::get_doc_data()->class_list.has(name)) {
help_bit->set_text(vformat("[%s] %s", name, brief_desc));
} else {
// Use nested `vformat()` as translators shouldn't interfere with BBCode tags.
help_bit->set_text(vformat(TTR("No description available for %s."), vformat("[b]%s[/b]", name)));
help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 0.5));
help_bit->set_text(vformat("[url=%s]%s[/url]", brief_desc, name));
}

help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 1));

get_ok()->set_disabled(false);
}

void CreateDialog::_script_selected(const Variant &p_object, int p_column, int p_id) {
TreeItem *p_item = Object::cast_to<TreeItem>(p_object);
String script_path = p_item->get_tooltip(0);
if (!script_path.empty()) {
Ref<Script> script = ResourceLoader::load(script_path, "Script");
if (script.is_valid()) {
EditorNode::get_singleton()->edit_resource(script);
} else {
print_error("Failed to load script: " + script_path);
}
hide();
}
}

void CreateDialog::_favorite_toggled() {
TreeItem *item = search_options->get_selected();
if (!item) {
Expand Down Expand Up @@ -743,6 +749,7 @@ void CreateDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_confirmed"), &CreateDialog::_confirmed);
ClassDB::bind_method(D_METHOD("_sbox_input"), &CreateDialog::_sbox_input);
ClassDB::bind_method(D_METHOD("_item_selected"), &CreateDialog::_item_selected);
ClassDB::bind_method(D_METHOD("_script_selected"), &CreateDialog::_script_selected);
ClassDB::bind_method(D_METHOD("_favorite_toggled"), &CreateDialog::_favorite_toggled);
ClassDB::bind_method(D_METHOD("_history_selected"), &CreateDialog::_history_selected);
ClassDB::bind_method(D_METHOD("_favorite_selected"), &CreateDialog::_favorite_selected);
Expand Down Expand Up @@ -821,6 +828,7 @@ CreateDialog::CreateDialog() {
set_hide_on_ok(false);
search_options->connect("item_activated", this, "_confirmed");
search_options->connect("cell_selected", this, "_item_selected");
search_options->connect("button_pressed", this, "_script_selected");
base_type = "Object";
preferred_search_result_type = "";

Expand Down
1 change: 1 addition & 0 deletions editor/create_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CreateDialog : public ConfirmationDialog {
Set<StringName> type_blacklist;

void _item_selected();
void _script_selected(const Variant &p_object, int p_column, int p_id);

void _update_search();
void _update_favorite_list();
Expand Down