Mercurial > hg > octave-jordi
changeset 20692: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 | dc2be2485968 |
children | a7dbc4fc3732 |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/shortcut-manager.cc |
diffstat | 3 files changed, 67 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -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
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -234,6 +234,9 @@ void zoom_out (bool); void zoom_normal (bool); + void switch_left_tab (); + void switch_right_tab (); + void create_context_menu (QMenu *); void edit_status_update (bool, bool); @@ -253,6 +256,8 @@ void toggle_preference (const QString& preference, bool def); + void switch_tab (int direction); + bool editor_tab_has_focus (); QWidget *find_tab_widget (const QString& openFileName) const; @@ -338,6 +343,9 @@ QAction *_preferences_action; QAction *_styles_preferences_action; + QAction *_switch_left_tab_action; + QAction *_switch_right_tab_action; + QAction *_toggle_breakpoint_action; QAction *_next_breakpoint_action; QAction *_previous_breakpoint_action;
--- a/libgui/src/shortcut-manager.cc +++ b/libgui/src/shortcut-manager.cc @@ -316,6 +316,13 @@ QKeySequence::HelpContents); init (tr ("Document on Keyword"), "editor_help:doc_keyword", QKeySequence (Qt::SHIFT + Qt::Key_F1)); + + // tab navigation + init (tr ("Switch to left tab"), "editor_tabs:switch_left_tab", + QKeySequence (ctrl + Qt::Key_PageDown)); + init (tr ("Switch to right tab"), "editor_tabs:switch_right_tab", + QKeySequence (ctrl + Qt::Key_PageUp)); + } void @@ -385,6 +392,8 @@ editor_run->setText (0, tr ("Run")); QTreeWidgetItem *editor_help = new QTreeWidgetItem (editor); editor_help->setText (0, tr ("Help")); + QTreeWidgetItem *editor_tabs = new QTreeWidgetItem (editor); + editor_tabs->setText (0, tr ("Tabs")); _level_hash["editor_file"] = editor_file; _level_hash["editor_edit"] = editor_edit; @@ -392,6 +401,7 @@ _level_hash["editor_debug"] = editor_debug; _level_hash["editor_run"] = editor_run; _level_hash["editor_help"] = editor_help; + _level_hash["editor_tabs"] = editor_tabs; connect (tree_view, SIGNAL (itemDoubleClicked (QTreeWidgetItem*, int)), this, SLOT (handle_double_clicked (QTreeWidgetItem*, int)));