Skip to content

Commit 1639174

Browse files
committed
Merge pull request godotengine#100558 from KoBeWi/docking_in_progress
Rework dock layout management
2 parents ce6c3c5 + b8f34bb commit 1639174

File tree

7 files changed

+56
-28
lines changed

7 files changed

+56
-28
lines changed

editor/editor_dock_manager.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "editor/editor_node.h"
4141
#include "editor/editor_settings.h"
4242
#include "editor/editor_string_names.h"
43-
#include "editor/filesystem_dock.h"
4443
#include "editor/gui/editor_bottom_panel.h"
4544
#include "editor/themes/editor_scale.h"
4645
#include "editor/window_wrapper.h"
@@ -480,6 +479,8 @@ void EditorDockManager::save_docks_to_config(Ref<ConfigFile> p_layout, const Str
480479
Array bottom_docks_dump;
481480
Array closed_docks_dump;
482481
for (const KeyValue<Control *, DockInfo> &d : all_docks) {
482+
d.key->call(SNAME("_save_layout_to_config"), p_layout, p_section);
483+
483484
if (!d.value.at_bottom && d.value.open && (!d.value.previous_at_bottom || !d.value.dock_window)) {
484485
continue;
485486
}
@@ -516,8 +517,6 @@ void EditorDockManager::save_docks_to_config(Ref<ConfigFile> p_layout, const Str
516517
for (int i = 0; i < hsplits.size(); i++) {
517518
p_layout->set_value(p_section, "dock_hsplit_" + itos(i + 1), int(hsplits[i]->get_split_offset() / EDSCALE));
518519
}
519-
520-
FileSystemDock::get_singleton()->save_layout_to_config(p_layout, p_section);
521520
}
522521

523522
void EditorDockManager::load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section, bool p_first_load) {
@@ -548,6 +547,7 @@ void EditorDockManager::load_docks_from_config(Ref<ConfigFile> p_layout, const S
548547
continue;
549548
}
550549
Control *dock = dock_map[name];
550+
dock->call(SNAME("_load_layout_from_config"), p_layout, p_section);
551551

552552
if (!all_docks[dock].enabled) {
553553
// Don't open disabled docks.
@@ -612,9 +612,6 @@ void EditorDockManager::load_docks_from_config(Ref<ConfigFile> p_layout, const S
612612
int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1));
613613
hsplits[i]->set_split_offset(ofs * EDSCALE);
614614
}
615-
616-
FileSystemDock::get_singleton()->load_layout_from_config(p_layout, p_section);
617-
618615
_update_docks_menu();
619616
}
620617

editor/filesystem_dock.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ FileSystemList::FileSystemList() {
184184
popup_editor->connect("popup_hide", callable_mp(this, &FileSystemList::_text_editor_popup_modal_close));
185185
}
186186

