diff --git a/libs/widgetutils/kis_action_registry.cpp b/libs/widgetutils/kis_action_registry.cpp index 7d0686e1bb..25846c8651 100644 --- a/libs/widgetutils/kis_action_registry.cpp +++ b/libs/widgetutils/kis_action_registry.cpp @@ -1,485 +1,484 @@ /* * Copyright (c) 2015 Michael Abrahams * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include "kis_debug.h" #include "KoResourcePaths.h" #include "kis_icon_utils.h" #include "kactioncollection.h" #include "kactioncategory.h" #include "kis_action_registry.h" #include "kshortcutschemeshelper_p.h" namespace { /** * We associate several pieces of information with each shortcut. The first * piece of information is a QDomElement, containing the raw data from the * .action XML file. The second and third are QKeySequences, the first of * which is the default shortcut, the last of which is any custom shortcut. * The last two are the KActionCollection and KActionCategory used to * organize the shortcut editor. */ struct ActionInfoItem { QDomElement xmlData; QList defaultShortcuts; QList customShortcuts; QString collectionName; QString categoryName; }; // Convenience macros to extract text of a child node. QString getChildContent(QDomElement xml, QString node) { return xml.firstChildElement(node).text(); }; ActionInfoItem emptyActionInfo; // Used as default return value // Use Krita debug logging categories instead of KDE's default qDebug() for // harmless empty strings and translations QString quietlyTranslate(const QString &s) { if (s.isEmpty()) { return s; } QString translatedString = i18nc("action", s.toUtf8()); if (translatedString == s) { translatedString = i18n(s.toUtf8()); } if (translatedString.isEmpty()) { dbgAction << "No translation found for" << s; return s; } return translatedString; }; QList preferredShortcuts(ActionInfoItem action) { if (action.customShortcuts.isEmpty()) { return action.defaultShortcuts; } else { return action.customShortcuts; } }; }; class Q_DECL_HIDDEN KisActionRegistry::Private { public: Private(KisActionRegistry *_q) : q(_q) {}; // This is the main place containing ActionInfoItems. QMap actionInfoList; void loadActionFiles(); void loadActionCollections(); void loadCustomShortcuts(QString filename = QStringLiteral("kritashortcutsrc")); ActionInfoItem &actionInfo(const QString &name) { if (!actionInfoList.contains(name)) { dbgAction << "Tried to look up info for unknown action" << name; } return actionInfoList[name]; }; KisActionRegistry *q; KActionCollection * defaultActionCollection; QMap actionCollections; }; Q_GLOBAL_STATIC(KisActionRegistry, s_instance); KisActionRegistry *KisActionRegistry::instance() { return s_instance; }; KisActionRegistry::KisActionRegistry() : d(new KisActionRegistry::Private(this)) { d->loadActionFiles(); KConfigGroup cg = KSharedConfig::openConfig()->group("Shortcut Schemes"); QString schemeName = cg.readEntry("Current Scheme", "Default"); loadShortcutScheme(schemeName); loadCustomShortcuts(); } QList KisActionRegistry::getCustomShortcut(const QString &name) { return d->actionInfo(name).customShortcuts; }; QList KisActionRegistry::getPreferredShortcut(const QString &name) { return preferredShortcuts(d->actionInfo(name)); }; QString KisActionRegistry::getCategory(const QString &name) { return d->actionInfo(name).categoryName; }; QStringList KisActionRegistry::allActions() { return d->actionInfoList.keys(); }; KActionCollection * KisActionRegistry::getDefaultCollection() { return d->actionCollections.value("Krita"); }; void KisActionRegistry::addAction(const QString &name, QAction *a) { auto info = d->actionInfo(name); KActionCollection *collection = d->actionCollections.value(info.collectionName); if (!collection) { dbgAction << "No collection found for action" << name; return; } if (collection->action(name)) { dbgAction << "duplicate action" << name << "in collection" << collection->componentName(); } else { } collection->addCategorizedAction(name, a, info.categoryName); }; void KisActionRegistry::notifySettingsUpdated() { d->loadCustomShortcuts(); }; void KisActionRegistry::loadCustomShortcuts(const QString &path) { if (path.isEmpty()) { d->loadCustomShortcuts(); } else { d->loadCustomShortcuts(path); } }; void KisActionRegistry::loadShortcutScheme(const QString &schemeName) { // Load scheme file if (schemeName != QStringLiteral("Default")) { QString schemeFileName = KShortcutSchemesHelper::schemeFileLocations().value(schemeName); if (schemeFileName.isEmpty()) { // qDebug() << "No configuration file found for scheme" << schemeName; return; } KConfig schemeConfig(schemeFileName, KConfig::SimpleConfig); applyShortcutScheme(&schemeConfig); } else { // Apply default scheme, updating KisActionRegistry data applyShortcutScheme(); } } QAction * KisActionRegistry::makeQAction(const QString &name, QObject *parent) { QAction * a = new QAction(parent); if (!d->actionInfoList.contains(name)) { dbgAction << "Warning: requested data for unknown action" << name; return a; } propertizeAction(name, a); return a; }; void KisActionRegistry::setupDialog(KisShortcutsDialog *dlg) { for (auto i = d->actionCollections.constBegin(); i != d->actionCollections.constEnd(); i++ ) { dlg->addCollection(i.value(), i.key()); } } void KisActionRegistry::settingsPageSaved() { // For now, custom shortcuts are dealt with by writing to file and reloading. loadCustomShortcuts(); // Announce UI should reload current shortcuts. emit shortcutsUpdated(); } void KisActionRegistry::applyShortcutScheme(const KConfigBase *config) { // First, update the things in KisActionRegistry if (config == 0) { // Use default shortcut scheme. Simplest just to reload everything. d->actionInfoList.clear(); d->loadActionFiles(); loadCustomShortcuts(); } else { const auto schemeEntries = config->group(QStringLiteral("Shortcuts")).entryMap(); // Load info item for each shortcut, reset custom shortcuts auto it = schemeEntries.constBegin(); while (it != schemeEntries.end()) { ActionInfoItem &info = d->actionInfo(it.key()); if (!it.value().isEmpty()) info.defaultShortcuts = QKeySequence::listFromString(it.value()); it++; } } } void KisActionRegistry::updateShortcut(const QString &name, QAction *action) { - const ActionInfoItem info = d->actionInfo(name); - auto newShortcuts = preferredShortcuts(info); - action->setShortcuts(newShortcuts); + const ActionInfoItem &info = d->actionInfo(name); + action->setShortcuts(preferredShortcuts(info)); - action->setProperty("defaultShortcuts", qVariantFromValue(newShortcuts)); + action->setProperty("defaultShortcuts", qVariantFromValue(info.defaultShortcuts)); } bool KisActionRegistry::propertizeAction(const QString &name, QAction * a) { const ActionInfoItem info = d->actionInfo(name); QDomElement actionXml = info.xmlData; if (actionXml.text().isEmpty()) { dbgAction << "No XML data found for action" << name; return false; } // i18n requires converting format from QString. auto getChildContent_i18n = [=](QString node){return quietlyTranslate(getChildContent(actionXml, node));}; // Note: the fields in the .action documents marked for translation are determined by extractrc. QString icon = getChildContent(actionXml, "icon"); QString text = getChildContent_i18n("text"); QString whatsthis = getChildContent_i18n("whatsThis"); QString toolTip = getChildContent_i18n("toolTip"); QString statusTip = getChildContent_i18n("statusTip"); QString iconText = getChildContent_i18n("iconText"); bool isCheckable = getChildContent(actionXml, "isCheckable") == QString("true"); a->setObjectName(name); // This is helpful, should be added more places in Krita a->setIcon(KisIconUtils::loadIcon(icon.toLatin1())); a->setText(text); a->setObjectName(name); a->setWhatsThis(whatsthis); a->setToolTip(toolTip); a->setStatusTip(statusTip); a->setIconText(iconText); a->setCheckable(isCheckable); updateShortcut(name, a); // TODO: check for colliding shortcuts in .action files either here or in loading code #if 0 QMap existingShortcuts; Q_FOREACH (QAction* action, actionCollection->actions()) { if(action->shortcut() == QKeySequence(0)) { continue; } if (existingShortcuts.contains(action->shortcut())) { dbgAction << QString("Actions %1 and %2 have the same shortcut: %3") \ .arg(action->text()) \ .arg(existingShortcuts[action->shortcut()]->text()) \ .arg(action->shortcut()); } else { existingShortcuts[action->shortcut()] = action; } } #endif return true; } QString KisActionRegistry::getActionProperty(const QString &name, const QString &property) { ActionInfoItem info = d->actionInfo(name); QDomElement actionXml = info.xmlData; if (actionXml.text().isEmpty()) { dbgAction << "No XML data found for action" << name; return QString(); } return getChildContent(actionXml, property); } void KisActionRegistry::writeCustomShortcuts(KConfigBase *config) const { KConfigGroup cg; if (config == 0) { cg = KConfigGroup(KSharedConfig::openConfig("kritashortcutsrc"), QStringLiteral("Shortcuts")); } else { cg = KConfigGroup(config, QStringLiteral("Shortcuts")); } for (auto it = d->actionInfoList.constBegin(); it != d->actionInfoList.constEnd(); ++it) { QString actionName = it.key(); QString s = QKeySequence::listToString(it.value().customShortcuts); if (s.isEmpty()) { cg.deleteEntry(actionName, KConfigGroup::Persistent); } else { cg.writeEntry(actionName, s, KConfigGroup::Persistent); } } cg.sync(); } void KisActionRegistry::Private::loadActionFiles() { auto searchType = KoResourcePaths::Recursive | KoResourcePaths::NoDuplicates; QStringList actionDefinitions = KoResourcePaths::findAllResources("kis_actions", "*.action", searchType); // Extract actions all XML .action files. Q_FOREACH (const QString &actionDefinition, actionDefinitions) { QDomDocument doc; QFile f(actionDefinition); f.open(QFile::ReadOnly); doc.setContent(f.readAll()); QDomElement base = doc.documentElement(); // "ActionCollection" outer group QString collectionName = base.attribute("name"); QString version = base.attribute("version"); if (version != "2") { errAction << ".action XML file" << actionDefinition << "has incorrect version; skipping."; continue; } KActionCollection *actionCollection; if (!actionCollections.contains(collectionName)) { actionCollection = new KActionCollection(q, collectionName); actionCollections.insert(collectionName, actionCollection); dbgAction << "Adding a new action collection " << collectionName; } else { actionCollection = actionCollections.value(collectionName); } // Loop over nodes. Each of these corresponds to a // KActionCategory, producing a group of actions in the shortcut dialog. QDomElement actions = base.firstChild().toElement(); while (!actions.isNull()) { // field QDomElement categoryTextNode = actions.firstChild().toElement(); QString categoryName = quietlyTranslate(categoryTextNode.text()); // KActionCategory *category = actionCollection->getCategory(categoryName); // dbgAction << "Using category" << categoryName; // tags QDomElement actionXml = categoryTextNode.nextSiblingElement(); // Loop over individual actions while (!actionXml.isNull()) { if (actionXml.tagName() == "Action") { // Read name from format QString name = actionXml.attribute("name"); // Bad things if (name.isEmpty()) { errAction << "Unnamed action in definitions file " << actionDefinition; } else if (actionInfoList.contains(name)) { // errAction << "NOT COOL: Duplicated action name from xml data: " << name; } else { ActionInfoItem info; info.xmlData = actionXml; // Use empty list to signify no shortcut QString shortcutText = getChildContent(actionXml, "shortcut"); if (!shortcutText.isEmpty()) info.defaultShortcuts << QKeySequence(shortcutText); info.categoryName = categoryName; info.collectionName = collectionName; // dbgAction << "default shortcut for" << name << " - " << info.defaultShortcut; actionInfoList.insert(name,info); } } actionXml = actionXml.nextSiblingElement(); } actions = actions.nextSiblingElement(); } } }; void KisActionRegistry::Private::loadCustomShortcuts(QString filename) { const KConfigGroup localShortcuts(KSharedConfig::openConfig(filename), QStringLiteral("Shortcuts")); if (!localShortcuts.exists()) { return; } for (auto i = actionInfoList.begin(); i != actionInfoList.end(); ++i) { if (localShortcuts.hasKey(i.key())) { QString entry = localShortcuts.readEntry(i.key(), QString()); if (entry != QStringLiteral("none")) { i.value().customShortcuts = QKeySequence::listFromString(entry); continue; } } i.value().customShortcuts = QList(); } }; diff --git a/libs/widgetutils/xmlgui/KisShortcutsDialog.cpp b/libs/widgetutils/xmlgui/KisShortcutsDialog.cpp index 88e4e771fc..5ac833889f 100644 --- a/libs/widgetutils/xmlgui/KisShortcutsDialog.cpp +++ b/libs/widgetutils/xmlgui/KisShortcutsDialog.cpp @@ -1,147 +1,147 @@ /* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe Copyright (C) 1997 Nicolas Hadacek Copyright (C) 1998 Mark Donohoe Copyright (C) 1998 Matthias Ettrich Copyright (C) 1999 Espen Sand Copyright (C) 2001 Ellis Whitehead Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz Copyright (C) 2008 Michael Jansen Copyright (C) 2008 Alexander Dymo Copyright (C) 2009 Chani Armitage This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisShortcutsDialog.h" #include "KisShortcutsDialog_p.h" #include "kshortcutschemeshelper_p.h" #include "kshortcutschemeseditor.h" #include #include #include #include #include #include #include #include #include "kxmlguiclient.h" #include "kxmlguifactory.h" #include "kactioncollection.h" KisShortcutsDialog::KisShortcutsDialog(KisShortcutsEditor::ActionTypes types, KisShortcutsEditor::LetterShortcuts allowLetterShortcuts, QWidget *parent) : QWidget(parent) , d(new KisShortcutsDialogPrivate(this)) { d->m_shortcutsEditor = new KisShortcutsEditor(this, types, allowLetterShortcuts); /* Construct & Connect UI */ QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(d->m_shortcutsEditor); QHBoxLayout *bottomLayout = new QHBoxLayout; d->m_schemeEditor = new KShortcutSchemesEditor(this); connect(d->m_schemeEditor, SIGNAL(shortcutsSchemeChanged(QString)), this, SLOT(changeShortcutScheme(QString))); bottomLayout->addLayout(d->m_schemeEditor); QPushButton *printButton = new QPushButton; KGuiItem::assign(printButton, KStandardGuiItem::print()); QDialogButtonBox *buttonBox = new QDialogButtonBox(this); buttonBox->addButton(printButton, QDialogButtonBox::ActionRole); bottomLayout->addWidget(buttonBox); mainLayout->addLayout(bottomLayout); connect(printButton, SIGNAL(clicked()), d->m_shortcutsEditor, SLOT(printShortcuts())); KConfigGroup group(KSharedConfig::openConfig(), "KisShortcutsDialog Settings"); resize(group.readEntry("Dialog Size", sizeHint())); } KisShortcutsDialog::~KisShortcutsDialog() { KConfigGroup group(KSharedConfig::openConfig(), "KisShortcutsDialog Settings"); group.writeEntry("Dialog Size", size()); delete d; } void KisShortcutsDialog::addCollection(KActionCollection *collection, const QString &title) { d->m_shortcutsEditor->addCollection(collection, title); d->m_collections.insert(title, collection); } void KisShortcutsDialog::save() { d->save(); } QList KisShortcutsDialog::actionCollections() const { return d->m_collections.values(); } QSize KisShortcutsDialog::sizeHint() const { return QSize(600, 480); } void KisShortcutsDialog::allDefault() { d->m_shortcutsEditor->allDefault(); } void KisShortcutsDialog::importConfiguration(const QString &path) { - KConfig config(path); - d->m_shortcutsEditor->importConfiguration(static_cast(&config), true); + auto config = KSharedConfig::openConfig(path); + d->m_shortcutsEditor->importConfiguration(config.data(), true); } void KisShortcutsDialog::exportConfiguration(const QString &path) const { - KConfig config(path); - d->m_shortcutsEditor->exportConfiguration(static_cast(&config)); + auto config = KSharedConfig::openConfig(path); + d->m_shortcutsEditor->exportConfiguration(config.data()); } void KisShortcutsDialog::saveCustomShortcuts(const QString &path) const { - KConfig config(path); - KConfigGroup cg(&config, QStringLiteral("Shortcuts")); - d->m_shortcutsEditor->saveShortcuts(&cg); + auto cg = KSharedConfig::openConfig(path)->group(QStringLiteral("Shortcuts")); + d->m_shortcutsEditor->saveShortcuts(&cg); + d->m_shortcutsEditor->commit(); } void KisShortcutsDialog::loadCustomShortcuts(const QString &path) { - KConfig config(path); - d->m_shortcutsEditor->importConfiguration(static_cast(&config), false); + auto config = KSharedConfig::openConfig(path); + d->m_shortcutsEditor->importConfiguration(config.data(), false); } #include "moc_KisShortcutsDialog.cpp" diff --git a/libs/widgetutils/xmlgui/KisShortcutsEditor.cpp b/libs/widgetutils/xmlgui/KisShortcutsEditor.cpp index c2c990e32b..55b6e82485 100644 --- a/libs/widgetutils/xmlgui/KisShortcutsEditor.cpp +++ b/libs/widgetutils/xmlgui/KisShortcutsEditor.cpp @@ -1,322 +1,321 @@ /* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe Copyright (C) 1997 Nicolas Hadacek Copyright (C) 1998 Matthias Ettrich Copyright (C) 2001 Ellis Whitehead Copyright (C) 2006 Hamish Rodda Copyright (C) 2007 Roberto Raggi Copyright (C) 2007 Andreas Hartmetz Copyright (C) 2008 Michael Jansen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisShortcutsEditor.h" #include "KisShortcutsEditor_p.h" #include "kshortcutschemeshelper_p.h" #include "config-xmlgui.h" #include "kis_action_registry.h" // The following is needed for KisShortcutsEditorPrivate and QTreeWidgetHack // #include "KisShortcutsDialog_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kactioncollection.h" #include "kactioncategory.h" #include //--------------------------------------------------------------------- // KisShortcutsEditor //--------------------------------------------------------------------- Q_DECLARE_METATYPE(KisShortcutsEditorItem *) KisShortcutsEditor::KisShortcutsEditor(QWidget *parent, ActionTypes actionType, LetterShortcuts allowLetterShortcuts) : QWidget(parent) , d(new KisShortcutsEditorPrivate(this)) { d->initGUI(actionType, allowLetterShortcuts); } KisShortcutsEditor::~KisShortcutsEditor() { delete d; } bool KisShortcutsEditor::isModified() const { // Iterate over all items QTreeWidgetItemIterator it(d->ui.list, QTreeWidgetItemIterator::NoChildren); for (; (*it); ++it) { KisShortcutsEditorItem *item = dynamic_cast(*it); if (item && item->isModified()) { return true; } } return false; } void KisShortcutsEditor::clearCollections() { d->delegate->contractAll(); d->ui.list->clear(); d->actionCollections.clear(); QTimer::singleShot(0, this, SLOT(resizeColumns())); } void KisShortcutsEditor::clearSearch() { d->ui.searchFilter->searchLine()->clear(); } void KisShortcutsEditor::addCollection(KActionCollection *collection, const QString &title) { // KXmlGui add action collections unconditionally. If some plugin doesn't // provide actions we don't want to create empty subgroups. if (collection->isEmpty()) { return; } // Pause updating. setUpdatesEnabled(false); /** * Forward this actioncollection to the delegate which will do conflict checking. * This _replaces_ existing collections in the delegate. */ d->actionCollections.append(collection); d->delegate->setCheckActionCollections(d->actionCollections); // Determine how we should label this collection in the widget. QString collectionTitle; if (!title.isEmpty()) { collectionTitle = title; } else { // Use the programName (Translated). collectionTitle = collection->componentDisplayName(); } // Create the collection root node. QTreeWidgetItem *hierarchy[3]; hierarchy[KisShortcutsEditorPrivate::Root] = d->ui.list->invisibleRootItem(); hierarchy[KisShortcutsEditorPrivate::Program] = d->findOrMakeItem(hierarchy[KisShortcutsEditorPrivate::Root], collectionTitle); hierarchy[KisShortcutsEditorPrivate::Action] = 0; // Remember which actions we have seen. We will be adding categorized // actions first, so this will help us keep track of which actions haven't // been categorized yet, so we can add them as uncategorized at the end. QSet actionsSeen; // Add a subtree for each category? Perhaps easier to think that this // doesn't exist. Basically you add KActionCategory as a QObject child of // KActionCollection, and then tag objects as belonging to the category. foreach (KActionCategory *category, collection->categories()) { // Don't display empty categories. if (category->actions().isEmpty()) { continue; } hierarchy[KisShortcutsEditorPrivate::Action] = d->findOrMakeItem(hierarchy[KisShortcutsEditorPrivate::Program], category->text()); // Add every item from the category. foreach (QAction *action, category->actions()) { actionsSeen.insert(action); d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Action); } // Fold in each KActionCategory by default. hierarchy[KisShortcutsEditorPrivate::Action]->setExpanded(false); } // Finally, tack on any uncategorized actions. foreach (QAction *action, collection->actions()) { if (!actionsSeen.contains(action)) { d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Program); } } // sort the list d->ui.list->sortItems(Name, Qt::AscendingOrder); // Now turn on updating again. setUpdatesEnabled(true); QTimer::singleShot(0, this, SLOT(resizeColumns())); } void KisShortcutsEditor::clearConfiguration() { d->clearConfiguration(); } void KisShortcutsEditor::importConfiguration(KConfigBase *config, bool isScheme) { Q_ASSERT(config); if (!config) { return; } // If this is a shortcut scheme, apply it if (isScheme) { KisActionRegistry::instance()->applyShortcutScheme(config); } // Update the dialog entry items const KConfigGroup schemeShortcuts(config, QStringLiteral("Shortcuts")); for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) { if (!(*it)->parent()) { continue; } KisShortcutsEditorItem *item = static_cast(*it); const QString actionId = item->data(Id).toString(); if (!schemeShortcuts.hasKey(actionId)) continue; QList sc = QKeySequence::listFromString(schemeShortcuts.readEntry(actionId, QString())); d->changeKeyShortcut(item, LocalPrimary, primarySequence(sc)); d->changeKeyShortcut(item, LocalAlternate, alternateSequence(sc)); } } void KisShortcutsEditor::exportConfiguration(KConfigBase *config) const { Q_ASSERT(config); if (!config) { return; } if (d->actionTypes) { - QString groupName(QStringLiteral("Shortcuts")); - KConfigGroup group(config, groupName); + KConfigGroup group(config,QStringLiteral("Shortcuts")); foreach (KActionCollection *collection, d->actionCollections) { collection->writeSettings(&group, true); } } KisActionRegistry::instance()->notifySettingsUpdated(); } void KisShortcutsEditor::saveShortcuts(KConfigGroup *config) const { // This is a horrible mess with pointers... KConfigGroup cg; if (config == 0) { cg = KConfigGroup(KSharedConfig::openConfig("kritashortcutsrc"), QStringLiteral("Shortcuts")); config = &cg; } // Clear and reset temporary shortcuts config->deleteGroup(); foreach (KActionCollection *collection, d->actionCollections) { collection->writeSettings(config, false); } KisActionRegistry::instance()->notifySettingsUpdated(); } //slot void KisShortcutsEditor::resizeColumns() { for (int i = 0; i < d->ui.list->columnCount(); i++) { d->ui.list->resizeColumnToContents(i); } } void KisShortcutsEditor::commit() { for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) { if (KisShortcutsEditorItem *item = dynamic_cast(*it)) { item->commit(); } } } void KisShortcutsEditor::save() { saveShortcuts(); commit(); // Not doing this would be bad } void KisShortcutsEditor::undo() { // TODO: is this working? for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) { if (KisShortcutsEditorItem *item = dynamic_cast(*it)) { item->undo(); } } } void KisShortcutsEditor::allDefault() { d->allDefault(); } void KisShortcutsEditor::printShortcuts() const { d->printShortcuts(); } void KisShortcutsEditor::searchUpdated(QString s) { if (s.isEmpty()) { // Reset the tree area d->ui.list->collapseAll(); d->ui.list->expandToDepth(0); } else { d->ui.list->expandAll(); } } KisShortcutsEditor::ActionTypes KisShortcutsEditor::actionTypes() const { return d->actionTypes; } void KisShortcutsEditor::setActionTypes(ActionTypes actionTypes) { d->setActionTypes(actionTypes); } #include "moc_KisShortcutsEditor.cpp"