Skip to content

Rework editor docks #106503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions doc/classes/EditorDock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorDock" inherits="MarginContainer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Dockable container for the editor.
</brief_description>
<description>
EditorDock is a [Container] node that can be docked in one of the editor's dock slots. Docks are added by plugins to provide space for controls related to an [EditorPlugin]. The editor comes with a few built-in docks, such as the Scene dock, FileSystem dock, etc.
You can add a dock by using [method EditorPlugin.add_dock]. The dock can be customized by changing its properties.
[codeblock]
extends EditorPlugin

# Dock reference.
var dock

# Plugin initialization.
func _enter_tree():
dock = EditorDock.new()
dock.title = "My Dock"
dock.dock_icon = load("./dock_icon.png")
dock.default_slot = EditorPlugin.DOCK_SLOT_RIGHT_UL
var dock_content = preload("./dock_content.tscn").instantiate()
dock.add_child(dock_content)
add_dock(dock)

# Plugin clean-up.
func _exit_tree():
remove_dock(dock)
dock.queue_free()
dock = null
[/codeblock]
</description>
<tutorials>
<link title="Making plugins">$DOCS_URL/plugins/editor/making_plugins.html</link>
</tutorials>
<methods>
<method name="_load_layout_from_config" qualifiers="virtual">
<return type="void" />
<param index="0" name="config" type="ConfigFile" />
<param index="1" name="section" type="String" />
<description>
Implement this method to handle loading of this dock's layout. It's equivalent to [method EditorPlugin._set_window_layout]. [param section] is a unique section based on [member layout_key].
</description>
</method>
<method name="_save_layout_to_config" qualifiers="virtual const">
<return type="void" />
<param index="0" name="config" type="ConfigFile" />
<param index="1" name="section" type="String" />
<description>
Implement this method to handle saving of this dock's layout. It's equivalent to [method EditorPlugin._get_window_layout]. [param section] is a unique section based on [member layout_key].
</description>
</method>
<method name="_update_layout" qualifiers="virtual">
<return type="void" />
<param index="0" name="layout" type="int" />
<description>
Implement this method to handle the layout switching for this dock. [param layout] is one of [enum DockLayout] constants.
[codeblock]
_update_layout(layout):
box_container.vertical = (layout == DOCK_LAYOUT_VERTICAL)
[/codeblock]
</description>
</method>
</methods>
<members>
<member name="available_layouts" type="int" setter="set_available_layouts" getter="get_available_layouts" enum="EditorDock.DockLayout" is_bitfield="true" default="1">
The available layouts for this dock, as a bitmask.
If you want to make all layouts available, use [code]available_layouts = DOCK_LAYOUT_VERTICAL | DOCK_LAYOUT_HORIZONTAL[/code].
</member>
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
<member name="default_slot" type="int" setter="set_default_slot" getter="get_default_slot" enum="EditorPlugin.DockSlot" default="-1">
The default dock slot used when adding the dock with [method EditorPlugin.add_dock].
After the dock is added, it can be moved to a different slot and the editor will automatically remember its position between sessions. If you remove and re-add the dock, it will be reset to default.
</member>
<member name="dock_icon" type="Texture2D" setter="set_dock_icon" getter="get_dock_icon">
The icon for the dock, as a texture. If specified, it will override [member icon_name].
</member>
<member name="dock_shortcut" type="Shortcut" setter="set_dock_shortcut" getter="get_dock_shortcut">
The shortcut used to open the dock. This property can only be set before this dock is added via [method EditorPlugin.add_dock].
</member>
<member name="icon_name" type="StringName" setter="set_icon_name" getter="get_icon_name" default="&amp;&quot;&quot;">
The icon for the dock, as a name from the [code]EditorIcons[/code] theme type in the editor theme. You can find the list of available icons [url=https://godot-editor-icons.github.io/]here[/url].
</member>
<member name="layout_key" type="String" setter="set_layout_key" getter="get_layout_key" default="&quot;&quot;">
The key representing this dock in the editor's layout file. If empty, the dock's displayed name will be used instead.
</member>
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;&quot;">
The title of the dock's tab. If empty, the dock's [member Node.name] will be used. If the name is auto-generated (contains [code]@[/code]), the first child's name will be used instead.
</member>
</members>
<constants>
<constant name="DOCK_LAYOUT_VERTICAL" value="1" enum="DockLayout" is_bitfield="true">
Allows placing the dock in the vertical dock slots on either sides of the editor.
[b]Note:[/b] Currently this flag has no effect, because the bottom panel is not a proper dock slot. This means that the dock can always be vertical.
</constant>
<constant name="DOCK_LAYOUT_HORIZONTAL" value="2" enum="DockLayout" is_bitfield="true">
Allows placing the dock in the editor's bottom panel. Implement [method _update_layout] to handle changing layouts.
</constant>
</constants>
</class>
24 changes: 21 additions & 3 deletions doc/classes/EditorPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
When your plugin is deactivated, make sure to remove your custom control with [method remove_control_from_container] and free it with [method Node.queue_free].
</description>
</method>
<method name="add_control_to_dock">
<method name="add_control_to_dock" deprecated="Use [method add_dock] instead.">
<return type="void" />
<param index="0" name="slot" type="int" enum="EditorPlugin.DockSlot" />
<param index="1" name="control" type="Control" />
Expand Down Expand Up @@ -464,6 +464,14 @@
Adds a [Script] as debugger plugin to the Debugger. The script must extend [EditorDebuggerPlugin].
</description>
</method>
<method name="add_dock">
<return type="void" />
<param index="0" name="dock" type="EditorDock" />
<description>
Adds a new dock.
When your plugin is deactivated, make sure to remove your custom dock with [method remove_dock] and free it with [method Node.queue_free].
</description>
</method>
<method name="add_export_platform">
<return type="void" />
<param index="0" name="platform" type="EditorExportPlatform" />
Expand Down Expand Up @@ -655,7 +663,7 @@
Removes the control from the specified container. You have to manually [method Node.queue_free] the control.
</description>
</method>
<method name="remove_control_from_docks">
<method name="remove_control_from_docks" deprecated="Use [method remove_dock] instead.">
<return type="void" />
<param index="0" name="control" type="Control" />
<description>
Expand All @@ -676,6 +684,13 @@
Removes the debugger plugin with given script from the Debugger.
</description>
</method>
<method name="remove_dock">
<return type="void" />
<param index="0" name="dock" type="EditorDock" />
<description>
Removes [param dock] from the available docks. You should manually call [method Node.queue_free] to free it.
</description>
</method>
<method name="remove_export_platform">
<return type="void" />
<param index="0" name="platform" type="EditorExportPlatform" />
Expand Down Expand Up @@ -753,7 +768,7 @@
Removes a callback previously added by [method add_undo_redo_inspector_hook_callback].
</description>
</method>
<method name="set_dock_tab_icon">
<method name="set_dock_tab_icon" deprecated="Use [member EditorDock.dock_icon] instead.">
<return type="void" />
<param index="0" name="control" type="Control" />
<param index="1" name="icon" type="Texture2D" />
Expand Down Expand Up @@ -854,6 +869,9 @@
<constant name="CONTAINER_PROJECT_SETTING_TAB_RIGHT" value="11" enum="CustomControlContainer">
Tab of Project Settings dialog, to the right of other tabs.
</constant>
<constant name="DOCK_SLOT_NONE" value="-1" enum="DockSlot">
The dock is closed.
</constant>
<constant name="DOCK_SLOT_LEFT_UL" value="0" enum="DockSlot">
Dock slot, left side, upper-left (empty in default layout).
</constant>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/FileSystemDock.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FileSystemDock" inherits="VBoxContainer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="FileSystemDock" inherits="EditorDock" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause binary compatibility issues?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All checks have passed, so no idea. I doubt anyone would use FileSystemDock in a way that it would cause problem.

<brief_description>
Godot editor's dock for managing files in the project.
</brief_description>
Expand Down
131 changes: 131 additions & 0 deletions editor/editor_dock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**************************************************************************/
/* editor_dock.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "editor_dock.h"

#include "core/input/shortcut.h"
#include "core/io/config_file.h"

void EditorDock::_set_default_slot_bind(EditorPlugin::DockSlot p_slot) {
ERR_FAIL_INDEX(p_slot, EditorPlugin::DOCK_SLOT_MAX);
default_slot = (EditorDockManager::DockSlot)p_slot;
}

void EditorDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &EditorDock::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &EditorDock::get_title);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");

ClassDB::bind_method(D_METHOD("set_layout_key", "layout_key"), &EditorDock::set_layout_key);
ClassDB::bind_method(D_METHOD("get_layout_key"), &EditorDock::get_layout_key);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "layout_key"), "set_layout_key", "get_layout_key");

ClassDB::bind_method(D_METHOD("set_icon_name", "icon_name"), &EditorDock::set_icon_name);
ClassDB::bind_method(D_METHOD("get_icon_name"), &EditorDock::get_icon_name);
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "icon_name"), "set_icon_name", "get_icon_name");

ClassDB::bind_method(D_METHOD("set_dock_icon", "icon"), &EditorDock::set_dock_icon);
ClassDB::bind_method(D_METHOD("get_dock_icon"), &EditorDock::get_dock_icon);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dock_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_dock_icon", "get_dock_icon");

ClassDB::bind_method(D_METHOD("set_dock_shortcut", "shortcut"), &EditorDock::set_dock_shortcut);
ClassDB::bind_method(D_METHOD("get_dock_shortcut"), &EditorDock::get_dock_shortcut);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dock_shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_dock_shortcut", "get_dock_shortcut");

ClassDB::bind_method(D_METHOD("set_default_slot", "slot"), &EditorDock::_set_default_slot_bind);
ClassDB::bind_method(D_METHOD("get_default_slot"), &EditorDock::_get_default_slot_bind);
ADD_PROPERTY(PropertyInfo(Variant::INT, "default_slot"), "set_default_slot", "get_default_slot");

ClassDB::bind_method(D_METHOD("set_available_layouts", "layouts"), &EditorDock::set_available_layouts);
ClassDB::bind_method(D_METHOD("get_available_layouts"), &EditorDock::get_available_layouts);
ADD_PROPERTY(PropertyInfo(Variant::INT, "available_layouts", PROPERTY_HINT_FLAGS, "Vertical:1,Horizontal:2"), "set_available_layouts", "get_available_layouts");

BIND_BITFIELD_FLAG(DOCK_LAYOUT_VERTICAL);
BIND_BITFIELD_FLAG(DOCK_LAYOUT_HORIZONTAL);

GDVIRTUAL_BIND(_update_layout, "layout");
GDVIRTUAL_BIND(_save_layout_to_config, "config", "section");
GDVIRTUAL_BIND(_load_layout_from_config, "config", "section");
}

EditorDock::EditorDock() {
set_clip_contents(true);
add_user_signal(MethodInfo("tab_style_changed"));
}

void EditorDock::set_title(const String &p_title) {
if (title == p_title) {
return;
}
title = p_title;
emit_signal("tab_style_changed");
}

void EditorDock::set_icon_name(const StringName &p_name) {
if (icon_name == p_name) {
return;
}
icon_name = p_name;
emit_signal("tab_style_changed");
}

void EditorDock::set_dock_icon(const Ref<Texture2D> &p_icon) {
if (dock_icon == p_icon) {
return;
}
dock_icon = p_icon;
emit_signal("tab_style_changed");
}

void EditorDock::set_default_slot(EditorDockManager::DockSlot p_slot) {
ERR_FAIL_INDEX(p_slot, EditorDockManager::DOCK_SLOT_MAX);
default_slot = p_slot;
}

String EditorDock::get_display_title() const {
if (!title.is_empty()) {
return title;
}

const String sname = get_name();
if (sname.contains("@")) {
// Auto-generated name, try to use something better.
const Node *child = get_child_count() > 0 ? get_child(0) : nullptr;
if (child) {
// In user plugins, the child will usually be dock's content and have a proper name.
return child->get_name();
}
}
return sname;
}

String EditorDock::get_effective_layout_key() const {
return layout_key.is_empty() ? get_display_title() : layout_key;
}
Loading