Commit 4d9c0bab authored by Michael Abrahams's avatar Michael Abrahams

Implement "Load custom shortcuts"

parent 505d234c
......@@ -181,9 +181,13 @@ void KisActionRegistry::notifySettingsUpdated()
d->loadCustomShortcuts();
};
void KisActionRegistry::loadCustomShortcuts()
void KisActionRegistry::loadCustomShortcuts(const QString &path)
{
d->loadCustomShortcuts();
if (path.isEmpty()) {
d->loadCustomShortcuts();
} else {
d->loadCustomShortcuts(path);
}
};
void KisActionRegistry::loadShortcutScheme(const QString &schemeName)
......@@ -457,9 +461,7 @@ void KisActionRegistry::Private::loadActionFiles()
void KisActionRegistry::Private::loadCustomShortcuts(QString filename)
{
Q_UNUSED(filename);
const KConfigGroup localShortcuts(KSharedConfig::openConfig("kritashortcutsrc"),
const KConfigGroup localShortcuts(KSharedConfig::openConfig(filename),
QStringLiteral("Shortcuts"));
......@@ -471,6 +473,8 @@ void KisActionRegistry::Private::loadCustomShortcuts(QString filename)
if (localShortcuts.hasKey(i.key())) {
QString entry = localShortcuts.readEntry(i.key(), QString());
i.value().customShortcut = QKeySequence(entry);
} else {
i.value().customShortcut = QKeySequence();
}
}
};
......@@ -122,7 +122,7 @@ public:
/**
* Reload custom shortcuts from kritashortcutsrc
*/
void loadCustomShortcuts();
void loadCustomShortcuts(const QString &path = QString());
/**
......
......@@ -156,7 +156,7 @@ void KisShortcutsDialog::allDefault()
void KisShortcutsDialog::importConfiguration(const QString &path)
{
KConfig config(path);
d->m_shortcutsEditor->importConfiguration(static_cast<KConfigBase *>(&config));
d->m_shortcutsEditor->importConfiguration(static_cast<KConfigBase *>(&config), true);
}
void KisShortcutsDialog::exportConfiguration(const QString &path) const
......@@ -172,4 +172,10 @@ void KisShortcutsDialog::saveCustomShortcuts(const QString &path) const
d->m_shortcutsEditor->saveShortcuts(&cg);
}
void KisShortcutsDialog::loadCustomShortcuts(const QString &path)
{
KConfig config(path);
d->m_shortcutsEditor->importConfiguration(static_cast<KConfigBase *>(&config), false);
}
#include "moc_KisShortcutsDialog.cpp"
......@@ -156,6 +156,10 @@ public:
*/
void exportConfiguration(const QString &path) const;
/**
* Import custom shortcuts from @p path
*/
void loadCustomShortcuts(const QString &path);
/**
* Exports custom shortcuts to @p path
......
......@@ -248,10 +248,11 @@ public:
private Q_SLOTS:
void newScheme();
void deleteScheme();
void importShortcutsScheme();
void exportShortcutsScheme();
void loadCustomShortcuts();
void saveCustomShortcuts();
// void saveAsDefaultsForScheme(); //Not implemented
void importShortcutsScheme();
Q_SIGNALS:
void shortcutsSchemeChanged(const QString &);
......
......@@ -187,15 +187,17 @@ void KisShortcutsEditor::clearConfiguration()
d->clearConfiguration();
}
void KisShortcutsEditor::importConfiguration(KConfigBase *config)
void KisShortcutsEditor::importConfiguration(KConfigBase *config, bool isScheme)
{
Q_ASSERT(config);
if (!config) {
return;
}
// Reload the configuration file
KisActionRegistry::instance()->applyShortcutScheme(config);
// 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"));
......
......@@ -199,11 +199,12 @@ public:
/**
* Import a shortcut scheme from configuration file
* Import a shortcut configuration file.
*
* @param config Config object to save to.
* @param config Config object to load from.
* @param isScheme true for shortcut scheme, false for custom shortcuts
*/
void importConfiguration(KConfigBase *config);
void importConfiguration(KConfigBase *config, bool isScheme);
/**
* Sets the types of actions to display in this widget.
......
......@@ -84,6 +84,8 @@ KShortcutSchemesEditor::KShortcutSchemesEditor(KisShortcutsDialog *parent)
moreActionsMenu->addAction(i18n("Save Custom Shortcuts"),
this, SLOT(saveCustomShortcuts()));
moreActionsMenu->addAction(i18n("Load Custom Shortcuts"),
this, SLOT(loadCustomShortcuts()));
moreActionsMenu->addAction(i18n("Export Scheme..."),
this, SLOT(exportShortcutsScheme()));
moreActionsMenu->addAction(i18n("Import Scheme..."),
......@@ -191,6 +193,24 @@ void KShortcutSchemesEditor::saveCustomShortcuts()
m_dialog->saveCustomShortcuts(path);
}
void KShortcutSchemesEditor::loadCustomShortcuts()
{
auto path = QFileDialog::getOpenFileName(m_dialog,
i18n("Import Shortcuts"),
QDir::currentPath(),
i18n("Shortcuts (*.shortcuts)"));
if (path.isEmpty()) {
return;
}
// auto ar = KisActionRegistry::instance();
// ar->loadCustomShortcuts(path);
m_dialog->loadCustomShortcuts(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