connections_dialog.cpp 56 KB

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