Skip to content

Commit 208557f

Browse files
committed
Improve Class display in Create dialog
1 parent c3c918e commit 208557f

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

editor/create_dialog.cpp

Lines changed: 29 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,35 @@ 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(("[%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+
if (!p_item) {
572+
return;
573+
}
574+
String script_path = p_item->get_tooltip(0);
575+
if (!script_path.empty()) {
576+
Ref<Script> script = ResourceLoader::load(script_path, "Script");
577+
if (script.is_valid()) {
578+
EditorNode::get_singleton()->edit_resource(script);
579+
} else {
580+
print_error("Failed to load script: " + script_path);
581+
}
582+
}
583+
hide();
584+
}
585+
577586
void CreateDialog::_favorite_toggled() {
578587
TreeItem *item = search_options->get_selected();
579588
if (!item) {
@@ -743,6 +752,7 @@ void CreateDialog::_bind_methods() {
743752
ClassDB::bind_method(D_METHOD("_confirmed"), &CreateDialog::_confirmed);
744753
ClassDB::bind_method(D_METHOD("_sbox_input"), &CreateDialog::_sbox_input);
745754
ClassDB::bind_method(D_METHOD("_item_selected"), &CreateDialog::_item_selected);
755+
ClassDB::bind_method(D_METHOD("_script_selected"), &CreateDialog::_script_selected);
746756
ClassDB::bind_method(D_METHOD("_favorite_toggled"), &CreateDialog::_favorite_toggled);
747757
ClassDB::bind_method(D_METHOD("_history_selected"), &CreateDialog::_history_selected);
748758
ClassDB::bind_method(D_METHOD("_favorite_selected"), &CreateDialog::_favorite_selected);
@@ -821,6 +831,7 @@ CreateDialog::CreateDialog() {
821831
set_hide_on_ok(false);
822832
search_options->connect("item_activated", this, "_confirmed");
823833
search_options->connect("cell_selected", this, "_item_selected");
834+
search_options->connect("button_pressed", this, "_script_selected");
824835
base_type = "Object";
825836
preferred_search_result_type = "";
826837

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)