# HG changeset patch # User John W. Eaton # Date 1670014304 18000 # Node ID cd833a9baaa7da38eab9c7aaa1ece241f9fe774c # Parent 1f57ea5dfd4a1e7c13899b44f1aff77e820f5cf7 use separate functions for importing and resetting default shortcuts * shortcut-manager.h, shortcut-manager.cc (shortcut_manager::import_shortcuts): Don't reset defaults if settings is nullptr. Handle that case in a separate function. (shortcut_manager::reset_default_shortcuts): New function, adapted from previous import_shortcuts function. diff -r 1f57ea5dfd4a -r cd833a9baaa7 libgui/src/shortcut-manager.cc --- a/libgui/src/shortcut-manager.cc Fri Dec 02 10:36:13 2022 -0500 +++ b/libgui/src/shortcut-manager.cc Fri Dec 02 15:51:44 2022 -0500 @@ -560,9 +560,7 @@ } } else - { - import_shortcuts (nullptr); - } + reset_default_shortcuts (); return true; } @@ -745,27 +743,54 @@ m_dialog->exec (); } - // import a shortcut set from a given settings file or reset to - // the defaults (settings = 0) and refresh the tree view + // import a shortcut set from a given settings file and refresh the + // tree view void shortcut_manager::import_shortcuts (gui_settings *settings) { for (int i = 0; i < m_sc.count (); i++) { // update the list of all shortcuts - shortcut_t sc = m_sc.at (i); // make a copy + + // make a copy + shortcut_t sc = m_sc.at (i); - if (settings) - sc.m_actual_sc = QKeySequence ( // get new shortcut from settings - settings->value (sc_group + sc.m_settings_key,sc.m_actual_sc). - toString ()); // and use the old one as default - else - sc.m_actual_sc = QKeySequence (sc.m_default_sc); // get default shortcut + // get new shortcut from settings and use the old one as default + sc.m_actual_sc = QKeySequence (settings->value (sc_group + sc.m_settings_key,sc.m_actual_sc).toString ()); - m_sc.replace (i, sc); // replace the old with the new one + // replace the old with the new one + m_sc.replace (i, sc); // update the tree view - QTreeWidgetItem *tree_item = m_index_item_hash[i]; // get related tree item - tree_item->setText (2, sc.m_actual_sc.toString ()); // display new shortcut + // get related tree item + QTreeWidgetItem *tree_item = m_index_item_hash[i]; + + // display new shortcut + tree_item->setText (2, sc.m_actual_sc.toString ()); + } + } + + // reset to the defaults and refresh the tree view + void shortcut_manager::reset_default_shortcuts (void) + { + for (int i = 0; i < m_sc.count (); i++) + { + // update the list of all shortcuts + + // make a copy + shortcut_t sc = m_sc.at (i); + + // get default shortcut + sc.m_actual_sc = QKeySequence (sc.m_default_sc); + + // replace the old with the new one + m_sc.replace (i, sc); + + // update the tree view + // get related tree item + QTreeWidgetItem *tree_item = m_index_item_hash[i]; + + // display new shortcut + tree_item->setText (2, sc.m_actual_sc.toString ()); } } diff -r 1f57ea5dfd4a -r cd833a9baaa7 libgui/src/shortcut-manager.h --- a/libgui/src/shortcut-manager.h Fri Dec 02 10:36:13 2022 -0500 +++ b/libgui/src/shortcut-manager.h Fri Dec 02 15:51:44 2022 -0500 @@ -109,6 +109,7 @@ void init (const QString&, const sc_pref& scpref); void shortcut_dialog (int); void import_shortcuts (gui_settings *settings); + void reset_default_shortcuts (void); bool overwrite_all_shortcuts (void); class shortcut_t