# HG changeset patch # User Daniel J Sebald # Date 1523420523 18000 # Node ID 07bddddc58567e5960a77b8a79e0790cbb6a24d8 # Parent 164399071f4dc36c695cee6d727c81e8217fd011 Restore Variable Editor focusWidget lost in dock/undock transition (bug #53410) * variable-editor.cc (variable_editor::variable_editor): Initialize new member variable m_variable_focus_widget to nullptr. (variable_editor::focusInEvent): If the m_main window's focusWidget() is nullptr, check if the recorded m_variable_focus_widget is still valid within the m_main container. If so, use it as a valid pointer and restore its focus. (variable_editor::focusOutEvent): Record m_main's focusWidget() just prior to transition to/from docked state. * variable-editor.h (variable_editor:octave_dock_widget): A class member variable m_variable_focus_widget to keep track of focusWidget(). diff -r 164399071f4d -r 07bddddc5856 libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc Wed Apr 11 15:13:10 2018 -0400 +++ b/libgui/src/variable-editor.cc Tue Apr 10 23:22:03 2018 -0500 @@ -990,7 +990,8 @@ m_sel_font (), m_table_colors (), m_current_focus_vname (""), - m_hovered_focus_vname ("") + m_hovered_focus_vname (""), + m_variable_focus_widget (nullptr) { setObjectName ("VariableEditor"); set_title (tr ("Variable Editor")); @@ -1038,10 +1039,20 @@ { octave_dock_widget::focusInEvent (ev); - // set focus to the current variable + // set focus to the current variable or most recent if still valid QWidget *fw = m_main->focusWidget (); if (fw != nullptr) fw->setFocus (); + else if (m_main->isAncestorOf (m_variable_focus_widget)) + m_variable_focus_widget->setFocus (); + } + + void variable_editor::focusOutEvent (QFocusEvent *ev) + { + // focusWidget() appears lost in transition to/from main window + m_variable_focus_widget = m_main->focusWidget (); + + octave_dock_widget::focusOutEvent (ev); } // Add an action to a menu or the widget itself. diff -r 164399071f4d -r 07bddddc5856 libgui/src/variable-editor.h --- a/libgui/src/variable-editor.h Wed Apr 11 15:13:10 2018 -0400 +++ b/libgui/src/variable-editor.h Tue Apr 10 23:22:03 2018 -0500 @@ -338,6 +338,8 @@ void focusInEvent (QFocusEvent *ev); + void focusOutEvent (QFocusEvent *ev); + private: QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, @@ -377,6 +379,8 @@ QString m_current_focus_vname; QString m_hovered_focus_vname; + + QWidget *m_variable_focus_widget; }; }