Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Properly deprecate _has_main_screen() method

kobewic40a331252e4
diff --git a/editor/docks/editor_dock_manager.cpp b/editor/docks/editor_dock_manager.cpp
index 34e6727a732..b997f67c0cc 100644
--- a/editor/docks/editor_dock_manager.cpp
+++ b/editor/docks/editor_dock_manager.cpp
@@ -252,7 +252,7 @@ void EditorDockManager::_docks_menu_option(int p_id) {
ERR_FAIL_NULL(parent_menu);
parent_menu->hide();
}
- focus_dock(dock);
+ force_focus_dock(dock);
}
void EditorDockManager::_window_close_request(WindowWrapper *p_wrapper) {
@@ -720,7 +720,7 @@ void EditorDockManager::_make_dock_visible(EditorDock *p_dock, bool p_grab_focus
}
DockTabContainer *tab_container = p_dock->get_parent_container();
- if (!tab_container || !tab_container->can_switch_dock()) {
+ if (!tab_container || (!forced_focus && !tab_container->can_switch_dock())) {
return;
}
@@ -750,6 +750,12 @@ void EditorDockManager::focus_dock(EditorDock *p_dock) {
_make_dock_visible(p_dock, true);
}
+void EditorDockManager::force_focus_dock(EditorDock *p_dock) {
+ forced_focus = true;
+ focus_dock(p_dock);
+ forced_focus = false;
+}
+
void EditorDockManager::add_dock(EditorDock *p_dock) {
ERR_FAIL_NULL(p_dock);
ERR_FAIL_COND_MSG(all_docks.has(p_dock), vformat("Cannot add dock '%s', already added.", p_dock->get_display_title()));
@@ -1029,7 +1035,7 @@ void DockShortcutHandler::shortcut_input(const Ref<InputEvent> &p_event) {
if (dock_shortcut.is_valid() && dock_shortcut->matches_event(p_event)) {
bool was_visible = dock->is_visible();
if (!dock->transient || dock->is_open) {
- EditorDockManager::get_singleton()->focus_dock(dock);
+ EditorDockManager::get_singleton()->force_focus_dock(dock);
}
DockTabContainer *dock_container = dock->get_parent_container();
if (dock_container) {
diff --git a/editor/docks/editor_dock_manager.h b/editor/docks/editor_dock_manager.h
index 4eb76abfcab..cbdecce09da 100644
--- a/editor/docks/editor_dock_manager.h
+++ b/editor/docks/editor_dock_manager.h
@@ -102,6 +102,7 @@ private:
EditorDock *dock_tab_dragged = nullptr;
bool docks_visible = true;
+ bool forced_focus = false;
DockContextPopup *dock_context_popup = nullptr;
PopupMenu *docks_menu = nullptr;
@@ -155,6 +156,7 @@ public:
void close_dock(EditorDock *p_dock);
void open_dock(EditorDock *p_dock, bool p_set_current = true);
void focus_dock(EditorDock *p_dock);
+ void force_focus_dock(EditorDock *p_dock); // Ignore can_switch_dock().
void make_dock_floating(EditorDock *p_dock);
void set_docks_visible(bool p_show);
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 62692285e73..bc3f5f7bdab 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -257,22 +257,10 @@ EditorSelectionHistory::EditorSelectionHistory() {
////////////////////////////////////////////////////////////
-EditorPlugin *EditorData::get_handling_main_editor(Object *p_object) {
- // We need to iterate backwards so that we can check user-created plugins first.
- // Otherwise, it would not be possible for plugins to handle CanvasItem and Spatial nodes.
- for (int i = editor_plugins.size() - 1; i > -1; i--) {
- if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
- return editor_plugins[i];
- }
- }
-
- return nullptr;
-}
-
Vector<EditorPlugin *> EditorData::get_handling_sub_editors(Object *p_object) {
Vector<EditorPlugin *> sub_plugins;
for (EditorPlugin *plugin : editor_plugins) {
- if (!plugin->has_main_screen() && plugin->handles(p_object)) {
+ if (plugin->handles(p_object)) {
sub_plugins.push_back(plugin);
}
}
diff --git a/editor/editor_data.h b/editor/editor_data.h
index 624b833668a..1b14e3ca4d4 100644
--- a/editor/editor_data.h
+++ b/editor/editor_data.h
@@ -155,7 +155,6 @@ private:
Ref<Texture2D> _load_script_icon(const String &p_path) const;
public:
- EditorPlugin *get_handling_main_editor(Object *p_object);
Vector<EditorPlugin *> get_handling_sub_editors(Object *p_object);
EditorPlugin *get_editor_by_name(const String &p_name);
diff --git a/editor/editor_main_screen.cpp b/editor/editor_main_screen.cpp
index 30e888c7768..e4db368a4dc 100644
--- a/editor/editor_main_screen.cpp
+++ b/editor/editor_main_screen.cpp
@@ -126,23 +126,12 @@ Rect2 EditorMainScreen::get_drag_hint_rect() const {
return final_rect;
}
-void EditorMainScreen::edit(Object *p_object) {
- EditorPlugin *handling_plugin = EditorNode::get_editor_data().get_handling_main_editor(p_object);
- if (selected_plugin) {
- if (handling_plugin == selected_plugin) {
- selected_plugin->edit(p_object);
- } else {
- selected_plugin->edit(nullptr);
- if (handling_plugin) {
- selected_plugin->make_visible(false);
- }
- }
- }
- selected_plugin = handling_plugin;
- if (selected_plugin) {
- selected_plugin->edit(p_object);
- selected_plugin->make_visible(true);
+bool EditorMainScreen::can_switch_dock() const {
+ if (get_current_tab() == -1) {
+ return true;
}
+ EditorDock *dock = get_dock(get_current_tab());
+ return dock->is_allow_switch_screen();
}
void EditorMainScreen::select_next() {
@@ -167,18 +156,6 @@ void EditorMainScreen::select_prev() {
}
}
-EditorPlugin *EditorMainScreen::get_selected_plugin() const {
- return selected_plugin;
-}
-
-bool EditorMainScreen::can_auto_switch_screens() const {
- if (get_current_tab() == -1) {
- return true;
- }
- EditorDock *dock = get_dock(get_current_tab());
- return dock->is_allow_switch_screen();
-}
-
#ifndef DISABLE_DEPRECATED
VBoxContainer *EditorMainScreen::get_control() const {
return main_screen_vbox;
@@ -189,9 +166,6 @@ void EditorMainScreen::add_main_plugin(EditorPlugin *p_editor) {
}
void EditorMainScreen::remove_main_plugin(EditorPlugin *p_editor) {
- if (selected_plugin == p_editor) {
- selected_plugin = nullptr;
- }
if (p_editor->has_meta("_dock")) {
EditorDock *dock = Object::cast_to<EditorDock>(p_editor->get_meta("_dock").get_validated_object());
if (dock) {
diff --git a/editor/editor_main_screen.h b/editor/editor_main_screen.h
index 483647db779..122d2b51794 100644
--- a/editor/editor_main_screen.h
+++ b/editor/editor_main_screen.h
@@ -57,8 +57,6 @@ private:
VBoxContainer *main_screen_vbox = nullptr;
Vector<EditorPlugin *> editor_table;
#endif
- EditorPlugin *selected_plugin = nullptr;
-
void _on_tab_changed(int p_tab);
protected:
@@ -67,7 +65,7 @@ protected:
virtual void update_visibility() override { show(); } // Never hide main screen.
virtual TabStyle get_tab_style() const override;
virtual Rect2 get_drag_hint_rect() const override;
- virtual bool can_switch_dock() const override { return true; } // Main Screen is not affected by distraction-free mode.
+ virtual bool can_switch_dock() const override;
public:
#ifndef DISABLE_DEPRECATED
@@ -77,12 +75,8 @@ public:
void remove_main_plugin(EditorPlugin *p_editor);
#endif
- void edit(Object *p_object);
-
void select_next();
void select_prev();
- EditorPlugin *get_selected_plugin() const;
- bool can_auto_switch_screens() const;
EditorMainScreen();
};
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index fe1c5648acb..93b80a0a0a4 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -3193,7 +3193,6 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
bool is_resource = Object::cast_to<Resource>(current_obj);
bool is_node = Object::cast_to<Node>(current_obj);
- bool skip_main_plugin = false;
String editable_info; // None by default.
bool info_is_warning = false;
@@ -3245,9 +3244,6 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
SceneTreeDock::get_singleton()->set_selected(current_node);
SceneTreeDock::get_singleton()->set_selection({ current_node });
InspectorDock::get_singleton()->update(current_node);
- if (!inspector_only && !skip_main_plugin) {
- skip_main_plugin = !editor_main_screen->can_auto_switch_screens();
- }
} else {
SignalsDock::get_singleton()->set_object(nullptr);
GroupsDock::get_singleton()->set_selection(Vector<Node *>());
@@ -3316,9 +3312,6 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
// Take care of the main editor plugin.
if (!inspector_only) {
- if (!skip_main_plugin) {
- editor_main_screen->edit(current_obj);
- }
edit_item(current_obj, editor_owner);
}
@@ -4749,17 +4742,6 @@ Dictionary EditorNode::_get_main_scene_state() {
}
void EditorNode::_set_main_scene_state(const Dictionary &p_state) {
- if (get_edited_scene()) {
- if (!restoring_scenes && 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();
- }
- editor_main_screen->edit(selected_node);
- }
- }
-
if (p_state.has("scene_tree_offset")) {
SceneTreeDock::get_singleton()->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->set_value(p_state["scene_tree_offset"]);
}
diff --git a/editor/plugins/editor_plugin.cpp b/editor/plugins/editor_plugin.cpp
index 26e2276fc17..d06d40aa141 100644
--- a/editor/plugins/editor_plugin.cpp
+++ b/editor/plugins/editor_plugin.cpp
@@ -358,11 +358,13 @@ void EditorPlugin::set_plugin_version(const String &p_version) {
plugin_version = p_version;
}
+#ifndef DISABLE_DEPRECATED
bool EditorPlugin::has_main_screen() const {
bool success = false;
GDVIRTUAL_CALL(_has_main_screen, success);
return success;
}
+#endif
void EditorPlugin::make_visible(bool p_visible) {
GDVIRTUAL_CALL(_make_visible, p_visible);
@@ -703,7 +705,9 @@ void EditorPlugin::_bind_methods() {
GDVIRTUAL_BIND(_forward_3d_force_draw_over_viewport, "viewport_control");
GDVIRTUAL_BIND(_get_plugin_name);
GDVIRTUAL_BIND(_get_plugin_icon);
+#ifndef DISABLE_DEPRECATED
GDVIRTUAL_BIND(_has_main_screen);
+#endif
GDVIRTUAL_BIND(_make_visible, "visible");
GDVIRTUAL_BIND(_edit, "object");
GDVIRTUAL_BIND(_handles, "object");
diff --git a/editor/plugins/editor_plugin.h b/editor/plugins/editor_plugin.h
index 5a3993b6735..ac5e43c1e63 100644
--- a/editor/plugins/editor_plugin.h
+++ b/editor/plugins/editor_plugin.h
@@ -127,7 +127,9 @@ protected:
GDVIRTUAL1(_forward_3d_force_draw_over_viewport, Control *)
GDVIRTUAL0RC(String, _get_plugin_name)
GDVIRTUAL0RC(Ref<Texture2D>, _get_plugin_icon)
+#ifndef DISABLE_DEPRECATED
GDVIRTUAL0RC(bool, _has_main_screen)
+#endif
GDVIRTUAL1(_make_visible, bool)
GDVIRTUAL1(_edit, Object *)
GDVIRTUAL1RC(bool, _handles, Object *)
@@ -197,7 +199,9 @@ public:
virtual const Ref<Texture2D> get_plugin_icon() const;
virtual String get_plugin_version() const;
virtual void set_plugin_version(const String &p_version);
+#ifndef DISABLE_DEPRECATED
virtual bool has_main_screen() const;
+#endif
virtual void make_visible(bool p_visible);
virtual void set_current() {}
virtual void edit(Object *p_object);
diff --git a/editor/scene/3d/node_3d_editor_plugin.h b/editor/scene/3d/node_3d_editor_plugin.h
index 775eadaabc9..75bc64d59ec 100644
--- a/editor/scene/3d/node_3d_editor_plugin.h
+++ b/editor/scene/3d/node_3d_editor_plugin.h
@@ -568,7 +568,6 @@ class Node3DEditorPlugin : public EditorPlugin {
public:
Node3DEditor *get_spatial_editor() { return spatial_editor; }
virtual String get_plugin_name() const override { return "3D"; }
- bool has_main_screen() const override { return true; }
virtual void make_visible(bool p_visible) override;
virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override;
diff --git a/editor/scene/canvas_item_editor_plugin.h b/editor/scene/canvas_item_editor_plugin.h
index 184d60601a5..f38cafce2c9 100644
--- a/editor/scene/canvas_item_editor_plugin.h
+++ b/editor/scene/canvas_item_editor_plugin.h
@@ -661,7 +661,6 @@ protected:
public:
virtual String get_plugin_name() const override { return "2D"; }
- bool has_main_screen() const override { return true; }
virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override;
virtual void make_visible(bool p_visible) override;
diff --git a/editor/script/script_editor_plugin.h b/editor/script/script_editor_plugin.h
index bf73b06b7e8..b2f52fb0927 100644
--- a/editor/script/script_editor_plugin.h
+++ b/editor/script/script_editor_plugin.h
@@ -548,7 +548,6 @@ public:
static bool open_in_external_editor(const String &p_path, int p_line, int p_col, bool p_ignore_project = false);
virtual String get_plugin_name() const override { return "Script"; }
- virtual bool has_main_screen() const override { return true; }
virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override;
virtual void make_visible(bool p_visible) override;