Commit f9c3bbe7 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Allow multiple tabs for Konsole plugin(s)

You can use "Ctrl + Shift + t" to create a new tab (when konsole plugin
has focus). Not sure how to make this more discoverable atm.

BUG: 437922

 419710 435398 200322 145203
Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 2dc2ff79
Pipeline #73349 passed with stage
in 5 minutes and 58 seconds
......@@ -33,6 +33,7 @@
#include <QPushButton>
#include <QShowEvent>
#include <QStyle>
#include <QTabWidget>
#include <QVBoxLayout>
#include <KAboutData>
......@@ -204,6 +205,10 @@ void KateConsole::loadConsoleIfNeeded()
return;
}
if (auto konsoleTabWidget = qobject_cast<QTabWidget *>(m_part->widget())) {
konsoleTabWidget->setTabBarAutoHide(true);
konsoleTabWidget->installEventFilter(this);
}
layout()->addWidget(m_part->widget());
// start the terminal
......@@ -212,7 +217,6 @@ void KateConsole::loadConsoleIfNeeded()
// KGlobal::locale()->insertCatalog("konsole"); // FIXME KF5: insert catalog
setFocusProxy(m_part->widget());
m_part->widget()->show();
connect(m_part, &KParts::ReadOnlyPart::destroyed, this, &KateConsole::slotDestroyed);
// clang-format off
......@@ -221,6 +225,29 @@ void KateConsole::loadConsoleIfNeeded()
slotSync();
}
static bool isCtrlShiftT(QKeyEvent *ke)
{
return ke->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && ke->key() == Qt::Key_T;
}
bool KateConsole::eventFilter(QObject *w, QEvent *e)
{
if (!m_part) {
return QWidget::eventFilter(w, e);
}
if (e->type() == QEvent::KeyPress || e->type() == QEvent::ShortcutOverride) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (isCtrlShiftT(keyEvent)) {
e->accept();
QMetaObject::invokeMethod(m_part, "newTab");
return true;
}
}
return QWidget::eventFilter(w, e);
}
void KateConsole::slotDestroyed()
{
m_part = nullptr;
......
......@@ -122,6 +122,8 @@ public:
return m_mw;
}
bool eventFilter(QObject *w, QEvent *e) override;
public Q_SLOTS:
/**
* pipe current document to console
......
......@@ -15,6 +15,8 @@
#include <KSharedConfig>
#include <kde_terminal_interface.h>
#include <QTabWidget>
KPluginFactory *KateProjectInfoViewTerminal::s_pluginFactory = nullptr;
KateProjectInfoViewTerminal::KateProjectInfoViewTerminal(KateProjectPluginView *pluginView, const QString &directory)
......@@ -92,7 +94,12 @@ void KateProjectInfoViewTerminal::loadTerminal()
/**
* add to widget
*/
if (auto konsoleTabWidget = qobject_cast<QTabWidget *>(m_konsolePart->widget())) {
konsoleTabWidget->setTabBarAutoHide(true);
konsoleTabWidget->installEventFilter(this);
}
m_layout->addWidget(m_konsolePart->widget());
setFocusProxy(m_konsolePart->widget());
/**
......@@ -147,3 +154,25 @@ void KateProjectInfoViewTerminal::respawn(const QString &directory)
loadTerminal();
}
static bool isCtrlShiftT(QKeyEvent *ke)
{
return ke->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && ke->key() == Qt::Key_T;
}
bool KateProjectInfoViewTerminal::eventFilter(QObject *w, QEvent *e)
{
if (!m_konsolePart) {
return QWidget::eventFilter(w, e);
}
if (e->type() == QEvent::KeyPress || e->type() == QEvent::ShortcutOverride) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (isCtrlShiftT(keyEvent)) {
e->accept();
QMetaObject::invokeMethod(m_konsolePart, "newTab");
return true;
}
}
return QWidget::eventFilter(w, e);
}
......@@ -52,6 +52,8 @@ public:
void respawn(const QString &dirPath);
bool eventFilter(QObject *o, QEvent *e) override;
private Q_SLOTS:
/**
* Construct a new terminal for this view
......
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