Skip to content
Merged
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
19 changes: 19 additions & 0 deletions editor/editor_main_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ EditorPlugin *EditorMainScreen::get_plugin_by_name(const String &p_plugin_name)
return main_editor_plugins[p_plugin_name];
}

bool EditorMainScreen::can_auto_switch_screens() const {
if (selected_plugin == nullptr) {
return true;
}
// Only allow auto-switching if the selected button is to the left of the Script button.
for (int i = 0; i < button_hb->get_child_count(); i++) {
Button *button = Object::cast_to<Button>(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() == selected_plugin->get_plugin_name()) {
// Selected button is before the Script button.
return true;
}
}
return false;
}

VBoxContainer *EditorMainScreen::get_control() const {
return main_screen_vbox;
}
Expand Down
1 change: 1 addition & 0 deletions editor/editor_main_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class EditorMainScreen : public PanelContainer {
int get_plugin_index(EditorPlugin *p_editor) const;
EditorPlugin *get_selected_plugin() const;
EditorPlugin *get_plugin_by_name(const String &p_plugin_name) const;
bool can_auto_switch_screens() const;

VBoxContainer *get_control() const;

Expand Down
22 changes: 11 additions & 11 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,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 = !editor_main_screen->can_auto_switch_screens();
}
}
} else {
NodeDock::get_singleton()->set_node(nullptr);
Expand Down Expand Up @@ -2798,9 +2802,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 @@ -3998,18 +4000,15 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
changing_scene = false;

if (get_edited_scene()) {
int current_tab = editor_main_screen->get_selected_index();
if (current_tab < 2) {
if (editor_main_screen->can_auto_switch_screens()) {
// Switch between 2D and 3D if currently in 2D or 3D.
Node *selected_node = SceneTreeDock::get_singleton()->get_tree_editor()->get_selected();
if (!selected_node) {
selected_node = get_edited_scene();
}

if (Object::cast_to<CanvasItem>(selected_node)) {
editor_main_screen->select(EditorMainScreen::EDITOR_2D);
} else if (Object::cast_to<Node3D>(selected_node)) {
editor_main_screen->select(EditorMainScreen::EDITOR_3D);
const int plugin_index = editor_main_screen->get_plugin_index(editor_data.get_handling_main_editor(selected_node));
if (plugin_index >= 0) {
editor_main_screen->select(plugin_index);
}
}
}
Expand Down Expand Up @@ -7710,6 +7709,7 @@ EditorNode::EditorNode() {

HBoxContainer *main_editor_button_hb = memnew(HBoxContainer);
main_editor_button_hb->set_mouse_filter(Control::MOUSE_FILTER_STOP);
main_editor_button_hb->set_name("EditorMainScreenButtons");
editor_main_screen->set_button_container(main_editor_button_hb);
title_bar->add_child(main_editor_button_hb);
title_bar->set_center_control(main_editor_button_hb);
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 @@ -1849,15 +1849,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 @@ -208,7 +208,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_files_button() {}

virtual bool show_members_overview() = 0;
Expand Down Expand Up @@ -589,8 +588,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