From e90a297c8004af22f04c65eec361dcf30ae25220 Mon Sep 17 00:00:00 2001 From: Bob Bai Date: Sat, 23 Nov 2019 15:55:40 +0800 Subject: [PATCH 1/7] Enable closing a tab by middle button click --- shell/shell.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shell/shell.cpp b/shell/shell.cpp index 5a7113fa7..a97139e39 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -171,6 +171,18 @@ bool Shell::eventFilter(QObject *obj, QEvent *event) dEvent->setAccepted(true); return true; } + + // Handle middle button click events on the tab bar + if (obj == m_tabWidget && event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mEvent = static_cast(event); + if (mEvent->button() == Qt::MiddleButton) { + int tabIndex = m_tabWidget->tabBar()->tabAt(mEvent->pos()); + if (tabIndex != -1) { + m_tabWidget->removeTab(tabIndex); + return true; + } + } + } return false; } -- GitLab From aa3bbfbc9847968bb9ef8b5d1da2683cd7fec1ac Mon Sep 17 00:00:00 2001 From: Bob Bai Date: Tue, 26 Nov 2019 12:46:35 +0800 Subject: [PATCH 2/7] Fix removeTab => closeTab --- shell/shell.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/shell.cpp b/shell/shell.cpp index a97139e39..3a75764a7 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -178,7 +178,7 @@ bool Shell::eventFilter(QObject *obj, QEvent *event) if (mEvent->button() == Qt::MiddleButton) { int tabIndex = m_tabWidget->tabBar()->tabAt(mEvent->pos()); if (tabIndex != -1) { - m_tabWidget->removeTab(tabIndex); + closeTab(tabIndex); return true; } } -- GitLab From 0b5accbcbeccc09596c55fc10a7e7e1144eeb0bc Mon Sep 17 00:00:00 2001 From: Bob Bai Date: Tue, 26 Nov 2019 20:48:19 +0800 Subject: [PATCH 3/7] Add undo close tab menu item --- shell/shell.cpp | 23 +++++++++++++++++++++++ shell/shell.h | 4 ++++ shell/shell.rc | 1 + 3 files changed, 28 insertions(+) diff --git a/shell/shell.cpp b/shell/shell.cpp index 3a75764a7..a27529f5f 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -374,6 +374,13 @@ void Shell::setupActions() actionCollection()->setDefaultShortcuts(m_prevTabAction, KStandardShortcut::tabPrev()); m_prevTabAction->setEnabled( false ); connect( m_prevTabAction, &QAction::triggered, this, &Shell::activatePrevTab ); + + m_undoCloseTab = actionCollection()->addAction(QStringLiteral("undo-close-tab")); + m_undoCloseTab->setText( i18n("Undo close tab") ); + actionCollection()->setDefaultShortcut(m_undoCloseTab, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_T)); + m_undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo"))); + m_undoCloseTab->setEnabled( false ); + connect( m_undoCloseTab, &QAction::triggered, this, &Shell::undoCloseTab ); } void Shell::saveProperties(KConfigGroup &group) @@ -639,6 +646,7 @@ void Shell::setActiveTab( int tab ) void Shell::closeTab( int tab ) { KParts::ReadWritePart* const part = m_tabs[tab].part; + QUrl url = part->url(); if( part->closeUrl() && m_tabs.count() > 1 ) { if( part->factory() ) @@ -647,6 +655,8 @@ void Shell::closeTab( int tab ) part->deleteLater(); m_tabs.removeAt( tab ); m_tabWidget->removeTab( tab ); + m_undoCloseTab->setEnabled( true ); + m_closedTabUrls.push_back( url ); if( m_tabWidget->count() == 1 ) { @@ -762,6 +772,19 @@ void Shell::activatePrevTab() setActiveTab( prevTab ); } +void Shell::undoCloseTab() +{ + if ( m_closedTabUrls.size() == 0 ) + return; + + const QUrl lastTabUrl = m_closedTabUrls.takeLast(); + + if ( m_closedTabUrls.size() == 0 ) + m_undoCloseTab->setEnabled(false); + + openUrl(lastTabUrl); +} + void Shell::setTabIcon( const QMimeType& mimeType ) { int i = findTabIndex( sender() ); diff --git a/shell/shell.h b/shell/shell.h index 5b8e6cfe3..6dd13e546 100644 --- a/shell/shell.h +++ b/shell/shell.h @@ -21,6 +21,7 @@ #include #include #include +#include #include // krazy:exclude=includes @@ -124,6 +125,7 @@ private Q_SLOTS: void closeTab( int tab ); void activateNextTab(); void activatePrevTab(); + void undoCloseTab(); void moveTabData( int from, int to ); void slotFitWindowToPage( const QSize& pageViewSize, const QSize& pageSize ); @@ -168,8 +170,10 @@ private: bool closeEnabled; }; QList m_tabs; + QLinkedList m_closedTabUrls; QAction* m_nextTabAction; QAction* m_prevTabAction; + QAction* m_undoCloseTab; #ifndef Q_OS_WIN KActivities::ResourceInstance* m_activityResource; diff --git a/shell/shell.rc b/shell/shell.rc index 93fbc4175..0452b3f23 100644 --- a/shell/shell.rc +++ b/shell/shell.rc @@ -5,6 +5,7 @@ +