| 1 | /**************************************************************************/ |
| 2 | /* editor_dock_manager.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_manager.h" |
| 32 | |
| 33 | #include "scene/gui/box_container.h" |
| 34 | #include "scene/gui/button.h" |
| 35 | #include "scene/gui/label.h" |
| 36 | #include "scene/gui/split_container.h" |
| 37 | #include "scene/gui/tab_container.h" |
| 38 | #include "scene/main/window.h" |
| 39 | |
| 40 | #include "editor/docks/editor_dock.h" |
| 41 | #include "editor/editor_node.h" |
| 42 | #include "editor/editor_string_names.h" |
| 43 | #include "editor/gui/editor_bottom_panel.h" |
| 44 | #include "editor/gui/window_wrapper.h" |
| 45 | #include "editor/settings/editor_settings.h" |
| 46 | #include "editor/themes/editor_scale.h" |
| 47 | #include "scene/resources/style_box_flat.h" |
| 48 | |
| 49 | enum class TabStyle { |
| 50 | TEXT_ONLY, |
| 51 | ICON_ONLY, |
| 52 | TEXT_AND_ICON, |
| 53 | }; |
| 54 | |
| 55 | static inline Ref<Texture2D> _get_dock_icon(const EditorDock *p_dock, const Callable &p_icon_fetch) { |
| 56 | Ref<Texture2D> icon = p_dock->get_dock_icon(); |
| 57 | if (icon.is_null() && !p_dock->get_icon_name().is_empty()) { |
| 58 | icon = p_icon_fetch.call(p_dock->get_icon_name()); |
| 59 | } |
| 60 | return icon; |
| 61 | } |
| 62 | |
| 63 | bool EditorDockDragHint::can_drop_data(const Point2 &p_point, const Variant &p_data) const { |
| 64 | return can_drop_dock; |
| 65 | } |
| 66 | |
| 67 | void EditorDockDragHint::drop_data(const Point2 &p_point, const Variant &p_data) { |
| 68 | // Drop dock into last spot if not over tabbar. |
| 69 | if (drop_tabbar->get_rect().has_point(p_point)) { |
| 70 | drop_tabbar->_handle_drop_data("tab_container_tab", p_point, p_data, callable_mp(this, &EditorDockDragHint::_drag_move_tab), callable_mp(this, &EditorDockDragHint::_drag_move_tab_from)); |
| 71 | } else { |
| 72 | dock_manager->_move_dock(dock_manager->_get_dock_tab_dragged(), dock_manager->dock_slots[occupied_slot].container, drop_tabbar->get_tab_count()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void EditorDockDragHint::_drag_move_tab(int p_from_index, int p_to_index) { |
| 77 | dock_manager->_move_dock_tab_index(dock_manager->_get_dock_tab_dragged(), p_to_index, true); |
| 78 | } |
| 79 | |
| 80 | void EditorDockDragHint::_drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index) { |
| 81 | dock_manager->_move_dock(dock_manager->_get_dock_tab_dragged(), dock_manager->dock_slots[occupied_slot].container, p_to_index); |
| 82 | } |
| 83 | |
| 84 | void EditorDockDragHint::gui_input(const Ref<InputEvent> &p_event) { |
| 85 | ERR_FAIL_COND(p_event.is_null()); |
| 86 | |
| 87 | Ref<InputEventMouseMotion> mm = p_event; |
| 88 | if (mm.is_valid()) { |
| 89 | Point2 pos = mm->get_position(); |
| 90 | |
| 91 | // Redraw when inside the tabbar and just exited. |
| 92 | if (mouse_inside_tabbar) { |
| 93 | queue_redraw(); |
| 94 | } |
| 95 | mouse_inside_tabbar = drop_tabbar->get_rect().has_point(pos); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void EditorDockDragHint::set_slot(DockConstants::DockSlot p_slot) { |
| 100 | occupied_slot = p_slot; |
| 101 | drop_tabbar = dock_manager->dock_slots[occupied_slot].container->get_tab_bar(); |
| 102 | } |
| 103 | |
| 104 | void EditorDockDragHint::_notification(int p_what) { |
| 105 | switch (p_what) { |
| 106 | case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { |
| 107 | if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/theme")) { |
| 108 | dock_drop_highlight->set_corner_radius_all(EDSCALE * EDITOR_GET("interface/theme/corner_radius").operator int()); |
| 109 | if (mouse_inside) { |
| 110 | queue_redraw(); |
| 111 | } |
| 112 | } |
| 113 | } break; |
| 114 | |
| 115 | case NOTIFICATION_THEME_CHANGED: { |
| 116 | valid_drop_color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); |
| 117 | } break; |
| 118 | |
| 119 | case NOTIFICATION_MOUSE_ENTER: |
| 120 | case NOTIFICATION_MOUSE_EXIT: { |
| 121 | mouse_inside = p_what == NOTIFICATION_MOUSE_ENTER; |
| 122 | queue_redraw(); |
| 123 | } break; |
| 124 | |
| 125 | case NOTIFICATION_DRAG_BEGIN: { |
| 126 | EditorDock *dragged_dock = dock_manager->_get_dock_tab_dragged(); |
| 127 | if (!dragged_dock) { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | can_drop_dock = dragged_dock->get_available_layouts() & (EditorDock::DockLayout)EditorDockManager::get_singleton()->dock_slots[occupied_slot].layout; |
| 132 | |
| 133 | dock_drop_highlight->set_border_color(valid_drop_color); |
| 134 | dock_drop_highlight->set_bg_color(valid_drop_color * Color(1, 1, 1, 0.1)); |
| 135 | } break; |
| 136 | case NOTIFICATION_DRAG_END: { |
| 137 | dock_manager->_dock_drag_stopped(); |
| 138 | can_drop_dock = false; |
| 139 | mouse_inside = false; |
| 140 | hide(); |
| 141 | } break; |
| 142 | |
| 143 | case NOTIFICATION_DRAW: { |
| 144 | if (!mouse_inside || !can_drop_dock) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | // Draw highlights around docks that can be dropped. |
| 149 | Rect2 dock_rect = Rect2(Point2(), get_size()).grow(2 * EDSCALE); |
| 150 | draw_style_box(dock_drop_highlight, dock_rect); |
| 151 | |
| 152 | // Only display tabbar hint if the mouse is over the tabbar. |
| 153 | if (drop_tabbar->get_global_rect().has_point(get_global_mouse_position())) { |
| 154 | draw_set_transform(drop_tabbar->get_position()); // The TabBar isn't always on top. |
| 155 | drop_tabbar->_draw_tab_drop(get_canvas_item()); |
| 156 | } |
| 157 | } break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | EditorDockDragHint::EditorDockDragHint() { |
| 162 | dock_manager = EditorDockManager::get_singleton(); |
| 163 | |
| 164 | set_as_top_level(true); |
| 165 | dock_drop_highlight.instantiate(); |
| 166 | dock_drop_highlight->set_corner_radius_all(EDSCALE * EDITOR_GET("interface/theme/corner_radius").operator int()); |
| 167 | dock_drop_highlight->set_border_width_all(Math::round(2 * EDSCALE)); |
| 168 | } |
| 169 | |
| 170 | //////////////////////////////////////////////// |
| 171 | //////////////////////////////////////////////// |
| 172 | |
| 173 | void DockSplitContainer::_update_visibility() { |
| 174 | if (is_updating) { |
| 175 | return; |
| 176 | } |
| 177 | is_updating = true; |
| 178 | bool any_visible = false; |
| 179 | for (int i = 0; i < get_child_count(false); i++) { |
| 180 | Control *c = Object::cast_to<Control>(get_child(i, false)); |
| 181 | if (!c || !c->is_visible() || c->is_set_as_top_level()) { |
| 182 | continue; |
| 183 | } |
| 184 | any_visible = c; |
| 185 | break; |
| 186 | } |
| 187 | set_visible(any_visible); |
| 188 | is_updating = false; |
| 189 | } |
| 190 | |
| 191 | void DockSplitContainer::add_child_notify(Node *p_child) { |
| 192 | SplitContainer::add_child_notify(p_child); |
| 193 | |
| 194 | Control *child_control = nullptr; |
| 195 | for (int i = 0; i < get_child_count(false); i++) { |
| 196 | Control *c = Object::cast_to<Control>(get_child(i, false)); |
| 197 | if (!c || c->is_set_as_top_level()) { |
| 198 | continue; |
| 199 | } |
| 200 | if (p_child == c) { |
| 201 | child_control = c; |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | if (!child_control) { |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | child_control->connect(SceneStringName(visibility_changed), callable_mp(this, &DockSplitContainer::_update_visibility)); |
| 210 | _update_visibility(); |
| 211 | } |
| 212 | |
| 213 | void DockSplitContainer::remove_child_notify(Node *p_child) { |
| 214 | SplitContainer::remove_child_notify(p_child); |
| 215 | |
| 216 | Control *child_control = nullptr; |
| 217 | for (int i = 0; i < get_child_count(false); i++) { |
| 218 | Control *c = Object::cast_to<Control>(get_child(i, false)); |
| 219 | if (!c || c->is_set_as_top_level()) { |
| 220 | continue; |
| 221 | } |
| 222 | if (p_child == c) { |
| 223 | child_control = c; |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | if (!child_control) { |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | child_control->disconnect(SceneStringName(visibility_changed), callable_mp(this, &DockSplitContainer::_update_visibility)); |
| 232 | _update_visibility(); |
| 233 | } |
| 234 | |
| 235 | DockSplitContainer::DockSplitContainer() { |
| 236 | if (EDITOR_GET("interface/touchscreen/enable_touch_optimizations")) { |
| 237 | callable_mp((SplitContainer *)this, &SplitContainer::set_touch_dragger_enabled).call_deferred(true); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | //////////////////////////////////////////////// |
| 242 | //////////////////////////////////////////////// |
| 243 | |
| 244 | EditorDock *EditorDockManager::_get_dock_tab_dragged() { |
| 245 | if (dock_tab_dragged) { |
| 246 | return dock_tab_dragged; |
| 247 | } |
| 248 | |
| 249 | Dictionary dock_drop_data = dock_slots[DockConstants::DOCK_SLOT_LEFT_BL].container->get_viewport()->gui_get_drag_data(); |
| 250 | |
| 251 | // Check if we are dragging a dock. |
| 252 | if (dock_drop_data.get("type", "").operator String() != "tab") { |
| 253 | return nullptr; |
| 254 | } |
| 255 | |
| 256 | const String tab_type = dock_drop_data.get("tab_type", ""); |
| 257 | if (tab_type == "tab_container_tab") { |
| 258 | Node *source_tab_bar = EditorNode::get_singleton()->get_node(dock_drop_data["from_path"]); |
| 259 | if (!source_tab_bar) { |
| 260 | return nullptr; |
| 261 | } |
| 262 | |
| 263 | TabContainer *source_tab_container = Object::cast_to<TabContainer>(source_tab_bar->get_parent()); |
| 264 | if (!source_tab_container) { |
| 265 | return nullptr; |
| 266 | } |
| 267 | |
| 268 | dock_tab_dragged = Object::cast_to<EditorDock>(source_tab_container->get_tab_control(dock_drop_data["tab_index"])); |
| 269 | if (!dock_tab_dragged) { |
| 270 | return nullptr; |
| 271 | } |
| 272 | |
| 273 | for (int i = 0; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 274 | if (dock_slots[i].container->is_visible_in_tree()) { |
| 275 | dock_slots[i].drag_hint->set_rect(dock_slots[i].container->get_global_rect()); |
| 276 | dock_slots[i].drag_hint->show(); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | return dock_tab_dragged; |
| 281 | } |
| 282 | return nullptr; |
| 283 | } |
| 284 | |
| 285 | void EditorDockManager::_dock_drag_stopped() { |
| 286 | dock_tab_dragged = nullptr; |
| 287 | } |
| 288 | |
| 289 | void EditorDockManager::_dock_split_dragged(int p_offset) { |
| 290 | EditorNode::get_singleton()->save_editor_layout_delayed(); |
| 291 | } |
| 292 | |
| 293 | void EditorDockManager::_dock_container_popup(int p_tab_idx, TabContainer *p_dock_container) { |
| 294 | EditorDock *hovered_dock = Object::cast_to<EditorDock>(p_dock_container->get_tab_control(p_tab_idx)); |
| 295 | if (hovered_dock == nullptr) { |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | // Right click context menu. |
| 300 | dock_context_popup->set_dock(hovered_dock); |
| 301 | dock_context_popup->set_position(p_dock_container->get_tab_bar()->get_screen_position() + p_dock_container->get_tab_bar()->get_local_mouse_position()); |
| 302 | dock_context_popup->popup(); |
| 303 | } |
| 304 | |
| 305 | void EditorDockManager::_dock_container_update_visibility(TabContainer *p_dock_container) { |
| 306 | if (!docks_visible) { |
| 307 | return; |
| 308 | } |
| 309 | // Hide the dock container if there are no tabs. |
| 310 | p_dock_container->set_visible(p_dock_container->get_tab_count() > 0); |
| 311 | } |
| 312 | |
| 313 | void EditorDockManager::_update_layout() { |
| 314 | if (!dock_context_popup->is_inside_tree() || EditorNode::get_singleton()->is_exiting()) { |
| 315 | return; |
| 316 | } |
| 317 | dock_context_popup->docks_updated(); |
| 318 | update_docks_menu(); |
| 319 | EditorNode::get_singleton()->save_editor_layout_delayed(); |
| 320 | } |
| 321 | |
| 322 | void EditorDockManager::update_docks_menu() { |
| 323 | docks_menu->clear(); |
| 324 | docks_menu->reset_size(); |
| 325 | |
| 326 | const Ref<Texture2D> default_icon = docks_menu->get_editor_theme_icon(SNAME("Window")); |
| 327 | const Color closed_icon_color_mod = Color(1, 1, 1, 0.5); |
| 328 | |
| 329 | bool global_menu = !bool(EDITOR_GET("interface/editor/use_embedded_menu")) && NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU); |
| 330 | bool dark_mode = DisplayServer::get_singleton()->is_dark_mode_supported() && DisplayServer::get_singleton()->is_dark_mode(); |
| 331 | int icon_max_width = EditorNode::get_singleton()->get_editor_theme()->get_constant(SNAME("class_icon_size"), EditorStringName(Editor)); |
| 332 | |
| 333 | // Add docks. |
| 334 | docks_menu_docks.clear(); |
| 335 | int id = 0; |
| 336 | const Callable icon_fetch = callable_mp(EditorNode::get_singleton(), &EditorNode::get_editor_theme_native_menu_icon).bind(global_menu, dark_mode); |
| 337 | for (EditorDock *dock : all_docks) { |
| 338 | if (!dock->enabled || !dock->global) { |
| 339 | continue; |
| 340 | } |
| 341 | if (dock->shortcut.is_valid()) { |
| 342 | docks_menu->add_shortcut(dock->shortcut, id); |
| 343 | docks_menu->set_item_text(id, dock->get_display_title()); |
| 344 | } else { |
| 345 | docks_menu->add_item(dock->get_display_title(), id); |
| 346 | } |
| 347 | docks_menu->set_item_icon_max_width(id, icon_max_width); |
| 348 | |
| 349 | const Ref<Texture2D> icon = _get_dock_icon(dock, icon_fetch); |
| 350 | docks_menu->set_item_icon(id, icon.is_valid() ? icon : default_icon); |
| 351 | if (!dock->is_open) { |
| 352 | docks_menu->set_item_icon_modulate(id, closed_icon_color_mod); |
| 353 | docks_menu->set_item_tooltip(id, vformat(TTR("Open the %s dock."), dock->get_display_title())); |
| 354 | } else { |
| 355 | docks_menu->set_item_tooltip(id, vformat(TTR("Focus on the %s dock."), dock->get_display_title())); |
| 356 | } |
| 357 | docks_menu_docks.push_back(dock); |
| 358 | id++; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | void EditorDockManager::_docks_menu_option(int p_id) { |
| 363 | EditorDock *dock = docks_menu_docks[p_id]; |
| 364 | ERR_FAIL_NULL(dock); |
| 365 | ERR_FAIL_COND_MSG(!all_docks.has(dock), vformat("Menu option for unknown dock '%s'.", dock->get_display_title())); |
| 366 | if (dock->enabled && dock->is_open) { |
| 367 | PopupMenu *parent_menu = Object::cast_to<PopupMenu>(docks_menu->get_parent()); |
| 368 | ERR_FAIL_NULL(parent_menu); |
| 369 | parent_menu->hide(); |
| 370 | } |
| 371 | focus_dock(dock); |
| 372 | } |
| 373 | |
| 374 | void EditorDockManager::_window_close_request(WindowWrapper *p_wrapper) { |
| 375 | // Give the dock back to the original owner. |
| 376 | EditorDock *dock = _close_window(p_wrapper); |
| 377 | ERR_FAIL_COND(!all_docks.has(dock)); |
| 378 | |
| 379 | if (dock->dock_slot_index != DockConstants::DOCK_SLOT_NONE) { |
| 380 | dock->is_open = false; |
| 381 | open_dock(dock); |
| 382 | focus_dock(dock); |
| 383 | } else { |
| 384 | close_dock(dock); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | EditorDock *EditorDockManager::_close_window(WindowWrapper *p_wrapper) { |
| 389 | p_wrapper->set_block_signals(true); |
| 390 | EditorDock *dock = Object::cast_to<EditorDock>(p_wrapper->release_wrapped_control()); |
| 391 | p_wrapper->set_block_signals(false); |
| 392 | ERR_FAIL_COND_V(!all_docks.has(dock), nullptr); |
| 393 | |
| 394 | dock->dock_window = nullptr; |
| 395 | dock_windows.erase(p_wrapper); |
| 396 | p_wrapper->queue_free(); |
| 397 | return dock; |
| 398 | } |
| 399 | |
| 400 | void EditorDockManager::_open_dock_in_window(EditorDock *p_dock, bool p_show_window, bool p_reset_size) { |
| 401 | ERR_FAIL_NULL(p_dock); |
| 402 | |
| 403 | Size2 borders = Size2(4, 4) * EDSCALE; |
| 404 | // Remember size and position before removing it from the main window. |
| 405 | Size2 dock_size = p_dock->get_size() + borders * 2; |
| 406 | Point2 dock_screen_pos = p_dock->get_screen_position(); |
| 407 | |
| 408 | WindowWrapper *wrapper = memnew(WindowWrapper); |
| 409 | wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR(p_dock->get_display_title()))); |
| 410 | wrapper->set_margins_enabled(true); |
| 411 | |
| 412 | EditorNode::get_singleton()->get_gui_base()->add_child(wrapper); |
| 413 | |
| 414 | _move_dock(p_dock, nullptr); |
| 415 | p_dock->update_layout(EditorDock::DOCK_LAYOUT_FLOATING); |
| 416 | p_dock->current_layout = EditorDock::DOCK_LAYOUT_FLOATING; |
| 417 | wrapper->set_wrapped_control(p_dock); |
| 418 | |
| 419 | p_dock->dock_window = wrapper; |
| 420 | p_dock->is_open = true; |
| 421 | p_dock->show(); |
| 422 | |
| 423 | wrapper->connect("window_close_requested", callable_mp(this, &EditorDockManager::_window_close_request).bind(wrapper)); |
| 424 | dock_windows.push_back(wrapper); |
| 425 | |
| 426 | if (p_show_window) { |
| 427 | wrapper->restore_window(Rect2i(dock_screen_pos, dock_size), EditorNode::get_singleton()->get_gui_base()->get_window()->get_current_screen()); |
| 428 | _update_layout(); |
| 429 | if (p_reset_size) { |
| 430 | // Use a default size of one third the current window size. |
| 431 | Size2i popup_size = EditorNode::get_singleton()->get_window()->get_size() / 3.0; |
| 432 | p_dock->get_window()->set_size(popup_size); |
| 433 | p_dock->get_window()->move_to_center(); |
| 434 | } |
| 435 | p_dock->get_window()->grab_focus(); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | void EditorDockManager::_restore_dock_to_saved_window(EditorDock *p_dock, const Dictionary &p_window_dump) { |
| 440 | if (!p_dock->dock_window) { |
| 441 | _open_dock_in_window(p_dock, false); |
| 442 | } |
| 443 | |
| 444 | p_dock->dock_window->restore_window_from_saved_position( |
| 445 | p_window_dump.get("window_rect", Rect2i()), |
| 446 | p_window_dump.get("window_screen", -1), |
| 447 | p_window_dump.get("window_screen_rect", Rect2i())); |
| 448 | } |
| 449 | |
| 450 | void EditorDockManager::_move_dock_tab_index(EditorDock *p_dock, int p_tab_index, bool p_set_current) { |
| 451 | TabContainer *dock_tab_container = Object::cast_to<TabContainer>(p_dock->get_parent()); |
| 452 | if (!dock_tab_container) { |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | dock_tab_container->set_block_signals(true); |
| 457 | int target_index = CLAMP(p_tab_index, 0, dock_tab_container->get_tab_count() - 1); |
| 458 | dock_tab_container->move_child(p_dock, dock_tab_container->get_tab_control(target_index)->get_index(false)); |
| 459 | p_dock->previous_tab_index = target_index; |
| 460 | |
| 461 | if (p_set_current) { |
| 462 | dock_tab_container->set_current_tab(target_index); |
| 463 | } |
| 464 | dock_tab_container->set_block_signals(false); |
| 465 | } |
| 466 | |
| 467 | void EditorDockManager::_move_dock(EditorDock *p_dock, Control *p_target, int p_tab_index, bool p_set_current) { |
| 468 | ERR_FAIL_NULL(p_dock); |
| 469 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot move unknown dock '%s'.", p_dock->get_display_title())); |
| 470 | |
| 471 | Node *parent = p_dock->get_parent(); |
| 472 | if (parent == p_target) { |
| 473 | if (parent && p_tab_index >= 0) { |
| 474 | // Only change the tab index. |
| 475 | _move_dock_tab_index(p_dock, p_tab_index, p_set_current); |
| 476 | } |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | // Remove dock from its existing parent. |
| 481 | if (parent) { |
| 482 | if (p_dock->dock_window) { |
| 483 | _close_window(p_dock->dock_window); |
| 484 | } else { |
| 485 | TabContainer *parent_tabs = Object::cast_to<TabContainer>(parent); |
| 486 | if (parent_tabs) { |
| 487 | p_dock->previous_tab_index = parent_tabs->get_tab_idx_from_control(p_dock); |
| 488 | } |
| 489 | parent->set_block_signals(true); |
| 490 | parent->remove_child(p_dock); |
| 491 | parent->set_block_signals(false); |
| 492 | if (parent_tabs) { |
| 493 | _dock_container_update_visibility(parent_tabs); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (!p_target) { |
| 499 | p_dock->is_open = false; |
| 500 | return; |
| 501 | } |
| 502 | |
| 503 | if (p_target != closed_dock_parent) { |
| 504 | EditorDock::DockLayout layout = p_target->get_meta("dock_layout"); |
| 505 | if (layout != p_dock->current_layout) { |
| 506 | p_dock->update_layout(layout); |
| 507 | p_dock->current_layout = layout; |
| 508 | } |
| 509 | p_dock->dock_slot_index = p_target->get_meta("dock_slot"); |
| 510 | } |
| 511 | |
| 512 | // Add dock to its new parent, at the given tab index. |
| 513 | p_target->set_block_signals(true); |
| 514 | p_target->add_child(p_dock); |
| 515 | p_target->set_block_signals(false); |
| 516 | |
| 517 | TabContainer *dock_tab_container = Object::cast_to<TabContainer>(p_target); |
| 518 | if (dock_tab_container) { |
| 519 | if (dock_tab_container->is_inside_tree()) { |
| 520 | _update_tab_style(p_dock); |
| 521 | } |
| 522 | if (p_tab_index >= 0) { |
| 523 | _move_dock_tab_index(p_dock, p_tab_index, p_set_current); |
| 524 | } |
| 525 | _dock_container_update_visibility(dock_tab_container); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | void EditorDockManager::_queue_update_tab_style(EditorDock *p_dock) { |
| 530 | if (dirty_docks.is_empty()) { |
| 531 | callable_mp(this, &EditorDockManager::_update_dirty_dock_tabs).call_deferred(); |
| 532 | } |
| 533 | dirty_docks.insert(p_dock); |
| 534 | } |
| 535 | |
| 536 | void EditorDockManager::_update_dirty_dock_tabs() { |
| 537 | bool update_menu = false; |
| 538 | for (EditorDock *dock : dirty_docks) { |
| 539 | update_menu = update_menu || dock->global; |
| 540 | _update_tab_style(dock); |
| 541 | } |
| 542 | dirty_docks.clear(); |
| 543 | |
| 544 | if (update_menu) { |
| 545 | update_docks_menu(); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | void EditorDockManager::_update_tab_style(EditorDock *p_dock) { |
| 550 | if (!p_dock->enabled || !p_dock->is_open) { |
| 551 | return; // Disabled by feature profile or manually closed by user. |
| 552 | } |
| 553 | if (p_dock->dock_window) { |
| 554 | return; // Floating. |
| 555 | } |
| 556 | |
| 557 | TabContainer *tab_container = get_dock_tab_container(p_dock); |
| 558 | ERR_FAIL_NULL(tab_container); |
| 559 | |
| 560 | int index = tab_container->get_tab_idx_from_control(p_dock); |
| 561 | ERR_FAIL_COND(index == -1); |
| 562 | |
| 563 | tab_container->get_tab_bar()->set_font_color_override_all(index, p_dock->title_color); |
| 564 | |
| 565 | const TabStyle style = (tab_container == EditorNode::get_bottom_panel()) |
| 566 | ? (TabStyle)EDITOR_GET("interface/editor/bottom_dock_tab_style").operator int() |
| 567 | : (TabStyle)EDITOR_GET("interface/editor/dock_tab_style").operator int(); |
| 568 | |
| 569 | const Ref<Texture2D> icon = _get_dock_icon(p_dock, callable_mp((Control *)tab_container, &Control::get_editor_theme_icon)); |
| 570 | bool assign_icon = p_dock->force_show_icon; |
| 571 | String tooltip; |
| 572 | switch (style) { |
| 573 | case TabStyle::TEXT_ONLY: { |
| 574 | tab_container->set_tab_title(index, p_dock->get_display_title()); |
| 575 | } break; |
| 576 | case TabStyle::ICON_ONLY: { |
| 577 | tab_container->set_tab_title(index, icon.is_valid() ? String() : p_dock->get_display_title()); |
| 578 | tooltip = TTR(p_dock->get_display_title()); |
| 579 | assign_icon = true; |
| 580 | } break; |
| 581 | case TabStyle::TEXT_AND_ICON: { |
| 582 | tab_container->set_tab_title(index, p_dock->get_display_title()); |
| 583 | assign_icon = true; |
| 584 | } break; |
| 585 | } |
| 586 | |
| 587 | if (p_dock->shortcut.is_valid() && p_dock->shortcut->has_valid_event()) { |
| 588 | tooltip += (tooltip.is_empty() ? "" : "\n") + TTR(p_dock->shortcut->get_name()) + " (" + p_dock->shortcut->get_as_text() + ")"; |
| 589 | } |
| 590 | tab_container->set_tab_tooltip(index, tooltip); |
| 591 | |
| 592 | if (assign_icon) { |
| 593 | tab_container->set_tab_icon(index, icon); |
| 594 | } else { |
| 595 | tab_container->set_tab_icon(index, Ref<Texture2D>()); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | void EditorDockManager::save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const { |
| 600 | // Save docks by dock slot. |
| 601 | for (int i = 0; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 602 | const DockSlot &dock_slot = dock_slots[i]; |
| 603 | |
| 604 | PackedStringArray names; |
| 605 | names.reserve_exact(dock_slot.container->get_tab_count()); |
| 606 | for (int j = 0; j < dock_slot.container->get_tab_count(); j++) { |
| 607 | const String name = Object::cast_to<EditorDock>(dock_slot.container->get_tab_control(j))->get_effective_layout_key(); |
| 608 | names.append(name); |
| 609 | } |
| 610 | |
| 611 | const String config_key = "dock_" + itos(i + 1); |
| 612 | if (p_layout->has_section_key(p_section, config_key)) { |
| 613 | p_layout->erase_section_key(p_section, config_key); |
| 614 | } |
| 615 | |
| 616 | if (!names.is_empty()) { |
| 617 | p_layout->set_value(p_section, config_key, String(",").join(names)); |
| 618 | } |
| 619 | |
| 620 | const String tab_key = config_key + "_selected_tab_idx"; |
| 621 | |
| 622 | int selected_tab_idx = dock_slots[i].container->get_current_tab(); |
| 623 | if (selected_tab_idx >= 0) { |
| 624 | p_layout->set_value(p_section, tab_key, selected_tab_idx); |
| 625 | } else if (p_layout->has_section_key(p_section, tab_key)) { |
| 626 | p_layout->erase_section_key(p_section, tab_key); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | // Clear the special dock slot for docks without default slots (index -1 = dock_0). |
| 631 | // This prevents closed docks from being infinitely appended to the config on each save. |
| 632 | const String no_slot_config_key = "dock_0"; |
| 633 | if (p_layout->has_section_key(p_section, no_slot_config_key)) { |
| 634 | p_layout->erase_section_key(p_section, no_slot_config_key); |
| 635 | } |
| 636 | |
| 637 | // Save docks in windows. |
| 638 | Dictionary floating_docks_dump; |
| 639 | for (WindowWrapper *wrapper : dock_windows) { |
| 640 | EditorDock *dock = Object::cast_to<EditorDock>(wrapper->get_wrapped_control()); |
| 641 | |
| 642 | Dictionary window_dump; |
| 643 | window_dump["window_rect"] = wrapper->get_window_rect(); |
| 644 | |
| 645 | int screen = wrapper->get_window_screen(); |
| 646 | window_dump["window_screen"] = wrapper->get_window_screen(); |
| 647 | window_dump["window_screen_rect"] = DisplayServer::get_singleton()->screen_get_usable_rect(screen); |
| 648 | |
| 649 | String name = dock->get_effective_layout_key(); |
| 650 | if (!dock->transient) { |
| 651 | floating_docks_dump[name] = window_dump; |
| 652 | } |
| 653 | |
| 654 | // Append to regular dock section so we know where to restore it to. |
| 655 | int dock_slot_id = dock->dock_slot_index; |
| 656 | String config_key = "dock_" + itos(dock_slot_id + 1); |
| 657 | |
| 658 | String names = p_layout->get_value(p_section, config_key, ""); |
| 659 | if (names.is_empty()) { |
| 660 | names = name; |
| 661 | } else { |
| 662 | names += "," + name; |
| 663 | } |
| 664 | p_layout->set_value(p_section, config_key, names); |
| 665 | } |
| 666 | p_layout->set_value(p_section, "dock_floating", floating_docks_dump); |
| 667 | |
| 668 | // Save closed docks. |
| 669 | Array closed_docks_dump; |
| 670 | for (const EditorDock *dock : all_docks) { |
| 671 | const String section_name = p_section + "/" + dock->get_effective_layout_key(); |
| 672 | dock->save_layout_to_config(p_layout, section_name); |
| 673 | |
| 674 | if (dock->is_open) { |
| 675 | continue; |
| 676 | } |
| 677 | |
| 678 | const String name = dock->get_effective_layout_key(); |
| 679 | if (!dock->is_open && !dock->transient) { |
| 680 | closed_docks_dump.push_back(name); |
| 681 | } |
| 682 | |
| 683 | int dock_slot_id = dock->dock_slot_index; |
| 684 | String config_key = "dock_" + itos(dock_slot_id + 1); |
| 685 | |
| 686 | String names = p_layout->get_value(p_section, config_key, ""); |
| 687 | if (names.is_empty()) { |
| 688 | names = name; |
| 689 | } else { |
| 690 | names += "," + name; |
| 691 | } |
| 692 | p_layout->set_value(p_section, config_key, names); |
| 693 | } |
| 694 | p_layout->set_value(p_section, "dock_closed", closed_docks_dump); |
| 695 | |
| 696 | // Save SplitContainer offsets. |
| 697 | for (int i = 0; i < vsplits.size(); i++) { |
| 698 | if (vsplits[i]->is_visible_in_tree()) { |
| 699 | p_layout->set_value(p_section, "dock_split_" + itos(i + 1), vsplits[i]->get_split_offset()); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | PackedInt32Array split_offsets = main_hsplit->get_split_offsets(); |
| 704 | int index = 0; |
| 705 | for (int i = 0; i < vsplits.size(); i++) { |
| 706 | int value = 0; |
| 707 | if (vsplits[i]->is_visible() && index < split_offsets.size()) { |
| 708 | value = split_offsets[index] / EDSCALE; |
| 709 | index++; |
| 710 | } |
| 711 | p_layout->set_value(p_section, "dock_hsplit_" + itos(i + 1), value); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | void EditorDockManager::load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section, bool p_first_load) { |
| 716 | Dictionary floating_docks_dump = p_layout->get_value(p_section, "dock_floating", Dictionary()); |
| 717 | Array closed_docks = p_layout->get_value(p_section, "dock_closed", Array()); |
| 718 | |
| 719 | bool allow_floating_docks = EditorNode::get_singleton()->is_multi_window_enabled() && (!p_first_load || EDITOR_GET("interface/multi_window/restore_windows_on_load")); |
| 720 | |
| 721 | // Store the docks by name for easy lookup. |
| 722 | HashMap<String, EditorDock *> dock_map; |
| 723 | for (EditorDock *dock : all_docks) { |
| 724 | dock_map[dock->get_effective_layout_key()] = dock; |
| 725 | } |
| 726 | |
| 727 | // Load docks by slot. Index -1 is for docks that have no slot. |
| 728 | for (int i = -1; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 729 | if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) { |
| 730 | continue; |
| 731 | } |
| 732 | |
| 733 | Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(","); |
| 734 | |
| 735 | for (int j = names.size() - 1; j >= 0; j--) { |
| 736 | const String &name = names[j]; |
| 737 | const String section_name = p_section + "/" + name; |
| 738 | |
| 739 | if (!dock_map.has(name)) { |
| 740 | continue; |
| 741 | } |
| 742 | EditorDock *dock = dock_map[name]; |
| 743 | |
| 744 | if (!dock->enabled) { |
| 745 | // Don't is_open disabled docks. |
| 746 | dock->load_layout_from_config(p_layout, section_name); |
| 747 | continue; |
| 748 | } |
| 749 | |
| 750 | if (allow_floating_docks && floating_docks_dump.has(name)) { |
| 751 | _restore_dock_to_saved_window(dock, floating_docks_dump[name]); |
| 752 | } else if (i >= 0 && !(dock->transient && !dock->is_open)) { |
| 753 | // Safe to include transient open docks here because they won't be in the closed dock dump. |
| 754 | if (closed_docks.has(name)) { |
| 755 | dock->is_open = false; |
| 756 | dock->hide(); |
| 757 | _move_dock(dock, closed_dock_parent); |
| 758 | } else { |
| 759 | dock->is_open = true; |
| 760 | _move_dock(dock, dock_slots[i].container, 0); |
| 761 | } |
| 762 | } |
| 763 | dock->load_layout_from_config(p_layout, section_name); |
| 764 | |
| 765 | dock->dock_slot_index = i; |
| 766 | dock->previous_tab_index = i >= 0 ? j : 0; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | // Set the selected tabs. |
| 771 | for (int i = 0; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 772 | const DockSlot &dock_slot = dock_slots[i]; |
| 773 | |
| 774 | int selected_tab_idx = p_layout->get_value(p_section, "dock_" + itos(i + 1) + "_selected_tab_idx", -1); |
| 775 | if (selected_tab_idx <= 0 || selected_tab_idx >= dock_slot.container->get_tab_count()) { |
| 776 | if (i == DockConstants::DOCK_SLOT_BOTTOM) { |
| 777 | dock_slot.container->set_current_tab(-1); |
| 778 | } |
| 779 | continue; |
| 780 | } |
| 781 | |
| 782 | EditorDock *selected_dock = Object::cast_to<EditorDock>(dock_slot.container->get_tab_control(selected_tab_idx)); |
| 783 | if (!selected_dock) { |
| 784 | continue; |
| 785 | } |
| 786 | dock_slot.container->set_block_signals(true); |
| 787 | dock_slot.container->set_current_tab(selected_tab_idx); |
| 788 | dock_slot.container->set_block_signals(false); |
| 789 | } |
| 790 | |
| 791 | // Load SplitContainer offsets. |
| 792 | PackedInt32Array offsets; |
| 793 | for (int i = 0; i < vsplits.size(); i++) { |
| 794 | if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) { |
| 795 | continue; |
| 796 | } |
| 797 | int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1)); |
| 798 | vsplits[i]->set_split_offset(ofs); |
| 799 | |
| 800 | // Only visible ones need a split offset for the main hsplit, even though they all have a value saved. |
| 801 | if (vsplits[i]->is_visible() && p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) { |
| 802 | int offset = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1)); |
| 803 | offsets.push_back(offset * EDSCALE); |
| 804 | } |
| 805 | } |
| 806 | main_hsplit->set_split_offsets(offsets); |
| 807 | |
| 808 | update_docks_menu(); |
| 809 | } |
| 810 | |
| 811 | void EditorDockManager::set_dock_enabled(EditorDock *p_dock, bool p_enabled) { |
| 812 | ERR_FAIL_NULL(p_dock); |
| 813 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot set enabled unknown dock '%s'.", p_dock->get_display_title())); |
| 814 | |
| 815 | if (p_dock->enabled == p_enabled) { |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | p_dock->enabled = p_enabled; |
| 820 | if (p_enabled) { |
| 821 | open_dock(p_dock, false); |
| 822 | } else { |
| 823 | close_dock(p_dock); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | void EditorDockManager::close_dock(EditorDock *p_dock) { |
| 828 | ERR_FAIL_NULL(p_dock); |
| 829 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot close unknown dock '%s'.", p_dock->get_display_title())); |
| 830 | |
| 831 | if (!p_dock->is_open) { |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | p_dock->is_open = false; |
| 836 | |
| 837 | EditorBottomPanel *bottom_panel = EditorNode::get_bottom_panel(); |
| 838 | if (get_dock_tab_container(p_dock) == bottom_panel && bottom_panel->get_current_tab_control() == p_dock) { |
| 839 | bottom_panel->hide_bottom_panel(); |
| 840 | } |
| 841 | // Hide before moving to remove inconsistent signals. |
| 842 | p_dock->hide(); |
| 843 | _move_dock(p_dock, closed_dock_parent); |
| 844 | |
| 845 | _update_layout(); |
| 846 | } |
| 847 | |
| 848 | void EditorDockManager::open_dock(EditorDock *p_dock, bool p_set_current) { |
| 849 | ERR_FAIL_NULL(p_dock); |
| 850 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot open unknown dock '%s'.", p_dock->get_display_title())); |
| 851 | |
| 852 | if (p_dock->is_open) { |
| 853 | // Show the dock if it is already open. |
| 854 | if (p_set_current) { |
| 855 | _make_dock_visible(p_dock, false); |
| 856 | } |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | p_dock->is_open = true; |
| 861 | |
| 862 | // Open dock to its previous location. |
| 863 | if (p_dock->dock_slot_index != DockConstants::DOCK_SLOT_NONE) { |
| 864 | TabContainer *slot = dock_slots[p_dock->dock_slot_index].container; |
| 865 | int tab_index = p_dock->previous_tab_index; |
| 866 | if (tab_index < 0) { |
| 867 | tab_index = slot->get_tab_count(); |
| 868 | } |
| 869 | _move_dock(p_dock, slot, tab_index, p_set_current); |
| 870 | } else { |
| 871 | _open_dock_in_window(p_dock, true, true); |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | _update_layout(); |
| 876 | } |
| 877 | |
| 878 | void EditorDockManager::make_dock_floating(EditorDock *p_dock) { |
| 879 | ERR_FAIL_NULL(p_dock); |
| 880 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot make unknown dock '%s' floating.", p_dock->get_display_title())); |
| 881 | |
| 882 | if (!p_dock->dock_window) { |
| 883 | _open_dock_in_window(p_dock); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | TabContainer *EditorDockManager::get_dock_tab_container(Control *p_dock) const { |
| 888 | return Object::cast_to<TabContainer>(p_dock->get_parent()); |
| 889 | } |
| 890 | |
| 891 | void EditorDockManager::_make_dock_visible(EditorDock *p_dock, bool p_grab_focus) { |
| 892 | if (p_dock->dock_window) { |
| 893 | if (p_grab_focus) { |
| 894 | p_dock->get_window()->grab_focus(); |
| 895 | } |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | if (p_dock->get_parent() == EditorNode::get_bottom_panel()) { |
| 900 | if (EditorNode::get_bottom_panel()->is_locked()) { |
| 901 | return; |
| 902 | } |
| 903 | } else if (!docks_visible) { |
| 904 | return; |
| 905 | } |
| 906 | |
| 907 | TabContainer *tab_container = get_dock_tab_container(p_dock); |
| 908 | if (tab_container) { |
| 909 | if (p_grab_focus) { |
| 910 | tab_container->get_tab_bar()->grab_focus(); |
| 911 | } |
| 912 | |
| 913 | int tab_index = tab_container->get_tab_idx_from_control(p_dock); |
| 914 | tab_container->set_current_tab(tab_index); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | void EditorDockManager::focus_dock(EditorDock *p_dock) { |
| 919 | ERR_FAIL_NULL(p_dock); |
| 920 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot focus unknown dock '%s'.", p_dock->get_display_title())); |
| 921 | |
| 922 | if (!p_dock->enabled) { |
| 923 | return; |
| 924 | } |
| 925 | |
| 926 | if (!p_dock->is_open) { |
| 927 | open_dock(p_dock, false); |
| 928 | } |
| 929 | |
| 930 | _make_dock_visible(p_dock, true); |
| 931 | } |
| 932 | |
| 933 | void EditorDockManager::add_dock(EditorDock *p_dock) { |
| 934 | ERR_FAIL_NULL(p_dock); |
| 935 | ERR_FAIL_COND_MSG(all_docks.has(p_dock), vformat("Cannot add dock '%s', already added.", p_dock->get_display_title())); |
| 936 | |
| 937 | p_dock->dock_slot_index = p_dock->default_slot; |
| 938 | all_docks.push_back(p_dock); |
| 939 | p_dock->connect("_tab_style_changed", callable_mp(this, &EditorDockManager::_queue_update_tab_style).bind(p_dock)); |
| 940 | p_dock->connect("renamed", callable_mp(this, &EditorDockManager::_queue_update_tab_style).bind(p_dock)); |
| 941 | |
| 942 | if (p_dock->default_slot != EditorDock::DOCK_SLOT_NONE) { |
| 943 | open_dock(p_dock, false); |
| 944 | } else { |
| 945 | closed_dock_parent->add_child(p_dock); |
| 946 | p_dock->hide(); |
| 947 | _update_layout(); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | void EditorDockManager::remove_dock(EditorDock *p_dock) { |
| 952 | ERR_FAIL_NULL(p_dock); |
| 953 | ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot remove unknown dock '%s'.", p_dock->get_display_title())); |
| 954 | |
| 955 | _move_dock(p_dock, nullptr); |
| 956 | |
| 957 | all_docks.erase(p_dock); |
| 958 | p_dock->disconnect("_tab_style_changed", callable_mp(this, &EditorDockManager::_queue_update_tab_style)); |
| 959 | p_dock->disconnect("renamed", callable_mp(this, &EditorDockManager::_queue_update_tab_style)); |
| 960 | _update_layout(); |
| 961 | } |
| 962 | |
| 963 | void EditorDockManager::set_docks_visible(bool p_show) { |
| 964 | if (docks_visible == p_show) { |
| 965 | return; |
| 966 | } |
| 967 | docks_visible = p_show; |
| 968 | for (int i = 0; i < DockConstants::DOCK_SLOT_BOTTOM; i++) { |
| 969 | // Show and hide in reverse order due to the SplitContainer prioritizing the last split offset. |
| 970 | TabContainer *container = dock_slots[docks_visible ? i : DockConstants::DOCK_SLOT_BOTTOM - i - 1].container; |
| 971 | container->set_visible(docks_visible && container->get_tab_count() > 0); |
| 972 | } |
| 973 | _update_layout(); |
| 974 | } |
| 975 | |
| 976 | bool EditorDockManager::are_docks_visible() const { |
| 977 | return docks_visible; |
| 978 | } |
| 979 | |
| 980 | void EditorDockManager::update_tab_styles() { |
| 981 | for (EditorDock *dock : all_docks) { |
| 982 | _update_tab_style(dock); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | void EditorDockManager::set_tab_icon_max_width(int p_max_width) { |
| 987 | for (int i = 0; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 988 | TabContainer *tab_container = dock_slots[i].container; |
| 989 | tab_container->add_theme_constant_override(SNAME("icon_max_width"), p_max_width); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | void EditorDockManager::add_vsplit(DockSplitContainer *p_split) { |
| 994 | vsplits.push_back(p_split); |
| 995 | p_split->connect("dragged", callable_mp(this, &EditorDockManager::_dock_split_dragged)); |
| 996 | } |
| 997 | |
| 998 | void EditorDockManager::set_hsplit(DockSplitContainer *p_split) { |
| 999 | main_hsplit = p_split; |
| 1000 | p_split->connect("dragged", callable_mp(this, &EditorDockManager::_dock_split_dragged)); |
| 1001 | } |
| 1002 | |
| 1003 | void EditorDockManager::register_dock_slot(DockConstants::DockSlot p_dock_slot, TabContainer *p_tab_container, DockConstants::DockLayout p_layout) { |
| 1004 | ERR_FAIL_NULL(p_tab_container); |
| 1005 | ERR_FAIL_INDEX(p_dock_slot, DockConstants::DOCK_SLOT_MAX); |
| 1006 | |
| 1007 | DockSlot slot; |
| 1008 | slot.layout = p_layout; |
| 1009 | |
| 1010 | slot.container = p_tab_container; |
| 1011 | p_tab_container->set_popup(dock_context_popup); |
| 1012 | p_tab_container->connect("pre_popup_pressed", callable_mp(dock_context_popup, &DockContextPopup::select_current_dock_in_dock_slot).bind(p_dock_slot)); |
| 1013 | p_tab_container->get_tab_bar()->set_switch_on_release(true); |
| 1014 | p_tab_container->get_tab_bar()->connect("tab_rmb_clicked", callable_mp(this, &EditorDockManager::_dock_container_popup).bind(p_tab_container)); |
| 1015 | p_tab_container->set_drag_to_rearrange_enabled(true); |
| 1016 | p_tab_container->set_tabs_rearrange_group(1); |
| 1017 | p_tab_container->connect("tab_changed", callable_mp(this, &EditorDockManager::_update_layout).unbind(1)); |
| 1018 | p_tab_container->connect("active_tab_rearranged", callable_mp(this, &EditorDockManager::_update_layout).unbind(1)); |
| 1019 | p_tab_container->connect("child_order_changed", callable_mp(this, &EditorDockManager::_dock_container_update_visibility).bind(p_tab_container)); |
| 1020 | p_tab_container->hide(); |
| 1021 | p_tab_container->set_meta("dock_slot", p_dock_slot); |
| 1022 | p_tab_container->set_meta("dock_layout", p_layout); |
| 1023 | |
| 1024 | if (p_layout == DockConstants::DOCK_LAYOUT_VERTICAL) { |
| 1025 | p_tab_container->set_custom_minimum_size(Size2(170, 0) * EDSCALE); |
| 1026 | p_tab_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1027 | p_tab_container->set_use_hidden_tabs_for_min_size(true); |
| 1028 | } |
| 1029 | |
| 1030 | // Create dock dragging hint. |
| 1031 | slot.drag_hint = memnew(EditorDockDragHint); |
| 1032 | slot.drag_hint->hide(); |
| 1033 | EditorNode::get_singleton()->get_gui_base()->add_child(slot.drag_hint); |
| 1034 | |
| 1035 | dock_slots[p_dock_slot] = slot; |
| 1036 | slot.drag_hint->set_slot(p_dock_slot); |
| 1037 | } |
| 1038 | |
| 1039 | int EditorDockManager::get_vsplit_count() const { |
| 1040 | return vsplits.size(); |
| 1041 | } |
| 1042 | |
| 1043 | PopupMenu *EditorDockManager::get_docks_menu() { |
| 1044 | return docks_menu; |
| 1045 | } |
| 1046 | |
| 1047 | EditorDockManager::EditorDockManager() { |
| 1048 | singleton = this; |
| 1049 | |
| 1050 | closed_dock_parent = memnew(Control); |
| 1051 | closed_dock_parent->hide(); |
| 1052 | EditorNode::get_singleton()->get_gui_base()->add_child(closed_dock_parent); |
| 1053 | |
| 1054 | dock_context_popup = memnew(DockContextPopup); |
| 1055 | EditorNode::get_singleton()->get_gui_base()->add_child(dock_context_popup); |
| 1056 | EditorNode::get_singleton()->add_child(memnew(DockShortcutHandler)); |
| 1057 | |
| 1058 | docks_menu = memnew(PopupMenu); |
| 1059 | docks_menu->set_hide_on_item_selection(false); |
| 1060 | docks_menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorDockManager::_docks_menu_option)); |
| 1061 | EditorNode::get_singleton()->get_gui_base()->connect(SceneStringName(theme_changed), callable_mp(this, &EditorDockManager::update_docks_menu)); |
| 1062 | } |
| 1063 | |
| 1064 | //////////////////////////////////////////////// |
| 1065 | //////////////////////////////////////////////// |
| 1066 | |
| 1067 | void DockContextPopup::_notification(int p_what) { |
| 1068 | switch (p_what) { |
| 1069 | case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED: |
| 1070 | case NOTIFICATION_TRANSLATION_CHANGED: |
| 1071 | case NOTIFICATION_THEME_CHANGED: { |
| 1072 | if (make_float_button) { |
| 1073 | make_float_button->set_button_icon(get_editor_theme_icon(SNAME("MakeFloating"))); |
| 1074 | } |
| 1075 | if (is_layout_rtl()) { |
| 1076 | tab_move_left_button->set_button_icon(get_editor_theme_icon(SNAME("Forward"))); |
| 1077 | tab_move_right_button->set_button_icon(get_editor_theme_icon(SNAME("Back"))); |
| 1078 | tab_move_left_button->set_tooltip_text(TTR("Move this dock right one tab.")); |
| 1079 | tab_move_right_button->set_tooltip_text(TTR("Move this dock left one tab.")); |
| 1080 | } else { |
| 1081 | tab_move_left_button->set_button_icon(get_editor_theme_icon(SNAME("Back"))); |
| 1082 | tab_move_right_button->set_button_icon(get_editor_theme_icon(SNAME("Forward"))); |
| 1083 | tab_move_left_button->set_tooltip_text(TTR("Move this dock left one tab.")); |
| 1084 | tab_move_right_button->set_tooltip_text(TTR("Move this dock right one tab.")); |
| 1085 | } |
| 1086 | close_button->set_button_icon(get_editor_theme_icon(SNAME("Close"))); |
| 1087 | } break; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | void DockContextPopup::_tab_move_left() { |
| 1092 | TabContainer *tab_container = dock_manager->get_dock_tab_container(context_dock); |
| 1093 | if (!tab_container) { |
| 1094 | return; |
| 1095 | } |
| 1096 | int new_index = tab_container->get_tab_idx_from_control(context_dock) - 1; |
| 1097 | dock_manager->_move_dock(context_dock, tab_container, new_index); |
| 1098 | dock_manager->_update_layout(); |
| 1099 | dock_select->queue_redraw(); |
| 1100 | } |
| 1101 | |
| 1102 | void DockContextPopup::_tab_move_right() { |
| 1103 | TabContainer *tab_container = dock_manager->get_dock_tab_container(context_dock); |
| 1104 | if (!tab_container) { |
| 1105 | return; |
| 1106 | } |
| 1107 | int new_index = tab_container->get_tab_idx_from_control(context_dock) + 1; |
| 1108 | dock_manager->_move_dock(context_dock, tab_container, new_index); |
| 1109 | dock_manager->_update_layout(); |
| 1110 | dock_select->queue_redraw(); |
| 1111 | } |
| 1112 | |
| 1113 | void DockContextPopup::_close_dock() { |
| 1114 | hide(); |
| 1115 | context_dock->emit_signal("closed"); |
| 1116 | dock_manager->close_dock(context_dock); |
| 1117 | } |
| 1118 | |
| 1119 | void DockContextPopup::_float_dock() { |
| 1120 | hide(); |
| 1121 | dock_manager->_open_dock_in_window(context_dock); |
| 1122 | } |
| 1123 | |
| 1124 | bool DockContextPopup::_is_slot_available(int p_slot) const { |
| 1125 | return context_dock->available_layouts & (EditorDock::DockLayout)EditorDockManager::get_singleton()->dock_slots[p_slot].layout; |
| 1126 | } |
| 1127 | |
| 1128 | void DockContextPopup::_dock_select_input(const Ref<InputEvent> &p_input) { |
| 1129 | Ref<InputEventMouse> me = p_input; |
| 1130 | |
| 1131 | if (me.is_valid()) { |
| 1132 | Vector2 point = me->get_position(); |
| 1133 | |
| 1134 | int over_dock_slot = -1; |
| 1135 | for (int i = 0; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 1136 | if (dock_select_rects[i].has_point(point)) { |
| 1137 | over_dock_slot = i; |
| 1138 | break; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | if (over_dock_slot != dock_select_rect_over_idx) { |
| 1143 | dock_select->queue_redraw(); |
| 1144 | dock_select_rect_over_idx = over_dock_slot; |
| 1145 | } |
| 1146 | |
| 1147 | if (over_dock_slot == -1) { |
| 1148 | return; |
| 1149 | } |
| 1150 | |
| 1151 | Ref<InputEventMouseButton> mb = me; |
| 1152 | TabContainer *target_tab_container = dock_manager->dock_slots[over_dock_slot].container; |
| 1153 | |
| 1154 | if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) { |
| 1155 | if (dock_manager->get_dock_tab_container(context_dock) != target_tab_container && _is_slot_available(over_dock_slot)) { |
| 1156 | dock_manager->_move_dock(context_dock, target_tab_container, target_tab_container->get_tab_count()); |
| 1157 | dock_manager->_update_layout(); |
| 1158 | hide(); |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | void DockContextPopup::_dock_select_mouse_exited() { |
| 1165 | dock_select_rect_over_idx = -1; |
| 1166 | dock_select->queue_redraw(); |
| 1167 | } |
| 1168 | |
| 1169 | void DockContextPopup::_dock_select_draw() { |
| 1170 | Color used_dock_color = Color(0.6, 0.6, 0.6, 0.8); |
| 1171 | Color hovered_dock_color = Color(0.8, 0.8, 0.8, 0.8); |
| 1172 | Color tab_selected_color = dock_select->get_theme_color(SNAME("mono_color"), EditorStringName(Editor)); |
| 1173 | Color tab_unselected_color = used_dock_color; |
| 1174 | Color unused_dock_color = used_dock_color; |
| 1175 | unused_dock_color.a = 0.4; |
| 1176 | Color unusable_dock_color = unused_dock_color; |
| 1177 | unusable_dock_color.a = 0.1; |
| 1178 | |
| 1179 | // Update sizes. |
| 1180 | Size2 dock_size = dock_select->get_size(); |
| 1181 | dock_size.x /= 6.0; |
| 1182 | dock_size.y /= 2.0; |
| 1183 | |
| 1184 | real_t center_panel_width = dock_size.x * 2.0; |
| 1185 | Rect2 center_panel_rect(center_panel_width, 0, center_panel_width, dock_size.y); |
| 1186 | |
| 1187 | if (dock_select->is_layout_rtl()) { |
| 1188 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_UR] = Rect2(Point2(), dock_size); |
| 1189 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_BR] = Rect2(Point2(0, dock_size.y), dock_size); |
| 1190 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_UL] = Rect2(Point2(dock_size.x, 0), dock_size); |
| 1191 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_BL] = Rect2(dock_size, dock_size); |
| 1192 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_UR] = Rect2(Point2(dock_size.x * 4, 0), dock_size); |
| 1193 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_BR] = Rect2(Point2(dock_size.x * 4, dock_size.y), dock_size); |
| 1194 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_UL] = Rect2(Point2(dock_size.x * 5, 0), dock_size); |
| 1195 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_BL] = Rect2(Point2(dock_size.x * 5, dock_size.y), dock_size); |
| 1196 | } else { |
| 1197 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_UL] = Rect2(Point2(), dock_size); |
| 1198 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_BL] = Rect2(Point2(0, dock_size.y), dock_size); |
| 1199 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_UR] = Rect2(Point2(dock_size.x, 0), dock_size); |
| 1200 | dock_select_rects[DockConstants::DOCK_SLOT_LEFT_BR] = Rect2(dock_size, dock_size); |
| 1201 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_UL] = Rect2(Point2(dock_size.x * 4, 0), dock_size); |
| 1202 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_BL] = Rect2(Point2(dock_size.x * 4, dock_size.y), dock_size); |
| 1203 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_UR] = Rect2(Point2(dock_size.x * 5, 0), dock_size); |
| 1204 | dock_select_rects[DockConstants::DOCK_SLOT_RIGHT_BR] = Rect2(Point2(dock_size.x * 5, dock_size.y), dock_size); |
| 1205 | } |
| 1206 | dock_select_rects[DockConstants::DOCK_SLOT_BOTTOM] = Rect2(center_panel_width, dock_size.y, center_panel_width, dock_size.y); |
| 1207 | |
| 1208 | int rtl_dir = dock_select->is_layout_rtl() ? -1 : 1; |
| 1209 | real_t tab_height = 3.0 * EDSCALE; |
| 1210 | real_t tab_spacing = 1.0 * EDSCALE; |
| 1211 | real_t dock_spacing = 2.0 * EDSCALE; |
| 1212 | real_t dock_top_spacing = tab_height + dock_spacing; |
| 1213 | |
| 1214 | TabContainer *context_tab_container = dock_manager->get_dock_tab_container(context_dock); |
| 1215 | int context_tab_index = -1; |
| 1216 | if (context_tab_container && context_tab_container->get_tab_count() > 0) { |
| 1217 | context_tab_index = context_tab_container->get_tab_idx_from_control(context_dock); |
| 1218 | } |
| 1219 | |
| 1220 | // Draw center panel. |
| 1221 | Rect2 center_panel_draw_rect = center_panel_rect.grow_individual(-dock_spacing, -dock_top_spacing, -dock_spacing, -dock_spacing); |
| 1222 | dock_select->draw_rect(center_panel_draw_rect, unusable_dock_color); |
| 1223 | |
| 1224 | // Draw all dock slots. |
| 1225 | for (int i = 0; i < DockConstants::DOCK_SLOT_MAX; i++) { |
| 1226 | int max_tabs = (i == DockConstants::DOCK_SLOT_BOTTOM) ? 6 : 3; |
| 1227 | const EditorDockManager::DockSlot &dock_slot = dock_manager->dock_slots[i]; |
| 1228 | |
| 1229 | Rect2 dock_slot_draw_rect = dock_select_rects[i].grow_individual(-dock_spacing, -dock_top_spacing, -dock_spacing, -dock_spacing); |
| 1230 | real_t tab_width = Math::round(dock_slot_draw_rect.size.width / max_tabs); |
| 1231 | Rect2 tab_draw_rect = Rect2(dock_slot_draw_rect.position.x, dock_select_rects[i].position.y, tab_width - tab_spacing, tab_height); |
| 1232 | |
| 1233 | real_t max_width = tab_width * max_tabs; |
| 1234 | // Tabs may not fit perfectly, so they need to be re-centered. |
| 1235 | if (max_width > dock_slot_draw_rect.size.x) { |
| 1236 | tab_draw_rect.position.x -= int(max_width - dock_slot_draw_rect.size.x) / 2 * rtl_dir; |
| 1237 | } |
| 1238 | if (dock_select->is_layout_rtl()) { |
| 1239 | tab_draw_rect.position.x += dock_slot_draw_rect.size.x - tab_draw_rect.size.x; |
| 1240 | } |
| 1241 | |
| 1242 | int tabs_to_draw = MIN(max_tabs, dock_slot.container->get_tab_count()); |
| 1243 | bool is_context_dock = context_tab_container == dock_slot.container; |
| 1244 | if (i == context_dock->dock_slot_index) { |
| 1245 | dock_select->draw_rect(dock_slot_draw_rect, tab_selected_color); |
| 1246 | } else if (!_is_slot_available(i)) { |
| 1247 | dock_select->draw_rect(dock_slot_draw_rect, unusable_dock_color); |
| 1248 | } else if (i == dock_select_rect_over_idx) { |
| 1249 | dock_select->draw_rect(dock_slot_draw_rect, hovered_dock_color); |
| 1250 | } else if (tabs_to_draw == 0) { |
| 1251 | dock_select->draw_rect(dock_slot_draw_rect, unused_dock_color); |
| 1252 | } else { |
| 1253 | dock_select->draw_rect(dock_slot_draw_rect, used_dock_color); |
| 1254 | } |
| 1255 | |
| 1256 | // Draw tabs above each used dock slot. |
| 1257 | for (int j = 0; j < tabs_to_draw; j++) { |
| 1258 | Color tab_color = tab_unselected_color; |
| 1259 | if (is_context_dock && context_tab_index == j) { |
| 1260 | tab_color = tab_selected_color; |
| 1261 | } |
| 1262 | Rect2 tabj_draw_rect = tab_draw_rect; |
| 1263 | tabj_draw_rect.position.x += tab_width * j * rtl_dir; |
| 1264 | dock_select->draw_rect(tabj_draw_rect, tab_color); |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | void DockContextPopup::_update_buttons() { |
| 1270 | TabContainer *context_tab_container = dock_manager->get_dock_tab_container(context_dock); |
| 1271 | if (context_dock->global || context_dock->closable) { |
| 1272 | close_button->set_tooltip_text(TTRC("Close this dock.")); |
| 1273 | close_button->set_disabled(false); |
| 1274 | } else { |
| 1275 | close_button->set_tooltip_text(TTRC("This dock can't be closed.")); |
| 1276 | close_button->set_disabled(true); |
| 1277 | } |
| 1278 | if (EditorNode::get_singleton()->is_multi_window_enabled()) { |
| 1279 | if (!(context_dock->available_layouts & EditorDock::DOCK_LAYOUT_FLOATING)) { |
| 1280 | make_float_button->set_tooltip_text(TTRC("This dock does not support floating.")); |
| 1281 | make_float_button->set_disabled(true); |
| 1282 | } else { |
| 1283 | make_float_button->set_tooltip_text(TTRC("Make this dock floating.")); |
| 1284 | make_float_button->set_disabled(false); |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | // Update tab move buttons. |
| 1289 | tab_move_left_button->set_disabled(true); |
| 1290 | tab_move_right_button->set_disabled(true); |
| 1291 | if (context_tab_container && context_tab_container->get_tab_count() > 0) { |
| 1292 | int context_tab_index = context_tab_container->get_tab_idx_from_control(context_dock); |
| 1293 | tab_move_left_button->set_disabled(context_tab_index == 0); |
| 1294 | tab_move_right_button->set_disabled(context_tab_index >= context_tab_container->get_tab_count() - 1); |
| 1295 | } |
| 1296 | reset_size(); |
| 1297 | } |
| 1298 | |
| 1299 | void DockContextPopup::select_current_dock_in_dock_slot(int p_dock_slot) { |
| 1300 | context_dock = Object::cast_to<EditorDock>(dock_manager->dock_slots[p_dock_slot].container->get_current_tab_control()); |
| 1301 | _update_buttons(); |
| 1302 | } |
| 1303 | |
| 1304 | void DockContextPopup::set_dock(EditorDock *p_dock) { |
| 1305 | context_dock = p_dock; |
| 1306 | _update_buttons(); |
| 1307 | } |
| 1308 | |
| 1309 | EditorDock *DockContextPopup::get_dock() const { |
| 1310 | return context_dock; |
| 1311 | } |
| 1312 | |
| 1313 | void DockContextPopup::docks_updated() { |
| 1314 | if (!is_visible()) { |
| 1315 | return; |
| 1316 | } |
| 1317 | _update_buttons(); |
| 1318 | } |
| 1319 | |
| 1320 | DockContextPopup::DockContextPopup() { |
| 1321 | dock_manager = EditorDockManager::get_singleton(); |
| 1322 | |
| 1323 | dock_select_popup_vb = memnew(VBoxContainer); |
| 1324 | add_child(dock_select_popup_vb); |
| 1325 | |
| 1326 | HBoxContainer *header_hb = memnew(HBoxContainer); |
| 1327 | tab_move_left_button = memnew(Button); |
| 1328 | tab_move_left_button->set_accessibility_name(TTRC("Move Tab Left")); |
| 1329 | tab_move_left_button->set_flat(true); |
| 1330 | tab_move_left_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1331 | tab_move_left_button->connect(SceneStringName(pressed), callable_mp(this, &DockContextPopup::_tab_move_left)); |
| 1332 | header_hb->add_child(tab_move_left_button); |
| 1333 | |
| 1334 | Label *position_label = memnew(Label); |
| 1335 | position_label->set_text(TTRC("Dock Position")); |
| 1336 | position_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1337 | position_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 1338 | header_hb->add_child(position_label); |
| 1339 | |
| 1340 | tab_move_right_button = memnew(Button); |
| 1341 | tab_move_right_button->set_accessibility_name(TTRC("Move Tab Right")); |
| 1342 | tab_move_right_button->set_flat(true); |
| 1343 | tab_move_right_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1344 | tab_move_right_button->connect(SceneStringName(pressed), callable_mp(this, &DockContextPopup::_tab_move_right)); |
| 1345 | |
| 1346 | header_hb->add_child(tab_move_right_button); |
| 1347 | dock_select_popup_vb->add_child(header_hb); |
| 1348 | |
| 1349 | dock_select = memnew(Control); |
| 1350 | dock_select->set_custom_minimum_size(Size2(128, 64) * EDSCALE); |
| 1351 | dock_select->connect(SceneStringName(gui_input), callable_mp(this, &DockContextPopup::_dock_select_input)); |
| 1352 | dock_select->connect(SceneStringName(draw), callable_mp(this, &DockContextPopup::_dock_select_draw)); |
| 1353 | dock_select->connect(SceneStringName(mouse_exited), callable_mp(this, &DockContextPopup::_dock_select_mouse_exited)); |
| 1354 | dock_select->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1355 | dock_select_popup_vb->add_child(dock_select); |
| 1356 | |
| 1357 | make_float_button = memnew(Button); |
| 1358 | make_float_button->set_text(TTRC("Make Floating")); |
| 1359 | if (!EditorNode::get_singleton()->is_multi_window_enabled()) { |
| 1360 | make_float_button->set_disabled(true); |
| 1361 | make_float_button->set_tooltip_text(EditorNode::get_singleton()->get_multiwindow_support_tooltip_text()); |
| 1362 | } |
| 1363 | make_float_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1364 | make_float_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1365 | make_float_button->connect(SceneStringName(pressed), callable_mp(this, &DockContextPopup::_float_dock)); |
| 1366 | dock_select_popup_vb->add_child(make_float_button); |
| 1367 | |
| 1368 | close_button = memnew(Button); |
| 1369 | close_button->set_text(TTRC("Close")); |
| 1370 | close_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1371 | close_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1372 | close_button->connect(SceneStringName(pressed), callable_mp(this, &DockContextPopup::_close_dock)); |
| 1373 | dock_select_popup_vb->add_child(close_button); |
| 1374 | } |
| 1375 | |
| 1376 | void DockShortcutHandler::shortcut_input(const Ref<InputEvent> &p_event) { |
| 1377 | if (p_event.is_null() || !p_event->is_pressed() || p_event->is_echo()) { |
| 1378 | return; |
| 1379 | } |
| 1380 | |
| 1381 | for (EditorDock *dock : EditorDockManager::get_singleton()->all_docks) { |
| 1382 | const Ref<Shortcut> &dock_shortcut = dock->get_dock_shortcut(); |
| 1383 | if (dock_shortcut.is_valid() && dock_shortcut->matches_event(p_event)) { |
| 1384 | if (dock->is_visible() && dock->get_parent() == EditorNode::get_bottom_panel()) { |
| 1385 | EditorNode::get_bottom_panel()->hide_bottom_panel(); |
| 1386 | } else if (!dock->transient || dock->is_open) { |
| 1387 | EditorDockManager::get_singleton()->focus_dock(dock); |
| 1388 | } |
| 1389 | get_viewport()->set_input_as_handled(); |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | } |