diff --git a/kcms/runners/CMakeLists.txt b/kcms/runners/CMakeLists.txt --- a/kcms/runners/CMakeLists.txt +++ b/kcms/runners/CMakeLists.txt @@ -11,6 +11,7 @@ KF5::KIOWidgets KF5::CoreAddons KF5::KCMUtils + KF5::XmlGui KF5::Runner KF5::I18n KF5::IconThemes diff --git a/kcms/runners/kcm.h b/kcms/runners/kcm.h --- a/kcms/runners/kcm.h +++ b/kcms/runners/kcm.h @@ -22,6 +22,9 @@ #include #include +#include +#include + class QToolButton; class KCModuleProxy; @@ -51,6 +54,8 @@ private: KPluginSelector *m_pluginSelector; + KShortcutsEditor *m_shortcutsEditor; + KActionCollection *m_shortcuts; KConfig m_config; }; diff --git a/kcms/runners/kcm.cpp b/kcms/runners/kcm.cpp --- a/kcms/runners/kcm.cpp +++ b/kcms/runners/kcm.cpp @@ -30,14 +30,17 @@ #include #include #include +#include +#include #include #include #include #include #include #include #include +#include K_PLUGIN_FACTORY(SearchConfigModuleFactory, registerPlugin();) @@ -52,34 +55,117 @@ setAboutData(about); setButtons(Apply | Default); - QVBoxLayout* layout = new QVBoxLayout(this); - - QHBoxLayout *headerLayout = new QHBoxLayout(this); - - QLabel *label = new QLabel(i18n("Select the search plugins:")); + QHBoxLayout* tabLayout = new QHBoxLayout(this); + QTabWidget* tabWidget = new QTabWidget(this); + tabLayout->addWidget(tabWidget); + + QWidget* generalPage = new QWidget(tabWidget); + QVBoxLayout* generalTabLayout = new QVBoxLayout(generalPage); + generalPage->setLayout(generalTabLayout); + tabWidget->addTab(generalPage, "General"); + + QWidget* shortcutsPage = new QWidget(tabWidget); + QVBoxLayout* shortcutsTabLayout = new QVBoxLayout(shortcutsPage); + shortcutsPage->setLayout(shortcutsTabLayout); + tabWidget->addTab(shortcutsPage, "Shortcuts"); + + m_shortcuts = new KActionCollection(this); + m_shortcuts->setComponentName(about->componentName()); + m_shortcuts->setComponentDisplayName("KRunner"); + + QAction *moveToStartOfLine = new QAction(nullptr); + moveToStartOfLine->setText(i18n("Start of Line")); + m_shortcuts->setDefaultShortcut(moveToStartOfLine, QKeySequence::MoveToStartOfLine); + m_shortcuts->addAction(QStringLiteral("Start of Line"), moveToStartOfLine); + + QAction *moveToEndOfLine = new QAction(nullptr); + moveToEndOfLine->setText(i18n("End of Line")); + m_shortcuts->setDefaultShortcut(moveToEndOfLine, QKeySequence::MoveToEndOfLine); + m_shortcuts->addAction(QStringLiteral("End of Line"), moveToEndOfLine); + + QAction *previousItem = new QAction(nullptr); + previousItem->setText(i18n("Previous Item in List")); + previousItem->setIcon(QIcon::fromTheme("go-previous")); + m_shortcuts->setDefaultShortcuts(previousItem, QList() << QKeySequence::MoveToPreviousLine << QKeySequence(Qt::CTRL + Qt::Key_K)); + m_shortcuts->addAction(QStringLiteral("Previous Item in List"), previousItem); + + QAction *nextItem = new QAction(nullptr); + nextItem->setText(i18n("Next Item in List")); + nextItem->setIcon(QIcon::fromTheme("go-next")); + m_shortcuts->setDefaultShortcuts(nextItem, QList() << QKeySequence::MoveToNextLine << QKeySequence(Qt::CTRL + Qt::Key_J)); + m_shortcuts->addAction(QStringLiteral("Next Item in List"), nextItem); + + QAction *runItem = new QAction(nullptr); + runItem->setText(i18n("Run Selected Item")); + m_shortcuts->setDefaultShortcuts(runItem, QList() << Qt::Key_Return << Qt::Key_Enter); + m_shortcuts->addAction(QStringLiteral("Run Selected Item"), runItem); + + QAction *hideRunnerWindow = new QAction(nullptr); + hideRunnerWindow->setText(i18n("Hide Runner Window")); + hideRunnerWindow->setIcon(QIcon::fromTheme("application-exit")); + m_shortcuts->setDefaultShortcut(hideRunnerWindow, Qt::Key_Escape); + m_shortcuts->addAction(QStringLiteral("Hide Runner Window"), hideRunnerWindow); + + QAction *cutSelected = new QAction(nullptr); + cutSelected->setText(i18n("Cut")); + cutSelected->setIcon(QIcon::fromTheme("edit-cut")); + m_shortcuts->setDefaultShortcut(cutSelected, QKeySequence::Cut); + m_shortcuts->addAction(QStringLiteral("Cut"), cutSelected); + + QAction *copySelected = new QAction(nullptr); + copySelected->setText(i18n("Copy")); + copySelected->setIcon(QIcon::fromTheme("edit-copy")); + m_shortcuts->setDefaultShortcut(copySelected, QKeySequence::Copy); + m_shortcuts->addAction(QStringLiteral("Copy"), copySelected); + + QAction *pasteSelected = new QAction(nullptr); + pasteSelected->setText(i18n("Paste")); + pasteSelected->setIcon(QIcon::fromTheme("edit-paste")); + m_shortcuts->setDefaultShortcut(pasteSelected, QKeySequence::Paste); + m_shortcuts->addAction(QStringLiteral("Paste"), pasteSelected); + + QAction *clearAll = new QAction(nullptr); + clearAll->setText(i18n("Clear")); + clearAll->setIcon(QIcon::fromTheme("edit-clear")); + m_shortcuts->setDefaultShortcut(clearAll, QKeySequence(Qt::CTRL + Qt::Key_U)); + m_shortcuts->addAction(QStringLiteral("Clear"), clearAll); + + QAction *selectAll = new QAction(nullptr); + selectAll->setText(i18n("Select All")); + selectAll->setIcon(QIcon::fromTheme("edit-select-all")); + m_shortcuts->setDefaultShortcut(selectAll, QKeySequence::SelectAll); + m_shortcuts->addAction(QStringLiteral("Select All"), selectAll); + + QAction *deselectSelected = new QAction(nullptr); + deselectSelected->setText(i18n("Deselect")); + deselectSelected->setIcon(QIcon::fromTheme("edit-select-none")); + m_shortcuts->setDefaultShortcut(deselectSelected, QKeySequence::Deselect); + m_shortcuts->addAction(QStringLiteral("Deselect"), deselectSelected); + + m_shortcutsEditor = new KShortcutsEditor(this); + m_shortcutsEditor->setActionTypes(KShortcutsEditor::ApplicationAction); + m_shortcutsEditor->addCollection(m_shortcuts); + shortcutsTabLayout->addWidget(m_shortcutsEditor); + connect(m_shortcutsEditor, &KShortcutsEditor::keyChange, [&] { + Q_EMIT changed(m_shortcutsEditor->isModified()); + }); QPushButton *clearHistoryButton = new QPushButton(i18n("Clear History")); clearHistoryButton->setIcon(QIcon::fromTheme(isRightToLeft() ? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl"))); + generalTabLayout->addWidget(clearHistoryButton); connect(clearHistoryButton, &QPushButton::clicked, this, [this] { KConfigGroup generalConfig(m_config.group("General")); generalConfig.deleteEntry("history"); generalConfig.sync(); }); - headerLayout->addWidget(label); - headerLayout->addStretch(); - headerLayout->addWidget(clearHistoryButton); - m_pluginSelector = new KPluginSelector(this); - + generalTabLayout->addWidget(m_pluginSelector); //overload, can't use the new syntax connect(m_pluginSelector, SIGNAL(changed(bool)), this, SIGNAL(changed(bool))); - layout->addLayout(headerLayout); - layout->addWidget(m_pluginSelector); - Plasma::RunnerManager *manager = new Plasma::RunnerManager(this); manager->reloadConfiguration(); } @@ -93,12 +179,18 @@ KPluginSelector::ReadConfigFile, i18n("Available Plugins"), QString(), KSharedConfig::openConfig(QLatin1String( "krunnerrc" ))); -} + KConfigGroup group = m_config.group("Shortcuts"); + m_shortcuts->readSettings(&group); +} void SearchConfigModule::save() { m_pluginSelector->save(); + + KConfigGroup group = m_config.group("Shortcuts"); + m_shortcuts->writeSettings(&group); + group.sync(); } void SearchConfigModule::defaults()