# HG changeset patch # User Torsten # Date 1359228826 -3600 # Node ID 6c0fce0632a4f0d1ba3d3a43db5bd090b1116b12 # Parent 3cd3b548f90b77be0d668c4a79885ed7a14a048c gui: set keyboard focus when switching between dock widgets (bug #36957) * main-window.cc (handle_command_window_visible, handle_command_history_visible, handle_current_directory_visible, handle_workspace_visible, handle_editor_visible, handle_documentation_visible): slots for signal visibilityChanged, emitted when widgets get visible * main-window.cc (construct): connect signal visibilityChanged to slots * main-window.cc (focus_editor): call editor's own function for setting focus * main-window.h: declaration of new slots * file-editor.cc (set_focus): new function: setting focus to actual editor tab * file-editor.cc (add_file_editor_tab): connect signal fetab_set_focus to the slot set_focus of file_editor_tab * file-editor.h: new function set_focus and new signal fetab_set_focus * file-editor-interface.h: new virtual function set_focus * file-editor-tab.cc (set_focus): new slot for singal fetab_set_focus from file_editor, setting the focus to edit area * file-edtortab.h: new slot set_focus diff --git a/libgui/src/m-editor/file-editor-interface.h b/libgui/src/m-editor/file-editor-interface.h --- a/libgui/src/m-editor/file-editor-interface.h +++ b/libgui/src/m-editor/file-editor-interface.h @@ -48,6 +48,7 @@ virtual void handle_entered_debug_mode () = 0; virtual void handle_quit_debug_mode () = 0; + virtual void set_focus () = 0; public slots: virtual void request_new_file () = 0; diff --git a/libgui/src/m-editor/file-editor-tab.cc b/libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -259,6 +259,15 @@ _edit_area->setLexer (lexer); } +// slot for fetab_set_focus: sets the focus to the current edit area +void +file_editor_tab::set_focus (const QWidget* ID) +{ + if (ID != this) + return; + _edit_area->setFocus (); +} + void file_editor_tab::undo (const QWidget* ID) { diff --git a/libgui/src/m-editor/file-editor-tab.h b/libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -52,6 +52,7 @@ /** Simply transmit file name. */ void file_name_query (const QWidget* ID); + void set_focus (const QWidget* ID); void undo (const QWidget* ID); void redo (const QWidget* ID); void copy (const QWidget* ID); diff --git a/libgui/src/m-editor/file-editor.cc b/libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -64,6 +64,18 @@ settings->sync (); } +// set focus to editor and its current tab +void +file_editor::set_focus () +{ + setFocus (); + activateWindow (); + raise (); + QWidget *fileEditorTab = _tab_widget->currentWidget (); + if (fileEditorTab) + emit fetab_set_focus (fileEditorTab); +} + QMenu * file_editor::debug_menu () { @@ -819,6 +831,8 @@ f, SLOT (uncomment_selected_text (const QWidget*))); connect (this, SIGNAL (fetab_find (const QWidget*)), f, SLOT (find (const QWidget*))); + connect (this, SIGNAL (fetab_set_focus (const QWidget*)), + f, SLOT (set_focus (const QWidget*))); _tab_widget->setCurrentWidget (f); } diff --git a/libgui/src/m-editor/file-editor.h b/libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -54,6 +54,7 @@ QMenu * debug_menu (); QToolBar * toolbar (); + void set_focus (); void handle_entered_debug_mode (); void handle_quit_debug_mode (); @@ -85,6 +86,7 @@ void fetab_comment_selected_text (const QWidget* ID); void fetab_uncomment_selected_text (const QWidget* ID); void fetab_find (const QWidget* ID); + void fetab_set_focus (const QWidget* ID); public slots: void request_new_file (); diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc --- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -393,6 +393,7 @@ _workspace_view->raise (); } + void main_window::focus_editor () { @@ -401,10 +402,8 @@ { _file_editor->setVisible (true); } - - _file_editor->setFocus (); - _file_editor->activateWindow (); - _file_editor->raise (); + // call own function of editor in order to set focus to the current editor tab + _file_editor->set_focus (); #endif } @@ -422,6 +421,54 @@ } void +main_window::handle_command_window_visible (bool visible) +{ + // if widget is changed to visible and is not floating + if (visible && !_terminal_dock_widget->isFloating ()) + focus_command_window (); +} + +void +main_window::handle_command_history_visible (bool visible) +{ + // if changed to visible and widget is not floating + if (visible && !_history_dock_widget->isFloating ()) + focus_command_history (); +} + +void +main_window::handle_current_directory_visible (bool visible) +{ + // if changed to visible and widget is not floating + if (visible && !_files_dock_widget->isFloating ()) + focus_current_directory (); +} + +void +main_window::handle_workspace_visible (bool visible) +{ + // if changed to visible and widget is not floating + if (visible && !_workspace_view->isFloating ()) + focus_workspace (); +} + +void +main_window::handle_editor_visible (bool visible) +{ + // if changed to visible and widget is not floating + if (visible && !_file_editor->isFloating ()) + focus_editor (); +} + +void +main_window::handle_documentation_visible (bool visible) +{ + // if changed to visible and widget is not floating + if (visible && !_documentation_dock_widget->isFloating ()) + focus_documentation (); +} + +void main_window::handle_entered_debug_mode () { setWindowTitle ("Octave (Debugging)"); @@ -943,6 +990,18 @@ this, SLOT (focus_editor ())); connect (documentation_action, SIGNAL (triggered ()), this, SLOT (focus_documentation ())); + connect (_terminal_dock_widget, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_command_window_visible (bool))); + connect (_workspace_view, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_workspace_visible (bool))); + connect (_history_dock_widget, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_command_history_visible (bool))); + connect (_files_dock_widget, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_current_directory_visible (bool))); + connect (_file_editor, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_editor_visible (bool))); + connect (_documentation_dock_widget, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_documentation_visible (bool))); connect (reset_windows_action, SIGNAL (triggered ()), this, SLOT (reset_windows ())); diff --git a/libgui/src/main-window.h b/libgui/src/main-window.h --- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -106,6 +106,12 @@ void focus_workspace (); void focus_editor (); void focus_documentation (); + void handle_command_window_visible (bool); + void handle_command_history_visible (bool); + void handle_current_directory_visible (bool); + void handle_workspace_visible (bool); + void handle_editor_visible (bool); + void handle_documentation_visible (bool); void handle_entered_debug_mode (); void handle_quit_debug_mode ();