comparison libgui/src/m-editor/file-editor.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 095fdef3d67c
children
comparison
equal deleted inserted replaced
18923:58f1178f49ef 18944:b2c4d6d461f0
1086 a->setShortcutContext (Qt::WidgetWithChildrenShortcut); 1086 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
1087 return a; 1087 return a;
1088 } 1088 }
1089 1089
1090 void 1090 void
1091 file_editor::enable_menu_shortcuts (bool enable)
1092 {
1093 QHash<QMenu*, QStringList>::const_iterator i = _hash_menu_text.constBegin();
1094
1095 while (i != _hash_menu_text.constEnd())
1096 {
1097 i.key ()->setTitle (i.value ().at (! enable));
1098 ++i;
1099 }
1100 }
1101
1102 QMenu*
1103 file_editor::m_add_menu (QMenuBar *p, QString name)
1104 {
1105 QMenu *menu = p->addMenu (name);
1106
1107 QString base_name = name; // get a copy
1108 // replace intended '&' ("&&") by a temp. string
1109 base_name.replace ("&&","___octave_amp_replacement___");
1110 // remove single '&' (shortcut)
1111 base_name.remove ("&");
1112 // restore intended '&'
1113 base_name.replace ("___octave_amp_replacement___","&&");
1114
1115 // remember names with and without shortcut
1116 _hash_menu_text[menu] = QStringList () << name << base_name;
1117
1118 return menu;
1119 }
1120
1121 void
1091 file_editor::construct (void) 1122 file_editor::construct (void)
1092 { 1123 {
1093 QWidget *editor_widget = new QWidget (this); 1124 QWidget *editor_widget = new QWidget (this);
1094 1125
1095 // FIXME: what was the intended purpose of this unused variable? 1126 // FIXME: what was the intended purpose of this unused variable?
1118 1149
1119 // menu bar 1150 // menu bar
1120 1151
1121 // file menu 1152 // file menu
1122 1153
1123 _fileMenu = new QMenu (tr ("&File"), _menu_bar); 1154 _fileMenu = m_add_menu (_menu_bar, tr ("&File"));
1124 1155
1125 // new and open menus are inserted later by the main window 1156 // new and open menus are inserted later by the main window
1126 _mru_file_menu = new QMenu (tr ("&Recent Editor Files"), _fileMenu); 1157 _mru_file_menu = new QMenu (tr ("&Recent Editor Files"), _fileMenu);
1127 for (int i = 0; i < MaxMRUFiles; ++i) 1158 for (int i = 0; i < MaxMRUFiles; ++i)
1128 _mru_file_menu->addAction (_mru_file_actions[i]); 1159 _mru_file_menu->addAction (_mru_file_actions[i]);
1155 _fileMenu->addSeparator (); 1186 _fileMenu->addSeparator ();
1156 1187
1157 _print_action = add_action (_fileMenu, QIcon (":/actions/icons/fileprint.png"), 1188 _print_action = add_action (_fileMenu, QIcon (":/actions/icons/fileprint.png"),
1158 tr ("Print..."), SLOT (request_print_file (bool))); 1189 tr ("Print..."), SLOT (request_print_file (bool)));
1159 1190
1160 _menu_bar->addMenu (_fileMenu);
1161
1162 // edit menu 1191 // edit menu
1163 1192
1164 QMenu *editMenu = new QMenu (tr ("&Edit"), _menu_bar); 1193 QMenu *editMenu = m_add_menu (_menu_bar, tr ("&Edit"));
1165 1194
1166 _undo_action = add_action (editMenu, QIcon (":/actions/icons/undo.png"), 1195 _undo_action = add_action (editMenu, QIcon (":/actions/icons/undo.png"),
1167 tr ("&Undo"), SLOT (request_undo (bool))); 1196 tr ("&Undo"), SLOT (request_undo (bool)));
1168 _undo_action->setEnabled (false); 1197 _undo_action->setEnabled (false);
1169 _redo_action = add_action (editMenu, QIcon (":/actions/icons/redo.png"), 1198 _redo_action = add_action (editMenu, QIcon (":/actions/icons/redo.png"),
1263 tr ("&Preferences..."), SLOT (request_preferences (bool))); 1292 tr ("&Preferences..."), SLOT (request_preferences (bool)));
1264 _styles_preferences_action = add_action (editMenu, 1293 _styles_preferences_action = add_action (editMenu,
1265 QIcon (":/actions/icons/configure.png"), 1294 QIcon (":/actions/icons/configure.png"),
1266 tr ("&Styles Preferences..."), SLOT (request_styles_preferences (bool))); 1295 tr ("&Styles Preferences..."), SLOT (request_styles_preferences (bool)));
1267 1296
1268 _menu_bar->addMenu (editMenu);
1269
1270 // view menu 1297 // view menu
1271 1298
1272 QMenu *view_menu = new QMenu (tr ("&View"), _menu_bar); 1299 QMenu *view_menu = m_add_menu (_menu_bar, tr ("&View"));
1273 1300
1274 _zoom_in_action = add_action (view_menu, QIcon (), 1301 _zoom_in_action = add_action (view_menu, QIcon (),
1275 tr ("Zoom &In"), SLOT (zoom_in (bool))); 1302 tr ("Zoom &In"), SLOT (zoom_in (bool)));
1276 _zoom_out_action = add_action (view_menu, QIcon (), 1303 _zoom_out_action = add_action (view_menu, QIcon (),
1277 tr ("Zoom &Out"), SLOT (zoom_out (bool))); 1304 tr ("Zoom &Out"), SLOT (zoom_out (bool)));
1280 1307
1281 _menu_bar->addMenu (view_menu); 1308 _menu_bar->addMenu (view_menu);
1282 1309
1283 // debug menu 1310 // debug menu
1284 1311
1285 _debug_menu = new QMenu (tr ("&Debug"), _menu_bar); 1312 _debug_menu = m_add_menu (_menu_bar, tr ("&Debug"));
1286 1313
1287 _toggle_breakpoint_action = add_action (_debug_menu, 1314 _toggle_breakpoint_action = add_action (_debug_menu,
1288 QIcon (":/actions/icons/bp_toggle.png"), tr ("Toggle &Breakpoint"), 1315 QIcon (":/actions/icons/bp_toggle.png"), tr ("Toggle &Breakpoint"),
1289 SLOT (request_toggle_breakpoint (bool))); 1316 SLOT (request_toggle_breakpoint (bool)));
1290 _next_breakpoint_action = add_action (_debug_menu, 1317 _next_breakpoint_action = add_action (_debug_menu,
1299 1326
1300 _debug_menu->addSeparator (); 1327 _debug_menu->addSeparator ();
1301 1328
1302 // The other debug actions will be added by the main window. 1329 // The other debug actions will be added by the main window.
1303 1330
1304 _menu_bar->addMenu (_debug_menu);
1305
1306 // run menu 1331 // run menu
1307 1332
1308 QMenu *_run_menu = new QMenu (tr ("&Run"), _menu_bar); 1333 QMenu *_run_menu = m_add_menu (_menu_bar, tr ("&Run"));
1309 1334
1310 _run_action = add_action (_run_menu, QIcon (":/actions/icons/artsbuilderexecute.png"), 1335 _run_action = add_action (_run_menu, QIcon (":/actions/icons/artsbuilderexecute.png"),
1311 tr ("Save File and Run"), SLOT (request_run_file (bool))); 1336 tr ("Save File and Run"), SLOT (request_run_file (bool)));
1312 _run_selection_action = add_action (_run_menu, QIcon (), 1337 _run_selection_action = add_action (_run_menu, QIcon (),
1313 tr ("Run &Selection"), SLOT (request_context_run (bool))); 1338 tr ("Run &Selection"), SLOT (request_context_run (bool)));
1314 _run_selection_action->setEnabled (false); 1339 _run_selection_action->setEnabled (false);
1315 1340
1316 _menu_bar->addMenu (_run_menu);
1317
1318 // help menu 1341 // help menu
1319 1342
1320 QMenu *_help_menu = new QMenu (tr ("&Help"), _menu_bar); 1343 QMenu *_help_menu = m_add_menu (_menu_bar, tr ("&Help"));
1321 1344
1322 _context_help_action = add_action (_help_menu, QIcon (), 1345 _context_help_action = add_action (_help_menu, QIcon (),
1323 tr ("&Help on Keyword"), SLOT (request_context_help (bool))); 1346 tr ("&Help on Keyword"), SLOT (request_context_help (bool)));
1324 _context_doc_action = add_action (_help_menu, QIcon (), 1347 _context_doc_action = add_action (_help_menu, QIcon (),
1325 tr ("&Documentation on Keyword"), SLOT (request_context_doc (bool))); 1348 tr ("&Documentation on Keyword"), SLOT (request_context_doc (bool)));
1326
1327 _menu_bar->addMenu (_help_menu);
1328 1349
1329 // toolbar 1350 // toolbar
1330 1351
1331 // new and open actions are inserted later from main window 1352 // new and open actions are inserted later from main window
1332 _tool_bar->addAction (_save_action); 1353 _tool_bar->addAction (_save_action);