Changeset View
Changeset View
Standalone View
Standalone View
libs/widgetutils/xmlgui/kactioncollection.cpp
Show All 23 Lines | 1 | /* This file is part of the KDE libraries | |||
---|---|---|---|---|---|
24 | Boston, MA 02110-1301, USA. | 24 | Boston, MA 02110-1301, USA. | ||
25 | */ | 25 | */ | ||
26 | 26 | | |||
27 | #include "kactioncollection.h" | 27 | #include "kactioncollection.h" | ||
28 | #include "config-xmlgui.h" | 28 | #include "config-xmlgui.h" | ||
29 | #include "kactioncategory.h" | 29 | #include "kactioncategory.h" | ||
30 | #include "kxmlguiclient.h" | 30 | #include "kxmlguiclient.h" | ||
31 | #include "kxmlguifactory.h" | 31 | #include "kxmlguifactory.h" | ||
32 | #include "kactioncategory.h" | ||||
33 | #include "kis_action_registry.h" | ||||
32 | 34 | | |||
33 | #include <kauthorized.h> | 35 | #include <kauthorized.h> | ||
34 | #include <kconfiggroup.h> | 36 | #include <kconfiggroup.h> | ||
35 | #include <ksharedconfig.h> | 37 | #include <ksharedconfig.h> | ||
36 | 38 | | |||
37 | #include <QDebug> | 39 | #include <QDebug> | ||
38 | #include <QtXml/QDomDocument> | 40 | #include <QtXml/QDomDocument> | ||
39 | #include <QtCore/QSet> | 41 | #include <QtCore/QSet> | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | |||||
118 | 120 | | |||
119 | KActionCollection::~KActionCollection() | 121 | KActionCollection::~KActionCollection() | ||
120 | { | 122 | { | ||
121 | KActionCollectionPrivate::s_allCollections.removeAll(this); | 123 | KActionCollectionPrivate::s_allCollections.removeAll(this); | ||
122 | 124 | | |||
123 | delete d; | 125 | delete d; | ||
124 | } | 126 | } | ||
125 | 127 | | |||
128 | | ||||
129 | QList<KActionCategory *> KActionCollection::categories() const | ||||
130 | { | ||||
131 | return this->findChildren<KActionCategory *>(); | ||||
132 | } | ||||
133 | | ||||
134 | KActionCategory *KActionCollection::getCategory(const QString &name) { | ||||
135 | KActionCategory *category = 0; | ||||
136 | foreach (KActionCategory *c, categories()) { | ||||
137 | if (c->text() == name) { | ||||
138 | category = c; | ||||
139 | } | ||||
140 | } | ||||
141 | | ||||
142 | if (category == 0) { | ||||
143 | category = new KActionCategory(name, this); | ||||
144 | } | ||||
145 | return category; | ||||
146 | }; | ||||
147 | | ||||
148 | | ||||
126 | void KActionCollection::clear() | 149 | void KActionCollection::clear() | ||
127 | { | 150 | { | ||
128 | d->actionByName.clear(); | 151 | d->actionByName.clear(); | ||
129 | qDeleteAll(d->actions); | 152 | qDeleteAll(d->actions); | ||
130 | d->actions.clear(); | 153 | d->actions.clear(); | ||
131 | } | 154 | } | ||
132 | 155 | | |||
133 | QAction *KActionCollection::action(const QString &name) const | 156 | QAction *KActionCollection::action(const QString &name) const | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 244 | { | |||
222 | QSet<QActionGroup *> set; | 245 | QSet<QActionGroup *> set; | ||
223 | Q_FOREACH (QAction *action, d->actions) | 246 | Q_FOREACH (QAction *action, d->actions) | ||
224 | if (action->actionGroup()) { | 247 | if (action->actionGroup()) { | ||
225 | set.insert(action->actionGroup()); | 248 | set.insert(action->actionGroup()); | ||
226 | } | 249 | } | ||
227 | return set.toList(); | 250 | return set.toList(); | ||
228 | } | 251 | } | ||
229 | 252 | | |||
253 | QAction *KActionCollection::addCategorizedAction(const QString &name, QAction *action, const QString &categoryName) | ||||
254 | { | ||||
255 | return getCategory(categoryName)->addAction(name, action); | ||||
256 | } | ||||
257 | | ||||
230 | QAction *KActionCollection::addAction(const QString &name, QAction *action) | 258 | QAction *KActionCollection::addAction(const QString &name, QAction *action) | ||
231 | { | 259 | { | ||
232 | if (!action) { | 260 | if (!action) { | ||
233 | return action; | 261 | return action; | ||
234 | } | 262 | } | ||
235 | 263 | | |||
236 | const QString objectName = action->objectName(); | 264 | const QString objectName = action->objectName(); | ||
237 | QString indexName = name; | 265 | QString indexName = name; | ||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 433 | { | |||
406 | return d->configGroup; | 434 | return d->configGroup; | ||
407 | } | 435 | } | ||
408 | 436 | | |||
409 | void KActionCollection::setConfigGroup(const QString &group) | 437 | void KActionCollection::setConfigGroup(const QString &group) | ||
410 | { | 438 | { | ||
411 | d->configGroup = group; | 439 | d->configGroup = group; | ||
412 | } | 440 | } | ||
413 | 441 | | |||
442 | void KActionCollection::updateShortcuts() | ||||
443 | { | ||||
444 | auto actionRegistry = KisActionRegistry::instance(); | ||||
445 | | ||||
446 | for (QMap<QString, QAction *>::ConstIterator it = d->actionByName.constBegin(); | ||||
447 | it != d->actionByName.constEnd(); ++it) { | ||||
448 | actionRegistry->updateShortcut(it.key(), it.value()); | ||||
449 | } | ||||
450 | } | ||||
451 | | ||||
452 | | ||||
414 | void KActionCollection::readSettings(KConfigGroup *config) | 453 | void KActionCollection::readSettings(KConfigGroup *config) | ||
415 | { | 454 | { | ||
416 | KConfigGroup cg(KSharedConfig::openConfig(), configGroup()); | 455 | // TODO: perhaps get rid of this | ||
456 | KConfigGroup cg(KSharedConfig::openConfig("kritashortcutsrc"), configGroup()); | ||||
417 | if (!config) { | 457 | if (!config) { | ||
418 | config = &cg; | 458 | config = &cg; | ||
419 | } | 459 | } | ||
420 | 460 | | |||
421 | if (!config->exists()) { | 461 | if (!config->exists()) { | ||
422 | return; | 462 | return; | ||
423 | } | 463 | } | ||
424 | 464 | | |||
▲ Show 20 Lines • Show All 305 Lines • Show Last 20 Lines |