connections_dialog.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /*************************************************************************/
  2. /* connections_dialog.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "editor/doc_tools.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_scale.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_undo_redo_manager.h"
  36. #include "editor/scene_tree_dock.h"
  37. #include "plugins/script_editor_plugin.h"
  38. #include "scene/resources/packed_scene.h"
  39. static Node *_find_first_script(Node *p_root, Node *p_node) {
  40. if (p_node != p_root && p_node->get_owner() != p_root) {
  41. return nullptr;
  42. }
  43. if (!p_node->get_script().is_null()) {
  44. return p_node;
  45. }
  46. for (int i = 0; i < p_node->get_child_count(); i++) {
  47. Node *ret = _find_first_script(p_root, p_node->get_child(i));
  48. if (ret) {
  49. return ret;
  50. }
  51. }
  52. return nullptr;
  53. }
  54. class ConnectDialogBinds : public Object {
  55. GDCLASS(ConnectDialogBinds, Object);
  56. public:
  57. Vector<Variant> params;
  58. bool _set(const StringName &p_name, const Variant &p_value) {
  59. String name = p_name;
  60. if (name.begins_with("bind/argument_")) {
  61. int which = name.get_slice("_", 1).to_int() - 1;
  62. ERR_FAIL_INDEX_V(which, params.size(), false);
  63. params.write[which] = p_value;
  64. } else {
  65. return false;
  66. }
  67. return true;
  68. }
  69. bool _get(const StringName &p_name, Variant &r_ret) const {
  70. String name = p_name;
  71. if (name.begins_with("bind/argument_")) {
  72. int which = name.get_slice("_", 1).to_int() - 1;
  73. ERR_FAIL_INDEX_V(which, params.size(), false);
  74. r_ret = params[which];
  75. } else {
  76. return false;
  77. }
  78. return true;
  79. }
  80. void _get_property_list(List<PropertyInfo> *p_list) const {
  81. for (int i = 0; i < params.size(); i++) {
  82. p_list->push_back(PropertyInfo(params[i].get_type(), "bind/argument_" + itos(i + 1)));
  83. }
  84. }
  85. void notify_changed() {
  86. notify_property_list_changed();
  87. }
  88. ConnectDialogBinds() {
  89. }
  90. };
  91. /*
  92. * Signal automatically called by parent dialog.
  93. */
  94. void ConnectDialog::ok_pressed() {
  95. String method_name = dst_method->get_text();
  96. if (method_name.is_empty()) {
  97. error->set_text(TTR("Method in target node must be specified."));
  98. error->popup_centered();
  99. return;
  100. }
  101. if (!method_name.strip_edges().is_valid_identifier()) {
  102. error->set_text(TTR("Method name must be a valid identifier."));
  103. error->popup_centered();
  104. return;
  105. }
  106. Node *target = tree->get_selected();
  107. if (!target) {
  108. return; // Nothing selected in the tree, not an error.
  109. }
  110. if (target->get_script().is_null()) {
  111. if (!target->has_method(method_name)) {
  112. error->set_text(TTR("Target method not found. Specify a valid method or attach a script to the target node."));
  113. error->popup_centered();
  114. return;
  115. }
  116. }
  117. emit_signal(SNAME("connected"));
  118. hide();
  119. }
  120. void ConnectDialog::_cancel_pressed() {
  121. hide();
  122. }
  123. void ConnectDialog::_item_activated() {
  124. _ok_pressed(); // From AcceptDialog.
  125. }
  126. void ConnectDialog::_text_submitted(const String &p_text) {
  127. _ok_pressed(); // From AcceptDialog.
  128. }
  129. /*
  130. * Called each time a target node is selected within the target node tree.
  131. */
  132. void ConnectDialog::_tree_node_selected() {
  133. Node *current = tree->get_selected();
  134. if (!current) {
  135. return;
  136. }
  137. dst_path = source->get_path_to(current);
  138. if (!edit_mode) {
  139. set_dst_method(generate_method_callback_name(source, signal, current));
  140. }
  141. _update_ok_enabled();
  142. }
  143. void ConnectDialog::_unbind_count_changed(double p_count) {
  144. for (Control *control : bind_controls) {
  145. BaseButton *b = Object::cast_to<BaseButton>(control);
  146. if (b) {
  147. b->set_disabled(p_count > 0);
  148. }
  149. EditorInspector *e = Object::cast_to<EditorInspector>(control);
  150. if (e) {
  151. e->set_read_only(p_count > 0);
  152. }
  153. }
  154. }
  155. /*
  156. * Adds a new parameter bind to connection.
  157. */
  158. void ConnectDialog::_add_bind() {
  159. Variant::Type type = (Variant::Type)type_list->get_item_id(type_list->get_selected());
  160. Variant value;
  161. Callable::CallError err;
  162. Variant::construct(type, value, nullptr, 0, err);
  163. cdbinds->params.push_back(value);
  164. cdbinds->notify_changed();
  165. }
  166. /*
  167. * Remove parameter bind from connection.
  168. */
  169. void ConnectDialog::_remove_bind() {
  170. String st = bind_editor->get_selected_path();
  171. if (st.is_empty()) {
  172. return;
  173. }
  174. int idx = st.get_slice("/", 1).to_int() - 1;
  175. ERR_FAIL_INDEX(idx, cdbinds->params.size());
  176. cdbinds->params.remove_at(idx);
  177. cdbinds->notify_changed();
  178. }
  179. /*
  180. * Automatically generates a name for the callback method.
  181. */
  182. StringName ConnectDialog::generate_method_callback_name(Node *p_source, String p_signal_name, Node *p_target) {
  183. String node_name = p_source->get_name();
  184. for (int i = 0; i < node_name.length(); i++) { // TODO: Regex filter may be cleaner.
  185. char32_t c = node_name[i];
  186. if (!is_ascii_identifier_char(c)) {
  187. if (c == ' ') {
  188. // Replace spaces with underlines.
  189. c = '_';
  190. } else {
  191. // Remove any other characters.
  192. node_name.remove_at(i);
  193. i--;
  194. continue;
  195. }
  196. }
  197. node_name[i] = c;
  198. }
  199. Dictionary subst;
  200. subst["NodeName"] = node_name.to_pascal_case();
  201. subst["nodeName"] = node_name.to_camel_case();
  202. subst["node_name"] = node_name.to_snake_case();
  203. subst["SignalName"] = p_signal_name.to_pascal_case();
  204. subst["signalName"] = p_signal_name.to_camel_case();
  205. subst["signal_name"] = p_signal_name.to_snake_case();
  206. String dst_method;
  207. if (p_source == p_target) {
  208. dst_method = String(EDITOR_GET("interface/editors/default_signal_callback_to_self_name")).format(subst);
  209. } else {
  210. dst_method = String(EDITOR_GET("interface/editors/default_signal_callback_name")).format(subst);
  211. }
  212. return dst_method;
  213. }
  214. /*
  215. * Enables or disables the connect button. The connect button is enabled if a
  216. * node is selected and valid in the selected mode.
  217. */
  218. void ConnectDialog::_update_ok_enabled() {
  219. Node *target = tree->get_selected();
  220. if (target == nullptr) {
  221. get_ok_button()->set_disabled(true);
  222. return;
  223. }
  224. if (!advanced->is_pressed() && target->get_script().is_null()) {
  225. get_ok_button()->set_disabled(true);
  226. return;
  227. }
  228. get_ok_button()->set_disabled(false);
  229. }
  230. void ConnectDialog::_notification(int p_what) {
  231. switch (p_what) {
  232. case NOTIFICATION_ENTER_TREE: {
  233. bind_editor->edit(cdbinds);
  234. [[fallthrough]];
  235. }
  236. case NOTIFICATION_THEME_CHANGED: {
  237. for (int i = 0; i < type_list->get_item_count(); i++) {
  238. String type_name = Variant::get_type_name((Variant::Type)type_list->get_item_id(i));
  239. type_list->set_item_icon(i, get_theme_icon(type_name, SNAME("EditorIcons")));
  240. }
  241. Ref<StyleBox> style = get_theme_stylebox("normal", "LineEdit")->duplicate();
  242. if (style.is_valid()) {
  243. style->set_default_margin(SIDE_TOP, style->get_default_margin(SIDE_TOP) + 1.0);
  244. from_signal->add_theme_style_override("normal", style);
  245. }
  246. } break;
  247. }
  248. }
  249. void ConnectDialog::_bind_methods() {
  250. ClassDB::bind_method("_cancel", &ConnectDialog::_cancel_pressed);
  251. ClassDB::bind_method("_update_ok_enabled", &ConnectDialog::_update_ok_enabled);
  252. ADD_SIGNAL(MethodInfo("connected"));
  253. }
  254. Node *ConnectDialog::get_source() const {
  255. return source;
  256. }
  257. StringName ConnectDialog::get_signal_name() const {
  258. return signal;
  259. }
  260. NodePath ConnectDialog::get_dst_path() const {
  261. return dst_path;
  262. }
  263. void ConnectDialog::set_dst_node(Node *p_node) {
  264. tree->set_selected(p_node);
  265. }
  266. StringName ConnectDialog::get_dst_method_name() const {
  267. String txt = dst_method->get_text();
  268. if (txt.contains("(")) {
  269. txt = txt.left(txt.find("(")).strip_edges();
  270. }
  271. return txt;
  272. }
  273. void ConnectDialog::set_dst_method(const StringName &p_method) {
  274. dst_method->set_text(p_method);
  275. }
  276. int ConnectDialog::get_unbinds() const {
  277. return int(unbind_count->get_value());
  278. }
  279. Vector<Variant> ConnectDialog::get_binds() const {
  280. return cdbinds->params;
  281. }
  282. bool ConnectDialog::get_deferred() const {
  283. return deferred->is_pressed();
  284. }
  285. bool ConnectDialog::get_one_shot() const {
  286. return one_shot->is_pressed();
  287. }
  288. /*
  289. * Returns true if ConnectDialog is being used to edit an existing connection.
  290. */
  291. bool ConnectDialog::is_editing() const {
  292. return edit_mode;
  293. }
  294. /*
  295. * Initialize ConnectDialog and populate fields with expected data.
  296. * If creating a connection from scratch, sensible defaults are used.
  297. * If editing an existing connection, previous data is retained.
  298. */
  299. void ConnectDialog::init(ConnectionData p_cd, bool p_edit) {
  300. set_hide_on_ok(false);
  301. source = static_cast<Node *>(p_cd.source);
  302. signal = p_cd.signal;
  303. tree->set_selected(nullptr);
  304. tree->set_marked(source, true);
  305. if (p_cd.target) {
  306. set_dst_node(static_cast<Node *>(p_cd.target));
  307. set_dst_method(p_cd.method);
  308. }
  309. _update_ok_enabled();
  310. bool b_deferred = (p_cd.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED;
  311. bool b_oneshot = (p_cd.flags & CONNECT_ONE_SHOT) == CONNECT_ONE_SHOT;
  312. deferred->set_pressed(b_deferred);
  313. one_shot->set_pressed(b_oneshot);
  314. MethodInfo r_signal;
  315. Ref<Script> source_script = source->get_script();
  316. if (source_script.is_valid() && source_script->has_script_signal(signal)) {
  317. List<MethodInfo> signals;
  318. source_script->get_script_signal_list(&signals);
  319. for (MethodInfo &mi : signals) {
  320. if (mi.name == signal) {
  321. r_signal = mi;
  322. break;
  323. }
  324. }
  325. } else {
  326. ClassDB::get_signal(source->get_class(), signal, &r_signal);
  327. }
  328. unbind_count->set_max(r_signal.arguments.size());
  329. unbind_count->set_value(p_cd.unbinds);
  330. _unbind_count_changed(p_cd.unbinds);
  331. cdbinds->params.clear();
  332. cdbinds->params = p_cd.binds;
  333. cdbinds->notify_changed();
  334. edit_mode = p_edit;
  335. }
  336. void ConnectDialog::popup_dialog(const String &p_for_signal) {
  337. from_signal->set_text(p_for_signal);
  338. error_label->add_theme_color_override("font_color", error_label->get_theme_color(SNAME("error_color"), SNAME("Editor")));
  339. if (!advanced->is_pressed()) {
  340. error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
  341. }
  342. if (first_popup) {
  343. first_popup = false;
  344. _advanced_pressed();
  345. }
  346. popup_centered();
  347. }
  348. void ConnectDialog::_advanced_pressed() {
  349. if (advanced->is_pressed()) {
  350. set_min_size(Size2(900, 500) * EDSCALE);
  351. connect_to_label->set_text(TTR("Connect to Node:"));
  352. tree->set_connect_to_script_mode(false);
  353. vbc_right->show();
  354. error_label->hide();
  355. } else {
  356. set_min_size(Size2(600, 500) * EDSCALE);
  357. reset_size();
  358. connect_to_label->set_text(TTR("Connect to Script:"));
  359. tree->set_connect_to_script_mode(true);
  360. vbc_right->hide();
  361. error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
  362. }
  363. _update_ok_enabled();
  364. EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "use_advanced_connections", advanced->is_pressed());
  365. popup_centered();
  366. }
  367. ConnectDialog::ConnectDialog() {
  368. set_min_size(Size2(600, 500) * EDSCALE);
  369. VBoxContainer *vbc = memnew(VBoxContainer);
  370. add_child(vbc);
  371. HBoxContainer *main_hb = memnew(HBoxContainer);
  372. vbc->add_child(main_hb);
  373. main_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  374. VBoxContainer *vbc_left = memnew(VBoxContainer);
  375. main_hb->add_child(vbc_left);
  376. vbc_left->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  377. from_signal = memnew(LineEdit);
  378. from_signal->set_editable(false);
  379. vbc_left->add_margin_child(TTR("From Signal:"), from_signal);
  380. tree = memnew(SceneTreeEditor(false));
  381. tree->set_connecting_signal(true);
  382. tree->set_show_enabled_subscene(true);
  383. tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ConnectDialog::_item_activated));
  384. tree->connect("node_selected", callable_mp(this, &ConnectDialog::_tree_node_selected));
  385. tree->set_connect_to_script_mode(true);
  386. Node *mc = vbc_left->add_margin_child(TTR("Connect to Script:"), tree, true);
  387. connect_to_label = Object::cast_to<Label>(vbc_left->get_child(mc->get_index() - 1));
  388. error_label = memnew(Label);
  389. error_label->set_text(TTR("Scene does not contain any script."));
  390. vbc_left->add_child(error_label);
  391. error_label->hide();
  392. vbc_right = memnew(VBoxContainer);
  393. main_hb->add_child(vbc_right);
  394. vbc_right->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  395. vbc_right->hide();
  396. HBoxContainer *add_bind_hb = memnew(HBoxContainer);
  397. type_list = memnew(OptionButton);
  398. type_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  399. add_bind_hb->add_child(type_list);
  400. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  401. if (i == Variant::NIL || i == Variant::OBJECT || i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
  402. // These types can't be constructed or serialized properly, so skip them.
  403. continue;
  404. }
  405. type_list->add_item(Variant::get_type_name(Variant::Type(i)), i);
  406. }
  407. bind_controls.push_back(type_list);
  408. Button *add_bind = memnew(Button);
  409. add_bind->set_text(TTR("Add"));
  410. add_bind_hb->add_child(add_bind);
  411. add_bind->connect("pressed", callable_mp(this, &ConnectDialog::_add_bind));
  412. bind_controls.push_back(add_bind);
  413. Button *del_bind = memnew(Button);
  414. del_bind->set_text(TTR("Remove"));
  415. add_bind_hb->add_child(del_bind);
  416. del_bind->connect("pressed", callable_mp(this, &ConnectDialog::_remove_bind));
  417. bind_controls.push_back(del_bind);
  418. vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);
  419. bind_editor = memnew(EditorInspector);
  420. bind_controls.push_back(bind_editor);
  421. vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
  422. unbind_count = memnew(SpinBox);
  423. unbind_count->set_tooltip_text(TTR("Allows to drop arguments sent by signal emitter."));
  424. unbind_count->connect("value_changed", callable_mp(this, &ConnectDialog::_unbind_count_changed));
  425. vbc_right->add_margin_child(TTR("Unbind Signal Arguments:"), unbind_count);
  426. dst_method = memnew(LineEdit);
  427. dst_method->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  428. dst_method->connect("text_submitted", callable_mp(this, &ConnectDialog::_text_submitted));
  429. vbc_left->add_margin_child(TTR("Receiver Method:"), dst_method);
  430. advanced = memnew(CheckButton);
  431. vbc_left->add_child(advanced);
  432. advanced->set_text(TTR("Advanced"));
  433. advanced->set_h_size_flags(Control::SIZE_SHRINK_BEGIN | Control::SIZE_EXPAND);
  434. advanced->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "use_advanced_connections", false));
  435. advanced->connect("pressed", callable_mp(this, &ConnectDialog::_advanced_pressed));
  436. HBoxContainer *hbox = memnew(HBoxContainer);
  437. vbc_right->add_child(hbox);
  438. deferred = memnew(CheckBox);
  439. deferred->set_h_size_flags(0);
  440. deferred->set_text(TTR("Deferred"));
  441. deferred->set_tooltip_text(TTR("Defers the signal, storing it in a queue and only firing it at idle time."));
  442. hbox->add_child(deferred);
  443. one_shot = memnew(CheckBox);
  444. one_shot->set_h_size_flags(0);
  445. one_shot->set_text(TTR("One Shot"));
  446. one_shot->set_tooltip_text(TTR("Disconnects the signal after its first emission."));
  447. hbox->add_child(one_shot);
  448. cdbinds = memnew(ConnectDialogBinds);
  449. error = memnew(AcceptDialog);
  450. add_child(error);
  451. error->set_title(TTR("Cannot connect signal"));
  452. error->set_ok_button_text(TTR("Close"));
  453. set_ok_button_text(TTR("Connect"));
  454. }
  455. ConnectDialog::~ConnectDialog() {
  456. memdelete(cdbinds);
  457. }
  458. //////////////////////////////////////////
  459. // Originally copied and adapted from EditorProperty, try to keep style in sync.
  460. Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
  461. EditorHelpBit *help_bit = memnew(EditorHelpBit);
  462. help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
  463. // p_text is expected to be something like this:
  464. // "gui_input::(event: InputEvent)::<Signal description>"
  465. // with the latter being possibly empty.
  466. PackedStringArray slices = p_text.split("::", false);
  467. if (slices.size() < 2) {
  468. // Shouldn't happen here, but just in case pass the text along.
  469. help_bit->set_text(p_text);
  470. return help_bit;
  471. }
  472. String text = TTR("Signal:") + " [u][b]" + slices[0] + "[/b][/u]";
  473. text += slices[1].strip_edges() + "\n";
  474. if (slices.size() > 2) {
  475. text += slices[2].strip_edges();
  476. } else {
  477. text += "[i]" + TTR("No description.") + "[/i]";
  478. }
  479. help_bit->set_text(text);
  480. return help_bit;
  481. }
  482. struct _ConnectionsDockMethodInfoSort {
  483. _FORCE_INLINE_ bool operator()(const MethodInfo &a, const MethodInfo &b) const {
  484. return a.name < b.name;
  485. }
  486. };
  487. void ConnectionsDock::_filter_changed(const String &p_text) {
  488. update_tree();
  489. }
  490. /*
  491. * Post-ConnectDialog callback for creating/editing connections.
  492. * Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
  493. */
  494. void ConnectionsDock::_make_or_edit_connection() {
  495. TreeItem *it = tree->get_selected();
  496. ERR_FAIL_COND(!it);
  497. NodePath dst_path = connect_dialog->get_dst_path();
  498. Node *target = selected_node->get_node(dst_path);
  499. ERR_FAIL_COND(!target);
  500. ConnectDialog::ConnectionData cd;
  501. cd.source = connect_dialog->get_source();
  502. cd.target = target;
  503. cd.signal = connect_dialog->get_signal_name();
  504. cd.method = connect_dialog->get_dst_method_name();
  505. cd.unbinds = connect_dialog->get_unbinds();
  506. if (cd.unbinds == 0) {
  507. cd.binds = connect_dialog->get_binds();
  508. }
  509. bool b_deferred = connect_dialog->get_deferred();
  510. bool b_oneshot = connect_dialog->get_one_shot();
  511. cd.flags = CONNECT_PERSIST | (b_deferred ? CONNECT_DEFERRED : 0) | (b_oneshot ? CONNECT_ONE_SHOT : 0);
  512. // Conditions to add function: must have a script and must not have the method already
  513. // (in the class, the script itself, or inherited).
  514. bool add_script_function = false;
  515. Ref<Script> scr = target->get_script();
  516. if (!scr.is_null() && !ClassDB::has_method(target->get_class(), cd.method)) {
  517. // There is a chance that the method is inherited from another script.
  518. bool found_inherited_function = false;
  519. Ref<Script> inherited_scr = scr->get_base_script();
  520. while (!inherited_scr.is_null()) {
  521. int line = inherited_scr->get_language()->find_function(cd.method, inherited_scr->get_source_code());
  522. if (line != -1) {
  523. found_inherited_function = true;
  524. break;
  525. }
  526. inherited_scr = inherited_scr->get_base_script();
  527. }
  528. add_script_function = !found_inherited_function;
  529. }
  530. PackedStringArray script_function_args;
  531. if (add_script_function) {
  532. // Pick up args here before "it" is deleted by update_tree.
  533. script_function_args = it->get_metadata(0).operator Dictionary()["args"];
  534. script_function_args.resize(script_function_args.size() - cd.unbinds);
  535. for (int i = 0; i < cd.binds.size(); i++) {
  536. script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cd.binds[i].get_type()));
  537. }
  538. }
  539. if (connect_dialog->is_editing()) {
  540. _disconnect(*it);
  541. _connect(cd);
  542. } else {
  543. _connect(cd);
  544. }
  545. // IMPORTANT NOTE: _disconnect and _connect cause an update_tree, which will delete the object "it" is pointing to.
  546. it = nullptr;
  547. if (add_script_function) {
  548. EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), target, cd.method, script_function_args);
  549. hide();
  550. }
  551. update_tree();
  552. }
  553. /*
  554. * Creates single connection w/ undo-redo functionality.
  555. */
  556. void ConnectionsDock::_connect(ConnectDialog::ConnectionData p_cd) {
  557. Node *source = Object::cast_to<Node>(p_cd.source);
  558. Node *target = Object::cast_to<Node>(p_cd.target);
  559. if (!source || !target) {
  560. return;
  561. }
  562. Callable callable = p_cd.get_callable();
  563. Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
  564. undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(p_cd.signal), String(p_cd.method)));
  565. undo_redo->add_do_method(source, "connect", p_cd.signal, callable, p_cd.flags);
  566. undo_redo->add_undo_method(source, "disconnect", p_cd.signal, callable);
  567. undo_redo->add_do_method(this, "update_tree");
  568. undo_redo->add_undo_method(this, "update_tree");
  569. undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
  570. undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  571. undo_redo->commit_action();
  572. }
  573. /*
  574. * Break single connection w/ undo-redo functionality.
  575. */
  576. void ConnectionsDock::_disconnect(TreeItem &p_item) {
  577. Connection connection = p_item.get_metadata(0);
  578. ConnectDialog::ConnectionData cd = connection;
  579. ERR_FAIL_COND(cd.source != selected_node); // Shouldn't happen but... Bugcheck.
  580. Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
  581. undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), cd.signal, cd.method));
  582. Callable callable = cd.get_callable();
  583. undo_redo->add_do_method(selected_node, "disconnect", cd.signal, callable);
  584. undo_redo->add_undo_method(selected_node, "connect", cd.signal, callable, cd.binds, cd.flags);
  585. undo_redo->add_do_method(this, "update_tree");
  586. undo_redo->add_undo_method(this, "update_tree");
  587. undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
  588. undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  589. undo_redo->commit_action();
  590. }
  591. /*
  592. * Break all connections of currently selected signal.
  593. * Can undo-redo as a single action.
  594. */
  595. void ConnectionsDock::_disconnect_all() {
  596. TreeItem *item = tree->get_selected();
  597. if (!_is_item_signal(*item)) {
  598. return;
  599. }
  600. TreeItem *child = item->get_first_child();
  601. String signal_name = item->get_metadata(0).operator Dictionary()["name"];
  602. Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
  603. undo_redo->create_action(vformat(TTR("Disconnect all from signal: '%s'"), signal_name));
  604. while (child) {
  605. Connection connection = child->get_metadata(0);
  606. if (!_is_connection_inherited(connection)) {
  607. ConnectDialog::ConnectionData cd = connection;
  608. undo_redo->add_do_method(selected_node, "disconnect", cd.signal, cd.get_callable());
  609. undo_redo->add_undo_method(selected_node, "connect", cd.signal, cd.get_callable(), cd.binds, cd.flags);
  610. }
  611. child = child->get_next();
  612. }
  613. undo_redo->add_do_method(this, "update_tree");
  614. undo_redo->add_undo_method(this, "update_tree");
  615. undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  616. undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
  617. undo_redo->commit_action();
  618. }
  619. void ConnectionsDock::_tree_item_selected() {
  620. TreeItem *item = tree->get_selected();
  621. if (!item) { // Unlikely. Disable button just in case.
  622. connect_button->set_text(TTR("Connect..."));
  623. connect_button->set_disabled(true);
  624. } else if (_is_item_signal(*item)) {
  625. connect_button->set_text(TTR("Connect..."));
  626. connect_button->set_disabled(false);
  627. } else {
  628. connect_button->set_text(TTR("Disconnect"));
  629. connect_button->set_disabled(false);
  630. }
  631. }
  632. void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click.
  633. TreeItem *item = tree->get_selected();
  634. if (!item) {
  635. return;
  636. }
  637. if (_is_item_signal(*item)) {
  638. _open_connection_dialog(*item);
  639. } else {
  640. _go_to_script(*item);
  641. }
  642. }
  643. bool ConnectionsDock::_is_item_signal(TreeItem &p_item) {
  644. return (p_item.get_parent() == tree->get_root() || p_item.get_parent()->get_parent() == tree->get_root());
  645. }
  646. bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
  647. Node *scene_root = EditorNode::get_singleton()->get_edited_scene();
  648. Ref<PackedScene> scn = ResourceLoader::load(scene_root->get_scene_file_path());
  649. ERR_FAIL_NULL_V(scn, false);
  650. Ref<SceneState> state = scn->get_state();
  651. ERR_FAIL_NULL_V(state, false);
  652. Node *source = Object::cast_to<Node>(p_connection.signal.get_object());
  653. Node *target = Object::cast_to<Node>(p_connection.callable.get_object());
  654. const NodePath source_path = scene_root->get_path_to(source);
  655. const NodePath target_path = scene_root->get_path_to(target);
  656. const StringName signal_name = p_connection.signal.get_name();
  657. const StringName method_name = p_connection.callable.get_method();
  658. // If it cannot be found in PackedScene, this connection was inherited.
  659. return !state->has_connection(source_path, signal_name, target_path, method_name, true);
  660. }
  661. /*
  662. * Open connection dialog with TreeItem data to CREATE a brand-new connection.
  663. */
  664. void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
  665. String signal_name = p_item.get_metadata(0).operator Dictionary()["name"];
  666. const String &signal_name_ref = signal_name;
  667. Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;
  668. if (!dst_node || dst_node->get_script().is_null()) {
  669. dst_node = _find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root());
  670. }
  671. ConnectDialog::ConnectionData cd;
  672. cd.source = selected_node;
  673. cd.signal = StringName(signal_name_ref);
  674. cd.target = dst_node;
  675. cd.method = ConnectDialog::generate_method_callback_name(cd.source, signal_name, cd.target);
  676. connect_dialog->popup_dialog(signal_name_ref);
  677. connect_dialog->init(cd);
  678. connect_dialog->set_title(TTR("Connect a Signal to a Method"));
  679. }
  680. /*
  681. * Open connection dialog with Connection data to EDIT an existing connection.
  682. */
  683. void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData p_cd) {
  684. Node *src = Object::cast_to<Node>(p_cd.source);
  685. Node *dst = Object::cast_to<Node>(p_cd.target);
  686. if (src && dst) {
  687. const String &signal_name_ref = p_cd.signal;
  688. connect_dialog->set_title(TTR("Edit Connection:") + p_cd.signal);
  689. connect_dialog->popup_dialog(signal_name_ref);
  690. connect_dialog->init(p_cd, true);
  691. }
  692. }
  693. /*
  694. * Open slot method location in script editor.
  695. */
  696. void ConnectionsDock::_go_to_script(TreeItem &p_item) {
  697. if (_is_item_signal(p_item)) {
  698. return;
  699. }
  700. Connection connection = p_item.get_metadata(0);
  701. ConnectDialog::ConnectionData cd = connection;
  702. ERR_FAIL_COND(cd.source != selected_node); // Shouldn't happen but... bugcheck.
  703. if (!cd.target) {
  704. return;
  705. }
  706. Ref<Script> scr = cd.target->get_script();
  707. if (scr.is_null()) {
  708. return;
  709. }
  710. if (scr.is_valid() && ScriptEditor::get_singleton()->script_goto_method(scr, cd.method)) {
  711. EditorNode::get_singleton()->editor_select(EditorNode::EDITOR_SCRIPT);
  712. }
  713. }
  714. void ConnectionsDock::_handle_signal_menu_option(int p_option) {
  715. TreeItem *item = tree->get_selected();
  716. if (!item) {
  717. return;
  718. }
  719. switch (p_option) {
  720. case CONNECT: {
  721. _open_connection_dialog(*item);
  722. } break;
  723. case DISCONNECT_ALL: {
  724. StringName signal_name = item->get_metadata(0).operator Dictionary()["name"];
  725. disconnect_all_dialog->set_text(vformat(TTR("Are you sure you want to remove all connections from the \"%s\" signal?"), signal_name));
  726. disconnect_all_dialog->popup_centered();
  727. } break;
  728. case COPY_NAME: {
  729. DisplayServer::get_singleton()->clipboard_set(item->get_metadata(0).operator Dictionary()["name"]);
  730. } break;
  731. }
  732. }
  733. void ConnectionsDock::_signal_menu_about_to_popup() {
  734. TreeItem *signal_item = tree->get_selected();
  735. bool disable_disconnect_all = true;
  736. for (int i = 0; i < signal_item->get_child_count(); i++) {
  737. if (!signal_item->get_child(i)->has_meta("_inherited_connection")) {
  738. disable_disconnect_all = false;
  739. }
  740. }
  741. signal_menu->set_item_disabled(slot_menu->get_item_index(DISCONNECT_ALL), disable_disconnect_all);
  742. }
  743. void ConnectionsDock::_handle_slot_menu_option(int p_option) {
  744. TreeItem *item = tree->get_selected();
  745. if (!item) {
  746. return;
  747. }
  748. switch (p_option) {
  749. case EDIT: {
  750. Connection connection = item->get_metadata(0);
  751. _open_connection_dialog(connection);
  752. } break;
  753. case GO_TO_SCRIPT: {
  754. _go_to_script(*item);
  755. } break;
  756. case DISCONNECT: {
  757. _disconnect(*item);
  758. update_tree();
  759. } break;
  760. }
  761. }
  762. void ConnectionsDock::_slot_menu_about_to_popup() {
  763. bool connection_is_inherited = tree->get_selected()->has_meta("_inherited_connection");
  764. slot_menu->set_item_disabled(slot_menu->get_item_index(EDIT), connection_is_inherited);
  765. slot_menu->set_item_disabled(slot_menu->get_item_index(DISCONNECT), connection_is_inherited);
  766. }
  767. void ConnectionsDock::_rmb_pressed(Vector2 p_position, MouseButton p_button) {
  768. if (p_button != MouseButton::RIGHT) {
  769. return;
  770. }
  771. TreeItem *item = tree->get_selected();
  772. if (!item) {
  773. return;
  774. }
  775. Vector2 screen_position = tree->get_screen_position() + p_position;
  776. if (_is_item_signal(*item)) {
  777. signal_menu->set_position(screen_position);
  778. signal_menu->reset_size();
  779. signal_menu->popup();
  780. } else {
  781. slot_menu->set_position(screen_position);
  782. slot_menu->reset_size();
  783. slot_menu->popup();
  784. }
  785. }
  786. void ConnectionsDock::_close() {
  787. hide();
  788. }
  789. void ConnectionsDock::_connect_pressed() {
  790. TreeItem *item = tree->get_selected();
  791. if (!item) {
  792. connect_button->set_disabled(true);
  793. return;
  794. }
  795. if (_is_item_signal(*item)) {
  796. _open_connection_dialog(*item);
  797. } else {
  798. _disconnect(*item);
  799. update_tree();
  800. }
  801. }
  802. void ConnectionsDock::_notification(int p_what) {
  803. switch (p_what) {
  804. case NOTIFICATION_ENTER_TREE:
  805. case NOTIFICATION_THEME_CHANGED: {
  806. search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  807. } break;
  808. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  809. update_tree();
  810. } break;
  811. }
  812. }
  813. void ConnectionsDock::_bind_methods() {
  814. ClassDB::bind_method("update_tree", &ConnectionsDock::update_tree);
  815. }
  816. void ConnectionsDock::set_node(Node *p_node) {
  817. selected_node = p_node;
  818. update_tree();
  819. }
  820. void ConnectionsDock::update_tree() {
  821. tree->clear();
  822. if (!selected_node) {
  823. return;
  824. }
  825. TreeItem *root = tree->create_item();
  826. List<MethodInfo> node_signals;
  827. selected_node->get_signal_list(&node_signals);
  828. bool did_script = false;
  829. StringName base = selected_node->get_class();
  830. while (base) {
  831. List<MethodInfo> node_signals2;
  832. Ref<Texture2D> icon;
  833. String name;
  834. if (!did_script) {
  835. // Get script signals (including signals from any base scripts).
  836. Ref<Script> scr = selected_node->get_script();
  837. if (scr.is_valid()) {
  838. scr->get_script_signal_list(&node_signals2);
  839. if (scr->get_path().is_resource_file()) {
  840. name = scr->get_path().get_file();
  841. } else {
  842. name = scr->get_class();
  843. }
  844. if (has_theme_icon(scr->get_class(), SNAME("EditorIcons"))) {
  845. icon = get_theme_icon(scr->get_class(), SNAME("EditorIcons"));
  846. }
  847. }
  848. } else {
  849. ClassDB::get_signal_list(base, &node_signals2, true);
  850. if (has_theme_icon(base, SNAME("EditorIcons"))) {
  851. icon = get_theme_icon(base, SNAME("EditorIcons"));
  852. }
  853. name = base;
  854. }
  855. if (icon.is_null()) {
  856. icon = get_theme_icon(SNAME("Object"), SNAME("EditorIcons"));
  857. }
  858. TreeItem *section_item = nullptr;
  859. // Create subsections.
  860. if (node_signals2.size()) {
  861. section_item = tree->create_item(root);
  862. section_item->set_text(0, name);
  863. section_item->set_icon(0, icon);
  864. section_item->set_selectable(0, false);
  865. section_item->set_editable(0, false);
  866. section_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
  867. node_signals2.sort();
  868. }
  869. for (MethodInfo &mi : node_signals2) {
  870. StringName signal_name = mi.name;
  871. String signaldesc = "(";
  872. PackedStringArray argnames;
  873. String filter_text = search_box->get_text();
  874. if (!filter_text.is_subsequence_ofn(signal_name)) {
  875. continue;
  876. }
  877. if (mi.arguments.size()) {
  878. for (int i = 0; i < mi.arguments.size(); i++) {
  879. PropertyInfo &pi = mi.arguments[i];
  880. if (i > 0) {
  881. signaldesc += ", ";
  882. }
  883. String tname = "var";
  884. if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
  885. tname = pi.class_name.operator String();
  886. } else if (pi.type != Variant::NIL) {
  887. tname = Variant::get_type_name(pi.type);
  888. }
  889. signaldesc += (pi.name.is_empty() ? String("arg " + itos(i)) : pi.name) + ": " + tname;
  890. argnames.push_back(pi.name + ":" + tname);
  891. }
  892. }
  893. signaldesc += ")";
  894. // Create the children of the subsection - the actual list of signals.
  895. TreeItem *signal_item = tree->create_item(section_item);
  896. signal_item->set_text(0, String(signal_name) + signaldesc);
  897. Dictionary sinfo;
  898. sinfo["name"] = signal_name;
  899. sinfo["args"] = argnames;
  900. signal_item->set_metadata(0, sinfo);
  901. signal_item->set_icon(0, get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")));
  902. // Set tooltip with the signal's documentation.
  903. {
  904. String descr;
  905. bool found = false;
  906. HashMap<StringName, HashMap<StringName, String>>::Iterator G = descr_cache.find(base);
  907. if (G) {
  908. HashMap<StringName, String>::Iterator F = G->value.find(signal_name);
  909. if (F) {
  910. found = true;
  911. descr = F->value;
  912. }
  913. }
  914. if (!found) {
  915. DocTools *dd = EditorHelp::get_doc_data();
  916. HashMap<String, DocData::ClassDoc>::Iterator F = dd->class_list.find(base);
  917. while (F && descr.is_empty()) {
  918. for (int i = 0; i < F->value.signals.size(); i++) {
  919. if (F->value.signals[i].name == signal_name.operator String()) {
  920. descr = DTR(F->value.signals[i].description);
  921. break;
  922. }
  923. }
  924. if (!F->value.inherits.is_empty()) {
  925. F = dd->class_list.find(F->value.inherits);
  926. } else {
  927. break;
  928. }
  929. }
  930. descr_cache[base][signal_name] = descr;
  931. }
  932. // "::" separators used in make_custom_tooltip for formatting.
  933. signal_item->set_tooltip_text(0, String(signal_name) + "::" + signaldesc + "::" + descr);
  934. }
  935. // List existing connections.
  936. List<Object::Connection> existing_connections;
  937. selected_node->get_signal_connection_list(signal_name, &existing_connections);
  938. for (const Object::Connection &F : existing_connections) {
  939. Connection connection = F;
  940. if (!(connection.flags & CONNECT_PERSIST)) {
  941. continue;
  942. }
  943. ConnectDialog::ConnectionData cd = connection;
  944. Node *target = Object::cast_to<Node>(cd.target);
  945. if (!target) {
  946. continue;
  947. }
  948. String path = String(selected_node->get_path_to(target)) + " :: " + cd.method + "()";
  949. if (cd.flags & CONNECT_DEFERRED) {
  950. path += " (deferred)";
  951. }
  952. if (cd.flags & CONNECT_ONE_SHOT) {
  953. path += " (one-shot)";
  954. }
  955. if (cd.unbinds > 0) {
  956. path += " unbinds(" + itos(cd.unbinds) + ")";
  957. } else if (!cd.binds.is_empty()) {
  958. path += " binds(";
  959. for (int i = 0; i < cd.binds.size(); i++) {
  960. if (i > 0) {
  961. path += ", ";
  962. }
  963. path += cd.binds[i].operator String();
  964. }
  965. path += ")";
  966. }
  967. TreeItem *connection_item = tree->create_item(signal_item);
  968. connection_item->set_text(0, path);
  969. connection_item->set_metadata(0, connection);
  970. connection_item->set_icon(0, get_theme_icon(SNAME("Slot"), SNAME("EditorIcons")));
  971. if (_is_connection_inherited(connection)) {
  972. // The scene inherits this connection.
  973. connection_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  974. connection_item->set_meta("_inherited_connection", true);
  975. }
  976. }
  977. }
  978. if (!did_script) {
  979. did_script = true;
  980. } else {
  981. base = ClassDB::get_parent_class(base);
  982. }
  983. }
  984. connect_button->set_text(TTR("Connect..."));
  985. connect_button->set_disabled(true);
  986. }
  987. ConnectionsDock::ConnectionsDock() {
  988. set_name(TTR("Signals"));
  989. VBoxContainer *vbc = this;
  990. search_box = memnew(LineEdit);
  991. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  992. search_box->set_placeholder(TTR("Filter Signals"));
  993. search_box->set_clear_button_enabled(true);
  994. search_box->connect("text_changed", callable_mp(this, &ConnectionsDock::_filter_changed));
  995. vbc->add_child(search_box);
  996. tree = memnew(ConnectionsDockTree);
  997. tree->set_columns(1);
  998. tree->set_select_mode(Tree::SELECT_ROW);
  999. tree->set_hide_root(true);
  1000. vbc->add_child(tree);
  1001. tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1002. tree->set_allow_rmb_select(true);
  1003. connect_button = memnew(Button);
  1004. HBoxContainer *hb = memnew(HBoxContainer);
  1005. vbc->add_child(hb);
  1006. hb->add_spacer();
  1007. hb->add_child(connect_button);
  1008. connect_button->connect("pressed", callable_mp(this, &ConnectionsDock::_connect_pressed));
  1009. connect_dialog = memnew(ConnectDialog);
  1010. add_child(connect_dialog);
  1011. disconnect_all_dialog = memnew(ConfirmationDialog);
  1012. add_child(disconnect_all_dialog);
  1013. disconnect_all_dialog->connect("confirmed", callable_mp(this, &ConnectionsDock::_disconnect_all));
  1014. disconnect_all_dialog->set_text(TTR("Are you sure you want to remove all connections from this signal?"));
  1015. signal_menu = memnew(PopupMenu);
  1016. add_child(signal_menu);
  1017. signal_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_signal_menu_option));
  1018. signal_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_signal_menu_about_to_popup));
  1019. signal_menu->add_item(TTR("Connect..."), CONNECT);
  1020. signal_menu->add_item(TTR("Disconnect All"), DISCONNECT_ALL);
  1021. signal_menu->add_item(TTR("Copy Name"), COPY_NAME);
  1022. slot_menu = memnew(PopupMenu);
  1023. add_child(slot_menu);
  1024. slot_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_slot_menu_option));
  1025. slot_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_slot_menu_about_to_popup));
  1026. slot_menu->add_item(TTR("Edit..."), EDIT);
  1027. slot_menu->add_item(TTR("Go to Method"), GO_TO_SCRIPT);
  1028. slot_menu->add_item(TTR("Disconnect"), DISCONNECT);
  1029. connect_dialog->connect("connected", callable_mp(this, &ConnectionsDock::_make_or_edit_connection));
  1030. tree->connect("item_selected", callable_mp(this, &ConnectionsDock::_tree_item_selected));
  1031. tree->connect("item_activated", callable_mp(this, &ConnectionsDock::_tree_item_activated));
  1032. tree->connect("item_mouse_selected", callable_mp(this, &ConnectionsDock::_rmb_pressed));
  1033. add_theme_constant_override("separation", 3 * EDSCALE);
  1034. EDITOR_DEF("interface/editors/default_signal_callback_name", "_on_{node_name}_{signal_name}");
  1035. EDITOR_DEF("interface/editors/default_signal_callback_to_self_name", "_on_{signal_name}");
  1036. }
  1037. ConnectionsDock::~ConnectionsDock() {
  1038. }