Debian Codegraph @

editor/docks/editor_dock.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_dock.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
31 #include "editor_dock.h"
32
33 #include "core/input/shortcut.h"
34 #include "core/io/config_file.h"
35 #include "editor/docks/editor_dock_manager.h"
36
37 void EditorDock::_set_default_slot_bind(DockSlot p_slot) {
38 ERR_FAIL_COND(p_slot < DOCK_SLOT_NONE || p_slot >= DOCK_SLOT_MAX);
39 default_slot = p_slot;
40 }
41
42 void EditorDock::_emit_changed() {
43 emit_signal(SNAME("_tab_style_changed"));
44 }
45
46 void EditorDock::_bind_methods() {
47 ClassDB::bind_method(D_METHOD("open"), &EditorDock::open);
48 ClassDB::bind_method(D_METHOD("make_visible"), &EditorDock::make_visible);
49 ClassDB::bind_method(D_METHOD("close"), &EditorDock::close);
50
51 ClassDB::bind_method(D_METHOD("set_title", "title"), &EditorDock::set_title);
52 ClassDB::bind_method(D_METHOD("get_title"), &EditorDock::get_title);
53 ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
54
55 ClassDB::bind_method(D_METHOD("set_layout_key", "layout_key"), &EditorDock::set_layout_key);
56 ClassDB::bind_method(D_METHOD("get_layout_key"), &EditorDock::get_layout_key);
57 ADD_PROPERTY(PropertyInfo(Variant::STRING, "layout_key"), "set_layout_key", "get_layout_key");
58
59 ClassDB::bind_method(D_METHOD("set_global", "global"), &EditorDock::set_global);
60 ClassDB::bind_method(D_METHOD("is_global"), &EditorDock::is_global);
61 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "global"), "set_global", "is_global");
62
63 ClassDB::bind_method(D_METHOD("set_transient", "transient"), &EditorDock::set_transient);
64 ClassDB::bind_method(D_METHOD("is_transient"), &EditorDock::is_transient);
65 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transient"), "set_transient", "is_transient");
66
67 ClassDB::bind_method(D_METHOD("set_closable", "closable"), &EditorDock::set_closable);
68 ClassDB::bind_method(D_METHOD("is_closable"), &EditorDock::is_closable);
69 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "closable"), "set_closable", "is_closable");
70
71 ClassDB::bind_method(D_METHOD("set_icon_name", "icon_name"), &EditorDock::set_icon_name);
72 ClassDB::bind_method(D_METHOD("get_icon_name"), &EditorDock::get_icon_name);
73 ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "icon_name"), "set_icon_name", "get_icon_name");
74
75 ClassDB::bind_method(D_METHOD("set_dock_icon", "icon"), &EditorDock::set_dock_icon);
76 ClassDB::bind_method(D_METHOD("get_dock_icon"), &EditorDock::get_dock_icon);
77 ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dock_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_dock_icon", "get_dock_icon");
78
79 ClassDB::bind_method(D_METHOD("set_force_show_icon", "force"), &EditorDock::set_force_show_icon);
80 ClassDB::bind_method(D_METHOD("get_force_show_icon"), &EditorDock::get_force_show_icon);
81 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_show_icon"), "set_force_show_icon", "get_force_show_icon");
82
83 ClassDB::bind_method(D_METHOD("set_title_color", "color"), &EditorDock::set_title_color);
84 ClassDB::bind_method(D_METHOD("get_title_color"), &EditorDock::get_title_color);
85 ADD_PROPERTY(PropertyInfo(Variant::COLOR, "title_color"), "set_title_color", "get_title_color");
86
87 ClassDB::bind_method(D_METHOD("set_dock_shortcut", "shortcut"), &EditorDock::set_dock_shortcut);
88 ClassDB::bind_method(D_METHOD("get_dock_shortcut"), &EditorDock::get_dock_shortcut);
89 ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dock_shortcut", PROPERTY_HINT_RESOURCE_TYPE, "Shortcut"), "set_dock_shortcut", "get_dock_shortcut");
90
91 ClassDB::bind_method(D_METHOD("set_default_slot", "slot"), &EditorDock::_set_default_slot_bind);
92 ClassDB::bind_method(D_METHOD("get_default_slot"), &EditorDock::_get_default_slot_bind);
93 ADD_PROPERTY(PropertyInfo(Variant::INT, "default_slot", PROPERTY_HINT_ENUM, "None:-1,Left Side Upper-Left,Left Side Bottom-Left,Left Side Upper-Right,Left Side Bottom-Right,Right Side Upper-Left,Right Side Bottom-Left,Right Side Upper-Right,Right Side Bottom-Right,Bottom"), "set_default_slot", "get_default_slot");
94
95 ClassDB::bind_method(D_METHOD("set_available_layouts", "layouts"), &EditorDock::set_available_layouts);
96 ClassDB::bind_method(D_METHOD("get_available_layouts"), &EditorDock::get_available_layouts);
97 ADD_PROPERTY(PropertyInfo(Variant::INT, "available_layouts", PROPERTY_HINT_FLAGS, "Vertical:1,Horizontal:2,Floating:4"), "set_available_layouts", "get_available_layouts");
98
99 ADD_SIGNAL(MethodInfo("closed"));
100 ADD_SIGNAL(MethodInfo("_tab_style_changed"));
101
102 BIND_BITFIELD_FLAG(DOCK_LAYOUT_VERTICAL);
103 BIND_BITFIELD_FLAG(DOCK_LAYOUT_HORIZONTAL);
104 BIND_BITFIELD_FLAG(DOCK_LAYOUT_FLOATING);
105 BIND_BITFIELD_FLAG(DOCK_LAYOUT_ALL);
106
107 BIND_ENUM_CONSTANT(DOCK_SLOT_NONE);
108 BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UL);
109 BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BL);
110 BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UR);
111 BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BR);
112 BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UL);
113 BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BL);
114 BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR);
115 BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR);
116 BIND_ENUM_CONSTANT(DOCK_SLOT_BOTTOM);
117 BIND_ENUM_CONSTANT(DOCK_SLOT_MAX);
118
119 GDVIRTUAL_BIND(_update_layout, "layout");
120 GDVIRTUAL_BIND(_save_layout_to_config, "config", "section");
121 GDVIRTUAL_BIND(_load_layout_from_config, "config", "section");
122 }
123
124 void EditorDock::open() {
125 if (!is_open) {
126 EditorDockManager::get_singleton()->open_dock(this, false);
127 }
128 }
129
130 void EditorDock::make_visible() {
131 EditorDockManager::get_singleton()->open_dock(this, true);
132 }
133
134 void EditorDock::close() {
135 if (is_open) {
136 EditorDockManager::get_singleton()->close_dock(this);
137 }
138 }
139
140 void EditorDock::set_title(const String &p_title) {
141 if (title == p_title) {
142 return;
143 }
144 title = p_title;
145 _emit_changed();
146 }
147
148 void EditorDock::set_global(bool p_global) {
149 if (global == p_global) {
150 return;
151 }
152 global = p_global;
153 if (is_inside_tree()) {
154 EditorDockManager::get_singleton()->update_docks_menu();
155 }
156 }
157
158 void EditorDock::set_icon_name(const StringName &p_name) {
159 if (icon_name == p_name) {
160 return;
161 }
162 icon_name = p_name;
163 _emit_changed();
164 }
165
166 void EditorDock::set_dock_icon(const Ref<Texture2D> &p_icon) {
167 if (dock_icon == p_icon) {
168 return;
169 }
170 dock_icon = p_icon;
171 _emit_changed();
172 }
173
174 void EditorDock::set_force_show_icon(bool p_force) {
175 if (force_show_icon == p_force) {
176 return;
177 }
178 force_show_icon = p_force;
179 _emit_changed();
180 }
181
182 void EditorDock::set_title_color(const Color &p_color) {
183 if (title_color == p_color) {
184 return;
185 }
186 title_color = p_color;
187 _emit_changed();
188 }
189
190 void EditorDock::set_dock_shortcut(const Ref<Shortcut> &p_shortcut) {
191 if (shortcut == p_shortcut) {
192 return;
193 }
194
195 const Callable changed_callback = callable_mp(this, &EditorDock::_emit_changed);
196 if (shortcut.is_valid()) {
197 shortcut->disconnect_changed(changed_callback);
198 }
199 shortcut = p_shortcut;
200 if (shortcut.is_valid()) {
201 shortcut->connect_changed(changed_callback);
202 }
203 _emit_changed();
204 }
205
206 void EditorDock::set_default_slot(DockSlot p_slot) {
207 ERR_FAIL_INDEX(p_slot, DOCK_SLOT_MAX);
208 default_slot = p_slot;
209 }
210
211 String EditorDock::get_display_title() const {
212 if (!title.is_empty()) {
213 return title;
214 }
215
216 const String sname = get_name();
217 if (sname.contains_char('@')) {
218 // Auto-generated name, try to use something better.
219 const Node *child = get_child_count() > 0 ? get_child(0) : nullptr;
220 if (child) {
221 // In user plugins, the child will usually be dock's content and have a proper name.
222 return child->get_name();
223 }
224 }
225 return sname;
226 }
227
228 String EditorDock::get_effective_layout_key() const {
229 return layout_key.is_empty() ? get_display_title() : layout_key;
230 }