connections_dialog.cpp 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. /**************************************************************************/
  2. /* connections_dialog.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "connections_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/templates/hash_set.h"
  33. #include "editor/editor_help.h"
  34. #include "editor/editor_inspector.h"
  35. #include "editor/editor_main_screen.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_settings.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/editor_undo_redo_manager.h"
  40. #include "editor/gui/scene_tree_editor.h"
  41. #include "editor/node_dock.h"
  42. #include "editor/plugins/script_editor_plugin.h"
  43. #include "editor/scene_tree_dock.h"
  44. #include "editor/themes/editor_scale.h"
  45. #include "scene/gui/button.h"
  46. #include "scene/gui/check_box.h"
  47. #include "scene/gui/label.h"
  48. #include "scene/gui/line_edit.h"
  49. #include "scene/gui/margin_container.h"
  50. #include "scene/gui/option_button.h"
  51. #include "scene/gui/popup_menu.h"
  52. #include "scene/gui/spin_box.h"
  53. static Node *_find_first_script(Node *p_root, Node *p_node) {
  54. if (p_node != p_root && p_node->get_owner() != p_root) {
  55. return nullptr;
  56. }
  57. if (!p_node->get_script().is_null()) {
  58. return p_node;
  59. }
  60. for (int i = 0; i < p_node->get_child_count(); i++) {
  61. Node *ret = _find_first_script(p_root, p_node->get_child(i));
  62. if (ret) {
  63. return ret;
  64. }
  65. }
  66. return nullptr;
  67. }
  68. class ConnectDialogBinds : public Object {
  69. GDCLASS(ConnectDialogBinds, Object);
  70. public:
  71. Vector<Variant> params;
  72. bool _set(const StringName &p_name, const Variant &p_value) {
  73. String name = p_name;
  74. if (name.begins_with("bind/argument_")) {
  75. int which = name.get_slice("_", 1).to_int() - 1;
  76. ERR_FAIL_INDEX_V(which, params.size(), false);
  77. params.write[which] = p_value;
  78. } else {
  79. return false;
  80. }
  81. return true;
  82. }
  83. bool _get(const StringName &p_name, Variant &r_ret) const {
  84. String name = p_name;
  85. if (name.begins_with("bind/argument_")) {
  86. int which = name.get_slice("_", 1).to_int() - 1;
  87. ERR_FAIL_INDEX_V(which, params.size(), false);
  88. r_ret = params[which];
  89. } else {
  90. return false;
  91. }
  92. return true;
  93. }
  94. void _get_property_list(List<PropertyInfo> *p_list) const {
  95. for (int i = 0; i < params.size(); i++) {
  96. p_list->push_back(PropertyInfo(params[i].get_type(), "bind/argument_" + itos(i + 1)));
  97. }
  98. }
  99. void notify_changed() {
  100. notify_property_list_changed();
  101. }
  102. ConnectDialogBinds() {
  103. }
  104. };
  105. /*
  106. * Signal automatically called by parent dialog.
  107. */
  108. void ConnectDialog::ok_pressed() {
  109. String method_name = dst_method->get_text();
  110. if (method_name.is_empty()) {
  111. error->set_text(TTR("Method in target node must be specified."));
  112. error->popup_centered();
  113. return;
  114. }
  115. if (!TS->is_valid_identifier(method_name.strip_edges())) {
  116. error->set_text(TTR("Method name must be a valid identifier."));
  117. error->popup_centered();
  118. return;
  119. }
  120. Node *target = tree->get_selected();
  121. if (!target) {
  122. return; // Nothing selected in the tree, not an error.
  123. }
  124. if (target->get_script().is_null()) {
  125. if (!target->has_method(method_name)) {
  126. error->set_text(TTR("Target method not found. Specify a valid method or attach a script to the target node."));
  127. error->popup_centered();
  128. return;
  129. }
  130. }
  131. emit_signal(SNAME("connected"));
  132. hide();
  133. }
  134. void ConnectDialog::_cancel_pressed() {
  135. hide();
  136. }
  137. void ConnectDialog::_item_activated() {
  138. _ok_pressed(); // From AcceptDialog.
  139. }
  140. /*
  141. * Called each time a target node is selected within the target node tree.
  142. */
  143. void ConnectDialog::_tree_node_selected() {
  144. Node *current = tree->get_selected();
  145. if (!current) {
  146. return;
  147. }
  148. dst_path = source->get_path_to(current);
  149. if (!edit_mode) {
  150. set_dst_method(generate_method_callback_name(source, signal, current));
  151. }
  152. _update_method_tree();
  153. _update_warning_label();
  154. _update_ok_enabled();
  155. }
  156. void ConnectDialog::_focus_currently_connected() {
  157. tree->set_selected(source);
  158. }
  159. void ConnectDialog::_unbind_count_changed(double p_count) {
  160. for (Control *control : bind_controls) {
  161. BaseButton *b = Object::cast_to<BaseButton>(control);
  162. if (b) {
  163. b->set_disabled(p_count > 0);
  164. }
  165. EditorInspector *e = Object::cast_to<EditorInspector>(control);
  166. if (e) {
  167. e->set_read_only(p_count > 0);
  168. }
  169. }
  170. }
  171. void ConnectDialog::_method_selected() {
  172. TreeItem *selected_item = method_tree->get_selected();
  173. dst_method->set_text(selected_item->get_metadata(0));
  174. }
  175. /*
  176. * Adds a new parameter bind to connection.
  177. */
  178. void ConnectDialog::_add_bind() {
  179. Variant::Type type = (Variant::Type)type_list->get_item_id(type_list->get_selected());
  180. Variant value;
  181. Callable::CallError err;
  182. Variant::construct(type, value, nullptr, 0, err);
  183. cdbinds->params.push_back(value);
  184. cdbinds->notify_changed();
  185. }
  186. /*
  187. * Remove parameter bind from connection.
  188. */
  189. void ConnectDialog::_remove_bind() {
  190. String st = bind_editor->get_selected_path();
  191. if (st.is_empty()) {
  192. return;
  193. }
  194. int idx = st.get_slice("/", 1).to_int() - 1;
  195. ERR_FAIL_INDEX(idx, cdbinds->params.size());
  196. cdbinds->params.remove_at(idx);
  197. cdbinds->notify_changed();
  198. }
  199. /*
  200. * Automatically generates a name for the callback method.
  201. */
  202. StringName ConnectDialog::generate_method_callback_name(Node *p_source, const String &p_signal_name, Node *p_target) {
  203. String node_name = p_source->get_name();
  204. for (int i = 0; i < node_name.length(); i++) { // TODO: Regex filter may be cleaner.
  205. char32_t c = node_name[i];
  206. if ((i == 0 && !is_unicode_identifier_start(c)) || (i > 0 && !is_unicode_identifier_continue(c))) {
  207. if (c == ' ') {
  208. // Replace spaces with underlines.
  209. c = '_';
  210. } else {
  211. // Remove any other characters.
  212. node_name.remove_at(i);
  213. i--;
  214. continue;
  215. }
  216. }
  217. node_name[i] = c;
  218. }
  219. Dictionary subst;
  220. subst["NodeName"] = node_name.to_pascal_case();
  221. subst["nodeName"] = node_name.to_camel_case();
  222. subst["node_name"] = node_name.to_snake_case();
  223. subst["SignalName"] = p_signal_name.to_pascal_case();
  224. subst["signalName"] = p_signal_name.to_camel_case();
  225. subst["signal_name"] = p_signal_name.to_snake_case();
  226. String dst_method;
  227. if (p_source == p_target) {
  228. dst_method = String(GLOBAL_GET("editor/naming/default_signal_callback_to_self_name")).format(subst);
  229. } else {
  230. dst_method = String(GLOBAL_GET("editor/naming/default_signal_callback_name")).format(subst);
  231. }
  232. return dst_method;
  233. }
  234. void ConnectDialog::_create_method_tree_items(const List<MethodInfo> &p_methods, TreeItem *p_parent_item) {
  235. for (const MethodInfo &mi : p_methods) {
  236. TreeItem *method_item = method_tree->create_item(p_parent_item);
  237. method_item->set_text(0, get_signature(mi));
  238. method_item->set_metadata(0, mi.name);
  239. }
  240. }
  241. List<MethodInfo> ConnectDialog::_filter_method_list(const List<MethodInfo> &p_methods, const MethodInfo &p_signal, const String &p_search_string) const {
  242. bool check_signal = compatible_methods_only->is_pressed();
  243. List<MethodInfo> ret;
  244. List<Pair<Variant::Type, StringName>> effective_args;
  245. int unbind = get_unbinds();
  246. for (int i = 0; i < p_signal.arguments.size() - unbind; i++) {
  247. PropertyInfo pi = p_signal.arguments.get(i);
  248. effective_args.push_back(Pair(pi.type, pi.class_name));
  249. }
  250. if (unbind == 0) {
  251. for (const Variant &variant : get_binds()) {
  252. effective_args.push_back(Pair(variant.get_type(), StringName()));
  253. }
  254. }
  255. for (const MethodInfo &mi : p_methods) {
  256. if (mi.name.begins_with("@")) {
  257. // GH-92782. GDScript inline setters/getters are historically present in `get_method_list()`
  258. // and can be called using `Object.call()`. However, these functions are meant to be internal
  259. // and their names are not valid identifiers, so let's hide them from the user.
  260. continue;
  261. }
  262. if (!p_search_string.is_empty() && !mi.name.containsn(p_search_string)) {
  263. continue;
  264. }
  265. if (check_signal) {
  266. if (mi.arguments.size() != effective_args.size()) {
  267. continue;
  268. }
  269. bool type_mismatch = false;
  270. const List<Pair<Variant::Type, StringName>>::Element *E = effective_args.front();
  271. for (const List<PropertyInfo>::Element *F = mi.arguments.front(); F; F = F->next(), E = E->next()) {
  272. Variant::Type stype = E->get().first;
  273. Variant::Type mtype = F->get().type;
  274. if (stype != Variant::NIL && mtype != Variant::NIL && stype != mtype) {
  275. type_mismatch = true;
  276. break;
  277. }
  278. if (stype == Variant::OBJECT && mtype == Variant::OBJECT && !ClassDB::is_parent_class(E->get().second, F->get().class_name)) {
  279. type_mismatch = true;
  280. break;
  281. }
  282. }
  283. if (type_mismatch) {
  284. continue;
  285. }
  286. }
  287. ret.push_back(mi);
  288. }
  289. return ret;
  290. }
  291. void ConnectDialog::_update_method_tree() {
  292. method_tree->clear();
  293. Color disabled_color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)) * 0.7;
  294. String search_string = method_search->get_text();
  295. Node *target = tree->get_selected();
  296. if (!target) {
  297. return;
  298. }
  299. MethodInfo signal_info;
  300. if (compatible_methods_only->is_pressed()) {
  301. List<MethodInfo> signals;
  302. source->get_signal_list(&signals);
  303. for (const MethodInfo &mi : signals) {
  304. if (mi.name == signal) {
  305. signal_info = mi;
  306. break;
  307. }
  308. }
  309. }
  310. TreeItem *root_item = method_tree->create_item();
  311. root_item->set_text(0, TTR("Methods"));
  312. root_item->set_selectable(0, false);
  313. // If a script is attached, get methods from it.
  314. ScriptInstance *si = target->get_script_instance();
  315. if (si) {
  316. if (si->get_script()->is_built_in()) {
  317. si->get_script()->reload();
  318. }
  319. List<MethodInfo> methods;
  320. si->get_method_list(&methods);
  321. methods = _filter_method_list(methods, signal_info, search_string);
  322. if (!methods.is_empty()) {
  323. TreeItem *si_item = method_tree->create_item(root_item);
  324. si_item->set_text(0, TTR("Attached Script"));
  325. si_item->set_icon(0, get_editor_theme_icon(SNAME("Script")));
  326. si_item->set_selectable(0, false);
  327. _create_method_tree_items(methods, si_item);
  328. }
  329. }
  330. if (script_methods_only->is_pressed()) {
  331. empty_tree_label->set_visible(root_item->get_first_child() == nullptr);
  332. return;
  333. }
  334. // Get methods from each class in the hierarchy.
  335. StringName current_class = target->get_class_name();
  336. do {
  337. TreeItem *class_item = method_tree->create_item(root_item);
  338. class_item->set_text(0, current_class);
  339. Ref<Texture2D> icon = get_editor_theme_icon(SNAME("Node"));
  340. if (has_theme_icon(current_class, EditorStringName(EditorIcons))) {
  341. icon = get_editor_theme_icon(current_class);
  342. }
  343. class_item->set_icon(0, icon);
  344. class_item->set_selectable(0, false);
  345. List<MethodInfo> methods;
  346. ClassDB::get_method_list(current_class, &methods, true);
  347. methods = _filter_method_list(methods, signal_info, search_string);
  348. if (methods.is_empty()) {
  349. class_item->set_custom_color(0, disabled_color);
  350. } else {
  351. _create_method_tree_items(methods, class_item);
  352. }
  353. current_class = ClassDB::get_parent_class_nocheck(current_class);
  354. } while (current_class != StringName());
  355. empty_tree_label->set_visible(root_item->get_first_child() == nullptr);
  356. }
  357. void ConnectDialog::_method_check_button_pressed(const CheckButton *p_button) {
  358. if (p_button == script_methods_only) {
  359. EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "show_script_methods_only", p_button->is_pressed());
  360. } else if (p_button == compatible_methods_only) {
  361. EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "show_compatible_methods_only", p_button->is_pressed());
  362. }
  363. _update_method_tree();
  364. }
  365. void ConnectDialog::_open_method_popup() {
  366. method_popup->popup_centered();
  367. method_search->clear();
  368. method_search->grab_focus();
  369. }
  370. /*
  371. * Enables or disables the connect button. The connect button is enabled if a
  372. * node is selected and valid in the selected mode.
  373. */
  374. void ConnectDialog::_update_ok_enabled() {
  375. Node *target = tree->get_selected();
  376. if (target == nullptr) {
  377. get_ok_button()->set_disabled(true);
  378. return;
  379. }
  380. if (dst_method->get_text().is_empty()) {
  381. get_ok_button()->set_disabled(true);
  382. return;
  383. }
  384. get_ok_button()->set_disabled(false);
  385. }
  386. void ConnectDialog::_update_warning_label() {
  387. Ref<Script> scr = source->get_node(dst_path)->get_script();
  388. if (scr.is_null()) {
  389. warning_label->set_visible(false);
  390. return;
  391. }
  392. ScriptLanguage *language = scr->get_language();
  393. if (language->can_make_function()) {
  394. warning_label->set_visible(false);
  395. return;
  396. }
  397. warning_label->set_text(vformat(TTR("%s: Callback code won't be generated, please add it manually."), language->get_name()));
  398. warning_label->set_visible(true);
  399. }
  400. void ConnectDialog::_post_popup() {
  401. callable_mp((Control *)dst_method, &Control::grab_focus).call_deferred();
  402. callable_mp(dst_method, &LineEdit::select_all).call_deferred();
  403. }
  404. void ConnectDialog::_notification(int p_what) {
  405. switch (p_what) {
  406. case NOTIFICATION_ENTER_TREE: {
  407. bind_editor->edit(cdbinds);
  408. [[fallthrough]];
  409. }
  410. case NOTIFICATION_THEME_CHANGED: {
  411. for (int i = 0; i < type_list->get_item_count(); i++) {
  412. String type_name = Variant::get_type_name((Variant::Type)type_list->get_item_id(i));
  413. type_list->set_item_icon(i, get_editor_theme_icon(type_name));
  414. }
  415. method_search->set_right_icon(get_editor_theme_icon("Search"));
  416. open_method_tree->set_button_icon(get_editor_theme_icon("Edit"));
  417. } break;
  418. }
  419. }
  420. void ConnectDialog::_bind_methods() {
  421. ADD_SIGNAL(MethodInfo("connected"));
  422. }
  423. Node *ConnectDialog::get_source() const {
  424. return source;
  425. }
  426. ConnectDialog::ConnectionData ConnectDialog::get_source_connection_data() const {
  427. return source_connection_data;
  428. }
  429. StringName ConnectDialog::get_signal_name() const {
  430. return signal;
  431. }
  432. PackedStringArray ConnectDialog::get_signal_args() const {
  433. return signal_args;
  434. }
  435. NodePath ConnectDialog::get_dst_path() const {
  436. return dst_path;
  437. }
  438. void ConnectDialog::set_dst_node(Node *p_node) {
  439. tree->set_selected(p_node);
  440. }
  441. StringName ConnectDialog::get_dst_method_name() const {
  442. String txt = dst_method->get_text();
  443. if (txt.contains("(")) {
  444. txt = txt.left(txt.find_char('(')).strip_edges();
  445. }
  446. return txt;
  447. }
  448. void ConnectDialog::set_dst_method(const StringName &p_method) {
  449. dst_method->set_text(p_method);
  450. }
  451. int ConnectDialog::get_unbinds() const {
  452. return int(unbind_count->get_value());
  453. }
  454. Vector<Variant> ConnectDialog::get_binds() const {
  455. return cdbinds->params;
  456. }
  457. String ConnectDialog::get_signature(const MethodInfo &p_method, PackedStringArray *r_arg_names) {
  458. PackedStringArray signature;
  459. signature.append(p_method.name);
  460. signature.append("(");
  461. int i = 0;
  462. for (List<PropertyInfo>::ConstIterator itr = p_method.arguments.begin(); itr != p_method.arguments.end(); ++itr, ++i) {
  463. if (itr != p_method.arguments.begin()) {
  464. signature.append(", ");
  465. }
  466. const PropertyInfo &pi = *itr;
  467. String type_name;
  468. switch (pi.type) {
  469. case Variant::NIL:
  470. type_name = "Variant";
  471. break;
  472. case Variant::INT:
  473. if ((pi.usage & PROPERTY_USAGE_CLASS_IS_ENUM) && pi.class_name != StringName() && !String(pi.class_name).begins_with("res://")) {
  474. type_name = pi.class_name;
  475. } else {
  476. type_name = "int";
  477. }
  478. break;
  479. case Variant::ARRAY:
  480. if (pi.hint == PROPERTY_HINT_ARRAY_TYPE && !pi.hint_string.is_empty() && !pi.hint_string.begins_with("res://")) {
  481. type_name = "Array[" + pi.hint_string + "]";
  482. } else {
  483. type_name = "Array";
  484. }
  485. break;
  486. case Variant::DICTIONARY:
  487. type_name = "Dictionary";
  488. if (pi.hint == PROPERTY_HINT_DICTIONARY_TYPE && !pi.hint_string.is_empty()) {
  489. String key_hint = pi.hint_string.get_slice(";", 0);
  490. String value_hint = pi.hint_string.get_slice(";", 1);
  491. if (key_hint.is_empty() || key_hint.begins_with("res://")) {
  492. key_hint = "Variant";
  493. }
  494. if (value_hint.is_empty() || value_hint.begins_with("res://")) {
  495. value_hint = "Variant";
  496. }
  497. if (key_hint != "Variant" || value_hint != "Variant") {
  498. type_name += "[" + key_hint + ", " + value_hint + "]";
  499. }
  500. }
  501. break;
  502. case Variant::OBJECT:
  503. if (pi.class_name != StringName()) {
  504. type_name = pi.class_name;
  505. } else {
  506. type_name = "Object";
  507. }
  508. break;
  509. default:
  510. type_name = Variant::get_type_name(pi.type);
  511. break;
  512. }
  513. String arg_name = pi.name.is_empty() ? "arg" + itos(i) : pi.name;
  514. signature.append(arg_name + ": " + type_name);
  515. if (r_arg_names) {
  516. r_arg_names->push_back(arg_name + ":" + type_name);
  517. }
  518. }
  519. signature.append(")");
  520. return String().join(signature);
  521. }
  522. bool ConnectDialog::get_deferred() const {
  523. return deferred->is_pressed();
  524. }
  525. bool ConnectDialog::get_one_shot() const {
  526. return one_shot->is_pressed();
  527. }
  528. /*
  529. * Returns true if ConnectDialog is being used to edit an existing connection.
  530. */
  531. bool ConnectDialog::is_editing() const {
  532. return edit_mode;
  533. }
  534. void ConnectDialog::shortcut_input(const Ref<InputEvent> &p_event) {
  535. const Ref<InputEventKey> &key = p_event;
  536. if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
  537. if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
  538. filter_nodes->grab_focus();
  539. filter_nodes->select_all();
  540. filter_nodes->accept_event();
  541. }
  542. }
  543. }
  544. /*
  545. * Initialize ConnectDialog and populate fields with expected data.
  546. * If creating a connection from scratch, sensible defaults are used.
  547. * If editing an existing connection, previous data is retained.
  548. */
  549. void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit) {
  550. set_hide_on_ok(false);
  551. source = static_cast<Node *>(p_cd.source);
  552. signal = p_cd.signal;
  553. signal_args = p_signal_args;
  554. tree->set_selected(nullptr);
  555. tree->set_marked(source);
  556. if (p_cd.target) {
  557. set_dst_node(static_cast<Node *>(p_cd.target));
  558. set_dst_method(p_cd.method);
  559. }
  560. _update_ok_enabled();
  561. bool b_deferred = (p_cd.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED;
  562. bool b_oneshot = (p_cd.flags & CONNECT_ONE_SHOT) == CONNECT_ONE_SHOT;
  563. deferred->set_pressed(b_deferred);
  564. one_shot->set_pressed(b_oneshot);
  565. unbind_count->set_max(p_signal_args.size());
  566. unbind_count->set_value(p_cd.unbinds);
  567. _unbind_count_changed(p_cd.unbinds);
  568. cdbinds->params.clear();
  569. cdbinds->params = p_cd.binds;
  570. cdbinds->notify_changed();
  571. edit_mode = p_edit;
  572. source_connection_data = p_cd;
  573. }
  574. void ConnectDialog::popup_dialog(const String &p_for_signal) {
  575. from_signal->set_text(p_for_signal);
  576. warning_label->add_theme_color_override(SceneStringName(font_color), warning_label->get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  577. error_label->add_theme_color_override(SceneStringName(font_color), error_label->get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  578. filter_nodes->clear();
  579. if (!advanced->is_pressed()) {
  580. error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
  581. }
  582. if (first_popup) {
  583. first_popup = false;
  584. _advanced_pressed();
  585. }
  586. popup_centered();
  587. }
  588. void ConnectDialog::_advanced_pressed() {
  589. if (advanced->is_pressed()) {
  590. connect_to_label->set_text(TTR("Connect to Node:"));
  591. tree->set_connect_to_script_mode(false);
  592. vbc_right->show();
  593. error_label->hide();
  594. } else {
  595. reset_size();
  596. connect_to_label->set_text(TTR("Connect to Script:"));
  597. tree->set_connect_to_script_mode(true);
  598. vbc_right->hide();
  599. error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
  600. }
  601. EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "use_advanced_connections", advanced->is_pressed());
  602. popup_centered();
  603. }
  604. ConnectDialog::ConnectDialog() {
  605. set_min_size(Size2(0, 500) * EDSCALE);
  606. HBoxContainer *main_hb = memnew(HBoxContainer);
  607. add_child(main_hb);
  608. VBoxContainer *vbc_left = memnew(VBoxContainer);
  609. main_hb->add_child(vbc_left);
  610. vbc_left->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  611. vbc_left->set_custom_minimum_size(Vector2(400 * EDSCALE, 0));
  612. from_signal = memnew(LineEdit);
  613. vbc_left->add_margin_child(TTR("From Signal:"), from_signal);
  614. from_signal->set_editable(false);
  615. tree = memnew(SceneTreeEditor(false));
  616. tree->set_connecting_signal(true);
  617. tree->set_show_enabled_subscene(true);
  618. tree->set_v_size_flags(Control::SIZE_FILL | Control::SIZE_EXPAND);
  619. tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ConnectDialog::_item_activated));
  620. tree->connect("node_selected", callable_mp(this, &ConnectDialog::_tree_node_selected));
  621. tree->set_connect_to_script_mode(true);
  622. HBoxContainer *hbc_filter = memnew(HBoxContainer);
  623. filter_nodes = memnew(LineEdit);
  624. hbc_filter->add_child(filter_nodes);
  625. filter_nodes->set_h_size_flags(Control::SIZE_FILL | Control::SIZE_EXPAND);
  626. filter_nodes->set_placeholder(TTR("Filter Nodes"));
  627. filter_nodes->set_clear_button_enabled(true);
  628. filter_nodes->connect(SceneStringName(text_changed), callable_mp(tree, &SceneTreeEditor::set_filter));
  629. Button *focus_current = memnew(Button);
  630. hbc_filter->add_child(focus_current);
  631. focus_current->set_text(TTR("Go to Source"));
  632. focus_current->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_focus_currently_connected));
  633. Node *mc = vbc_left->add_margin_child(TTR("Connect to Script:"), hbc_filter, false);
  634. connect_to_label = Object::cast_to<Label>(vbc_left->get_child(mc->get_index() - 1));
  635. vbc_left->add_child(tree);
  636. warning_label = memnew(Label);
  637. vbc_left->add_child(warning_label);
  638. warning_label->hide();
  639. error_label = memnew(Label);
  640. error_label->set_text(TTR("Scene does not contain any script."));
  641. vbc_left->add_child(error_label);
  642. error_label->hide();
  643. method_popup = memnew(AcceptDialog);
  644. method_popup->set_title(TTR("Select Method"));
  645. method_popup->set_min_size(Vector2(400, 600) * EDSCALE);
  646. add_child(method_popup);
  647. VBoxContainer *method_vbc = memnew(VBoxContainer);
  648. method_popup->add_child(method_vbc);
  649. method_search = memnew(LineEdit);
  650. method_vbc->add_child(method_search);
  651. method_search->set_placeholder(TTR("Filter Methods"));
  652. method_search->set_clear_button_enabled(true);
  653. method_search->connect(SceneStringName(text_changed), callable_mp(this, &ConnectDialog::_update_method_tree).unbind(1));
  654. method_tree = memnew(Tree);
  655. method_vbc->add_child(method_tree);
  656. method_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  657. method_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  658. method_tree->set_hide_root(true);
  659. method_tree->connect(SceneStringName(item_selected), callable_mp(this, &ConnectDialog::_method_selected));
  660. method_tree->connect("item_activated", callable_mp((Window *)method_popup, &Window::hide));
  661. empty_tree_label = memnew(Label(TTR("No method found matching given filters.")));
  662. method_popup->add_child(empty_tree_label);
  663. empty_tree_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  664. empty_tree_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  665. empty_tree_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
  666. script_methods_only = memnew(CheckButton(TTR("Script Methods Only")));
  667. method_vbc->add_child(script_methods_only);
  668. script_methods_only->set_h_size_flags(Control::SIZE_SHRINK_END);
  669. script_methods_only->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "show_script_methods_only", true));
  670. script_methods_only->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_method_check_button_pressed).bind(script_methods_only));
  671. compatible_methods_only = memnew(CheckButton(TTR("Compatible Methods Only")));
  672. method_vbc->add_child(compatible_methods_only);
  673. compatible_methods_only->set_h_size_flags(Control::SIZE_SHRINK_END);
  674. compatible_methods_only->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "show_compatible_methods_only", true));
  675. compatible_methods_only->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_method_check_button_pressed).bind(compatible_methods_only));
  676. vbc_right = memnew(VBoxContainer);
  677. main_hb->add_child(vbc_right);
  678. vbc_right->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  679. vbc_right->set_custom_minimum_size(Vector2(150 * EDSCALE, 0));
  680. vbc_right->hide();
  681. HBoxContainer *add_bind_hb = memnew(HBoxContainer);
  682. type_list = memnew(OptionButton);
  683. type_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  684. add_bind_hb->add_child(type_list);
  685. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  686. if (i == Variant::NIL || i == Variant::OBJECT || i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
  687. // These types can't be constructed or serialized properly, so skip them.
  688. continue;
  689. }
  690. type_list->add_item(Variant::get_type_name(Variant::Type(i)), i);
  691. }
  692. bind_controls.push_back(type_list);
  693. Button *add_bind = memnew(Button);
  694. add_bind->set_text(TTR("Add"));
  695. add_bind_hb->add_child(add_bind);
  696. add_bind->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_add_bind));
  697. bind_controls.push_back(add_bind);
  698. Button *del_bind = memnew(Button);
  699. del_bind->set_text(TTR("Remove"));
  700. add_bind_hb->add_child(del_bind);
  701. del_bind->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_remove_bind));
  702. bind_controls.push_back(del_bind);
  703. vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);
  704. bind_editor = memnew(EditorInspector);
  705. bind_controls.push_back(bind_editor);
  706. vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
  707. unbind_count = memnew(SpinBox);
  708. unbind_count->set_tooltip_text(TTR("Allows to drop arguments sent by signal emitter."));
  709. unbind_count->connect(SceneStringName(value_changed), callable_mp(this, &ConnectDialog::_unbind_count_changed));
  710. vbc_right->add_margin_child(TTR("Unbind Signal Arguments:"), unbind_count);
  711. HBoxContainer *hbc_method = memnew(HBoxContainer);
  712. vbc_left->add_margin_child(TTR("Receiver Method:"), hbc_method);
  713. dst_method = memnew(LineEdit);
  714. dst_method->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  715. dst_method->connect(SceneStringName(text_changed), callable_mp(method_tree, &Tree::deselect_all).unbind(1));
  716. hbc_method->add_child(dst_method);
  717. register_text_enter(dst_method);
  718. open_method_tree = memnew(Button);
  719. hbc_method->add_child(open_method_tree);
  720. open_method_tree->set_text("Pick");
  721. open_method_tree->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_open_method_popup));
  722. advanced = memnew(CheckButton(TTR("Advanced")));
  723. vbc_left->add_child(advanced);
  724. advanced->set_h_size_flags(Control::SIZE_SHRINK_BEGIN | Control::SIZE_EXPAND);
  725. advanced->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "use_advanced_connections", false));
  726. advanced->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_advanced_pressed));
  727. HBoxContainer *hbox = memnew(HBoxContainer);
  728. vbc_right->add_child(hbox);
  729. deferred = memnew(CheckBox);
  730. deferred->set_h_size_flags(0);
  731. deferred->set_text(TTR("Deferred"));
  732. deferred->set_tooltip_text(TTR("Defers the signal, storing it in a queue and only firing it at idle time."));
  733. hbox->add_child(deferred);
  734. one_shot = memnew(CheckBox);
  735. one_shot->set_h_size_flags(0);
  736. one_shot->set_text(TTR("One Shot"));
  737. one_shot->set_tooltip_text(TTR("Disconnects the signal after its first emission."));
  738. hbox->add_child(one_shot);
  739. cdbinds = memnew(ConnectDialogBinds);
  740. error = memnew(AcceptDialog);
  741. add_child(error);
  742. error->set_title(TTR("Cannot connect signal"));
  743. error->set_ok_button_text(TTR("Close"));
  744. set_ok_button_text(TTR("Connect"));
  745. }
  746. ConnectDialog::~ConnectDialog() {
  747. memdelete(cdbinds);
  748. }
  749. //////////////////////////////////////////
  750. Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
  751. // If it's not a doc tooltip, fallback to the default one.
  752. if (p_text.contains("::")) {
  753. return nullptr;
  754. }
  755. EditorHelpBit *help_bit = memnew(EditorHelpBit(p_text));
  756. EditorHelpBitTooltip::show_tooltip(help_bit, const_cast<ConnectionsDockTree *>(this));
  757. return memnew(Control); // Make the standard tooltip invisible.
  758. }
  759. struct _ConnectionsDockMethodInfoSort {
  760. _FORCE_INLINE_ bool operator()(const MethodInfo &a, const MethodInfo &b) const {
  761. return a.name < b.name;
  762. }
  763. };
  764. void ConnectionsDock::_filter_changed(const String &p_text) {
  765. update_tree();
  766. }
  767. /*
  768. * Post-ConnectDialog callback for creating/editing connections.
  769. * Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
  770. */
  771. void ConnectionsDock::_make_or_edit_connection() {
  772. NodePath dst_path = connect_dialog->get_dst_path();
  773. Node *target = selected_node->get_node(dst_path);
  774. ERR_FAIL_NULL(target);
  775. ConnectDialog::ConnectionData cd;
  776. cd.source = connect_dialog->get_source();
  777. cd.target = target;
  778. cd.signal = connect_dialog->get_signal_name();
  779. cd.method = connect_dialog->get_dst_method_name();
  780. cd.unbinds = connect_dialog->get_unbinds();
  781. if (cd.unbinds == 0) {
  782. cd.binds = connect_dialog->get_binds();
  783. }
  784. bool b_deferred = connect_dialog->get_deferred();
  785. bool b_oneshot = connect_dialog->get_one_shot();
  786. cd.flags = CONNECT_PERSIST | (b_deferred ? CONNECT_DEFERRED : 0) | (b_oneshot ? CONNECT_ONE_SHOT : 0);
  787. // If the function is found in target's own script, check the editor setting
  788. // to determine if the script should be opened.
  789. // If the function is found in an inherited class or script no need to do anything
  790. // except making a connection.
  791. bool add_script_function_request = false;
  792. Ref<Script> scr = target->get_script();
  793. if (scr.is_valid() && !ClassDB::has_method(target->get_class(), cd.method)) {
  794. // Check in target's own script.
  795. int line = scr->get_language()->find_function(cd.method, scr->get_source_code());
  796. if (line != -1) {
  797. add_script_function_request = EDITOR_GET("text_editor/behavior/navigation/open_script_when_connecting_signal_to_existing_method");
  798. } else {
  799. // There is a chance that the method is inherited from another script.
  800. bool found_inherited_function = false;
  801. Ref<Script> inherited_scr = scr->get_base_script();
  802. while (inherited_scr.is_valid()) {
  803. int inherited_line = inherited_scr->get_language()->find_function(cd.method, inherited_scr->get_source_code());
  804. if (inherited_line != -1) {
  805. found_inherited_function = true;
  806. break;
  807. }
  808. inherited_scr = inherited_scr->get_base_script();
  809. }
  810. add_script_function_request = !found_inherited_function;
  811. }
  812. }
  813. if (connect_dialog->is_editing()) {
  814. _disconnect(connect_dialog->get_source_connection_data());
  815. _connect(cd);
  816. } else {
  817. _connect(cd);
  818. }
  819. if (add_script_function_request) {
  820. PackedStringArray script_function_args = connect_dialog->get_signal_args();
  821. script_function_args.resize(script_function_args.size() - cd.unbinds);
  822. for (int i = 0; i < cd.binds.size(); i++) {
  823. script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cd.binds[i].get_type()));
  824. }
  825. EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), target, cd.method, script_function_args);
  826. }
  827. update_tree();
  828. }
  829. /*
  830. * Creates single connection w/ undo-redo functionality.
  831. */
  832. void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
  833. Node *source = Object::cast_to<Node>(p_cd.source);
  834. Node *target = Object::cast_to<Node>(p_cd.target);
  835. if (!source || !target) {
  836. return;
  837. }
  838. Callable callable = p_cd.get_callable();
  839. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  840. undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(p_cd.signal), String(p_cd.method)));
  841. undo_redo->add_do_method(source, "connect", p_cd.signal, callable, p_cd.flags);
  842. undo_redo->add_undo_method(source, "disconnect", p_cd.signal, callable);
  843. undo_redo->add_do_method(this, "update_tree");
  844. undo_redo->add_undo_method(this, "update_tree");
  845. undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
  846. undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  847. undo_redo->commit_action();
  848. }
  849. /*
  850. * Break single connection w/ undo-redo functionality.
  851. */
  852. void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {
  853. ERR_FAIL_COND(p_cd.source != selected_node); // Shouldn't happen but... Bugcheck.
  854. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  855. undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), p_cd.signal, p_cd.method));
  856. Callable callable = p_cd.get_callable();
  857. undo_redo->add_do_method(selected_node, "disconnect", p_cd.signal, callable);
  858. undo_redo->add_undo_method(selected_node, "connect", p_cd.signal, callable, p_cd.flags);
  859. undo_redo->add_do_method(this, "update_tree");
  860. undo_redo->add_undo_method(this, "update_tree");
  861. undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
  862. undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  863. undo_redo->commit_action();
  864. }
  865. /*
  866. * Break all connections of currently selected signal.
  867. * Can undo-redo as a single action.
  868. */
  869. void ConnectionsDock::_disconnect_all() {
  870. TreeItem *item = tree->get_selected();
  871. if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_SIGNAL) {
  872. return;
  873. }
  874. TreeItem *child = item->get_first_child();
  875. String signal_name = item->get_metadata(0).operator Dictionary()["name"];
  876. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  877. undo_redo->create_action(vformat(TTR("Disconnect all from signal: '%s'"), signal_name));
  878. while (child) {
  879. Connection connection = child->get_metadata(0);
  880. if (!_is_connection_inherited(connection)) {
  881. ConnectDialog::ConnectionData cd = connection;
  882. undo_redo->add_do_method(selected_node, "disconnect", cd.signal, cd.get_callable());
  883. undo_redo->add_undo_method(selected_node, "connect", cd.signal, cd.get_callable(), cd.flags);
  884. }
  885. child = child->get_next();
  886. }
  887. undo_redo->add_do_method(this, "update_tree");
  888. undo_redo->add_undo_method(this, "update_tree");
  889. undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  890. undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  891. undo_redo->commit_action();
  892. }
  893. void ConnectionsDock::_tree_item_selected() {
  894. TreeItem *item = tree->get_selected();
  895. if (item && _get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
  896. connect_button->set_text(TTR("Connect..."));
  897. connect_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
  898. connect_button->set_disabled(false);
  899. } else if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
  900. connect_button->set_text(TTR("Disconnect"));
  901. connect_button->set_button_icon(get_editor_theme_icon(SNAME("Unlinked")));
  902. Object::Connection connection = item->get_metadata(0);
  903. connect_button->set_disabled(_is_connection_inherited(connection));
  904. } else {
  905. connect_button->set_text(TTR("Connect..."));
  906. connect_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
  907. connect_button->set_disabled(true);
  908. }
  909. }
  910. void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click.
  911. TreeItem *item = tree->get_selected();
  912. if (!item) {
  913. return;
  914. }
  915. if (_get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
  916. _open_connection_dialog(*item);
  917. } else if (_get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
  918. _go_to_method(*item);
  919. }
  920. }
  921. ConnectionsDock::TreeItemType ConnectionsDock::_get_item_type(const TreeItem &p_item) const {
  922. if (&p_item == tree->get_root()) {
  923. return TREE_ITEM_TYPE_ROOT;
  924. } else if (p_item.get_parent() == tree->get_root()) {
  925. return TREE_ITEM_TYPE_CLASS;
  926. } else if (p_item.get_parent()->get_parent() == tree->get_root()) {
  927. return TREE_ITEM_TYPE_SIGNAL;
  928. } else {
  929. return TREE_ITEM_TYPE_CONNECTION;
  930. }
  931. }
  932. bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
  933. return bool(p_connection.flags & CONNECT_INHERITED);
  934. }
  935. /*
  936. * Open connection dialog with TreeItem data to CREATE a brand-new connection.
  937. */
  938. void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
  939. Dictionary sinfo = p_item.get_metadata(0);
  940. String signal_name = sinfo["name"];
  941. PackedStringArray signal_args = sinfo["args"];
  942. Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;
  943. if (!dst_node || dst_node->get_script().is_null()) {
  944. dst_node = _find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root());
  945. }
  946. ConnectDialog::ConnectionData cd;
  947. cd.source = selected_node;
  948. cd.signal = StringName(signal_name);
  949. cd.target = dst_node;
  950. cd.method = ConnectDialog::generate_method_callback_name(cd.source, signal_name, cd.target);
  951. connect_dialog->init(cd, signal_args);
  952. connect_dialog->set_title(TTR("Connect a Signal to a Method"));
  953. connect_dialog->popup_dialog(signal_name + "(" + String(", ").join(signal_args) + ")");
  954. }
  955. /*
  956. * Open connection dialog with Connection data to EDIT an existing connection.
  957. */
  958. void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
  959. TreeItem *signal_item = p_item.get_parent();
  960. ERR_FAIL_NULL(signal_item);
  961. Connection connection = p_item.get_metadata(0);
  962. ConnectDialog::ConnectionData cd = connection;
  963. Node *src = Object::cast_to<Node>(cd.source);
  964. Node *dst = Object::cast_to<Node>(cd.target);
  965. if (src && dst) {
  966. const String &signal_name_ref = cd.signal;
  967. PackedStringArray signal_args = signal_item->get_metadata(0).operator Dictionary()["args"];
  968. connect_dialog->set_title(vformat(TTR("Edit Connection: '%s'"), cd.signal));
  969. connect_dialog->popup_dialog(signal_name_ref);
  970. connect_dialog->init(cd, signal_args, true);
  971. }
  972. }
  973. /*
  974. * Open slot method location in script editor.
  975. */
  976. void ConnectionsDock::_go_to_method(TreeItem &p_item) {
  977. if (_get_item_type(p_item) != TREE_ITEM_TYPE_CONNECTION) {
  978. return;
  979. }
  980. Connection connection = p_item.get_metadata(0);
  981. ConnectDialog::ConnectionData cd = connection;
  982. ERR_FAIL_COND(cd.source != selected_node); // Shouldn't happen but... bugcheck.
  983. if (!cd.target) {
  984. return;
  985. }
  986. Ref<Script> scr = cd.target->get_script();
  987. if (scr.is_null()) {
  988. return;
  989. }
  990. if (scr.is_valid() && ScriptEditor::get_singleton()->script_goto_method(scr, cd.method)) {
  991. EditorNode::get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
  992. }
  993. }
  994. void ConnectionsDock::_handle_class_menu_option(int p_option) {
  995. switch (p_option) {
  996. case CLASS_MENU_OPEN_DOCS:
  997. ScriptEditor::get_singleton()->goto_help("class:" + class_menu_doc_class_name);
  998. EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
  999. break;
  1000. }
  1001. }
  1002. void ConnectionsDock::_class_menu_about_to_popup() {
  1003. class_menu->set_item_disabled(class_menu->get_item_index(CLASS_MENU_OPEN_DOCS), class_menu_doc_class_name.is_empty());
  1004. }
  1005. void ConnectionsDock::_handle_signal_menu_option(int p_option) {
  1006. TreeItem *item = tree->get_selected();
  1007. if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_SIGNAL) {
  1008. return;
  1009. }
  1010. Dictionary meta = item->get_metadata(0);
  1011. switch (p_option) {
  1012. case SIGNAL_MENU_CONNECT: {
  1013. _open_connection_dialog(*item);
  1014. } break;
  1015. case SIGNAL_MENU_DISCONNECT_ALL: {
  1016. disconnect_all_dialog->set_text(vformat(TTR("Are you sure you want to remove all connections from the \"%s\" signal?"), meta["name"]));
  1017. disconnect_all_dialog->popup_centered();
  1018. } break;
  1019. case SIGNAL_MENU_COPY_NAME: {
  1020. DisplayServer::get_singleton()->clipboard_set(meta["name"]);
  1021. } break;
  1022. case SIGNAL_MENU_OPEN_DOCS: {
  1023. ScriptEditor::get_singleton()->goto_help("class_signal:" + String(meta["class"]) + ":" + String(meta["name"]));
  1024. EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
  1025. } break;
  1026. }
  1027. }
  1028. void ConnectionsDock::_signal_menu_about_to_popup() {
  1029. TreeItem *item = tree->get_selected();
  1030. if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_SIGNAL) {
  1031. return;
  1032. }
  1033. Dictionary meta = item->get_metadata(0);
  1034. bool disable_disconnect_all = true;
  1035. for (int i = 0; i < item->get_child_count(); i++) {
  1036. if (!item->get_child(i)->has_meta("_inherited_connection")) {
  1037. disable_disconnect_all = false;
  1038. }
  1039. }
  1040. signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_DISCONNECT_ALL), disable_disconnect_all);
  1041. signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_OPEN_DOCS), String(meta["class"]).is_empty());
  1042. }
  1043. void ConnectionsDock::_handle_slot_menu_option(int p_option) {
  1044. TreeItem *item = tree->get_selected();
  1045. if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_CONNECTION) {
  1046. return;
  1047. }
  1048. switch (p_option) {
  1049. case SLOT_MENU_EDIT: {
  1050. _open_edit_connection_dialog(*item);
  1051. } break;
  1052. case SLOT_MENU_GO_TO_METHOD: {
  1053. _go_to_method(*item);
  1054. } break;
  1055. case SLOT_MENU_DISCONNECT: {
  1056. Connection connection = item->get_metadata(0);
  1057. _disconnect(connection);
  1058. update_tree();
  1059. } break;
  1060. }
  1061. }
  1062. void ConnectionsDock::_slot_menu_about_to_popup() {
  1063. TreeItem *item = tree->get_selected();
  1064. if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_CONNECTION) {
  1065. return;
  1066. }
  1067. bool connection_is_inherited = item->has_meta("_inherited_connection");
  1068. slot_menu->set_item_disabled(slot_menu->get_item_index(SLOT_MENU_EDIT), connection_is_inherited);
  1069. slot_menu->set_item_disabled(slot_menu->get_item_index(SLOT_MENU_DISCONNECT), connection_is_inherited);
  1070. }
  1071. void ConnectionsDock::_tree_gui_input(const Ref<InputEvent> &p_event) {
  1072. const Ref<InputEventKey> &key = p_event;
  1073. if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
  1074. if (ED_IS_SHORTCUT("connections_editor/disconnect", p_event)) {
  1075. TreeItem *item = tree->get_selected();
  1076. if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
  1077. Connection connection = item->get_metadata(0);
  1078. _disconnect(connection);
  1079. update_tree();
  1080. // Stop the Delete input from propagating elsewhere.
  1081. accept_event();
  1082. return;
  1083. }
  1084. } else if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
  1085. search_box->grab_focus();
  1086. search_box->select_all();
  1087. accept_event();
  1088. return;
  1089. }
  1090. }
  1091. // Handle RMB press.
  1092. const Ref<InputEventMouseButton> &mb_event = p_event;
  1093. if (mb_event.is_valid() && mb_event->is_pressed() && mb_event->get_button_index() == MouseButton::RIGHT) {
  1094. TreeItem *item = tree->get_item_at_position(mb_event->get_position());
  1095. if (!item) {
  1096. return;
  1097. }
  1098. if (item->is_selectable(0)) {
  1099. // Update selection now, before `about_to_popup` signal. Needed for SIGNAL and CONNECTION context menus.
  1100. tree->set_selected(item);
  1101. }
  1102. Vector2 screen_position = tree->get_screen_position() + mb_event->get_position();
  1103. switch (_get_item_type(*item)) {
  1104. case TREE_ITEM_TYPE_ROOT:
  1105. break;
  1106. case TREE_ITEM_TYPE_CLASS:
  1107. class_menu_doc_class_name = item->get_metadata(0);
  1108. class_menu->set_position(screen_position);
  1109. class_menu->reset_size();
  1110. class_menu->popup();
  1111. accept_event(); // Don't collapse item.
  1112. break;
  1113. case TREE_ITEM_TYPE_SIGNAL:
  1114. signal_menu->set_position(screen_position);
  1115. signal_menu->reset_size();
  1116. signal_menu->popup();
  1117. break;
  1118. case TREE_ITEM_TYPE_CONNECTION:
  1119. slot_menu->set_position(screen_position);
  1120. slot_menu->reset_size();
  1121. slot_menu->popup();
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. void ConnectionsDock::_close() {
  1127. hide();
  1128. }
  1129. void ConnectionsDock::_connect_pressed() {
  1130. TreeItem *item = tree->get_selected();
  1131. if (!item) {
  1132. connect_button->set_disabled(true);
  1133. return;
  1134. }
  1135. if (_get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
  1136. _open_connection_dialog(*item);
  1137. } else if (_get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
  1138. Connection connection = item->get_metadata(0);
  1139. _disconnect(connection);
  1140. update_tree();
  1141. }
  1142. }
  1143. void ConnectionsDock::_notification(int p_what) {
  1144. switch (p_what) {
  1145. case NOTIFICATION_ENTER_TREE:
  1146. case NOTIFICATION_THEME_CHANGED: {
  1147. search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  1148. class_menu->set_item_icon(class_menu->get_item_index(CLASS_MENU_OPEN_DOCS), get_editor_theme_icon(SNAME("Help")));
  1149. signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_CONNECT), get_editor_theme_icon(SNAME("Instance")));
  1150. signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_DISCONNECT_ALL), get_editor_theme_icon(SNAME("Unlinked")));
  1151. signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_COPY_NAME), get_editor_theme_icon(SNAME("ActionCopy")));
  1152. signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_OPEN_DOCS), get_editor_theme_icon(SNAME("Help")));
  1153. slot_menu->set_item_icon(slot_menu->get_item_index(SLOT_MENU_EDIT), get_editor_theme_icon(SNAME("Edit")));
  1154. slot_menu->set_item_icon(slot_menu->get_item_index(SLOT_MENU_GO_TO_METHOD), get_editor_theme_icon(SNAME("ArrowRight")));
  1155. slot_menu->set_item_icon(slot_menu->get_item_index(SLOT_MENU_DISCONNECT), get_editor_theme_icon(SNAME("Unlinked")));
  1156. tree->add_theme_constant_override("icon_max_width", get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)));
  1157. update_tree();
  1158. } break;
  1159. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1160. if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editors")) {
  1161. update_tree();
  1162. }
  1163. } break;
  1164. }
  1165. }
  1166. void ConnectionsDock::_bind_methods() {
  1167. ClassDB::bind_method("update_tree", &ConnectionsDock::update_tree);
  1168. }
  1169. void ConnectionsDock::set_node(Node *p_node) {
  1170. selected_node = p_node;
  1171. update_tree();
  1172. }
  1173. void ConnectionsDock::update_tree() {
  1174. String prev_selected;
  1175. if (tree->is_anything_selected()) {
  1176. prev_selected = tree->get_selected()->get_text(0);
  1177. }
  1178. tree->clear();
  1179. if (!selected_node) {
  1180. return;
  1181. }
  1182. TreeItem *root = tree->create_item();
  1183. DocTools *doc_data = EditorHelp::get_doc_data();
  1184. EditorData &editor_data = EditorNode::get_editor_data();
  1185. StringName native_base = selected_node->get_class();
  1186. Ref<Script> script_base = selected_node->get_script();
  1187. while (native_base != StringName()) {
  1188. String class_name;
  1189. String doc_class_name;
  1190. Ref<Texture2D> class_icon;
  1191. List<MethodInfo> class_signals;
  1192. if (script_base.is_valid()) {
  1193. class_name = script_base->get_global_name();
  1194. if (class_name.is_empty()) {
  1195. class_name = script_base->get_path().get_file();
  1196. }
  1197. doc_class_name = script_base->get_global_name();
  1198. if (doc_class_name.is_empty()) {
  1199. doc_class_name = script_base->get_path().trim_prefix("res://").quote();
  1200. }
  1201. if (!doc_class_name.is_empty() && !doc_data->class_list.find(doc_class_name)) {
  1202. doc_class_name = String();
  1203. }
  1204. class_icon = editor_data.get_script_icon(script_base);
  1205. if (class_icon.is_null() && has_theme_icon(native_base, EditorStringName(EditorIcons))) {
  1206. class_icon = get_editor_theme_icon(native_base);
  1207. }
  1208. script_base->get_script_signal_list(&class_signals);
  1209. // TODO: Core: Add optional parameter to ignore base classes (no_inheritance like in ClassDB).
  1210. Ref<Script> base = script_base->get_base_script();
  1211. if (base.is_valid()) {
  1212. List<MethodInfo> base_signals;
  1213. base->get_script_signal_list(&base_signals);
  1214. HashSet<String> base_signal_names;
  1215. for (List<MethodInfo>::Element *F = base_signals.front(); F; F = F->next()) {
  1216. base_signal_names.insert(F->get().name);
  1217. }
  1218. for (List<MethodInfo>::Element *F = class_signals.front(); F; F = F->next()) {
  1219. if (base_signal_names.has(F->get().name)) {
  1220. class_signals.erase(F);
  1221. }
  1222. }
  1223. }
  1224. script_base = base;
  1225. } else {
  1226. class_name = native_base;
  1227. doc_class_name = native_base;
  1228. if (!doc_data->class_list.find(doc_class_name)) {
  1229. doc_class_name = String();
  1230. }
  1231. if (has_theme_icon(native_base, EditorStringName(EditorIcons))) {
  1232. class_icon = get_editor_theme_icon(native_base);
  1233. }
  1234. ClassDB::get_signal_list(native_base, &class_signals, true);
  1235. native_base = ClassDB::get_parent_class(native_base);
  1236. }
  1237. if (class_icon.is_null()) {
  1238. class_icon = get_editor_theme_icon(SNAME("Object"));
  1239. }
  1240. TreeItem *section_item = nullptr;
  1241. // Create subsections.
  1242. if (!class_signals.is_empty()) {
  1243. class_signals.sort();
  1244. section_item = tree->create_item(root);
  1245. section_item->set_text(0, class_name);
  1246. // `|` separators used in `EditorHelpBit`.
  1247. section_item->set_tooltip_text(0, "class|" + doc_class_name + "|");
  1248. section_item->set_icon(0, class_icon);
  1249. section_item->set_selectable(0, false);
  1250. section_item->set_editable(0, false);
  1251. section_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  1252. section_item->set_metadata(0, doc_class_name);
  1253. }
  1254. for (MethodInfo &mi : class_signals) {
  1255. const StringName &signal_name = mi.name;
  1256. if (!search_box->get_text().is_subsequence_ofn(signal_name)) {
  1257. continue;
  1258. }
  1259. PackedStringArray argnames;
  1260. // Create the children of the subsection - the actual list of signals.
  1261. TreeItem *signal_item = tree->create_item(section_item);
  1262. String signame = connect_dialog->get_signature(mi, &argnames);
  1263. signal_item->set_text(0, signame);
  1264. if (signame == prev_selected) {
  1265. signal_item->select(0);
  1266. prev_selected = "";
  1267. }
  1268. Dictionary sinfo;
  1269. sinfo["class"] = doc_class_name;
  1270. sinfo["name"] = signal_name;
  1271. sinfo["args"] = argnames;
  1272. signal_item->set_metadata(0, sinfo);
  1273. signal_item->set_icon(0, get_editor_theme_icon(SNAME("Signal")));
  1274. // `|` separators used in `EditorHelpBit`.
  1275. signal_item->set_tooltip_text(0, "signal|" + doc_class_name + "|" + String(signal_name));
  1276. // List existing connections.
  1277. List<Object::Connection> existing_connections;
  1278. selected_node->get_signal_connection_list(signal_name, &existing_connections);
  1279. for (const Object::Connection &F : existing_connections) {
  1280. Connection connection = F;
  1281. if (!(connection.flags & CONNECT_PERSIST)) {
  1282. continue;
  1283. }
  1284. ConnectDialog::ConnectionData cd = connection;
  1285. Node *target = Object::cast_to<Node>(cd.target);
  1286. if (!target) {
  1287. continue;
  1288. }
  1289. String path = String(selected_node->get_path_to(target)) + " :: " + cd.method + "()";
  1290. if (cd.flags & CONNECT_DEFERRED) {
  1291. path += " (deferred)";
  1292. }
  1293. if (cd.flags & CONNECT_ONE_SHOT) {
  1294. path += " (one-shot)";
  1295. }
  1296. if (cd.unbinds > 0) {
  1297. path += " unbinds(" + itos(cd.unbinds) + ")";
  1298. } else if (!cd.binds.is_empty()) {
  1299. path += " binds(";
  1300. for (int i = 0; i < cd.binds.size(); i++) {
  1301. if (i > 0) {
  1302. path += ", ";
  1303. }
  1304. path += cd.binds[i].operator String();
  1305. }
  1306. path += ")";
  1307. }
  1308. TreeItem *connection_item = tree->create_item(signal_item);
  1309. connection_item->set_text(0, path);
  1310. connection_item->set_metadata(0, connection);
  1311. connection_item->set_icon(0, get_editor_theme_icon(SNAME("Slot")));
  1312. if (_is_connection_inherited(connection)) {
  1313. // The scene inherits this connection.
  1314. connection_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  1315. connection_item->set_meta("_inherited_connection", true);
  1316. }
  1317. }
  1318. }
  1319. }
  1320. connect_button->set_text(TTR("Connect..."));
  1321. connect_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
  1322. connect_button->set_disabled(true);
  1323. }
  1324. ConnectionsDock::ConnectionsDock() {
  1325. set_name(TTR("Signals"));
  1326. VBoxContainer *vbc = this;
  1327. search_box = memnew(LineEdit);
  1328. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1329. search_box->set_placeholder(TTR("Filter Signals"));
  1330. search_box->set_clear_button_enabled(true);
  1331. search_box->connect(SceneStringName(text_changed), callable_mp(this, &ConnectionsDock::_filter_changed));
  1332. vbc->add_child(search_box);
  1333. tree = memnew(ConnectionsDockTree);
  1334. tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1335. tree->set_columns(1);
  1336. tree->set_select_mode(Tree::SELECT_ROW);
  1337. tree->set_hide_root(true);
  1338. tree->set_column_clip_content(0, true);
  1339. vbc->add_child(tree);
  1340. tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1341. tree->set_allow_rmb_select(true);
  1342. connect_button = memnew(Button);
  1343. HBoxContainer *hb = memnew(HBoxContainer);
  1344. vbc->add_child(hb);
  1345. hb->add_spacer();
  1346. hb->add_child(connect_button);
  1347. connect_button->connect(SceneStringName(pressed), callable_mp(this, &ConnectionsDock::_connect_pressed));
  1348. connect_dialog = memnew(ConnectDialog);
  1349. connect_dialog->set_process_shortcut_input(true);
  1350. add_child(connect_dialog);
  1351. disconnect_all_dialog = memnew(ConfirmationDialog);
  1352. add_child(disconnect_all_dialog);
  1353. disconnect_all_dialog->connect(SceneStringName(confirmed), callable_mp(this, &ConnectionsDock::_disconnect_all));
  1354. disconnect_all_dialog->set_text(TTR("Are you sure you want to remove all connections from this signal?"));
  1355. class_menu = memnew(PopupMenu);
  1356. class_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ConnectionsDock::_handle_class_menu_option));
  1357. class_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_class_menu_about_to_popup));
  1358. class_menu->add_item(TTR("Open Documentation"), CLASS_MENU_OPEN_DOCS);
  1359. add_child(class_menu);
  1360. signal_menu = memnew(PopupMenu);
  1361. signal_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ConnectionsDock::_handle_signal_menu_option));
  1362. signal_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_signal_menu_about_to_popup));
  1363. signal_menu->add_item(TTR("Connect..."), SIGNAL_MENU_CONNECT);
  1364. signal_menu->add_item(TTR("Disconnect All"), SIGNAL_MENU_DISCONNECT_ALL);
  1365. signal_menu->add_item(TTR("Copy Name"), SIGNAL_MENU_COPY_NAME);
  1366. signal_menu->add_separator();
  1367. signal_menu->add_item(TTR("Open Documentation"), SIGNAL_MENU_OPEN_DOCS);
  1368. add_child(signal_menu);
  1369. slot_menu = memnew(PopupMenu);
  1370. slot_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ConnectionsDock::_handle_slot_menu_option));
  1371. slot_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_slot_menu_about_to_popup));
  1372. slot_menu->add_item(TTR("Edit..."), SLOT_MENU_EDIT);
  1373. slot_menu->add_item(TTR("Go to Method"), SLOT_MENU_GO_TO_METHOD);
  1374. slot_menu->add_shortcut(ED_SHORTCUT("connections_editor/disconnect", TTR("Disconnect"), Key::KEY_DELETE), SLOT_MENU_DISCONNECT);
  1375. add_child(slot_menu);
  1376. connect_dialog->connect("connected", callable_mp(this, &ConnectionsDock::_make_or_edit_connection));
  1377. tree->connect(SceneStringName(item_selected), callable_mp(this, &ConnectionsDock::_tree_item_selected));
  1378. tree->connect("item_activated", callable_mp(this, &ConnectionsDock::_tree_item_activated));
  1379. tree->connect(SceneStringName(gui_input), callable_mp(this, &ConnectionsDock::_tree_gui_input));
  1380. add_theme_constant_override("separation", 3 * EDSCALE);
  1381. }
  1382. ConnectionsDock::~ConnectionsDock() {
  1383. }