Mercurial > octave-libgccjit
comparison libgui/src/main-window.cc @ 18611:086093fbdc1a gui-release
first implementation of a shortcut manager (bug #41217)
* file-editor.cc (set_shortcuts): use shortcut-manager to set some shortcuts
* main_window.cc (set_global_shortcuts): use shortcut-manager to set some
shortcuts;
(construct_file_menu): all actions as class variables;
(construct_edit_menu): all actions as class variables;
* main_window.h: actions as class variables
* module.mk: new files shortcut_manager.cc, shortcut_manager.h
* octave-gui.cc (octave_start_gui): initialize the shortcut_manager
* settings-dialog.cc (constructor): call shortcut-manager for shortcut table
(write_changed_settings): call shortcut-manager for writing shortcuts
* settings-dialog.ui: new tab with a tree widget for the shortcuts
* shortcut_manager.cc (constructor, destructor): new class;
(instance_ok): checks if instance is valid, creates a new one otherwise;
(do_init_data): initialize the list with all shortcut's data;
(init): internal function for initializing the data list;
(do_fill_treewidget): fills the tree widget in the settings dialog;
(do_write_shortcuts): writes shortcuts from settings dialog into file;
(do_set_shortcut): setting the shortcut for an action;
(handle_double_clicked): slot for double clicking into the tree widget;
(shortcut_dialog): dialog for entering a new shortcut;
(shortcut_dialog_finished): processing the dialog's result;
(shortcut_dialog_set_default): setting the shortcut to it's default;
(enter_shortcut::enter_shortcut): new class derived from QLineEdit;
(enter_shortcut::handle_direct_shortcut): switch between normal editing and
directly entering a shortcut;
(enter_shortcut::keyPressEvent): event handler filtering the shortcuts;
* shortcut_manager.h (init_data): static function calling do_init_data;
(write_shortcuts): static function calling do_write_shortcuts;
(fill_treewidget): static function calling do_fill_treewidget;
(set_shortcut): static function calling do_set_shortcut;
author | Torsten <ttl@justmail.de> |
---|---|
date | Tue, 01 Apr 2014 21:29:48 +0200 |
parents | ebd063b7b1c6 |
children | 7cb98e81ecd1 |
comparison
equal
deleted
inserted
replaced
18610:6e81b59d657c | 18611:086093fbdc1a |
---|---|
49 #ifdef HAVE_QSCINTILLA | 49 #ifdef HAVE_QSCINTILLA |
50 #include "file-editor.h" | 50 #include "file-editor.h" |
51 #endif | 51 #endif |
52 #include "main-window.h" | 52 #include "main-window.h" |
53 #include "settings-dialog.h" | 53 #include "settings-dialog.h" |
54 #include "shortcut-manager.h" | |
54 | 55 |
55 #include "__init_qt__.h" | 56 #include "__init_qt__.h" |
56 | 57 |
57 #include "Array.h" | 58 #include "Array.h" |
58 #include "cmd-edit.h" | 59 #include "cmd-edit.h" |
678 _release_notes_icon = ":/actions/icons/logo.png"; | 679 _release_notes_icon = ":/actions/icons/logo.png"; |
679 | 680 |
680 int icon_size = settings->value ("toolbar_icon_size",16).toInt (); | 681 int icon_size = settings->value ("toolbar_icon_size",16).toInt (); |
681 _main_tool_bar->setIconSize (QSize (icon_size,icon_size)); | 682 _main_tool_bar->setIconSize (QSize (icon_size,icon_size)); |
682 | 683 |
684 set_global_shortcuts (true); | |
685 set_global_shortcuts (command_window_has_focus ()); | |
686 | |
683 resource_manager::update_network_settings (); | 687 resource_manager::update_network_settings (); |
684 } | 688 } |
685 | 689 |
686 | 690 |
687 void | 691 void |
1440 file_menu->addMenu (editor_window->get_mru_menu ()); | 1444 file_menu->addMenu (editor_window->get_mru_menu ()); |
1441 #endif | 1445 #endif |
1442 | 1446 |
1443 file_menu->addSeparator (); | 1447 file_menu->addSeparator (); |
1444 | 1448 |
1445 QAction *load_workspace_action | 1449 _load_workspace_action |
1446 = file_menu->addAction (tr ("Load Workspace...")); | 1450 = file_menu->addAction (tr ("Load Workspace...")); |
1447 | 1451 |
1448 QAction *save_workspace_action | 1452 _save_workspace_action |
1449 = file_menu->addAction (tr ("Save Workspace As...")); | 1453 = file_menu->addAction (tr ("Save Workspace As...")); |
1450 | 1454 |
1451 file_menu->addSeparator (); | 1455 file_menu->addSeparator (); |
1452 | 1456 |
1453 QAction *preferences_action | 1457 _preferences_action |
1454 = file_menu->addAction (QIcon (":/actions/icons/configure.png"), | 1458 = file_menu->addAction (QIcon (":/actions/icons/configure.png"), |
1455 tr ("Preferences...")); | 1459 tr ("Preferences...")); |
1456 | 1460 |
1457 file_menu->addSeparator (); | 1461 file_menu->addSeparator (); |
1458 | 1462 |
1459 _exit_action = file_menu->addAction (tr ("Exit")); | 1463 _exit_action = file_menu->addAction (tr ("Exit")); |
1460 _exit_action->setShortcutContext (Qt::ApplicationShortcut); | 1464 _exit_action->setShortcutContext (Qt::ApplicationShortcut); |
1461 | 1465 |
1462 connect (preferences_action, SIGNAL (triggered ()), | 1466 connect (_preferences_action, SIGNAL (triggered ()), |
1463 this, SLOT (process_settings_dialog_request ())); | 1467 this, SLOT (process_settings_dialog_request ())); |
1464 | 1468 |
1465 #ifdef HAVE_QSCINTILLA | 1469 #ifdef HAVE_QSCINTILLA |
1466 connect (_open_action, SIGNAL (triggered ()), | 1470 connect (_open_action, SIGNAL (triggered ()), |
1467 editor_window, SLOT (request_open_file ())); | 1471 editor_window, SLOT (request_open_file ())); |
1468 #endif | 1472 #endif |
1469 | 1473 |
1470 connect (load_workspace_action, SIGNAL (triggered ()), | 1474 connect (_load_workspace_action, SIGNAL (triggered ()), |
1471 this, SLOT (handle_load_workspace_request ())); | 1475 this, SLOT (handle_load_workspace_request ())); |
1472 | 1476 |
1473 connect (save_workspace_action, SIGNAL (triggered ()), | 1477 connect (_save_workspace_action, SIGNAL (triggered ()), |
1474 this, SLOT (handle_save_workspace_request ())); | 1478 this, SLOT (handle_save_workspace_request ())); |
1475 | 1479 |
1476 connect (_exit_action, SIGNAL (triggered ()), | 1480 connect (_exit_action, SIGNAL (triggered ()), |
1477 this, SLOT (close ())); | 1481 this, SLOT (close ())); |
1478 } | 1482 } |
1489 | 1493 |
1490 _new_function_action = new_menu->addAction (tr ("Function...")); | 1494 _new_function_action = new_menu->addAction (tr ("Function...")); |
1491 _new_function_action->setEnabled (true); | 1495 _new_function_action->setEnabled (true); |
1492 _new_function_action->setShortcutContext (Qt::ApplicationShortcut); | 1496 _new_function_action->setShortcutContext (Qt::ApplicationShortcut); |
1493 | 1497 |
1494 QAction *new_figure_action = new_menu->addAction (tr ("Figure")); | 1498 _new_figure_action = new_menu->addAction (tr ("Figure")); |
1495 new_figure_action->setEnabled (true); | 1499 _new_figure_action->setEnabled (true); |
1496 | 1500 |
1497 #ifdef HAVE_QSCINTILLA | 1501 #ifdef HAVE_QSCINTILLA |
1498 connect (_new_script_action, SIGNAL (triggered ()), | 1502 connect (_new_script_action, SIGNAL (triggered ()), |
1499 editor_window, SLOT (request_new_script ())); | 1503 editor_window, SLOT (request_new_script ())); |
1500 | 1504 |
1501 connect (_new_function_action, SIGNAL (triggered ()), | 1505 connect (_new_function_action, SIGNAL (triggered ()), |
1502 editor_window, SLOT (request_new_function ())); | 1506 editor_window, SLOT (request_new_function ())); |
1503 #endif | 1507 #endif |
1504 | 1508 |
1505 connect (new_figure_action, SIGNAL (triggered ()), | 1509 connect (_new_figure_action, SIGNAL (triggered ()), |
1506 this, SLOT (handle_new_figure_request ())); | 1510 this, SLOT (handle_new_figure_request ())); |
1507 } | 1511 } |
1508 | 1512 |
1509 void | 1513 void |
1510 main_window::construct_edit_menu (QMenuBar *p) | 1514 main_window::construct_edit_menu (QMenuBar *p) |
1513 | 1517 |
1514 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; | 1518 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; |
1515 | 1519 |
1516 _undo_action | 1520 _undo_action |
1517 = edit_menu->addAction (QIcon (":/actions/icons/undo.png"), tr ("Undo")); | 1521 = edit_menu->addAction (QIcon (":/actions/icons/undo.png"), tr ("Undo")); |
1518 _undo_action->setShortcut (QKeySequence::Undo); | |
1519 | 1522 |
1520 edit_menu->addSeparator (); | 1523 edit_menu->addSeparator (); |
1521 | 1524 |
1522 _copy_action | 1525 _copy_action |
1523 = edit_menu->addAction (QIcon (":/actions/icons/editcopy.png"), | 1526 = edit_menu->addAction (QIcon (":/actions/icons/editcopy.png"), |
1524 tr ("Copy"), this, SLOT (copyClipboard ())); | 1527 tr ("Copy"), this, SLOT (copyClipboard ())); |
1525 _copy_action->setShortcut (QKeySequence::Copy); | |
1526 | |
1527 | 1528 |
1528 _paste_action | 1529 _paste_action |
1529 = edit_menu->addAction (QIcon (":/actions/icons/editpaste.png"), | 1530 = edit_menu->addAction (QIcon (":/actions/icons/editpaste.png"), |
1530 tr ("Paste"), this, SLOT (pasteClipboard ())); | 1531 tr ("Paste"), this, SLOT (pasteClipboard ())); |
1531 _paste_action->setShortcut (QKeySequence::Paste); | 1532 |
1532 | 1533 _select_all_action |
1533 QAction * select_all_action | |
1534 = edit_menu->addAction (tr ("Select All"), this, SLOT (selectAll ())); | 1534 = edit_menu->addAction (tr ("Select All"), this, SLOT (selectAll ())); |
1535 | 1535 |
1536 _clear_clipboard_action | 1536 _clear_clipboard_action |
1537 = edit_menu->addAction (tr ("Clear Clipboard"), this, | 1537 = edit_menu->addAction (tr ("Clear Clipboard"), this, |
1538 SLOT (clear_clipboard ())); | 1538 SLOT (clear_clipboard ())); |
1541 | 1541 |
1542 _find_files_action = edit_menu->addAction (tr ("Find Files...")); | 1542 _find_files_action = edit_menu->addAction (tr ("Find Files...")); |
1543 | 1543 |
1544 edit_menu->addSeparator (); | 1544 edit_menu->addSeparator (); |
1545 | 1545 |
1546 QAction *clear_command_window_action | 1546 _clear_command_window_action |
1547 = edit_menu->addAction (tr ("Clear Command Window")); | 1547 = edit_menu->addAction (tr ("Clear Command Window")); |
1548 | 1548 |
1549 QAction *clear_command_history | 1549 _clear_command_history_action |
1550 = edit_menu->addAction (tr ("Clear Command History")); | 1550 = edit_menu->addAction (tr ("Clear Command History")); |
1551 | 1551 |
1552 QAction *clear_workspace_action | 1552 _clear_workspace_action |
1553 = edit_menu->addAction (tr ("Clear Workspace")); | 1553 = edit_menu->addAction (tr ("Clear Workspace")); |
1554 | 1554 |
1555 connect (_find_files_action, SIGNAL (triggered ()), | 1555 connect (_find_files_action, SIGNAL (triggered ()), |
1556 this, SLOT (find_files ())); | 1556 this, SLOT (find_files ())); |
1557 | 1557 |
1558 connect (clear_command_window_action, SIGNAL (triggered ()), | 1558 connect (_clear_command_window_action, SIGNAL (triggered ()), |
1559 this, SLOT (handle_clear_command_window_request ())); | 1559 this, SLOT (handle_clear_command_window_request ())); |
1560 | 1560 |
1561 connect (clear_command_history, SIGNAL (triggered ()), | 1561 connect (_clear_command_history_action, SIGNAL (triggered ()), |
1562 this, SLOT (handle_clear_history_request ())); | 1562 this, SLOT (handle_clear_history_request ())); |
1563 | 1563 |
1564 connect (clear_workspace_action, SIGNAL (triggered ()), | 1564 connect (_clear_workspace_action, SIGNAL (triggered ()), |
1565 this, SLOT (handle_clear_workspace_request ())); | 1565 this, SLOT (handle_clear_workspace_request ())); |
1566 | 1566 |
1567 connect (_clipboard, SIGNAL (changed (QClipboard::Mode)), | 1567 connect (_clipboard, SIGNAL (changed (QClipboard::Mode)), |
1568 this, SLOT (clipboard_has_changed (QClipboard::Mode))); | 1568 this, SLOT (clipboard_has_changed (QClipboard::Mode))); |
1569 clipboard_has_changed (QClipboard::Clipboard); | 1569 clipboard_has_changed (QClipboard::Clipboard); |
2280 main_window::set_global_shortcuts (bool set_shortcuts) | 2280 main_window::set_global_shortcuts (bool set_shortcuts) |
2281 { | 2281 { |
2282 if (set_shortcuts) | 2282 if (set_shortcuts) |
2283 { | 2283 { |
2284 | 2284 |
2285 _open_action->setShortcut (QKeySequence::Open); | 2285 // file menu |
2286 _new_script_action->setShortcut (QKeySequence::New); | 2286 shortcut_manager::set_shortcut (_open_action, "main_file:open_file"); |
2287 _new_function_action->setShortcut (Qt::ControlModifier | 2287 shortcut_manager::set_shortcut (_new_script_action, "main_file:new_file"); |
2288 + Qt::ShiftModifier | 2288 shortcut_manager::set_shortcut (_new_function_action, "main_file:new_function"); |
2289 + Qt::Key_N); | 2289 shortcut_manager::set_shortcut (_new_function_action, "main_file:new_figure"); |
2290 | 2290 shortcut_manager::set_shortcut (_load_workspace_action, "main_file:load_workspace"); |
2291 _exit_action->setShortcut (QKeySequence::Quit); | 2291 shortcut_manager::set_shortcut (_save_workspace_action, "main_file:save_workspace"); |
2292 | 2292 shortcut_manager::set_shortcut (_preferences_action, "main_file:preferences"); |
2293 _find_files_action->setShortcut (Qt::ControlModifier | 2293 shortcut_manager::set_shortcut (_exit_action,"main_file:exit"); |
2294 + Qt::ShiftModifier | 2294 |
2295 + Qt::Key_F); | 2295 // edit menu |
2296 shortcut_manager::set_shortcut (_copy_action, "main_edit:copy"); | |
2297 shortcut_manager::set_shortcut (_paste_action, "main_edit:paste"); | |
2298 shortcut_manager::set_shortcut (_undo_action, "main_edit:undo"); | |
2299 shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all"); | |
2300 shortcut_manager::set_shortcut (_clear_clipboard_action, "main_edit:clear_clipboard"); | |
2301 shortcut_manager::set_shortcut (_find_files_action, "main_edit:find_in_files"); | |
2302 shortcut_manager::set_shortcut (_clear_command_history_action, "main_edit:clear_history"); | |
2303 shortcut_manager::set_shortcut (_clear_command_window_action, "main_edit:clear_command_window"); | |
2304 shortcut_manager::set_shortcut (_clear_workspace_action, "main_edit:clear_workspace"); | |
2296 | 2305 |
2297 } | 2306 } |
2298 else | 2307 else |
2299 { | 2308 { |
2300 | 2309 |
2301 QKeySequence no_key = QKeySequence (); | 2310 QKeySequence no_key = QKeySequence (); |
2302 | 2311 |
2312 // file menu | |
2303 _open_action->setShortcut (no_key); | 2313 _open_action->setShortcut (no_key); |
2304 _new_script_action->setShortcut (no_key); | 2314 _new_script_action->setShortcut (no_key); |
2305 _new_function_action->setShortcut (no_key); | 2315 _new_function_action->setShortcut (no_key); |
2306 | 2316 _new_function_action->setShortcut (no_key); |
2317 _load_workspace_action->setShortcut (no_key); | |
2318 _save_workspace_action->setShortcut (no_key); | |
2319 _preferences_action->setShortcut (no_key); | |
2307 _exit_action->setShortcut (no_key); | 2320 _exit_action->setShortcut (no_key); |
2308 | 2321 |
2322 // edit menu | |
2323 //_copy_action->setShortcut (no_key); | |
2324 //_paste_action->setShortcut (no_key); | |
2325 //_undo_action->setShortcut (no_key); | |
2326 _select_all_action->setShortcut (no_key); | |
2327 _clear_clipboard_action->setShortcut (no_key); | |
2309 _find_files_action->setShortcut (no_key); | 2328 _find_files_action->setShortcut (no_key); |
2329 _clear_command_history_action->setShortcut (no_key); | |
2330 _clear_command_window_action->setShortcut (no_key); | |
2331 _clear_workspace_action->setShortcut (no_key); | |
2310 | 2332 |
2311 } | 2333 } |
2312 | 2334 |
2313 emit set_widget_shortcuts_signal (set_shortcuts); | 2335 emit set_widget_shortcuts_signal (set_shortcuts); |
2314 } | 2336 } |