Skip to content

Commit f5b4529

Browse files
authored
Merge pull request #105459 from illlustr/class-display
[3.x] Improve Class display in Create dialog
2 parents 2f4336b + 036a1a3 commit f5b4529

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

editor/create_dialog.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
182182
bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);
183183

184184
TreeItem *item = search_options->create_item(parent);
185+
item->set_text(0, p_type);
185186
if (cpp_type) {
186-
item->set_text(0, p_type);
187+
item->set_tooltip(0, DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description));
187188
} else {
189+
item->set_tooltip(0, ScriptServer::get_global_class_path(p_type));
190+
item->add_button(0, EditorNode::get_singleton()->get_class_icon("Script"));
188191
item->set_metadata(0, p_type);
189-
item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
190192
}
191193
if (!can_instance) {
192194
item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
@@ -244,9 +246,6 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
244246
item->set_collapsed(collapse);
245247
}
246248

247-
const String &description = DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description);
248-
item->set_tooltip(0, description);
249-
250249
String icon_fallback = has_icon(base_type, "EditorIcons") ? base_type : "Object";
251250
item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback));
252251

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

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

564+
help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 1));
565+
574566
get_ok()->set_disabled(false);
575567
}
576568

569+
void CreateDialog::_script_selected(const Variant &p_object, int p_column, int p_id) {
570+
TreeItem *p_item = Object::cast_to<TreeItem>(p_object);
571+
String script_path = p_item->get_tooltip(0);
572+
if (!script_path.empty()) {
573+
Ref<Script> script = ResourceLoader::load(script_path, "Script");
574+
if (script.is_valid()) {
575+
EditorNode::get_singleton()->edit_resource(script);
576+
} else {
577+
print_error("Failed to load script: " + script_path);
578+
}
579+
hide();
580+
}
581+
}
582+
577583
void CreateDialog::_favorite_toggled() {
578584
TreeItem *item = search_options->get_selected();
579585
if (!item) {
@@ -743,6 +749,7 @@ void CreateDialog::_bind_methods() {
743749
ClassDB::bind_method(D_METHOD("_confirmed"), &CreateDialog::_confirmed);
744750
ClassDB::bind_method(D_METHOD("_sbox_input"), &CreateDialog::_sbox_input);
745751
ClassDB::bind_method(D_METHOD("_item_selected"), &CreateDialog::_item_selected);
752+
ClassDB::bind_method(D_METHOD("_script_selected"), &CreateDialog::_script_selected);
746753
ClassDB::bind_method(D_METHOD("_favorite_toggled"), &CreateDialog::_favorite_toggled);
747754
ClassDB::bind_method(D_METHOD("_history_selected"), &CreateDialog::_history_selected);
748755
ClassDB::bind_method(D_METHOD("_favorite_selected"), &CreateDialog::_favorite_selected);
@@ -821,6 +828,7 @@ CreateDialog::CreateDialog() {
821828
set_hide_on_ok(false);
822829
search_options->connect("item_activated", this, "_confirmed");
823830
search_options->connect("cell_selected", this, "_item_selected");
831+
search_options->connect("button_pressed", this, "_script_selected");
824832
base_type = "Object";
825833
preferred_search_result_type = "";
826834

editor/create_dialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CreateDialog : public ConfirmationDialog {
5959
Set<StringName> type_blacklist;
6060

6161
void _item_selected();
62+
void _script_selected(const Variant &p_object, int p_column, int p_id);
6263

6364
void _update_search();
6465
void _update_favorite_list();

0 commit comments

Comments
 (0)