comparison 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
comparison
equal deleted inserted replaced
18972:19cb2530c16b 18976:dcb260e7a648
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 {
1334 // This can not be done when the editor is created because all functions 1336 // This can not be done when the editor is created because all functions
1335 // must be known for the lexer's auto completion informations 1337 // must be known for the lexer's auto completion informations
1336 editor_window->empty_script (true, false); 1338 editor_window->empty_script (true, false);
1337 #endif 1339 #endif
1338 1340
1341 focus_command_window (); // make sure that the command window has focus
1342
1339 } 1343 }
1340 1344
1341 1345
1342 void 1346 void
1343 main_window::construct_octave_qt_link (void) 1347 main_window::construct_octave_qt_link (void)
1464 a->setShortcutContext (Qt::ApplicationShortcut); 1468 a->setShortcutContext (Qt::ApplicationShortcut);
1465 return a; 1469 return a;
1466 } 1470 }
1467 1471
1468 void 1472 void
1473 main_window::enable_menu_shortcuts (bool enable)
1474 {
1475 QHash<QMenu*, QStringList>::const_iterator i = _hash_menu_text.constBegin();
1476
1477 while (i != _hash_menu_text.constEnd())
1478 {
1479 i.key ()->setTitle (i.value ().at (! enable));
1480 ++i;
1481 }
1482 }
1483
1484 QMenu*
1485 main_window::m_add_menu (QMenuBar *p, QString name)
1486 {
1487 QMenu *menu = p->addMenu (name);
1488
1489 QString base_name = name; // get a copy
1490 // replace intended '&' ("&&") by a temp. string
1491 base_name.replace ("&&","___octave_amp_replacement___");
1492 // remove single '&' (shortcut)
1493 base_name.remove ("&");
1494 // restore intended '&'
1495 base_name.replace ("___octave_amp_replacement___","&&");
1496
1497 // remember names with and without shortcut
1498 _hash_menu_text[menu] = QStringList () << name << base_name;
1499
1500 return menu;
1501 }
1502
1503 void
1469 main_window::construct_file_menu (QMenuBar *p) 1504 main_window::construct_file_menu (QMenuBar *p)
1470 { 1505 {
1471 QMenu *file_menu = p->addMenu (tr ("&File")); 1506 QMenu *file_menu = m_add_menu (p, tr ("&File"));
1472 1507
1473 construct_new_menu (file_menu); 1508 construct_new_menu (file_menu);
1474 1509
1475 _open_action 1510 _open_action
1476 = file_menu->addAction (QIcon (":/actions/icons/folder_documents.png"), 1511 = file_menu->addAction (QIcon (":/actions/icons/folder_documents.png"),
1552 } 1587 }
1553 1588
1554 void 1589 void
1555 main_window::construct_edit_menu (QMenuBar *p) 1590 main_window::construct_edit_menu (QMenuBar *p)
1556 { 1591 {
1557 QMenu *edit_menu = p->addMenu (tr ("&Edit")); 1592 QMenu *edit_menu = m_add_menu (p, tr ("&Edit"));
1558 1593
1559 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; 1594 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier;
1560 1595
1561 _undo_action 1596 _undo_action
1562 = edit_menu->addAction (QIcon (":/actions/icons/undo.png"), tr ("Undo")); 1597 = edit_menu->addAction (QIcon (":/actions/icons/undo.png"), tr ("Undo"));
1627 } 1662 }
1628 1663
1629 void 1664 void
1630 main_window::construct_debug_menu (QMenuBar *p) 1665 main_window::construct_debug_menu (QMenuBar *p)
1631 { 1666 {
1632 _debug_menu = p->addMenu (tr ("De&bug")); 1667 _debug_menu = m_add_menu (p, tr ("De&bug"));
1633 1668
1634 _debug_step_over = construct_debug_menu_item 1669 _debug_step_over = construct_debug_menu_item
1635 (":/actions/icons/db_step.png", tr ("Step"), 1670 (":/actions/icons/db_step.png", tr ("Step"),
1636 SLOT (debug_step_over ())); 1671 SLOT (debug_step_over ()));
1637 1672
1689 } 1724 }
1690 1725
1691 void 1726 void
1692 main_window::construct_window_menu (QMenuBar *p) 1727 main_window::construct_window_menu (QMenuBar *p)
1693 { 1728 {
1694 QMenu *window_menu = p->addMenu (tr ("&Window")); 1729 QMenu *window_menu = m_add_menu (p, tr ("&Window"));
1695 1730
1696 _show_command_window_action = construct_window_menu_item 1731 _show_command_window_action = construct_window_menu_item
1697 (window_menu, tr ("Show Command Window"), true, command_window); 1732 (window_menu, tr ("Show Command Window"), true, command_window);
1698 1733
1699 _show_history_action = construct_window_menu_item 1734 _show_history_action = construct_window_menu_item
1738 } 1773 }
1739 1774
1740 void 1775 void
1741 main_window::construct_help_menu (QMenuBar *p) 1776 main_window::construct_help_menu (QMenuBar *p)
1742 { 1777 {
1743 QMenu *help_menu = p->addMenu (tr ("&Help")); 1778 QMenu *help_menu = m_add_menu (p, tr ("&Help"));
1744 1779
1745 construct_documentation_menu (help_menu); 1780 construct_documentation_menu (help_menu);
1746 1781
1747 help_menu->addSeparator (); 1782 help_menu->addSeparator ();
1748 1783
1780 } 1815 }
1781 1816
1782 void 1817 void
1783 main_window::construct_news_menu (QMenuBar *p) 1818 main_window::construct_news_menu (QMenuBar *p)
1784 { 1819 {
1785 QMenu *news_menu = p->addMenu (tr ("&News")); 1820 QMenu *news_menu = m_add_menu (p, tr ("&News"));
1786 1821
1787 _release_notes_action = add_action (news_menu, QIcon (), 1822 _release_notes_action = add_action (news_menu, QIcon (),
1788 tr ("Release Notes"), SLOT (display_release_notes ())); 1823 tr ("Release Notes"), SLOT (display_release_notes ()));
1789 1824
1790 _current_news_action = add_action (news_menu, QIcon (), 1825 _current_news_action = add_action (news_menu, QIcon (),
2214 main_window::set_global_edit_shortcuts (bool enable) 2249 main_window::set_global_edit_shortcuts (bool enable)
2215 { 2250 {
2216 // this slot is called when editor gets/loses focus 2251 // this slot is called when editor gets/loses focus
2217 if (enable) 2252 if (enable)
2218 { // editor loses focus, set the global shortcuts 2253 { // editor loses focus, set the global shortcuts
2254 // and disable the editor's menu
2219 shortcut_manager::set_shortcut (_copy_action, "main_edit:copy"); 2255 shortcut_manager::set_shortcut (_copy_action, "main_edit:copy");
2220 shortcut_manager::set_shortcut (_paste_action, "main_edit:paste"); 2256 shortcut_manager::set_shortcut (_paste_action, "main_edit:paste");
2221 shortcut_manager::set_shortcut (_undo_action, "main_edit:undo"); 2257 shortcut_manager::set_shortcut (_undo_action, "main_edit:undo");
2222 shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all"); 2258 shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all");
2223 } 2259 }
2224 else 2260 else
2225 { // disable shortcuts that are also provided by the editor itself 2261 { // disable shortcuts that are also provided by the editor itself
2262 // and enable editor's menu
2226 QKeySequence no_key = QKeySequence (); 2263 QKeySequence no_key = QKeySequence ();
2227 _copy_action->setShortcut (no_key); 2264 _copy_action->setShortcut (no_key);
2228 _paste_action->setShortcut (no_key); 2265 _paste_action->setShortcut (no_key);
2229 _undo_action->setShortcut (no_key); 2266 _undo_action->setShortcut (no_key);
2230 _select_all_action->setShortcut (no_key); 2267 _select_all_action->setShortcut (no_key);
2231 } 2268 }
2269
2270 // enable/disable the main and the editor's menu shortcuts (alt-key)
2271 editor_window->enable_menu_shortcuts (! enable);
2272 enable_menu_shortcuts (enable);
2232 } 2273 }
2233 2274
2234 void 2275 void
2235 main_window::configure_shortcuts () 2276 main_window::configure_shortcuts ()
2236 { 2277 {