Mercurial > octave
changeset 29085:3b29d72645a9
fix alt-key stealing focus from current dock widget in gui
* file-editor-interface.h: define purely virtual method menubar
returning the editors menu bar
* file-editor.h (menubar): implementaiton of method menubar
* main-window.cc (main_window): intialize new class variabel for the
editors menu bar depending on the editor in use (gui or external);
(focus_changed): if new widget is one of the menubars, reset focus
to currently active widget m_active_dock and just return;
(prepare_to_exit): set m_active_dock to nullptr preventing
setting focus to a widget that might not exist anymore during
shutdown
* main-window.h: new clas variable m_editor_menubar
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Fri, 20 Nov 2020 23:25:42 +0100 |
parents | 2a70a068c4ab |
children | d0fe364977c1 |
files | libgui/src/m-editor/file-editor-interface.h libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h |
diffstat | 4 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-interface.h Fri Nov 20 20:02:29 2020 +0100 +++ b/libgui/src/m-editor/file-editor-interface.h Fri Nov 20 23:25:42 2020 +0100 @@ -51,6 +51,7 @@ virtual QMenu * get_mru_menu (void) = 0; virtual QMenu * debug_menu (void) = 0; virtual QToolBar * toolbar (void) = 0; + virtual QMenuBar * menubar (void) = 0; virtual void insert_global_actions (QList<QAction*>) = 0; virtual void handle_enter_debug_mode (void) = 0;
--- a/libgui/src/m-editor/file-editor.h Fri Nov 20 20:02:29 2020 +0100 +++ b/libgui/src/m-editor/file-editor.h Fri Nov 20 23:25:42 2020 +0100 @@ -98,6 +98,8 @@ QToolBar * toolbar (void) { return m_tool_bar; } + QMenuBar * menubar (void) { return m_menu_bar; } + void insert_global_actions (QList<QAction*>); enum shared_actions_idx
--- a/libgui/src/main-window.cc Fri Nov 20 20:02:29 2020 +0100 +++ b/libgui/src/main-window.cc Fri Nov 20 23:25:42 2020 +0100 @@ -189,9 +189,15 @@ // Set active editor depending on editor window. If the latter is // not initialized (qscintilla not present), use the external editor. if (m_editor_window) - m_active_editor = m_editor_window; + { + m_editor_menubar = m_editor_window->menubar (); + m_active_editor = m_editor_window; + } else - m_active_editor = m_external_editor; + { + m_editor_menubar = nullptr; + m_active_editor = m_external_editor; + } #if defined (HAVE_QGUIAPPLICATION_SETDESKTOPFILENAME) QGuiApplication::setDesktopFileName ("org.octave.Octave.desktop"); @@ -319,10 +325,18 @@ // catch focus changes and determine the active dock widget void main_window::focus_changed (QWidget *, QWidget *new_widget) { - // If there is no new widget (e.g., when pressing <alt> and the global - // menu gets active), we can return immediately - if (! new_widget) - return; + // If there is no new widget or the new widget is a menu bar + // (when pressing <alt>), we can return immediately and reset the + // focus to the previous widget + if (! new_widget + || (new_widget == menuBar ()) + || (new_widget == m_editor_menubar)) + { + if (m_active_dock) + m_active_dock->setFocus (); + + return; + } octave_dock_widget *dock = nullptr; QWidget *w_new = new_widget; // get a copy of new focus widget @@ -1008,6 +1022,10 @@ m_set_path_dlg->save_settings (); write_settings (); + + // No more active dock, otherwise, focus_changed would try to set + // the focus to a dock widget that might not exist anymore + m_active_dock = nullptr; } void main_window::go_to_previous_widget (void)