Merge pull request #115084 from lodetrick/unify-focus
Combine dock focus methods to prevent inconsistencies
This commit is contained in:
@@ -851,16 +851,7 @@ void EditorDockManager::open_dock(EditorDock *p_dock, bool p_set_current) {
|
|||||||
if (p_dock->is_open) {
|
if (p_dock->is_open) {
|
||||||
// Show the dock if it is already open.
|
// Show the dock if it is already open.
|
||||||
if (p_set_current) {
|
if (p_set_current) {
|
||||||
if (p_dock->dock_window) {
|
_make_dock_visible(p_dock, false);
|
||||||
p_dock->get_window()->grab_focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TabContainer *dock_tab_container = get_dock_tab_container(p_dock);
|
|
||||||
if (dock_tab_container) {
|
|
||||||
int tab_index = dock_tab_container->get_tab_idx_from_control(p_dock);
|
|
||||||
dock_tab_container->set_current_tab(tab_index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -896,20 +887,11 @@ TabContainer *EditorDockManager::get_dock_tab_container(Control *p_dock) const {
|
|||||||
return Object::cast_to<TabContainer>(p_dock->get_parent());
|
return Object::cast_to<TabContainer>(p_dock->get_parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorDockManager::focus_dock(EditorDock *p_dock) {
|
void EditorDockManager::_make_dock_visible(EditorDock *p_dock, bool p_grab_focus) {
|
||||||
ERR_FAIL_NULL(p_dock);
|
|
||||||
ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot focus unknown dock '%s'.", p_dock->get_display_title()));
|
|
||||||
|
|
||||||
if (!p_dock->enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!p_dock->is_open) {
|
|
||||||
open_dock(p_dock, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_dock->dock_window) {
|
if (p_dock->dock_window) {
|
||||||
p_dock->get_window()->grab_focus();
|
if (p_grab_focus) {
|
||||||
|
p_dock->get_window()->grab_focus();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -922,12 +904,29 @@ void EditorDockManager::focus_dock(EditorDock *p_dock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TabContainer *tab_container = get_dock_tab_container(p_dock);
|
TabContainer *tab_container = get_dock_tab_container(p_dock);
|
||||||
if (!tab_container) {
|
if (tab_container) {
|
||||||
|
if (p_grab_focus) {
|
||||||
|
tab_container->get_tab_bar()->grab_focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
int tab_index = tab_container->get_tab_idx_from_control(p_dock);
|
||||||
|
tab_container->set_current_tab(tab_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorDockManager::focus_dock(EditorDock *p_dock) {
|
||||||
|
ERR_FAIL_NULL(p_dock);
|
||||||
|
ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot focus unknown dock '%s'.", p_dock->get_display_title()));
|
||||||
|
|
||||||
|
if (!p_dock->enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int tab_index = tab_container->get_tab_idx_from_control(p_dock);
|
|
||||||
tab_container->get_tab_bar()->grab_focus();
|
if (!p_dock->is_open) {
|
||||||
tab_container->set_current_tab(tab_index);
|
open_dock(p_dock, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_make_dock_visible(p_dock, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorDockManager::add_dock(EditorDock *p_dock) {
|
void EditorDockManager::add_dock(EditorDock *p_dock) {
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ private:
|
|||||||
void _open_dock_in_window(EditorDock *p_dock, bool p_show_window = true, bool p_reset_size = false);
|
void _open_dock_in_window(EditorDock *p_dock, bool p_show_window = true, bool p_reset_size = false);
|
||||||
void _restore_dock_to_saved_window(EditorDock *p_dock, const Dictionary &p_window_dump);
|
void _restore_dock_to_saved_window(EditorDock *p_dock, const Dictionary &p_window_dump);
|
||||||
|
|
||||||
|
void _make_dock_visible(EditorDock *p_dock, bool p_grab_focus);
|
||||||
void _move_dock_tab_index(EditorDock *p_dock, int p_tab_index, bool p_set_current);
|
void _move_dock_tab_index(EditorDock *p_dock, int p_tab_index, bool p_set_current);
|
||||||
void _move_dock(EditorDock *p_dock, Control *p_target, int p_tab_index = -1, bool p_set_current = true);
|
void _move_dock(EditorDock *p_dock, Control *p_target, int p_tab_index = -1, bool p_set_current = true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user