Skip to content
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
72 changes: 43 additions & 29 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,11 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
SceneTreeDock::get_singleton()->set_selection({ current_node });
InspectorDock::get_singleton()->update(current_node);
if (!inspector_only && !skip_main_plugin) {
skip_main_plugin = stay_in_script_editor_on_node_selected && !ScriptEditor::get_singleton()->is_editor_floating() && ScriptEditor::get_singleton()->is_visible_in_tree();
if (!ScriptEditor::get_singleton()->is_editor_floating() && ScriptEditor::get_singleton()->is_visible_in_tree()) {
skip_main_plugin = stay_in_script_editor_on_node_selected;
} else {
skip_main_plugin = !_can_auto_switch_main_screens();
}
}
} else {
NodeDock::get_singleton()->set_node(nullptr);
Expand Down Expand Up @@ -2629,9 +2633,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
if (!changing_scene) {
main_plugin->edit(current_obj);
}
}

else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) {
} else if (main_plugin != editor_plugin_screen) {
// Unedit previous plugin.
editor_plugin_screen->edit(nullptr);
active_plugins[editor_owner_id].erase(editor_plugin_screen);
Expand Down Expand Up @@ -3839,32 +3841,13 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {

changing_scene = false;

int current_tab = -1;
for (int i = 0; i < editor_table.size(); i++) {
if (editor_plugin_screen == editor_table[i]) {
current_tab = i;
break;
}
}

if (p_state.has("editor_index")) {
int index = p_state["editor_index"];
if (current_tab < 2) { // If currently in spatial/2d, only switch to spatial/2d. If currently in script, stay there.
if (index < 2 || !get_edited_scene()) {
editor_select(index);
}
}
}

if (get_edited_scene()) {
if (current_tab < 2) {
Node *editor_node = SceneTreeDock::get_singleton()->get_tree_editor()->get_selected();
editor_node = editor_node == nullptr ? get_edited_scene() : editor_node;

if (Object::cast_to<CanvasItem>(editor_node)) {
editor_select(EDITOR_2D);
} else if (Object::cast_to<Node3D>(editor_node)) {
editor_select(EDITOR_3D);
if (_can_auto_switch_main_screens()) {
Node *selected_node = SceneTreeDock::get_singleton()->get_tree_editor()->get_selected();
selected_node = selected_node == nullptr ? get_edited_scene() : selected_node;
const int plugin_index = _get_plugin_index(editor_data.get_handling_main_editor(selected_node));
if (plugin_index >= 0) {
editor_select(plugin_index);
}
}
}
Expand All @@ -3891,6 +3874,36 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
RenderingServer::get_singleton()->sdfgi_reset();
}

bool EditorNode::_can_auto_switch_main_screens() const {
if (editor_plugin_screen == nullptr) {
return true;
}
// Only allow auto-switching if the selected button is to the left of the Script button.
for (int i = 0; i < main_editor_button_hb->get_child_count(); i++) {
Button *button = Object::cast_to<Button>(main_editor_button_hb->get_child(i));
if (button->get_text() == "Script") {
// Selected button is at or after the Script button.
return false;
}
if (button->get_text() == editor_plugin_screen->get_name()) {
// Selected button is before the Script button.
return true;
}
}
return false;
}

int EditorNode::_get_plugin_index(EditorPlugin *p_editor) const {
int screen = -1;
for (int i = 0; i < editor_table.size(); i++) {
if (p_editor == editor_table[i]) {
screen = i;
break;
}
}
return screen;
}

bool EditorNode::is_changing_scene() const {
return changing_scene;
}
Expand Down Expand Up @@ -7265,6 +7278,7 @@ EditorNode::EditorNode() {
}

main_editor_button_hb = memnew(HBoxContainer);
main_editor_button_hb->set_name("EditorMainScreenButtons");
title_bar->add_child(main_editor_button_hb);

// Options are added and handled by DebuggerEditorPlugin.
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ class EditorNode : public Node {

Dictionary _get_main_scene_state();
void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
bool _can_auto_switch_main_screens() const;
int _get_plugin_index(EditorPlugin *p_editor) const;

int _get_current_main_editor();

Expand Down
9 changes: 0 additions & 9 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1777,15 +1777,6 @@ void ScriptEditor::_notification(int p_what) {
}
}

bool ScriptEditor::can_take_away_focus() const {
ScriptEditorBase *current = _get_current_editor();
if (current) {
return current->can_lose_focus_on_node_selection();
} else {
return true;
}
}

void ScriptEditor::_close_builtin_scripts_from_scene(const String &p_scene) {
for (int i = 0; i < tab_container->get_tab_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i));
Expand Down
3 changes: 0 additions & 3 deletions editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class ScriptEditorBase : public VBoxContainer {
virtual void add_callback(const String &p_function, const PackedStringArray &p_args) = 0;
virtual void update_settings() = 0;
virtual void set_debugger_active(bool p_active) = 0;
virtual bool can_lose_focus_on_node_selection() { return true; }
virtual void update_toggle_scripts_button() {}

virtual bool show_members_overview() = 0;
Expand Down Expand Up @@ -566,8 +565,6 @@ class ScriptEditor : public PanelContainer {
void trigger_live_script_reload(const String &p_script_path);
void trigger_live_script_reload_all();

bool can_take_away_focus() const;

VSplitContainer *get_left_list_split() { return list_split; }

void set_live_auto_reload_running_scripts(bool p_enabled);
Expand Down
1 change: 0 additions & 1 deletion editor/plugins/text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class TextEditor : public ScriptEditorBase {
virtual void tag_saved_version() override;
virtual void update_settings() override;
virtual bool show_members_overview() override;
virtual bool can_lose_focus_on_node_selection() override { return true; }
virtual void set_debugger_active(bool p_active) override;
virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
virtual void add_callback(const String &p_function, const PackedStringArray &p_args) override;
Expand Down
Loading