comparison libgui/src/main-window.cc @ 18944:b2c4d6d461f0 gui-release

fix conflict between main and editor menus when using alt keys (bug #42659) * file-editor.cc (enable_menu_shortcuts): new function enabling/disabling the alt-key accelerators; (m_add_menu): new function adding a menu and storing menu title with and without the char & indicating the accelerator in a hash; (construct): use m_add_menu for adding a new menu to the menu bar * file-editor-interface.h: new virtual function enable_menu_shortcuts * file-editor.h: new functions enable_menu_shortcuts amd m_add_menu, new hash for storing the menu titles * main-window.cc (connect_visibility_changed): disable editors menu shortcuts; (enable_menu_shortcuts): new function enabling/disabling the alt-key accelerators; (m_add_menu): new function adding a menu and storing menu title with and without the char & indicating the accelerator in a hash; (construct_file_menu, construct_edit_menu, construct_debug_menu, construct_window_menu, construct_help_menu, construct_news_menu): use m_add_menu for adding a new menu to the menu bar; (set_global_edit_shortcuts): enable/disable the main and the editors menu shortcuts
author Torsten <ttl@justmail.de>
date Sun, 20 Jul 2014 20:44:30 +0200
parents e7b5be5a7f80
children d2100cb2331a
comparison
equal deleted inserted replaced
18923:58f1178f49ef 18944:b2c4d6d461f0
1022 void 1022 void
1023 main_window::connect_visibility_changed (void) 1023 main_window::connect_visibility_changed (void)
1024 { 1024 {
1025 foreach (octave_dock_widget *widget, dock_widget_list ()) 1025 foreach (octave_dock_widget *widget, dock_widget_list ())
1026 widget->connect_visibility_changed (); 1026 widget->connect_visibility_changed ();
1027
1028 editor_window->enable_menu_shortcuts (false);
1027 } 1029 }
1028 1030
1029 void 1031 void
1030 main_window::copyClipboard (void) 1032 main_window::copyClipboard (void)
1031 { 1033 {
1464 a->setShortcutContext (Qt::ApplicationShortcut); 1466 a->setShortcutContext (Qt::ApplicationShortcut);
1465 return a; 1467 return a;
1466 } 1468 }
1467 1469
1468 void 1470 void
1471 main_window::enable_menu_shortcuts (bool enable)
1472 {
1473 QHash<QMenu*, QStringList>::const_iterator i = _hash_menu_text.constBegin();
1474
1475 while (i != _hash_menu_text.constEnd())
1476 {
1477 i.key ()->setTitle (i.value ().at (! enable));
1478 ++i;
1479 }
1480 }
1481
1482 QMenu*
1483 main_window::m_add_menu (QMenuBar *p, QString name)
1484 {
1485 QMenu *menu = p->addMenu (name);
1486
1487 QString base_name = name; // get a copy
1488 // replace intended '&' ("&&") by a temp. string
1489 base_name.replace ("&&","___octave_amp_replacement___");
1490 // remove single '&' (shortcut)
1491 base_name.remove ("&");
1492 // restore intended '&'
1493 base_name.replace ("___octave_amp_replacement___","&&");
1494
1495 // remember names with and without shortcut
1496 _hash_menu_text[menu] = QStringList () << name << base_name;
1497
1498 return menu;
1499 }
1500
1501 void
1469 main_window::construct_file_menu (QMenuBar *p) 1502 main_window::construct_file_menu (QMenuBar *p)
1470 { 1503 {
1471 QMenu *file_menu = p->addMenu (tr ("&File")); 1504 QMenu *file_menu = m_add_menu (p, tr ("&File"));
1472 1505
1473 construct_new_menu (file_menu); 1506 construct_new_menu (file_menu);
1474 1507
1475 _open_action 1508 _open_action
1476 = file_menu->addAction (QIcon (":/actions/icons/folder_documents.png"), 1509 = file_menu->addAction (QIcon (":/actions/icons/folder_documents.png"),
1552 } 1585 }
1553 1586
1554 void 1587 void
1555 main_window::construct_edit_menu (QMenuBar *p) 1588 main_window::construct_edit_menu (QMenuBar *p)
1556 { 1589 {
1557 QMenu *edit_menu = p->addMenu (tr ("&Edit")); 1590 QMenu *edit_menu = m_add_menu (p, tr ("&Edit"));
1558 1591
1559 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; 1592 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier;
1560 1593
1561 _undo_action 1594 _undo_action
1562 = edit_menu->addAction (QIcon (":/actions/icons/undo.png"), tr ("Undo")); 1595 = edit_menu->addAction (QIcon (":/actions/icons/undo.png"), tr ("Undo"));
1627 } 1660 }
1628 1661
1629 void 1662 void
1630 main_window::construct_debug_menu (QMenuBar *p) 1663 main_window::construct_debug_menu (QMenuBar *p)
1631 { 1664 {
1632 _debug_menu = p->addMenu (tr ("De&bug")); 1665 _debug_menu = m_add_menu (p, tr ("De&bug"));
1633 1666
1634 _debug_step_over = construct_debug_menu_item 1667 _debug_step_over = construct_debug_menu_item
1635 (":/actions/icons/db_step.png", tr ("Step"), 1668 (":/actions/icons/db_step.png", tr ("Step"),
1636 SLOT (debug_step_over ())); 1669 SLOT (debug_step_over ()));
1637 1670
1689 } 1722 }
1690 1723
1691 void 1724 void
1692 main_window::construct_window_menu (QMenuBar *p) 1725 main_window::construct_window_menu (QMenuBar *p)
1693 { 1726 {
1694 QMenu *window_menu = p->addMenu (tr ("&Window")); 1727 QMenu *window_menu = m_add_menu (p, tr ("&Window"));
1695 1728
1696 _show_command_window_action = construct_window_menu_item 1729 _show_command_window_action = construct_window_menu_item
1697 (window_menu, tr ("Show Command Window"), true, command_window); 1730 (window_menu, tr ("Show Command Window"), true, command_window);
1698 1731
1699 _show_history_action = construct_window_menu_item 1732 _show_history_action = construct_window_menu_item
1738 } 1771 }
1739 1772
1740 void 1773 void
1741 main_window::construct_help_menu (QMenuBar *p) 1774 main_window::construct_help_menu (QMenuBar *p)
1742 { 1775 {
1743 QMenu *help_menu = p->addMenu (tr ("&Help")); 1776 QMenu *help_menu = m_add_menu (p, tr ("&Help"));
1744 1777
1745 construct_documentation_menu (help_menu); 1778 construct_documentation_menu (help_menu);
1746 1779
1747 help_menu->addSeparator (); 1780 help_menu->addSeparator ();
1748 1781
1780 } 1813 }
1781 1814
1782 void 1815 void
1783 main_window::construct_news_menu (QMenuBar *p) 1816 main_window::construct_news_menu (QMenuBar *p)
1784 { 1817 {
1785 QMenu *news_menu = p->addMenu (tr ("&News")); 1818 QMenu *news_menu = m_add_menu (p, tr ("&News"));
1786 1819
1787 _release_notes_action = add_action (news_menu, QIcon (), 1820 _release_notes_action = add_action (news_menu, QIcon (),
1788 tr ("Release Notes"), SLOT (display_release_notes ())); 1821 tr ("Release Notes"), SLOT (display_release_notes ()));
1789 1822
1790 _current_news_action = add_action (news_menu, QIcon (), 1823 _current_news_action = add_action (news_menu, QIcon (),
2214 main_window::set_global_edit_shortcuts (bool enable) 2247 main_window::set_global_edit_shortcuts (bool enable)
2215 { 2248 {
2216 // this slot is called when editor gets/loses focus 2249 // this slot is called when editor gets/loses focus
2217 if (enable) 2250 if (enable)
2218 { // editor loses focus, set the global shortcuts 2251 { // editor loses focus, set the global shortcuts
2252 // and disable the editor's menu
2219 shortcut_manager::set_shortcut (_copy_action, "main_edit:copy"); 2253 shortcut_manager::set_shortcut (_copy_action, "main_edit:copy");
2220 shortcut_manager::set_shortcut (_paste_action, "main_edit:paste"); 2254 shortcut_manager::set_shortcut (_paste_action, "main_edit:paste");
2221 shortcut_manager::set_shortcut (_undo_action, "main_edit:undo"); 2255 shortcut_manager::set_shortcut (_undo_action, "main_edit:undo");
2222 shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all"); 2256 shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all");
2223 } 2257 }
2224 else 2258 else
2225 { // disable shortcuts that are also provided by the editor itself 2259 { // disable shortcuts that are also provided by the editor itself
2260 // and enable editor's menu
2226 QKeySequence no_key = QKeySequence (); 2261 QKeySequence no_key = QKeySequence ();
2227 _copy_action->setShortcut (no_key); 2262 _copy_action->setShortcut (no_key);
2228 _paste_action->setShortcut (no_key); 2263 _paste_action->setShortcut (no_key);
2229 _undo_action->setShortcut (no_key); 2264 _undo_action->setShortcut (no_key);
2230 _select_all_action->setShortcut (no_key); 2265 _select_all_action->setShortcut (no_key);
2231 } 2266 }
2267
2268 // enable/disable the main and the editor's menu shortcuts (alt-key)
2269 editor_window->enable_menu_shortcuts (! enable);
2270 enable_menu_shortcuts (enable);
2232 } 2271 }
2233 2272
2234 void 2273 void
2235 main_window::configure_shortcuts () 2274 main_window::configure_shortcuts ()
2236 { 2275 {