From kde-commits Fri Jan 04 00:03:09 2008 From: Andreas Hartmetz Date: Fri, 04 Jan 2008 00:03:09 +0000 To: kde-commits Subject: KDE/kdelibs/kdeui Message-Id: <1199404989.139809.21893.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=119940499808899 SVN commit 757034 by ahartmetz: As discussed on k-c-d, only use the text() of an action as a fallback identifier in the context of global shortcuts when the more robust objectName() is empty. M +11 -1 actions/kaction.h M +16 -8 shortcuts/kglobalaccel.cpp --- trunk/KDE/kdelibs/kdeui/actions/kaction.h #757033:757034 @@ -341,7 +341,7 @@ * Unlike regular shortcuts, the application's window does not need focus * for them to be activated. * - * When an action, identified by main component name and text(), is assigned + * When an action is assigned * a global shortcut for the first time on a KDE installation the assignment will * be saved. The shortcut will then be restored every time the action's * globalShortcutAllowed flag becomes true. @@ -353,6 +353,16 @@ * setGlobalShortcut(KShortcut(), KAction::ActiveShortcut | KAction::DefaultShortcut, * KAction::NoAutoloading) * \endcode + * Note that actions will be recognized by their objectName() internally. + * In case of an empty objectName() text() will be used as a fallback. + * This fallback should be avoided if possible because it breaks + * when the application language is changed. + * Inserting an action into a KActionCollection with + * QAction *KActionCollection::addAction(const QString &name, QAction *action) or + * KAction *KActionCollection::addAction(const QString &name, KAction *action) + * will set the objectName() to @p name so you don't have to explicitly set an + * objectName after you have already done that. + * \param shortcut global shortcut(s) to assign * \param type the type of shortcut to be set, whether the active shortcut, the default shortcut, * or both (the default). --- trunk/KDE/kdelibs/kdeui/shortcuts/kglobalaccel.cpp #757033:757034 @@ -144,11 +144,15 @@ if (oldEnabled == newEnabled) return; - if (action->text().isEmpty()) - return; + QString actionName(action->objectName()); + if (actionName.isEmpty()) { + if (action->text().isEmpty()) { + return; + } + actionName = action->text(); //### breaks badly on change of language + } QStringList actionId(mainComponentName); - actionId.append(action->text()); - //TODO: what about i18ned names? + actionId.append(actionName); if (!oldEnabled && newEnabled) { uint setterFlags = KdedGlobalAccel::SetPresent; @@ -180,11 +184,15 @@ if (!action) return; - if (action->text().isEmpty()) - return; + QString actionName(action->objectName()); + if (actionName.isEmpty()) { + if (action->text().isEmpty()) { + return; + } + actionName = action->text(); //### breaks badly on change of language + } QStringList actionId(mainComponentName); - actionId.append(action->text()); - //TODO: what about i18ned names? + actionId.append(actionName); uint setterFlags = 0; if (flags & KAction::NoAutoloading)