[konsole] src: Add close tab and create new tab on middle click event
Kurt Hindenburg
null at kde.org
Wed Feb 20 01:50:58 GMT 2019
Git commit 42eb5132e0da4860b9fdd36b916f7d8fe7dbe5b0 by Kurt Hindenburg, on behalf of Shubham Jangra.
Committed on 20/02/2019 at 01:50.
Pushed by hindenburg into branch 'master'.
Add close tab and create new tab on middle click event
Summary:
Click with the middle mouse click on a tab: close it
Click with the middle click on empty portion of tab bar creates a new tab.
This makes konsole more streamlined with default behavior
found in other tabbed applications like browsers.
GUI option to enable/disable closing tab w/ mouse button. The default
is to have closing tab with button disabled to avoid possible data loss.
Tomaz Canabrava <tcanabrava at kde.org> also coded portion of this.
FEATURE: 398940
FIXED-IN: 19.04
GUI:
Test Plan: {F6618852}
Reviewers: ngraham, hindenburg, tcanabrava
Reviewed By: ngraham, hindenburg
Subscribers: emateli, thsurrel, ngraham, hindenburg, shubham, broulik, konsole-devel
Tags: #konsole
Differential Revision: https://phabricator.kde.org/D15742
M +27 -1 src/DetachableTabBar.cpp
M +4 -0 src/DetachableTabBar.h
M +4 -0 src/ViewContainer.cpp
M +7 -0 src/settings/TabBarSettings.ui
M +4 -0 src/settings/konsole.kcfg
https://commits.kde.org/konsole/42eb5132e0da4860b9fdd36b916f7d8fe7dbe5b0
diff --git a/src/DetachableTabBar.cpp b/src/DetachableTabBar.cpp
index 4508004c..bdbc07b8 100644
--- a/src/DetachableTabBar.cpp
+++ b/src/DetachableTabBar.cpp
@@ -18,6 +18,7 @@
*/
#include "DetachableTabBar.h"
+#include "KonsoleSettings.h"
#include "ViewContainer.h"
#include <QMouseEvent>
@@ -28,7 +29,8 @@ namespace Konsole {
DetachableTabBar::DetachableTabBar(QWidget *parent) :
QTabBar(parent),
dragType(DragType::NONE),
- _originalCursor(cursor())
+ _originalCursor(cursor()),
+ tabId(-1)
{}
bool DetachableTabBar::droppedContainerIsNotThis(const QPoint& currentPos) const
@@ -43,6 +45,15 @@ bool DetachableTabBar::droppedContainerIsNotThis(const QPoint& currentPos) const
return false;
}
+void DetachableTabBar::middleMouseButtonClickAt(const QPoint& pos)
+{
+ tabId = tabAt(pos);
+
+ if (tabId != -1) {
+ emit closeTab(tabId);
+ }
+}
+
void DetachableTabBar::mousePressEvent(QMouseEvent *event)
{
QTabBar::mousePressEvent(event);
@@ -87,6 +98,21 @@ void DetachableTabBar::mouseMoveEvent(QMouseEvent *event)
void DetachableTabBar::mouseReleaseEvent(QMouseEvent *event)
{
QTabBar::mouseReleaseEvent(event);
+
+ switch(event->button()) {
+ case Qt::MiddleButton : if (KonsoleSettings::closeTabOnMiddleMouseButton()) {
+ middleMouseButtonClickAt(event->pos());
+ }
+
+ tabId = tabAt(event->pos());
+ if (tabId == -1) {
+ emit newTabRequest();
+ }
+ break;
+ case Qt::LeftButton: _containers = window()->findChildren<Konsole::TabbedViewContainer*>(); break;
+ default: break;
+ }
+
setCursor(_originalCursor);
if (contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) {
diff --git a/src/DetachableTabBar.h b/src/DetachableTabBar.h
index 488ac409..77288786 100644
--- a/src/DetachableTabBar.h
+++ b/src/DetachableTabBar.h
@@ -34,7 +34,10 @@ public:
Q_SIGNALS:
void detachTab(int index);
void moveTabToWindow(int tabIndex, QWidget *otherWindow);
+ void closeTab(int index);
+ void newTabRequest();
protected:
+ void middleMouseButtonClickAt(const QPoint& pos);
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent*event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
@@ -44,6 +47,7 @@ private:
DragType dragType;
QCursor _originalCursor;
QList<TabbedViewContainer*> _containers;
+ int tabId;
};
}
diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp
index caa7abb9..eb934c89 100644
--- a/src/ViewContainer.cpp
+++ b/src/ViewContainer.cpp
@@ -89,6 +89,10 @@ TabbedViewContainer::TabbedViewContainer(ViewManager *connectedViewManager, QWid
connect(tabBarWidget, &DetachableTabBar::detachTab, this, [this](int idx) {
emit detachTab(this, terminalAt(idx));
});
+ connect(tabBarWidget, &DetachableTabBar::closeTab,
+ this, &TabbedViewContainer::closeTerminalTab);
+ connect(tabBarWidget, &DetachableTabBar::newTabRequest,
+ this, [this]{ emit newViewRequest(this); });
connect(this, &TabbedViewContainer::currentChanged, this, &TabbedViewContainer::currentTabChanged);
// The context menu of tab bar
diff --git a/src/settings/TabBarSettings.ui b/src/settings/TabBarSettings.ui
index 03994eaf..d50b76d2 100644
--- a/src/settings/TabBarSettings.ui
+++ b/src/settings/TabBarSettings.ui
@@ -151,6 +151,13 @@
</property>
</widget>
</item>
+ <item row="6" column="0" colspan="2">
+ <widget class="QCheckBox" name="kcfg_CloseTabOnMiddleMouseButton">
+ <property name="text">
+ <string>Close tab on middle-click</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
diff --git a/src/settings/konsole.kcfg b/src/settings/konsole.kcfg
index e1a3ab5d..e878ede6 100644
--- a/src/settings/konsole.kcfg
+++ b/src/settings/konsole.kcfg
@@ -91,6 +91,10 @@
<label>The .css file to use for the tab bar style</label>
<default></default>
</entry>
+ <entry name="CloseTabOnMiddleMouseButton" type="Bool">
+ <label>Allow middle-clicking on open tabs to close them</label>
+ <default>false</default>
+ </entry>
<entry name="NewTabButton" type="Bool">
<label>Control the visibility of 'New Tab' button on the tab bar</label>
<default>false</default>
More information about the kde-doc-english
mailing list