Mercurial > octave
diff libgui/src/m-editor/file-editor.cc @ 20693:7751bd56d0be
added actions and shortcuts for switching editor tabs
* file-editor.cc (add_action): allow actions added to the widget without menu
entry;
(construct): added action for switching to left/right tab;
(set_shortcuts): set the shortcuts to the new actions;
(switch_left_tab): slot for switching to left tab;
(switch_right_tab): slot for switching to right tab;
(switch_tab): common slot for switching tabs
* file-editor.h: new actions and slots for switching tabs
* shortcut-manager.cc (do_init_data): init the new shortcuts with the
default key sequences or the ones from the settings file;
(do_fill_treewidget): add tab navigation with the new shortcuts to the
tree widget in the settings dialog;
author | Torsten <ttl@justmail.de> |
---|---|
date | Wed, 11 Nov 2015 20:09:31 +0100 |
parents | 802dc52d4d46 |
children | 7f568368d247 |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Sun Nov 08 21:34:44 2015 -0800 +++ b/libgui/src/m-editor/file-editor.cc Wed Nov 11 20:09:31 2015 +0100 @@ -1206,9 +1206,19 @@ file_editor::add_action (QMenu *menu, const QIcon &icon, const QString &text, const char *member) { - QAction *a = menu->addAction (icon, text, this, member); + QAction *a; + + if (menu) + a = menu->addAction (icon, text, this, member); + else + { + a = new QAction (this); + connect (a, SIGNAL (triggered ()), this, member); + } + addAction (a); // important for shortcut context a->setShortcutContext (Qt::WidgetWithChildrenShortcut); + return a; } @@ -1519,6 +1529,13 @@ _context_doc_action = add_action (_help_menu, QIcon (), tr ("&Documentation on Keyword"), SLOT (request_context_doc (bool))); + // tab navigation (no menu, only actions) + + _switch_left_tab_action = add_action (0, QIcon (), "", + SLOT (switch_left_tab ())); + _switch_right_tab_action = add_action (0, QIcon (), "", + SLOT (switch_right_tab ())); + // toolbar // new and open actions are inserted later from main window @@ -1876,6 +1893,10 @@ shortcut_manager::set_shortcut (_context_help_action, "editor_help:help_keyword"); shortcut_manager::set_shortcut (_context_doc_action, "editor_help:doc_keyword"); + // Tab navigation without menu entries + shortcut_manager::set_shortcut (_switch_left_tab_action, "editor_tabs:switch_left_tab"); + shortcut_manager::set_shortcut (_switch_right_tab_action, "editor_tabs:switch_right_tab"); + } void @@ -2003,4 +2024,31 @@ } } +// slots for tab navigation +void +file_editor::switch_left_tab () +{ + switch_tab (-1); +} +void +file_editor::switch_right_tab () +{ + switch_tab (1); +} +void +file_editor::switch_tab (int direction) +{ + int tabs = _tab_widget->count (); + + if (tabs < 2) + return; + + int new_index = _tab_widget->currentIndex () + direction; + + if (new_index < 0 || new_index >= tabs) + new_index = new_index - direction*tabs; + + _tab_widget->setCurrentIndex (new_index); +} + #endif