connections_dialog.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**************************************************************************/
  2. /* connections_dialog.h */
  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. /**
  31. @author Juan Linietsky <reduzio@gmail.com>
  32. */
  33. #ifndef CONNECTIONS_DIALOG_H
  34. #define CONNECTIONS_DIALOG_H
  35. #include "core/undo_redo.h"
  36. #include "editor/editor_inspector.h"
  37. #include "editor/scene_tree_editor.h"
  38. #include "scene/gui/button.h"
  39. #include "scene/gui/check_button.h"
  40. #include "scene/gui/dialogs.h"
  41. #include "scene/gui/line_edit.h"
  42. #include "scene/gui/menu_button.h"
  43. #include "scene/gui/popup.h"
  44. #include "scene/gui/tree.h"
  45. class PopupMenu;
  46. class ConnectDialogBinds;
  47. class ConnectDialog : public ConfirmationDialog {
  48. GDCLASS(ConnectDialog, ConfirmationDialog);
  49. Label *connect_to_label;
  50. LineEdit *from_signal;
  51. Node *source;
  52. StringName signal;
  53. LineEdit *dst_method;
  54. ConnectDialogBinds *cdbinds;
  55. bool bEditMode;
  56. NodePath dst_path;
  57. VBoxContainer *vbc_right;
  58. SceneTreeEditor *tree;
  59. AcceptDialog *error;
  60. EditorInspector *bind_editor;
  61. OptionButton *type_list;
  62. CheckBox *deferred;
  63. CheckBox *oneshot;
  64. CheckButton *advanced;
  65. Label *error_label;
  66. void ok_pressed();
  67. void _cancel_pressed();
  68. void _tree_node_selected();
  69. void _add_bind();
  70. void _remove_bind();
  71. void _advanced_pressed();
  72. void _update_ok_enabled();
  73. protected:
  74. void _notification(int p_what);
  75. static void _bind_methods();
  76. public:
  77. Node *get_source() const;
  78. StringName get_signal_name() const;
  79. NodePath get_dst_path() const;
  80. void set_dst_node(Node *p_node);
  81. StringName get_dst_method_name() const;
  82. void set_dst_method(const StringName &p_method);
  83. Vector<Variant> get_binds() const;
  84. bool get_deferred() const;
  85. bool get_oneshot() const;
  86. bool is_editing() const;
  87. void init(Connection c, bool bEdit = false);
  88. void popup_dialog(const String &p_for_signal);
  89. ConnectDialog();
  90. ~ConnectDialog();
  91. };
  92. //////////////////////////////////////////
  93. // Custom Tree needed to use a RichTextLabel as tooltip control
  94. // when display signal documentation.
  95. class ConnectionsDockTree : public Tree {
  96. virtual Control *make_custom_tooltip(const String &p_text) const;
  97. };
  98. class ConnectionsDock : public VBoxContainer {
  99. GDCLASS(ConnectionsDock, VBoxContainer);
  100. //Right-click Pop-up Menu Options.
  101. enum SignalMenuOption {
  102. CONNECT,
  103. DISCONNECT_ALL
  104. };
  105. enum SlotMenuOption {
  106. EDIT,
  107. GO_TO_SCRIPT,
  108. DISCONNECT
  109. };
  110. Node *selectedNode;
  111. ConnectionsDockTree *tree;
  112. EditorNode *editor;
  113. ConfirmationDialog *disconnect_all_dialog;
  114. ConnectDialog *connect_dialog;
  115. Button *connect_button;
  116. PopupMenu *signal_menu;
  117. PopupMenu *slot_menu;
  118. UndoRedo *undo_redo;
  119. LineEdit *search_box;
  120. Map<StringName, Map<StringName, String>> descr_cache;
  121. void _filter_changed(const String &p_text);
  122. void _make_or_edit_connection();
  123. void _connect(Connection cToMake);
  124. void _disconnect(TreeItem &item);
  125. void _disconnect_all();
  126. void _tree_item_selected();
  127. void _tree_item_activated();
  128. bool _is_item_signal(TreeItem &item);
  129. void _open_connection_dialog(TreeItem &item);
  130. void _open_connection_dialog(Connection cToEdit);
  131. void _go_to_script(TreeItem &item);
  132. void _handle_signal_menu_option(int option);
  133. void _handle_slot_menu_option(int option);
  134. void _rmb_pressed(Vector2 position);
  135. void _close();
  136. protected:
  137. void _connect_pressed();
  138. void _notification(int p_what);
  139. static void _bind_methods();
  140. public:
  141. void set_undoredo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  142. void set_node(Node *p_node);
  143. void update_tree();
  144. ConnectionsDock(EditorNode *p_editor = nullptr);
  145. ~ConnectionsDock();
  146. };
  147. #endif // CONNECTIONS_DIALOG_H