Mercurial > octave
changeset 31618:cd833a9baaa7
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Dec 2022 15:51:44 -0500 |
parents | 1f57ea5dfd4a |
children | ad014fc78bd6 |
files | libgui/src/shortcut-manager.cc libgui/src/shortcut-manager.h |
diffstat | 2 files changed, 41 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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 ()); } }
--- 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