Commit 768dffb8 authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Start to add the Quick Activation plugin

parent eda2be47
......@@ -8,6 +8,8 @@ SOURCES
sshmanagermodel.cpp
sshmanagerfiltermodel.cpp
sshtreeview.cpp
sshquickaccesswidget.cpp
sshquickaccesswidget.h
${EXTRA_SSHPLUGIN_SRCS}
INSTALL_NAMESPACE
"konsoleplugins"
......
......@@ -18,6 +18,8 @@
#include <KLocalizedString>
#include "MainWindow.h"
#include "sshquickaccesswidget.h"
#include "terminalDisplay/TerminalDisplay.h"
K_PLUGIN_CLASS_WITH_JSON(SSHManagerPlugin, "konsole_sshmanager.json")
......@@ -26,16 +28,30 @@ struct SSHManagerPluginPrivate {
QMap<Konsole::MainWindow *, SSHManagerTreeWidget *> widgetForWindow;
QMap<Konsole::MainWindow *, QDockWidget *> dockForWindow;
SSHQuickAccessWidget *quickAccess = nullptr;
QAction *showQuickAccess = nullptr;
};
SSHManagerPlugin::SSHManagerPlugin(QObject *object, const QVariantList &args)
: Konsole::IKonsolePlugin(object, args)
, d(std::make_unique<SSHManagerPluginPrivate>())
{
d->quickAccess = new SSHQuickAccessWidget(&d->model);
connect(d->quickAccess, &QObject::destroyed, this, [this] {
// quick access can be destroyed if a terminal display is destroyed.
// so, just create a new one.
d->quickAccess = new SSHQuickAccessWidget(&d->model);
});
d->showQuickAccess = new QAction();
setName(QStringLiteral("SshManager"));
}
SSHManagerPlugin::~SSHManagerPlugin() = default;
SSHManagerPlugin::~SSHManagerPlugin()
{
disconnect(d->quickAccess);
}
void SSHManagerPlugin::createWidgetsForMainWindow(Konsole::MainWindow *mainWindow)
{
......@@ -70,11 +86,31 @@ QList<QAction *> SSHManagerPlugin::menuBarActions(Konsole::MainWindow *mainWindo
return {toggleVisibilityAction};
}
#include <iostream>
void SSHManagerPlugin::activeViewChanged(Konsole::SessionController *controller, Konsole::MainWindow *mainWindow)
{
Q_ASSERT(controller);
Q_ASSERT(mainWindow);
auto terminalDisplay = controller->view();
d->quickAccess->hide();
d->quickAccess->setParent(terminalDisplay);
d->quickAccess->setSessionController(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));
terminalDisplay->addAction(d->showQuickAccess);
connect(d->showQuickAccess, &QAction::triggered, this, [this, terminalDisplay] {
d->quickAccess->show();
d->quickAccess->setFocus();
terminalDisplay->installEventFilter(d->quickAccess);
});
if (mainWindow) {
d->widgetForWindow[mainWindow]->setCurrentController(controller);
}
......
......@@ -8,6 +8,7 @@
#ifndef SSSHMANAGERPLUGINWIDGET_H
#define SSSHMANAGERPLUGINWIDGET_H
#include <QModelIndex>
#include <QWidget>
#include <memory>
......
/* This file was part of the KDE libraries
SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "sshquickaccesswidget.h"
#include <session/SessionController.h>
#include <terminalDisplay/TerminalDisplay.h>
#include <QAbstractItemModel>
#include <QBoxLayout>
#include <QDebug>
#include <QFocusEvent>
#include <QKeyEvent>
#include <QLineEdit>
#include <QMouseEvent>
#include <QShowEvent>
#include <QTreeView>
struct SSHQuickAccessWidget::Private {
QAbstractItemModel *model = nullptr;
Konsole::SessionController *controller = nullptr;
};
SSHQuickAccessWidget::SSHQuickAccessWidget(QAbstractItemModel *model, QWidget *parent)
: QWidget(parent)
, d(std::make_unique<SSHQuickAccessWidget::Private>())
{
auto *filter = new QLineEdit(this);
filter->setPlaceholderText(tr("Filter"));
auto *view = new QTreeView(this);
view->setHeaderHidden(true);
view->setModel(model);
auto *layout = new QBoxLayout(QBoxLayout::Direction::TopToBottom);
layout->addWidget(filter);
layout->addWidget(view);
setLayout(layout);
layout->setSpacing(0);
d->model = model;
}
SSHQuickAccessWidget::~SSHQuickAccessWidget() = default;
void SSHQuickAccessWidget::setSessionController(Konsole::SessionController *controller)
{
d->controller = controller;
}
void SSHQuickAccessWidget::focusInEvent(QFocusEvent *ev)
{
}
void SSHQuickAccessWidget::mousePressEvent(QMouseEvent *event)
{
}
void SSHQuickAccessWidget::keyPressEvent(QKeyEvent *ev)
{
if (ev->key() == Qt::Key_Escape) {
hide();
d->controller->view()->setFocus();
}
}
void SSHQuickAccessWidget::showEvent(QShowEvent *ev)
{
if (!parentWidget()) {
return;
}
auto rect = parentWidget()->geometry();
int eigth = rect.width() / 8;
rect.adjust(eigth, eigth, -eigth, -eigth);
setGeometry(eigth, rect.topLeft().y(), rect.width(), rect.height());
}
bool SSHQuickAccessWidget::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress) {
hide();
d->controller->view()->setFocus();
removeEventFilter(watched);
return true;
}
return QWidget::eventFilter(watched, event);
}
/* This file was part of the KDE libraries
SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef SSHQUICKACCESSWIDGET
#define SSHQUICKACCESSWIDGET
#include <QWidget>
#include <memory>
class QAbstractItemModel;
namespace Konsole
{
class SessionController;
};
/* A Widget invoked by shortcut to quickly fill something
* on the terminal
*/
class SSHQuickAccessWidget : public QWidget
{
Q_OBJECT
public:
struct Private;
SSHQuickAccessWidget(QAbstractItemModel *model, QWidget *parent = nullptr);
~SSHQuickAccessWidget();
void setSessionController(Konsole::SessionController *controller);
void showEvent(QShowEvent *ev) override;
void focusInEvent(QFocusEvent *ev) override;
void keyPressEvent(QKeyEvent *ev) override;
void mousePressEvent(QMouseEvent *event) override;
bool eventFilter(QObject *watched, QEvent *event) override;
private:
std::unique_ptr<Private> d;
};
#endif
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