Commit 0d41d6bb authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Save and use shortcuts for the Plugins

parent 6099d61a
......@@ -10,6 +10,7 @@
#include <KActionCollection>
#include <KCommandBar>
#include <QMainWindow>
#include <QSettings>
#include "MainWindow.h"
#include <KLocalizedString>
......@@ -46,6 +47,16 @@ void QuickCommandsPlugin::createWidgetsForMainWindow(Konsole::MainWindow *mainWi
qcDockWidget->setVisible(false);
mainWindow->addDockWidget(Qt::LeftDockWidgetArea, qcDockWidget);
connect(qcWidget, &QuickCommandsWidget::quickAccessShortcutChanged, this, [this](QKeySequence s) {
priv->showQuickAccess->setShortcut(s);
QString sequenceText = s.toString();
QSettings settings;
settings.beginGroup(QStringLiteral("plugins"));
settings.beginGroup(QStringLiteral("quickcommands"));
settings.setValue(QStringLiteral("shortcut"), sequenceText);
settings.sync();
});
priv->widgetForWindow[mainWindow] = qcWidget;
priv->dockForWindow[mainWindow] = qcDockWidget;
......@@ -54,9 +65,19 @@ void QuickCommandsPlugin::createWidgetsForMainWindow(Konsole::MainWindow *mainWi
void QuickCommandsPlugin::activeViewChanged(Konsole::SessionController *controller, Konsole::MainWindow *mainWindow)
{
priv->showQuickAccess->deleteLater();
priv->showQuickAccess = new QAction(i18n("Show Quick Access for SSH Actions"));
priv->showQuickAccess = new QAction(i18n("Show Quick Access"));
QSettings settings;
settings.beginGroup(QStringLiteral("plugins"));
settings.beginGroup(QStringLiteral("quickcommands"));
const QKeySequence def(Qt::CTRL + Qt::ALT + Qt::Key_G);
const QString defText = def.toString();
const QString entry = settings.value(QStringLiteral("shortcut"), defText).toString();
const QKeySequence shortcutEntry(entry);
priv->showQuickAccess->setShortcut(shortcutEntry);
priv->showQuickAccess->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_G));
controller->view()->addAction(priv->showQuickAccess);
Konsole::TerminalDisplay *terminalDisplay = controller->view();
......
......@@ -12,6 +12,7 @@
#include "ui_qcwidget.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QSettings>
#include <QStandardPaths>
#include <QTemporaryFile>
#include <QTimer>
......@@ -70,6 +71,21 @@ QuickCommandsWidget::QuickCommandsWidget(QWidget *parent)
});
viewMode();
QSettings settings;
settings.beginGroup(QStringLiteral("plugins"));
settings.beginGroup(QStringLiteral("quickcommands"));
const QKeySequence def(Qt::CTRL + Qt::ALT + Qt::Key_G);
const QString defText = def.toString();
const QString entry = settings.value(QStringLiteral("shortcut"), defText).toString();
const QKeySequence shortcutEntry(entry);
connect(ui->keySequenceEdit, &QKeySequenceEdit::keySequenceChanged, this, [this] {
auto shortcut = ui->keySequenceEdit->keySequence();
Q_EMIT quickAccessShortcutChanged(shortcut);
});
ui->keySequenceEdit->setKeySequence(shortcutEntry);
}
QuickCommandsWidget::~QuickCommandsWidget() = default;
......
......@@ -5,7 +5,9 @@
#ifndef QUICKCOMMANDSWIDGET_H
#define QUICKCOMMANDSWIDGET_H
#include <QKeySequence>
#include <QWidget>
#include <memory>
#include "quickcommanddata.h"
......@@ -54,6 +56,8 @@ public:
void setModel(QuickCommandsModel *model);
void setCurrentController(Konsole::SessionController *controller);
Q_SIGNAL void quickAccessShortcutChanged(QKeySequence shortcut);
protected:
void showEvent(QShowEvent *) override;
......
......@@ -26,6 +26,7 @@
#include <KCommandBar>
#include <KLocalizedString>
#include <KMessageBox>
#include <QSettings>
#include "MainWindow.h"
#include "terminalDisplay/TerminalDisplay.h"
......@@ -71,6 +72,17 @@ void SSHManagerPlugin::createWidgetsForMainWindow(Konsole::MainWindow *mainWindo
connect(managerWidget, &SSHManagerTreeWidget::requestNewTab, this, [mainWindow] {
mainWindow->newTab();
});
connect(managerWidget, &SSHManagerTreeWidget::quickAccessShortcutChanged, this, [this](QKeySequence s) {
d->showQuickAccess->setShortcut(s);
QString sequenceText = s.toString();
QSettings settings;
settings.beginGroup(QStringLiteral("plugins"));
settings.beginGroup(QStringLiteral("sshplugin"));
settings.setValue(QStringLiteral("ssh_shortcut"), sequenceText);
settings.sync();
});
}
QList<QAction *> SSHManagerPlugin::menuBarActions(Konsole::MainWindow *mainWindow) const
......@@ -98,7 +110,16 @@ void SSHManagerPlugin::activeViewChanged(Konsole::SessionController *controller,
d->showQuickAccess->deleteLater();
d->showQuickAccess = new QAction(i18n("Show Quick Access for SSH Actions"));
d->showQuickAccess->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_H));
QSettings settings;
settings.beginGroup(QStringLiteral("plugins"));
settings.beginGroup(QStringLiteral("sshplugin"));
const QKeySequence def(Qt::CTRL + Qt::ALT + Qt::Key_H);
const QString defText = def.toString();
const QString entry = settings.value(QStringLiteral("ssh_shortcut"), defText).toString();
const QKeySequence shortcutEntry(entry);
d->showQuickAccess->setShortcut(shortcutEntry);
terminalDisplay->addAction(d->showQuickAccess);
connect(d->showQuickAccess, &QAction::triggered, this, [this, terminalDisplay, controller] {
......
......@@ -31,6 +31,10 @@
#include <QPoint>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QStandardPaths>
#include <KMessageBox>
......@@ -131,6 +135,21 @@ SSHManagerTreeWidget::SSHManagerTreeWidget(QWidget *parent)
ui->btnEdit->setEnabled(false);
clearSshInfo();
QSettings settings;
settings.beginGroup(QStringLiteral("plugins"));
settings.beginGroup(QStringLiteral("sshplugin"));
const QKeySequence def(Qt::CTRL + Qt::ALT + Qt::Key_H);
const QString defText = def.toString();
const QString entry = settings.value(QStringLiteral("ssh_shortcut"), defText).toString();
const QKeySequence shortcutEntry(entry);
connect(ui->keySequenceEdit, &QKeySequenceEdit::keySequenceChanged, this, [this] {
auto shortcut = ui->keySequenceEdit->keySequence();
Q_EMIT quickAccessShortcutChanged(shortcut);
});
ui->keySequenceEdit->setKeySequence(shortcutEntry);
}
SSHManagerTreeWidget::~SSHManagerTreeWidget() = default;
......
Q_SIGNAL void quickAccessShortcutChanged(QKeySequence shortcut);
/* This file was part of the KDE libraries
SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
......@@ -64,6 +65,8 @@ public:
void setCurrentController(Konsole::SessionController *controller);
void handleImportedData(bool isImported);
Q_SIGNAL void quickAccessShortcutChanged(QKeySequence shortcut);
protected:
void showEvent(QShowEvent *) override;
......
Supports Markdown
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