Skip to content

Commit

Permalink
Add Open Documentation button to signals
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-forge committed Aug 20, 2022
1 parent 0c5f254 commit 10b48ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ void ConnectionsDock::_handle_signal_menu_option(int p_option) {
disconnect_all_dialog->set_text(vformat(TTR("Are you sure you want to remove all connections from the \"%s\" signal?"), signal_name));
disconnect_all_dialog->popup_centered();
} break;
case OPEN_DOCUMENTATION: {
String doc_path = item->get_metadata(0).operator Dictionary()["doc_path"];
ScriptEditor::get_singleton()->goto_help(doc_path);
}
}
}

Expand Down Expand Up @@ -912,6 +916,7 @@ void ConnectionsDock::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
signal_menu->set_item_icon(signal_menu->get_item_index(OPEN_DOCUMENTATION), get_theme_icon(SNAME("Help"), SNAME("EditorIcons")));
} break;

case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
Expand Down Expand Up @@ -949,6 +954,9 @@ void ConnectionsDock::update_tree() {
List<MethodInfo> node_signals2;
Ref<Texture2D> icon;
String name;
// This determines whether to add quotes to the doc path
// for the "Open Documentation" context menu button.
bool name_is_script_file = false;

if (!did_script) {
// Get script signals (including signals from any base scripts).
Expand All @@ -957,6 +965,7 @@ void ConnectionsDock::update_tree() {
scr->get_script_signal_list(&node_signals2);
if (scr->get_path().is_resource_file()) {
name = scr->get_path().get_file();
name_is_script_file = true;
} else {
name = scr->get_class();
}
Expand Down Expand Up @@ -1022,11 +1031,18 @@ void ConnectionsDock::update_tree() {
// Create the children of the subsection - the actual list of signals.
TreeItem *signal_item = tree->create_item(section_item);
signal_item->set_text(0, String(signal_name) + signaldesc);
signal_item->set_icon(0, get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")));

// Add metadata to signal item.
Dictionary sinfo;
String doc_path_name = name;
if (name_is_script_file) {
doc_path_name = "\"" + name + "\"";
}
sinfo["doc_path"] = "class_signal:" + doc_path_name + ":" + signal_name;
sinfo["name"] = signal_name;
sinfo["args"] = argnames;
signal_item->set_metadata(0, sinfo);
signal_item->set_icon(0, get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")));

// Set tooltip with the signal's documentation.
{
Expand Down Expand Up @@ -1159,6 +1175,8 @@ ConnectionsDock::ConnectionsDock() {
signal_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_signal_menu_option));
signal_menu->add_item(TTR("Connect..."), CONNECT);
signal_menu->add_item(TTR("Disconnect All"), DISCONNECT_ALL);
signal_menu->add_separator();
signal_menu->add_item("Open Documentation", OPEN_DOCUMENTATION);

slot_menu = memnew(PopupMenu);
add_child(slot_menu);
Expand Down
3 changes: 2 additions & 1 deletion editor/connections_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class ConnectionsDock : public VBoxContainer {
//Right-click Pop-up Menu Options.
enum SignalMenuOption {
CONNECT,
DISCONNECT_ALL
DISCONNECT_ALL,
OPEN_DOCUMENTATION,
};

enum SlotMenuOption {
Expand Down
1 change: 0 additions & 1 deletion editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,6 @@ void EditorProperty::menu_option(int p_option) {
} break;
case MENU_OPEN_DOCUMENTATION: {
ScriptEditor::get_singleton()->goto_help(doc_path);
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
} break;
}
}
Expand Down

0 comments on commit 10b48ca

Please sign in to comment.