diff --git a/modules/code_editor/SCsub b/modules/code_editor/SCsub index 1fbde99cf..be27388f6 100644 --- a/modules/code_editor/SCsub +++ b/modules/code_editor/SCsub @@ -13,6 +13,7 @@ sources = [ "script_editor_quick_open.cpp", "script_editor_base.cpp", "script_editor.cpp", + "connection_info_dialog.cpp", ] env_mlp.add_source_files(env.modules_sources, sources) diff --git a/modules/code_editor/connection_info_dialog.cpp b/modules/code_editor/connection_info_dialog.cpp new file mode 100644 index 000000000..a92c0b737 --- /dev/null +++ b/modules/code_editor/connection_info_dialog.cpp @@ -0,0 +1,106 @@ +/*************************************************************************/ +/* script_text_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "connection_info_dialog.h" + +#include "editor/editor_node.h" +#include "editor/editor_scale.h" +#include "scene/gui/box_container.h" +#include "scene/gui/label.h" +#include "scene/gui/tree.h" +#include "scene/main/node.h" + +void ConnectionInfoDialog::ok_pressed() { +} + +void ConnectionInfoDialog::popup_connections(String p_method, Vector p_nodes) { + method->set_text(p_method); + + tree->clear(); + TreeItem *root = tree->create_item(); + + for (int i = 0; i < p_nodes.size(); i++) { + List all_connections; + p_nodes[i]->get_signals_connected_to_this(&all_connections); + + for (List::Element *E = all_connections.front(); E; E = E->next()) { + Connection connection = E->get(); + + if (connection.method != p_method) { + continue; + } + + TreeItem *node_item = tree->create_item(root); + + node_item->set_text(0, Object::cast_to(connection.source)->get_name()); + node_item->set_icon(0, EditorNode::get_singleton()->get_object_icon(connection.source, "Node")); + node_item->set_selectable(0, false); + node_item->set_editable(0, false); + + node_item->set_text(1, connection.signal); + node_item->set_icon(1, get_parent_control()->get_theme_icon("Slot", "EditorIcons")); + node_item->set_selectable(1, false); + node_item->set_editable(1, false); + + node_item->set_text(2, Object::cast_to(connection.target)->get_name()); + node_item->set_icon(2, EditorNode::get_singleton()->get_object_icon(connection.target, "Node")); + node_item->set_selectable(2, false); + node_item->set_editable(2, false); + } + } + + popup_centered(Size2(600, 300) * EDSCALE); +} + +ConnectionInfoDialog::ConnectionInfoDialog() { + set_title(TTR("Connections to method:")); + + VBoxContainer *vbc = memnew(VBoxContainer); + vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); + vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE); + vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE); + vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE); + add_child(vbc); + + method = memnew(Label); + method->set_align(Label::ALIGN_CENTER); + vbc->add_child(method); + + tree = memnew(Tree); + tree->set_columns(3); + tree->set_hide_root(true); + tree->set_column_titles_visible(true); + tree->set_column_title(0, TTR("Source")); + tree->set_column_title(1, TTR("Signal")); + tree->set_column_title(2, TTR("Target")); + vbc->add_child(tree); + tree->set_v_size_flags(SIZE_EXPAND_FILL); + tree->set_allow_rmb_select(true); +} diff --git a/modules/code_editor/connection_info_dialog.h b/modules/code_editor/connection_info_dialog.h new file mode 100644 index 000000000..624765726 --- /dev/null +++ b/modules/code_editor/connection_info_dialog.h @@ -0,0 +1,54 @@ +#ifndef CONNECTION_INFO_DIALOG_H +#define CONNECTION_INFO_DIALOG_H + +/*************************************************************************/ +/* script_text_editor.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "scene/gui/dialogs.h" + +class Label; +class Node; +class Tree; + +class ConnectionInfoDialog : public AcceptDialog { + GDCLASS(ConnectionInfoDialog, AcceptDialog); + + Label *method; + Tree *tree; + + virtual void ok_pressed(); + +public: + void popup_connections(String p_method, Vector p_nodes); + + ConnectionInfoDialog(); +}; + +#endif // SCRIPT_TEXT_EDITOR_H diff --git a/modules/code_editor/script_text_editor.cpp b/modules/code_editor/script_text_editor.cpp index e95b9f545..6ee74d0ec 100644 --- a/modules/code_editor/script_text_editor.cpp +++ b/modules/code_editor/script_text_editor.cpp @@ -71,78 +71,9 @@ #include "script_editor_plugin.h" #include "script_editor_quick_open.h" +#include "connection_info_dialog.h" #include "script_editor.h" -void ConnectionInfoDialog::ok_pressed() { -} - -void ConnectionInfoDialog::popup_connections(String p_method, Vector p_nodes) { - method->set_text(p_method); - - tree->clear(); - TreeItem *root = tree->create_item(); - - for (int i = 0; i < p_nodes.size(); i++) { - List all_connections; - p_nodes[i]->get_signals_connected_to_this(&all_connections); - - for (List::Element *E = all_connections.front(); E; E = E->next()) { - Connection connection = E->get(); - - if (connection.method != p_method) { - continue; - } - - TreeItem *node_item = tree->create_item(root); - - node_item->set_text(0, Object::cast_to(connection.source)->get_name()); - node_item->set_icon(0, EditorNode::get_singleton()->get_object_icon(connection.source, "Node")); - node_item->set_selectable(0, false); - node_item->set_editable(0, false); - - node_item->set_text(1, connection.signal); - node_item->set_icon(1, get_parent_control()->get_theme_icon("Slot", "EditorIcons")); - node_item->set_selectable(1, false); - node_item->set_editable(1, false); - - node_item->set_text(2, Object::cast_to(connection.target)->get_name()); - node_item->set_icon(2, EditorNode::get_singleton()->get_object_icon(connection.target, "Node")); - node_item->set_selectable(2, false); - node_item->set_editable(2, false); - } - } - - popup_centered(Size2(600, 300) * EDSCALE); -} - -ConnectionInfoDialog::ConnectionInfoDialog() { - set_title(TTR("Connections to method:")); - - VBoxContainer *vbc = memnew(VBoxContainer); - vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE); - add_child(vbc); - - method = memnew(Label); - method->set_align(Label::ALIGN_CENTER); - vbc->add_child(method); - - tree = memnew(Tree); - tree->set_columns(3); - tree->set_hide_root(true); - tree->set_column_titles_visible(true); - tree->set_column_title(0, TTR("Source")); - tree->set_column_title(1, TTR("Signal")); - tree->set_column_title(2, TTR("Target")); - vbc->add_child(tree); - tree->set_v_size_flags(SIZE_EXPAND_FILL); - tree->set_allow_rmb_select(true); -} - -//////////////////////////////////////////////////////////////////////////////// - Vector ScriptTextEditor::get_functions() { String errortxt; int line = -1, col; diff --git a/modules/code_editor/script_text_editor.h b/modules/code_editor/script_text_editor.h index 04478fba9..e512553e4 100644 --- a/modules/code_editor/script_text_editor.h +++ b/modules/code_editor/script_text_editor.h @@ -63,20 +63,7 @@ class Texture; class Tree; struct ScriptCodeCompletionOption; class ScriptEditorQuickOpen; - -class ConnectionInfoDialog : public AcceptDialog { - GDCLASS(ConnectionInfoDialog, AcceptDialog); - - Label *method; - Tree *tree; - - virtual void ok_pressed(); - -public: - void popup_connections(String p_method, Vector p_nodes); - - ConnectionInfoDialog(); -}; +class ConnectionInfoDialog; class ScriptTextEditor : public ScriptEditorBase { GDCLASS(ScriptTextEditor, ScriptEditorBase);