# HG changeset patch # User Torsten # Date 1396645148 -7200 # Node ID a827fc5fe59d2e33aca57f38b1db90260b76ee26 # Parent f1b91e3137b99058eaf409249db2d9097adf6a8e handle actions from the editors file and edit menu via the shortcut manager * file-editor.cc (set_shortcuts): set shortcuts via shortcut manager * shortcut-manager.cc (do_init_data): initialization of new shortcuts (init): code optimization and index check diff -r f1b91e3137b9 -r a827fc5fe59d libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Fri Apr 04 11:40:20 2014 -0400 +++ b/libgui/src/m-editor/file-editor.cc Fri Apr 04 22:59:08 2014 +0200 @@ -1555,23 +1555,37 @@ if (set) { + // File menu + shortcut_manager::set_shortcut (_context_edit_action, "editor_file:edit_function"); shortcut_manager::set_shortcut (_save_action, "editor_file:save"); shortcut_manager::set_shortcut (_save_as_action, "editor_file:save_as"); - - _comment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_R); - _uncomment_selection_action->setShortcut (Qt::SHIFT - + Qt::ControlModifier - + Qt::Key_R); + shortcut_manager::set_shortcut (_close_action, "editor_file:close"); + shortcut_manager::set_shortcut (_close_all_action, "editor_file:close_all"); + shortcut_manager::set_shortcut (_close_others_action, "editor_file:close_other"); + shortcut_manager::set_shortcut (_print_action, "editor_file:print"); - _indent_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_Tab); - _unindent_selection_action->setShortcut (Qt::SHIFT - + Qt::ControlModifier - + Qt::Key_Tab); + // Edit menu + shortcut_manager::set_shortcut (_undo_action, "editor_edit:undo"); + shortcut_manager::set_shortcut (_redo_action, "editor_edit:redo"); + shortcut_manager::set_shortcut (_copy_action, "editor_edit:copy"); + shortcut_manager::set_shortcut (_cut_action, "editor_edit:cut"); + shortcut_manager::set_shortcut (_paste_action, "editor_edit:paste"); + shortcut_manager::set_shortcut (_selectall_action, "editor_edit:select_all"); + shortcut_manager::set_shortcut (_find_action, "editor_edit:find_replace"); + shortcut_manager::set_shortcut (_comment_selection_action, "editor_edit:comment_selection"); + shortcut_manager::set_shortcut (_uncomment_selection_action, "editor_edit:uncomment_selection"); + shortcut_manager::set_shortcut (_indent_selection_action, "editor_edit:indent_selection"); + shortcut_manager::set_shortcut (_unindent_selection_action, "editor_edit:unindent_selection"); + shortcut_manager::set_shortcut (_completion_action, "editor_edit:completion_list"); + shortcut_manager::set_shortcut (_toggle_bookmark_action, "editor_edit:toggle_bookmark"); + shortcut_manager::set_shortcut (_next_bookmark_action, "editor_edit:next_bookmark"); + shortcut_manager::set_shortcut (_previous_bookmark_action, "editor_edit:previous_bookmark"); + shortcut_manager::set_shortcut (_remove_bookmark_action, "editor_edit:remove_bookmark"); + shortcut_manager::set_shortcut (_goto_line_action, "editor_edit:goto_line"); + shortcut_manager::set_shortcut (_preferences_action, "editor_edit:preferences"); + shortcut_manager::set_shortcut (_styles_preferences_action, "editor_edit:styles_preferences"); - _copy_action->setShortcut (QKeySequence::Copy); - _cut_action->setShortcut (QKeySequence::Cut); - _paste_action->setShortcut (QKeySequence::Paste); - _selectall_action->setShortcut (QKeySequence::SelectAll); + _context_help_action->setShortcut (QKeySequence::HelpContents); _context_doc_action->setShortcut (Qt::SHIFT + Qt::Key_F1); @@ -1579,64 +1593,60 @@ _zoom_out_action->setShortcuts (QKeySequence::ZoomOut); _zoom_normal_action->setShortcut (Qt::ControlModifier + Qt::Key_Slash); - _find_action->setShortcut (QKeySequence::Find); - _goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); - _completion_action->setShortcut (Qt::ControlModifier + Qt::Key_Space); - _next_bookmark_action->setShortcut (Qt::Key_F2); - _previous_bookmark_action->setShortcut (Qt::SHIFT + Qt::Key_F2); - _toggle_bookmark_action->setShortcut (Qt::Key_F7); - _print_action->setShortcut (QKeySequence::Print); _run_action->setShortcut (Qt::Key_F5); _context_run_action->setShortcut (Qt::Key_F9); - _context_edit_action->setShortcut (Qt::ControlModifier + Qt::Key_E); - _close_action->setShortcut (QKeySequence::Close); - _redo_action->setShortcut (QKeySequence::Redo); - _undo_action->setShortcut (QKeySequence::Undo); } else { QKeySequence no_key = QKeySequence (); - _comment_selection_action->setShortcut (no_key); - _uncomment_selection_action->setShortcut (no_key); + // File menu + _context_edit_action->setShortcut (no_key); + _save_action->setShortcut (no_key); + _save_as_action->setShortcut (no_key); + _close_action->setShortcut (no_key); + _close_all_action->setShortcut (no_key); + _close_others_action->setShortcut (no_key); + _print_action->setShortcut (no_key); - _indent_selection_action->setShortcut (no_key); - _unindent_selection_action->setShortcut (no_key); - + // Edit menu + _redo_action->setShortcut (no_key); + _undo_action->setShortcut (no_key); _copy_action->setShortcut (no_key); _cut_action->setShortcut (no_key); _paste_action->setShortcut (no_key); _selectall_action->setShortcut (no_key); + _find_action->setShortcut (no_key); + _comment_selection_action->setShortcut (no_key); + _uncomment_selection_action->setShortcut (no_key); + _indent_selection_action->setShortcut (no_key); + _unindent_selection_action->setShortcut (no_key); + _completion_action->setShortcut (no_key); + _toggle_bookmark_action->setShortcut (no_key); + _next_bookmark_action->setShortcut (no_key); + _previous_bookmark_action->setShortcut (no_key); + _remove_bookmark_action->setShortcut (no_key); + _goto_line_action->setShortcut (no_key); + _preferences_action->setShortcut (no_key); + _styles_preferences_action->setShortcut (no_key); + + _context_help_action->setShortcut (no_key); _zoom_in_action->setShortcut (no_key); _zoom_out_action->setShortcut (no_key); _zoom_normal_action->setShortcut (no_key); - _find_action->setShortcut (no_key); - _goto_line_action->setShortcut (no_key); - _completion_action->setShortcut (no_key); - _next_bookmark_action->setShortcut (no_key); - _previous_bookmark_action->setShortcut (no_key); - _toggle_bookmark_action->setShortcut (no_key); - _print_action->setShortcut (no_key); _run_action->setShortcut (no_key); _context_run_action->setShortcut (no_key); - _context_edit_action->setShortcut (no_key); - _save_action->setShortcut (no_key); - _save_as_action->setShortcut (no_key); - _close_action->setShortcut (no_key); - - _redo_action->setShortcut (no_key); - _undo_action->setShortcut (no_key); } } diff -r f1b91e3137b9 -r a827fc5fe59d libgui/src/shortcut-manager.cc --- a/libgui/src/shortcut-manager.cc Fri Apr 04 11:40:20 2014 -0400 +++ b/libgui/src/shortcut-manager.cc Fri Apr 04 22:59:08 2014 +0200 @@ -98,8 +98,34 @@ init (tr ("Clear Workspace"), "main_edit:clear_workspace", QKeySequence () ); // actions of the editor + init (tr ("Edit Function"), "editor_file:edit_function", QKeySequence (Qt::ControlModifier + Qt::Key_E) ); init (tr ("Save File"), "editor_file:save", QKeySequence::Save ); init (tr ("Save File As"), "editor_file:save_as", QKeySequence::SaveAs ); + init (tr ("Close"), "editor_file:close", QKeySequence::Close ); + init (tr ("Close All"), "editor_file:close_all", QKeySequence () ); + init (tr ("Close Other"), "editor_file:close_other", QKeySequence () ); + init (tr ("Print"), "editor_file:print", QKeySequence::Print ); + + init (tr ("Undo"), "editor_edit:undo", QKeySequence::Undo ); + init (tr ("Redo"), "editor_edit:redo", QKeySequence::Redo ); + init (tr ("Copy"), "editor_edit:copy", QKeySequence::Copy ); + init (tr ("Cuy"), "editor_edit:cut", QKeySequence::Cut ); + init (tr ("Paste"), "editor_edit:paste", QKeySequence::Paste ); + init (tr ("Select All"), "editor_edit:select_all", QKeySequence::SelectAll ); + init (tr ("Find and Replace"), "editor_edit:find_replace", QKeySequence::Find ); + init (tr ("Comment Selection"), "editor_edit:comment_selection", QKeySequence (Qt::ControlModifier + Qt::Key_R) ); + init (tr ("Uncomment Selection"), "editor_edit:uncomment_selection", QKeySequence (Qt::SHIFT + Qt::ControlModifier + Qt::Key_R) ); + init (tr ("Indent Selection"), "editor_edit:indent_selection", QKeySequence (Qt::ControlModifier + Qt::Key_Tab) ); + init (tr ("Unindent Selection"), "editor_edit:unindent_selection", QKeySequence (Qt::SHIFT + Qt::ControlModifier + Qt::Key_Tab) ); + init (tr ("Completion List"), "editor_edit:completion_list", QKeySequence (Qt::ControlModifier + Qt::Key_Space) ); + init (tr ("Toggle Bookmark"), "editor_edit:toggle_bookmark", QKeySequence (Qt::Key_F7) ); + init (tr ("Next Bookmark"), "editor_edit:next_bookmark", QKeySequence (Qt::Key_F2) ); + init (tr ("Previous Bookmark"), "editor_edit:previous_bookmark", QKeySequence (Qt::SHIFT + Qt::Key_F2) ); + init (tr ("Remove All Bookmark"), "editor_edit:remove_bookmark", QKeySequence () ); + init (tr ("Goto Line"), "editor_edit:goto_line", QKeySequence (Qt::ControlModifier+ Qt::Key_G) ); + init (tr ("Preferences"), "editor_edit:preferences", QKeySequence () ); + init (tr ("Styles Preferences"), "editor_edit:styles_preferences", QKeySequence () ); + } void @@ -107,9 +133,7 @@ { QSettings *settings = resource_manager::get_settings (); - settings->beginGroup ("shortcuts"); - QKeySequence actual = QKeySequence (settings->value (key, def_sc).toString ()); - settings->endGroup (); + QKeySequence actual = QKeySequence (settings->value ("shortcuts/"+key, def_sc).toString ()); shortcut_t shortcut_info; shortcut_info.description = description; @@ -217,9 +241,11 @@ QSettings *settings = resource_manager::get_settings (); int index = _action_hash[key] - 1; - - action->setShortcut ( - settings->value ("shortcuts/" + key, _sc.at (index).default_sc).toString ()); + if (index > -1 && index < _sc.count ()) + action->setShortcut ( + settings->value ("shortcuts/" + key, _sc.at (index).default_sc).toString ()); + else + qDebug () << "Key: " << key << " not found in _action_hash"; } void