Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/docks/editor_dock_manager.h
21212 views
1
/**************************************************************************/
2
/* editor_dock_manager.h */
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
#pragma once
32
33
#include "editor/docks/editor_dock.h"
34
#include "scene/gui/popup.h"
35
#include "scene/gui/split_container.h"
36
37
class Button;
38
class ConfigFile;
39
class Control;
40
class EditorDock;
41
class PopupMenu;
42
class TabBar;
43
class TabContainer;
44
class VBoxContainer;
45
class WindowWrapper;
46
class StyleBoxFlat;
47
48
class DockSplitContainer : public SplitContainer {
49
GDCLASS(DockSplitContainer, SplitContainer);
50
51
private:
52
bool is_updating = false;
53
54
protected:
55
void _update_visibility();
56
57
virtual void add_child_notify(Node *p_child) override;
58
virtual void remove_child_notify(Node *p_child) override;
59
60
public:
61
DockSplitContainer();
62
};
63
64
class DockShortcutHandler : public Node {
65
GDCLASS(DockShortcutHandler, Node);
66
67
protected:
68
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
69
70
public:
71
DockShortcutHandler() { set_process_shortcut_input(true); }
72
};
73
74
class DockContextPopup;
75
class EditorDockDragHint;
76
class DockTabContainer;
77
78
class EditorDockManager : public Object {
79
GDCLASS(EditorDockManager, Object);
80
81
private:
82
friend class DockContextPopup;
83
friend class EditorDockDragHint;
84
friend class DockShortcutHandler;
85
86
static inline EditorDockManager *singleton = nullptr;
87
88
// To access splits easily by index.
89
Vector<DockSplitContainer *> vsplits;
90
DockSplitContainer *main_hsplit = nullptr;
91
92
DockTabContainer *dock_slots[EditorDock::DOCK_SLOT_MAX];
93
Vector<WindowWrapper *> dock_windows;
94
LocalVector<EditorDock *> all_docks;
95
HashSet<EditorDock *> dirty_docks;
96
97
EditorDock *dock_tab_dragged = nullptr;
98
bool docks_visible = true;
99
100
DockContextPopup *dock_context_popup = nullptr;
101
PopupMenu *docks_menu = nullptr;
102
LocalVector<EditorDock *> docks_menu_docks;
103
Control *closed_dock_parent = nullptr;
104
105
EditorDock *_get_dock_tab_dragged();
106
void _dock_drag_stopped();
107
void _dock_split_dragged(int p_offset);
108
void _update_layout();
109
110
void _docks_menu_option(int p_id);
111
112
void _window_close_request(WindowWrapper *p_wrapper);
113
EditorDock *_close_window(WindowWrapper *p_wrapper);
114
void _open_dock_in_window(EditorDock *p_dock, bool p_show_window = true, bool p_reset_size = false);
115
void _restore_dock_to_saved_window(EditorDock *p_dock, const Dictionary &p_window_dump);
116
117
void _make_dock_visible(EditorDock *p_dock, bool p_grab_focus);
118
void _move_dock(EditorDock *p_dock, Control *p_target, int p_tab_index = -1, bool p_set_current = true);
119
120
void _queue_update_tab_style(EditorDock *p_dock);
121
void _update_dirty_dock_tabs();
122
123
public:
124
static EditorDockManager *get_singleton() { return singleton; }
125
126
void update_docks_menu();
127
void update_tab_styles();
128
void set_tab_icon_max_width(int p_max_width);
129
130
void add_vsplit(DockSplitContainer *p_split);
131
void set_hsplit(DockSplitContainer *p_split);
132
void register_dock_slot(DockTabContainer *p_tab_container);
133
int get_vsplit_count() const;
134
PopupMenu *get_docks_menu();
135
136
void save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
137
void load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section, bool p_first_load = false);
138
139
void set_dock_enabled(EditorDock *p_dock, bool p_enabled);
140
void close_dock(EditorDock *p_dock);
141
void open_dock(EditorDock *p_dock, bool p_set_current = true);
142
void focus_dock(EditorDock *p_dock);
143
void make_dock_floating(EditorDock *p_dock);
144
145
void set_docks_visible(bool p_show);
146
bool are_docks_visible() const;
147
148
void add_dock(EditorDock *p_dock);
149
void remove_dock(EditorDock *p_dock);
150
151
EditorDockManager();
152
};
153
154
class DockContextPopup : public PopupPanel {
155
GDCLASS(DockContextPopup, PopupPanel);
156
157
private:
158
VBoxContainer *dock_select_popup_vb = nullptr;
159
160
Button *make_float_button = nullptr;
161
Button *tab_move_left_button = nullptr;
162
Button *tab_move_right_button = nullptr;
163
Button *close_button = nullptr;
164
165
Control *dock_select = nullptr;
166
Rect2 dock_select_rects[EditorDock::DOCK_SLOT_MAX];
167
int dock_select_rect_over_idx = -1;
168
169
EditorDock *context_dock = nullptr;
170
171
EditorDockManager *dock_manager = nullptr;
172
173
void _tab_move_left();
174
void _tab_move_right();
175
void _close_dock();
176
void _float_dock();
177
178
void _dock_select_input(const Ref<InputEvent> &p_input);
179
void _dock_select_mouse_exited();
180
void _dock_select_draw();
181
182
void _update_buttons();
183
184
protected:
185
void _notification(int p_what);
186
187
public:
188
void set_dock(EditorDock *p_dock);
189
void docks_updated();
190
191
DockContextPopup();
192
};
193
194