187-
FileSystemDock *FileSystemDock::singleton = nullptr;
188-
189187
Ref<Texture2D> FileSystemDock::_get_tree_item_icon(bool p_is_valid, const String &p_file_type, const String &p_icon_path) {
190188
if (!p_icon_path.is_empty()) {
191189
Ref<Texture2D> icon = ResourceLoader::load(p_icon_path);
@@ -3950,6 +3948,9 @@ void FileSystemDock::_bind_methods() {
39503948
ClassDB::bind_method(D_METHOD("_set_dock_horizontal", "enable"), &FileSystemDock::_set_dock_horizontal);
39513949
ClassDB::bind_method(D_METHOD("_can_dock_horizontal"), &FileSystemDock::_can_dock_horizontal);
39523950

3951+
ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &FileSystemDock::_save_layout_to_config);
3952+
ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &FileSystemDock::_load_layout_from_config);
3953+
39533954
ADD_SIGNAL(MethodInfo("inherit", PropertyInfo(Variant::STRING, "file")));
39543955
ADD_SIGNAL(MethodInfo("instantiate", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
39553956

@@ -3963,7 +3964,7 @@ void FileSystemDock::_bind_methods() {
39633964
ADD_SIGNAL(MethodInfo("display_mode_changed"));
39643965
}
39653966

3966-
void FileSystemDock::save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const {
3967+
void FileSystemDock::_save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const {
39673968
p_layout->set_value(p_section, "dock_filesystem_h_split_offset", get_h_split_offset());
39683969
p_layout->set_value(p_section, "dock_filesystem_v_split_offset", get_v_split_offset());
39693970
p_layout->set_value(p_section, "dock_filesystem_display_mode", get_display_mode());
@@ -3975,7 +3976,7 @@ void FileSystemDock::save_layout_to_config(Ref<ConfigFile> p_layout, const Strin
39753976
p_layout->set_value(p_section, "dock_filesystem_uncollapsed_paths", searched_tokens.is_empty() ? uncollapsed_paths : uncollapsed_paths_before_search);
39763977
}
39773978

3978-
void FileSystemDock::load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
3979+
void FileSystemDock::_load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
39793980
if (p_layout->has_section_key(p_section, "dock_filesystem_h_split_offset")) {
39803981
int fs_h_split_ofs = p_layout->get_value(p_section, "dock_filesystem_h_split_offset");
39813982
set_h_split_offset(fs_h_split_ofs);

editor/filesystem_dock.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,11 @@ class FileSystemDock : public VBoxContainer {
357357
bool _can_dock_horizontal() const;
358358
void _set_dock_horizontal(bool p_enable);
359359

360+
void _save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
361+
void _load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section);
362+
360363
private:
361-
static FileSystemDock *singleton;
364+
inline static FileSystemDock *singleton = nullptr;
362365

363366
public:
364367
static FileSystemDock *get_singleton() { return singleton; }
@@ -414,9 +417,6 @@ class FileSystemDock : public VBoxContainer {
414417
void remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);
415418
Control *create_tooltip_for_path(const String &p_path) const;
416419

417-
void save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
418-
void load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section);
419-
420420
FileSystemDock();
421421
~FileSystemDock();
422422
};

editor/history_dock.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "history_dock.h"
3232

33+
#include "core/io/config_file.h"
3334
#include "editor/editor_node.h"
3435
#include "editor/editor_settings.h"
3536
#include "editor/editor_string_names.h"
@@ -172,6 +173,17 @@ void HistoryDock::refresh_version() {
172173
action_list->set_current(idx);
173174
}
174175

176+
void HistoryDock::_save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const {
177+
p_layout->set_value(p_section, "dock_history_include_scene", current_scene_checkbox->is_pressed());
178+
p_layout->set_value(p_section, "dock_history_include_global", global_history_checkbox->is_pressed());
179+
}
180+
181+
void HistoryDock::_load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
182+
current_scene_checkbox->set_pressed_no_signal(p_layout->get_value(p_section, "dock_history_include_scene", true));
183+
global_history_checkbox->set_pressed_no_signal(p_layout->get_value(p_section, "dock_history_include_global", true));
184+
refresh_history();
185+
}
186+
175187
void HistoryDock::seek_history(int p_index) {
176188
bool include_scene = current_scene_checkbox->is_pressed();
177189
bool include_global = global_history_checkbox->is_pressed();
@@ -220,9 +232,9 @@ void HistoryDock::_notification(int p_notification) {
220232
}
221233
}
222234

223-
void HistoryDock::save_options() {
224-
EditorSettings::get_singleton()->set_project_metadata("history", "include_scene", current_scene_checkbox->is_pressed());
225-
EditorSettings::get_singleton()->set_project_metadata("history", "include_global", global_history_checkbox->is_pressed());
235+
void HistoryDock::_bind_methods() {
236+
ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &HistoryDock::_save_layout_to_config);
237+
ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &HistoryDock::_load_layout_from_config);
226238
}
227239

228240
HistoryDock::HistoryDock() {
@@ -235,28 +247,21 @@ HistoryDock::HistoryDock() {
235247
HBoxContainer *mode_hb = memnew(HBoxContainer);
236248
add_child(mode_hb);
237249

238-
bool include_scene = EditorSettings::get_singleton()->get_project_metadata("history", "include_scene", true);
239-
bool include_global = EditorSettings::get_singleton()->get_project_metadata("history", "include_global", true);
240-
241250
current_scene_checkbox = memnew(CheckBox);
242251
mode_hb->add_child(current_scene_checkbox);
243252
current_scene_checkbox->set_flat(true);
244-
current_scene_checkbox->set_pressed(include_scene);
245253
current_scene_checkbox->set_text(TTR("Scene"));
246254
current_scene_checkbox->set_h_size_flags(SIZE_EXPAND_FILL);
247255
current_scene_checkbox->set_clip_text(true);
248256
current_scene_checkbox->connect(SceneStringName(toggled), callable_mp(this, &HistoryDock::refresh_history).unbind(1));
249-
current_scene_checkbox->connect(SceneStringName(toggled), callable_mp(this, &HistoryDock::save_options).unbind(1));
250257

251258
global_history_checkbox = memnew(CheckBox);
252259
mode_hb->add_child(global_history_checkbox);
253260
global_history_checkbox->set_flat(true);
254-
global_history_checkbox->set_pressed(include_global);
255261
global_history_checkbox->set_text(TTR("Global"));
256262
global_history_checkbox->set_h_size_flags(SIZE_EXPAND_FILL);
257263
global_history_checkbox->set_clip_text(true);
258264
global_history_checkbox->connect(SceneStringName(toggled), callable_mp(this, &HistoryDock::refresh_history).unbind(1));
259-
global_history_checkbox->connect(SceneStringName(toggled), callable_mp(this, &HistoryDock::save_options).unbind(1));
260265

261266
action_list = memnew(ItemList);
262267
action_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);

editor/history_dock.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "scene/gui/box_container.h"
3535

3636
class CheckBox;
37+
class ConfigFile;
3738
class ItemList;
3839
class EditorUndoRedoManager;
3940

@@ -53,10 +54,13 @@ class HistoryDock : public VBoxContainer {
5354
void refresh_history();
5455
void on_version_changed();
5556
void refresh_version();
56-
void save_options();
57+
58+
void _save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
59+
void _load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section);
5760

5861
protected:
5962
void _notification(int p_notification);
63+
static void _bind_methods();
6064

6165
public:
6266
void seek_history(int p_index);

editor/node_dock.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "node_dock.h"
3232

33+
#include "core/io/config_file.h"
3334
#include "editor/connections_dialog.h"
3435
#include "editor/themes/editor_scale.h"
3536

@@ -47,17 +48,32 @@ void NodeDock::show_connections() {
4748
connections->show();
4849
}
4950

51+
void NodeDock::_save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const {
52+
p_layout->set_value(p_section, "dock_node_current_tab", int(groups_button->is_pressed()));
53+
}
54+
55+
void NodeDock::_load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
56+
const int current_tab = p_layout->get_value(p_section, "dock_node_current_tab", 0);
57+
if (current_tab == 0) {
58+
show_connections();
59+
} else if (current_tab == 1) {
60+
show_groups();
61+
}
62+
}
63+
5064
void NodeDock::_notification(int p_what) {
5165
switch (p_what) {
52-
case NOTIFICATION_ENTER_TREE:
5366
case NOTIFICATION_THEME_CHANGED: {
5467
connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals")));
5568
groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
5669
} break;
5770
}
5871
}
5972

60-
NodeDock *NodeDock::singleton = nullptr;
73+
void NodeDock::_bind_methods() {
74+
ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
75+
ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
76+
}
6177

6278
void NodeDock::update_lists() {
6379
connections->update_tree();

editor/node_dock.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "groups_editor.h"
3535

36+
class ConfigFile;
3637
class ConnectionsDock;
3738

3839
class NodeDock : public VBoxContainer {
@@ -48,14 +49,18 @@ class NodeDock : public VBoxContainer {
4849

4950
Label *select_a_node = nullptr;
5051

52+
void _save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
53+
void _load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section);
54+
5155
private:
52-
static NodeDock *singleton;
56+
inline static NodeDock *singleton = nullptr;
5357

5458
public:
5559
static NodeDock *get_singleton() { return singleton; }
5660

5761
protected:
5862
void _notification(int p_what);
63+
static void _bind_methods();
5964

6065
public:
6166
void set_node(Node *p_node);

0 commit comments

Comments
 (0)