Commit f8942ce9 authored by Michael Abrahams's avatar Michael Abrahams

Add "Save custom shortcuts" command

This saves only user-customized shortcuts to a separate file.
parent 60dd2870
......@@ -345,12 +345,17 @@ QString KisActionRegistry::getActionProperty(const QString &name, const QString
}
void KisActionRegistry::writeCustomShortcuts() const
void KisActionRegistry::writeCustomShortcuts(KConfigBase *config) const
{
KConfigGroup cg(KSharedConfig::openConfig("kritashortcutsrc"),
QStringLiteral("Shortcuts"));
QList<QAction *> writeActions;
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) {
......
......@@ -113,12 +113,6 @@ public:
*/
QStringList allActions();
/**
* Save settings. Currently implemented in KisShortcutsEditor
*/
// void writeSettings(KActionCollection *ac);
/**
* Display the shortcut configuration dialog.
*/
......@@ -132,9 +126,9 @@ public:
/**
* Read custom shortcuts from kritashortcutsrc
* Write custom shortcuts to a specific file
*/
void writeCustomShortcuts() const;
void writeCustomShortcuts(KConfigBase *config) const;
/**
......
......@@ -165,4 +165,11 @@ void KisShortcutsDialog::exportConfiguration(const QString &path) const
d->m_shortcutsEditor->exportConfiguration(static_cast<KConfigBase *>(&config));
}
void KisShortcutsDialog::saveCustomShortcuts(const QString &path) const
{
KConfig config(path);
KConfigGroup cg(&config, QStringLiteral("Shortcuts"));
d->m_shortcutsEditor->saveShortcuts(&cg);
}
#include "moc_KisShortcutsDialog.cpp"
......@@ -156,6 +156,12 @@ public:
*/
void exportConfiguration(const QString &path) const;
/**
* Exports custom shortcuts to @p path
*/
void saveCustomShortcuts(const QString &path) const;
/**
* Pops up a modal (blocking) dialog for configuring key settings. The new
* shortcut settings will become active if the user presses OK.
......
......@@ -249,7 +249,8 @@ private Q_SLOTS:
void newScheme();
void deleteScheme();
void exportShortcutsScheme();
void saveAsDefaultsForScheme();
void saveCustomShortcuts();
// void saveAsDefaultsForScheme(); //Not implemented
void importShortcutsScheme();
Q_SIGNALS:
......
......@@ -197,10 +197,6 @@ void KisShortcutsEditor::importConfiguration(KConfigBase *config)
// Reload the configuration file
KisActionRegistry::instance()->applyShortcutScheme(config);
// XXX: Any need to update the actions themselves?
// Update the dialog entry items
const KConfigGroup schemeShortcuts(config, QStringLiteral("Shortcuts"));
for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
......@@ -240,8 +236,10 @@ void KisShortcutsEditor::exportConfiguration(KConfigBase *config) const
void KisShortcutsEditor::saveShortcuts(KConfigGroup *config) const
{
// This is a horrible mess with pointers...
auto cg = KConfigGroup(KSharedConfig::openConfig("kritashortcutsrc"), "Shortcuts");
KConfigGroup cg;
if (config == 0) {
cg = KConfigGroup(KSharedConfig::openConfig("kritashortcutsrc"),
QStringLiteral("Shortcuts"));
config = &cg;
}
......
......@@ -81,6 +81,8 @@ KShortcutSchemesEditor::KShortcutSchemesEditor(KisShortcutsDialog *parent)
QMenu *moreActionsMenu = new QMenu(m_dialog);
moreActionsMenu->addAction(i18n("Save as Scheme Defaults"),
this, SLOT(saveAsDefaultsForScheme()));
moreActionsMenu->addAction(i18n("Save Custom Shortcuts"),
this, SLOT(saveCustomShortcuts()));
moreActionsMenu->addAction(i18n("Export Scheme..."),
this, SLOT(exportShortcutsScheme()));
moreActionsMenu->addAction(i18n("Import Scheme..."),
......@@ -162,6 +164,19 @@ void KShortcutSchemesEditor::exportShortcutsScheme()
m_dialog->exportConfiguration(path);
}
void KShortcutSchemesEditor::saveCustomShortcuts()
{
//ask user about dir
QString path = QFileDialog::getSaveFileName(m_dialog, i18n("Save Shortcuts"),
QDir::currentPath(),
i18n("Shortcuts (*.shortcuts)"));
if (path.isEmpty()) {
return;
}
m_dialog->saveCustomShortcuts(path);
}
void KShortcutSchemesEditor::importShortcutsScheme()
{
//ask user about dir
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment