Skip to content

armgit / godot

Public Imported from GitHub
0

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

Focus Script Editor text on dock focus and click

kit901e28c9be8f
diff --git a/editor/docks/dock_tab_container.cpp b/editor/docks/dock_tab_container.cpp
index e5f49f5bdbf..5b3c7f78305 100644
--- a/editor/docks/dock_tab_container.cpp
+++ b/editor/docks/dock_tab_container.cpp
@@ -226,6 +226,14 @@ void DockTabContainer::_tab_rmb_clicked(int p_tab_idx) {
dock_context_popup->popup();
}
+void DockTabContainer::_tab_clicked() {
+ EditorDock *current_dock = get_dock(get_current_tab());
+ if (!current_dock) {
+ return;
+ }
+ EditorDockManager::get_singleton()->force_focus_dock(current_dock);
+}
+
void DockTabContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_POSTINITIALIZE) {
connect("pre_popup_pressed", callable_mp(this, &DockTabContainer::_pre_popup).bind(Size2i()));
@@ -359,6 +367,7 @@ DockTabContainer::DockTabContainer(int p_slot) {
get_tab_bar()->set_switch_on_release(true);
get_tab_bar()->connect("tab_rmb_clicked", callable_mp(this, &DockTabContainer::_tab_rmb_clicked));
+ get_tab_bar()->connect("tab_clicked", callable_mp(this, &DockTabContainer::_tab_clicked).unbind(1));
}
Rect2 SideDockTabContainer::get_floating_dock_rect(EditorDock *p_dock) {
diff --git a/editor/docks/dock_tab_container.h b/editor/docks/dock_tab_container.h
index d8b116938d1..0463cd8fa7f 100644
--- a/editor/docks/dock_tab_container.h
+++ b/editor/docks/dock_tab_container.h
@@ -82,6 +82,7 @@ class DockTabContainer : public TabContainer {
void _pre_popup(const Size2i &p_size);
void _tab_rmb_clicked(int p_tab_idx);
+ void _tab_clicked();
protected:
DockContextPopup *dock_context_popup = nullptr;
diff --git a/editor/docks/editor_dock.cpp b/editor/docks/editor_dock.cpp
index 963619d325b..ca7aa02e758 100644
--- a/editor/docks/editor_dock.cpp
+++ b/editor/docks/editor_dock.cpp
@@ -127,6 +127,7 @@ void EditorDock::_bind_methods() {
ADD_SIGNAL(MethodInfo("opened"));
ADD_SIGNAL(MethodInfo("closed"));
ADD_SIGNAL(MethodInfo("_tab_style_changed"));
+ ADD_SIGNAL(MethodInfo("_focused"));
BIND_BITFIELD_FLAG(DOCK_LAYOUT_VERTICAL);
BIND_BITFIELD_FLAG(DOCK_LAYOUT_HORIZONTAL);
diff --git a/editor/docks/editor_dock_manager.cpp b/editor/docks/editor_dock_manager.cpp
index b997f67c0cc..89620a6e529 100644
--- a/editor/docks/editor_dock_manager.cpp
+++ b/editor/docks/editor_dock_manager.cpp
@@ -262,7 +262,7 @@ void EditorDockManager::_window_close_request(WindowWrapper *p_wrapper) {
if (dock->dock_slot_index != EditorDock::DOCK_SLOT_NONE) {
dock->is_open = false;
- focus_dock(dock);
+ force_focus_dock(dock);
} else {
close_dock(dock);
}
@@ -317,7 +317,7 @@ void EditorDockManager::_open_dock_in_window(EditorDock *p_dock, bool p_show_win
p_dock->get_window()->set_size(popup_size);
p_dock->get_window()->move_to_center();
}
- p_dock->get_window()->grab_focus();
+ focus_dock(p_dock);
}
}
@@ -715,6 +715,7 @@ void EditorDockManager::_make_dock_visible(EditorDock *p_dock, bool p_grab_focus
if (p_dock->dock_window) {
if (p_grab_focus) {
p_dock->get_window()->grab_focus();
+ p_dock->emit_signal("_focused");
}
return;
}
@@ -726,6 +727,7 @@ void EditorDockManager::_make_dock_visible(EditorDock *p_dock, bool p_grab_focus
if (p_grab_focus) {
tab_container->get_tab_bar()->grab_focus(true);
+ p_dock->emit_signal("_focused");
}
if (!p_dock->is_visible_in_tree()) {
diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp
index ac90d389c16..86067e8ff91 100644
--- a/editor/editor_interface.cpp
+++ b/editor/editor_interface.cpp
@@ -445,7 +445,7 @@ SubViewport *EditorInterface::get_editor_viewport_3d(int p_idx) const {
void EditorInterface::set_main_screen_editor(const String &p_name) {
EditorDock *dock = EditorNode::get_singleton()->get_editor_main_screen()->get_dock_by_name(p_name);
ERR_FAIL_NULL_MSG(dock, "The editor name '" + p_name + "' was not found.");
- EditorDockManager::get_singleton()->focus_dock(dock);
+ EditorDockManager::get_singleton()->force_focus_dock(dock);
}
#endif
diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp
index 45f9cd38a46..e0322034a58 100644
--- a/editor/script/script_editor_plugin.cpp
+++ b/editor/script/script_editor_plugin.cpp
@@ -2717,6 +2717,16 @@ Vector<Control *> DocumentEditorContainer::get_all_editors() const {
return editors;
}
+void DocumentEditorContainer::focus_active_editor() {
+ ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(get_active_editor());
+ EditorHelp *eh = Object::cast_to<EditorHelp>(get_active_editor());
+ if (seb) {
+ seb->get_base_editor()->grab_focus();
+ } else if (eh) {
+ eh->set_focused();
+ }
+}
+
PackedStringArray DocumentEditorContainer::get_unsaved_scripts() const {
PackedStringArray unsaved_list;
@@ -4307,15 +4317,7 @@ bool ScriptEditor::should_use_external_editor(const Ref<Script> &p_for_script) {
}
void ScriptEditor::focus_editor() {
- EditorDockManager::get_singleton()->focus_dock(this);
- Control *active_editor = script_container->get_active_editor();
- ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(active_editor);
- EditorHelp *eh = Object::cast_to<EditorHelp>(active_editor);
- if (seb) {
- seb->get_base_editor()->grab_focus();
- } else if (eh) {
- eh->set_focused();
- }
+ EditorDockManager::get_singleton()->force_focus_dock(this);
}
void ScriptEditor::focus_script_editor(const Ref<Resource> &p_for_resource) {
@@ -4531,6 +4533,7 @@ ScriptEditor::ScriptEditor() {
script_container = memnew(DocumentEditorContainer(true, "ScriptEditor", "script_editor_cache.cfg"));
script_container->set_handled_resource_types({ "GDScript", "Script", "JSON" });
add_child(script_container);
+ connect("_focused", callable_mp(script_container, &DocumentEditorContainer::focus_active_editor));
help_search_dialog = memnew(EditorHelpSearch);
add_child(help_search_dialog);
diff --git a/editor/script/script_editor_plugin.h b/editor/script/script_editor_plugin.h
index 72e2f5ad237..5a632866c44 100644
--- a/editor/script/script_editor_plugin.h
+++ b/editor/script/script_editor_plugin.h
@@ -459,6 +459,7 @@ public:
Control *get_active_editor() const;
Vector<Control *> get_all_editors() const;
+ void focus_active_editor();
Vector<String> _get_breakpoints();
void get_breakpoints(List<String> *p_breakpoints);
diff --git a/editor/shader/shader_editor_plugin.cpp b/editor/shader/shader_editor_plugin.cpp
index b379e4f4afd..3080119e4c0 100644
--- a/editor/shader/shader_editor_plugin.cpp
+++ b/editor/shader/shader_editor_plugin.cpp
@@ -30,6 +30,7 @@
#include "shader_editor_plugin.h"
+#include "core/object/callable_mp.h"
#include "core/variant/variant.h"
#include "editor/docks/editor_dock.h"
#include "editor/docks/editor_dock_manager.h"
@@ -166,6 +167,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
shader_container->set_handled_resource_types({ "Shader", "VisualShader", "ShaderInclude" });
shader_dock->add_child(shader_container);
+ shader_dock->connect("_focused", callable_mp(shader_container, &DocumentEditorContainer::focus_active_editor));
}
ShaderEditorPlugin::~ShaderEditorPlugin() {