commit 6eae97b25ac30ac57ec74dc5cc40d79401ac7650 Author: Simon Persson <simonpersson1@gmail.com> Date: Thu Apr 14 00:19:11 2011 +0200 Allow all standard shortcuts to be edited, not only those used by a standard action. BUG: 193520 CCMAIL: kde@michael-jansen.biz DIGEST: Index: kcontrol/standard_actions/standard_actions_module.cpp =================================================================== --- a/kcontrol/standard_actions/standard_actions_module.cpp +++ b/kcontrol/standard_actions/standard_actions_module.cpp 2011-05-04 20:04:41.108417916 -0300 @@ -29,11 +29,33 @@ #include <KLocale> #include <QVBoxLayout> +#include <QSet> K_PLUGIN_FACTORY(StandardActionsModuleFactory, registerPlugin<StandardActionsModule>();) K_EXPORT_PLUGIN(StandardActionsModuleFactory("kcm_standard_actions")) - +static void dressUpAction(KAction *action, KStandardShortcut::StandardShortcut shortcutId) + { + // Remember the shortcutId so we know where to save changes. + action->setData(shortcutId); + // We have to manually adjust the action. We want to show the + // hardcoded default and the user set shortcut. But action currently + // only contain the active shortcuts as default shortcut. So we + // have to fill it correctly + KShortcut hardcoded = KStandardShortcut::hardcodedDefaultShortcut(shortcutId); + KShortcut active = KStandardShortcut::shortcut(shortcutId); + // Set the hardcoded default shortcut as default shortcut + action->setShortcut(hardcoded, KAction::DefaultShortcut); + // Set the user defined values as active shortcuts. If the user only + // has overwritten the primary shortcut make sure the alternate one + // still get's shown + if (active.alternate()==QKeySequence()) + { + active.setAlternate(hardcoded.alternate()); + } + action->setShortcut(active, KAction::ActiveShortcut); + } + StandardActionsModule::StandardActionsModule( QWidget *parent, const QVariantList &args ) @@ -78,7 +100,10 @@ this, StandardActionsModuleFactory::componentData()); - // Put all standard shortcuts into the collection + // Keeps track of which shortcut IDs have been added + QSet<int> shortcutIdsAdded; + + // Put all shortcuts for standard actions into the collection Q_FOREACH(KStandardAction::StandardAction id, KStandardAction::actionIds()) { KStandardShortcut::StandardShortcut shortcutId = KStandardAction::shortcutForActionId(id); @@ -90,24 +115,21 @@ } // Create the action KAction *action = KStandardAction::create(id, NULL, NULL, m_actionCollection); - // Remember the shortcutId so we know where to save changes. - action->setData(shortcutId); - // We have to manually adjust the action. We want to show the - // hardcoded default and the user set shortcut. But action currently - // only contain the active shortcuts as default shortcut. So we - // have to fill it correctly - KShortcut hardcoded = KStandardShortcut::hardcodedDefaultShortcut(shortcutId); - KShortcut active = KStandardShortcut::shortcut(shortcutId); - // Set the hardcoded default shortcut as default shortcut - action->setShortcut(hardcoded, KAction::DefaultShortcut); - // Set the user defined values as active shortcuts. If the user only - // has overwritten the primary shortcut make sure the alternate one - // still get's shown - if (active.alternate()==QKeySequence()) + dressUpAction(action, shortcutId); + shortcutIdsAdded << shortcutId; + } + + // Put in the remaining standard shortcuts too... + for(int i = int(KStandardShortcut::AccelNone) + 1; i < KStandardShortcut::StandardShortcutCount; ++i) + { + KStandardShortcut::StandardShortcut shortcutId = static_cast<KStandardShortcut::StandardShortcut>(i); + if(!shortcutIdsAdded.contains(shortcutId)) { - active.setAlternate(hardcoded.alternate()); + KAction *action = new KAction(KStandardShortcut::label(shortcutId), this); + action->setWhatsThis(KStandardShortcut::whatsThis(shortcutId)); + dressUpAction(action, shortcutId); + m_actionCollection->addAction(KStandardShortcut::name(shortcutId), action); } - action->setShortcut(active, KAction::ActiveShortcut); } // Hand the collection to the editor