|
| 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 | + |
| 36 | +void EditorDock::_set_default_slot_bind(EditorPlugin::DockSlot p_slot) { |
| 37 | + ERR_FAIL_COND(p_slot < EditorPlugin::DOCK_SLOT_NONE || p_slot >= EditorPlugin::DOCK_SLOT_MAX); |
| 38 | + default_slot = (EditorDockManager::DockSlot)p_slot; |
| 39 | +} |
| 40 | + |
| 41 | +void EditorDock::_bind_methods() { |
| 42 | + ClassDB::bind_method(D_METHOD("set_title", "title"), &EditorDock::set_title); |
| 43 | + ClassDB::bind_method(D_METHOD("get_title"), &EditorDock::get_title); |
| 44 | + ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title"); |
| 45 | + |
| 46 | + ClassDB::bind_method(D_METHOD("set_layout_key", "layout_key"), &EditorDock::set_layout_key); |
| 47 | + ClassDB::bind_method(D_METHOD("get_layout_key"), &EditorDock::get_layout_key); |
| 48 | + ADD_PROPERTY(PropertyInfo(Variant::STRING, "layout_key"), "set_layout_key", "get_layout_key"); |
| 49 | + |
| 50 | + ClassDB::bind_method(D_METHOD("set_icon_name", "icon_name"), &EditorDock::set_icon_name); |
| 51 | + ClassDB::bind_method(D_METHOD("get_icon_name"), &EditorDock::get_icon_name); |
| 52 | + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "icon_name"), "set_icon_name", "get_icon_name"); |
| 53 | + |
| 54 | + ClassDB::bind_method(D_METHOD("set_dock_icon", "icon"), &EditorDock::set_dock_icon); |
| 55 | + ClassDB::bind_method(D_METHOD("get_dock_icon"), &EditorDock::get_dock_icon); |
| 56 | + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dock_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_dock_icon", "get_dock_icon"); |
| 57 | + |
| 58 | + ClassDB::bind_method(D_METHOD("set_dock_shortcut", "shortcut"), &EditorDock::set_dock_shortcut); |
| 59 | + ClassDB::bind_method(D_METHOD("get_dock_shortcut"), &EditorDock::get_dock_shortcut); |
| 60 | + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dock_shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_dock_shortcut", "get_dock_shortcut"); |
| 61 | + |
| 62 | + ClassDB::bind_method(D_METHOD("set_default_slot", "slot"), &EditorDock::_set_default_slot_bind); |
| 63 | + ClassDB::bind_method(D_METHOD("get_default_slot"), &EditorDock::_get_default_slot_bind); |
| 64 | + ADD_PROPERTY(PropertyInfo(Variant::INT, "default_slot"), "set_default_slot", "get_default_slot"); |
| 65 | + |
| 66 | + ClassDB::bind_method(D_METHOD("set_available_layouts", "layouts"), &EditorDock::set_available_layouts); |
| 67 | + ClassDB::bind_method(D_METHOD("get_available_layouts"), &EditorDock::get_available_layouts); |
| 68 | + ADD_PROPERTY(PropertyInfo(Variant::INT, "available_layouts", PROPERTY_HINT_FLAGS, "Vertical:1,Horizontal:2"), "set_available_layouts", "get_available_layouts"); |
| 69 | + |
| 70 | + BIND_BITFIELD_FLAG(DOCK_LAYOUT_VERTICAL); |
| 71 | + BIND_BITFIELD_FLAG(DOCK_LAYOUT_HORIZONTAL); |
| 72 | + |
| 73 | + GDVIRTUAL_BIND(_update_layout, "layout"); |
| 74 | + GDVIRTUAL_BIND(_save_layout_to_config, "config", "section"); |
| 75 | + GDVIRTUAL_BIND(_load_layout_from_config, "config", "section"); |
| 76 | +} |
| 77 | + |
| 78 | +EditorDock::EditorDock() { |
| 79 | + set_clip_contents(true); |
| 80 | + add_user_signal(MethodInfo("tab_style_changed")); |
| 81 | +} |
| 82 | + |
| 83 | +void EditorDock::set_title(const String &p_title) { |
| 84 | + if (title == p_title) { |
| 85 | + return; |
| 86 | + } |
| 87 | + title = p_title; |
| 88 | + emit_signal("tab_style_changed"); |
| 89 | +} |
| 90 | + |
| 91 | +void EditorDock::set_icon_name(const StringName &p_name) { |
| 92 | + if (icon_name == p_name) { |
| 93 | + return; |
| 94 | + } |
| 95 | + icon_name = p_name; |
| 96 | + emit_signal("tab_style_changed"); |
| 97 | +} |
| 98 | + |
| 99 | +void EditorDock::set_dock_icon(const Ref<Texture2D> &p_icon) { |
| 100 | + if (dock_icon == p_icon) { |
| 101 | + return; |
| 102 | + } |
| 103 | + dock_icon = p_icon; |
| 104 | + emit_signal("tab_style_changed"); |
| 105 | +} |
| 106 | + |
| 107 | +void EditorDock::set_default_slot(EditorDockManager::DockSlot p_slot) { |
| 108 | + ERR_FAIL_INDEX(p_slot, EditorDockManager::DOCK_SLOT_MAX); |
| 109 | + default_slot = p_slot; |
| 110 | +} |
| 111 | + |
| 112 | +String EditorDock::get_display_title() const { |
| 113 | + if (!title.is_empty()) { |
| 114 | + return title; |
| 115 | + } |
| 116 | + |
| 117 | + const String sname = get_name(); |
| 118 | + if (sname.contains_char('@')) { |
| 119 | + // Auto-generated name, try to use something better. |
| 120 | + const Node *child = get_child_count() > 0 ? get_child(0) : nullptr; |
| 121 | + if (child) { |
| 122 | + // In user plugins, the child will usually be dock's content and have a proper name. |
| 123 | + return child->get_name(); |
| 124 | + } |
| 125 | + } |
| 126 | + return sname; |
| 127 | +} |
| 128 | + |
| 129 | +String EditorDock::get_effective_layout_key() const { |
| 130 | + return layout_key.is_empty() ? get_display_title() : layout_key; |
| 131 | +} |
0 commit comments