Mercurial > octave-dspies
diff libgui/src/main-window.cc @ 18976:dcb260e7a648
maint: Periodic merge of gui-release to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 Aug 2014 12:10:05 -0400 |
parents | 479d1d3cb5c3 d2100cb2331a |
children |
line wrap: on
line diff
--- a/libgui/src/main-window.cc Thu Jul 31 15:49:21 2014 +0200 +++ b/libgui/src/main-window.cc Fri Aug 01 12:10:05 2014 -0400 @@ -1024,6 +1024,8 @@ { foreach (octave_dock_widget *widget, dock_widget_list ()) widget->connect_visibility_changed (); + + editor_window->enable_menu_shortcuts (false); } void @@ -1336,6 +1338,8 @@ editor_window->empty_script (true, false); #endif + focus_command_window (); // make sure that the command window has focus + } @@ -1466,9 +1470,40 @@ } void +main_window::enable_menu_shortcuts (bool enable) +{ + QHash<QMenu*, QStringList>::const_iterator i = _hash_menu_text.constBegin(); + + while (i != _hash_menu_text.constEnd()) + { + i.key ()->setTitle (i.value ().at (! enable)); + ++i; + } +} + +QMenu* +main_window::m_add_menu (QMenuBar *p, QString name) +{ + QMenu *menu = p->addMenu (name); + + QString base_name = name; // get a copy + // replace intended '&' ("&&") by a temp. string + base_name.replace ("&&","___octave_amp_replacement___"); + // remove single '&' (shortcut) + base_name.remove ("&"); + // restore intended '&' + base_name.replace ("___octave_amp_replacement___","&&"); + + // remember names with and without shortcut + _hash_menu_text[menu] = QStringList () << name << base_name; + + return menu; +} + +void main_window::construct_file_menu (QMenuBar *p) { - QMenu *file_menu = p->addMenu (tr ("&File")); + QMenu *file_menu = m_add_menu (p, tr ("&File")); construct_new_menu (file_menu); @@ -1554,7 +1589,7 @@ void main_window::construct_edit_menu (QMenuBar *p) { - QMenu *edit_menu = p->addMenu (tr ("&Edit")); + QMenu *edit_menu = m_add_menu (p, tr ("&Edit")); QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; @@ -1629,7 +1664,7 @@ void main_window::construct_debug_menu (QMenuBar *p) { - _debug_menu = p->addMenu (tr ("De&bug")); + _debug_menu = m_add_menu (p, tr ("De&bug")); _debug_step_over = construct_debug_menu_item (":/actions/icons/db_step.png", tr ("Step"), @@ -1691,7 +1726,7 @@ void main_window::construct_window_menu (QMenuBar *p) { - QMenu *window_menu = p->addMenu (tr ("&Window")); + QMenu *window_menu = m_add_menu (p, tr ("&Window")); _show_command_window_action = construct_window_menu_item (window_menu, tr ("Show Command Window"), true, command_window); @@ -1740,7 +1775,7 @@ void main_window::construct_help_menu (QMenuBar *p) { - QMenu *help_menu = p->addMenu (tr ("&Help")); + QMenu *help_menu = m_add_menu (p, tr ("&Help")); construct_documentation_menu (help_menu); @@ -1782,7 +1817,7 @@ void main_window::construct_news_menu (QMenuBar *p) { - QMenu *news_menu = p->addMenu (tr ("&News")); + QMenu *news_menu = m_add_menu (p, tr ("&News")); _release_notes_action = add_action (news_menu, QIcon (), tr ("Release Notes"), SLOT (display_release_notes ())); @@ -2216,6 +2251,7 @@ // this slot is called when editor gets/loses focus if (enable) { // editor loses focus, set the global shortcuts + // and disable the editor's menu shortcut_manager::set_shortcut (_copy_action, "main_edit:copy"); shortcut_manager::set_shortcut (_paste_action, "main_edit:paste"); shortcut_manager::set_shortcut (_undo_action, "main_edit:undo"); @@ -2223,12 +2259,17 @@ } else { // disable shortcuts that are also provided by the editor itself + // and enable editor's menu QKeySequence no_key = QKeySequence (); _copy_action->setShortcut (no_key); _paste_action->setShortcut (no_key); _undo_action->setShortcut (no_key); _select_all_action->setShortcut (no_key); } + + // enable/disable the main and the editor's menu shortcuts (alt-key) + editor_window->enable_menu_shortcuts (! enable); + enable_menu_shortcuts (enable); } void