Merge pull request #78611 from YuriSizov/editor-cure-for-early-onset-layout-dementia

Handle contextual editors gracefully when restoring layout
This commit is contained in:
Yuri Sizov 2023-06-23 17:52:35 +02:00 committed by GitHub
commit f44b2d7898
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 11 deletions

View file

@ -1050,7 +1050,7 @@ void EditorAudioBuses::_update_buses() {
EditorAudioBuses *EditorAudioBuses::register_editor() {
EditorAudioBuses *audio_buses = memnew(EditorAudioBuses);
EditorNode::get_singleton()->add_bottom_panel_item(TTR("Audio"), audio_buses, true);
EditorNode::get_singleton()->add_bottom_panel_item(TTR("Audio"), audio_buses);
return audio_buses;
}

View file

@ -5256,13 +5256,15 @@ void EditorNode::_save_central_editor_layout_to_config(Ref<ConfigFile> p_config_
int selected_bottom_panel_item_idx = -1;
for (int i = 0; i < bottom_panel_items.size(); i++) {
if (bottom_panel_items[i].permanent && bottom_panel_items[i].button->is_pressed()) {
if (bottom_panel_items[i].button->is_pressed()) {
selected_bottom_panel_item_idx = i;
break;
}
}
if (selected_bottom_panel_item_idx != -1) {
p_config_file->set_value(EDITOR_NODE_CONFIG_SECTION, "selected_bottom_panel_item", selected_bottom_panel_item_idx);
} else {
p_config_file->set_value(EDITOR_NODE_CONFIG_SECTION, "selected_bottom_panel_item", Variant());
}
// Debugger tab.
@ -5281,6 +5283,8 @@ void EditorNode::_save_central_editor_layout_to_config(Ref<ConfigFile> p_config_
}
if (selected_main_editor_idx != -1) {
p_config_file->set_value(EDITOR_NODE_CONFIG_SECTION, "selected_main_editor_idx", selected_main_editor_idx);
} else {
p_config_file->set_value(EDITOR_NODE_CONFIG_SECTION, "selected_main_editor_idx", Variant());
}
}
@ -5295,7 +5299,10 @@ void EditorNode::_load_central_editor_layout_from_config(Ref<ConfigFile> p_confi
if (p_config_file->has_section_key(EDITOR_NODE_CONFIG_SECTION, "selected_bottom_panel_item")) {
int selected_bottom_panel_item_idx = p_config_file->get_value(EDITOR_NODE_CONFIG_SECTION, "selected_bottom_panel_item");
if (selected_bottom_panel_item_idx >= 0 && selected_bottom_panel_item_idx < bottom_panel_items.size()) {
_bottom_panel_switch(true, selected_bottom_panel_item_idx);
// Make sure we don't try to open contextual editors which are not enabled in the current context.
if (bottom_panel_items[selected_bottom_panel_item_idx].button->is_visible()) {
_bottom_panel_switch(true, selected_bottom_panel_item_idx);
}
}
}
@ -5663,7 +5670,7 @@ void EditorNode::_scene_tab_changed(int p_tab) {
set_current_scene(p_tab);
}
Button *EditorNode::add_bottom_panel_item(String p_text, Control *p_item, bool p_permanent) {
Button *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) {
Button *tb = memnew(Button);
tb->set_flat(true);
tb->connect("toggled", callable_mp(this, &EditorNode::_bottom_panel_switch).bind(bottom_panel_items.size()));
@ -5679,7 +5686,6 @@ Button *EditorNode::add_bottom_panel_item(String p_text, Control *p_item, bool p
bpi.button = tb;
bpi.control = p_item;
bpi.name = p_text;
bpi.permanent = p_permanent; // Serves as an information when saving editor layout.
bottom_panel_items.push_back(bpi);
return tb;
@ -7756,7 +7762,7 @@ EditorNode::EditorNode() {
bottom_panel_raise->connect("toggled", callable_mp(this, &EditorNode::_bottom_panel_raise_toggled));
log = memnew(EditorLog);
Button *output_button = add_bottom_panel_item(TTR("Output"), log, true);
Button *output_button = add_bottom_panel_item(TTR("Output"), log);
log->set_tool_button(output_button);
center_split->connect("resized", callable_mp(this, &EditorNode::_vp_resized));

View file

@ -252,7 +252,6 @@ private:
String name;
Control *control = nullptr;
Button *button = nullptr;
bool permanent = false;
};
struct ExportDefer {
@ -905,7 +904,7 @@ public:
bool is_exiting() const { return exiting; }
Button *add_bottom_panel_item(String p_text, Control *p_item, bool p_permanent = false);
Button *add_bottom_panel_item(String p_text, Control *p_item);
void make_bottom_panel_item_visible(Control *p_item);
void raise_bottom_panel_item(Control *p_item);
void hide_bottom_panel();

View file

@ -1998,7 +1998,7 @@ void AnimationPlayerEditorPlugin::make_visible(bool p_visible) {
AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin() {
anim_editor = memnew(AnimationPlayerEditor(this));
EditorNode::get_singleton()->add_bottom_panel_item(TTR("Animation"), anim_editor, true);
EditorNode::get_singleton()->add_bottom_panel_item(TTR("Animation"), anim_editor);
}
AnimationPlayerEditorPlugin::~AnimationPlayerEditorPlugin() {

View file

@ -53,7 +53,7 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) {
file_server = memnew(EditorFileServer);
EditorDebuggerNode *debugger = memnew(EditorDebuggerNode);
Button *db = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Debugger"), debugger, true);
Button *db = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Debugger"), debugger);
// Add separation for the warning/error icon that is displayed later.
db->add_theme_constant_override("h_separation", 6 * EDSCALE);
debugger->set_tool_button(db);

View file

@ -622,7 +622,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
empty.instantiate();
shader_tabs->add_theme_style_override("panel", empty);
button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Shader Editor"), window_wrapper, true);
button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Shader Editor"), window_wrapper);
// Defer connect because Editor class is not in the binding system yet.
EditorNode::get_singleton()->call_deferred("connect", "resource_saved", callable_mp(this, &ShaderEditorPlugin::_resource_saved), CONNECT_DEFERRED);