From ba0e0457a15cda103e2b9f96b0e8ba16bcef677e Mon Sep 17 00:00:00 2001 From: Herb Miller Jr Date: Wed, 30 Aug 2017 10:46:39 -0400 Subject: [PATCH] Close tab to the left or right. Vivaldi has a nice feature where you can close all tabs to the right of the current tab, which is increasingly popular, but also close tabs to the left. This adds that functionality to Otter. --- src/core/ActionsManager.cpp | 2 ++ src/core/ActionsManager.h | 2 ++ src/ui/MainWindow.cpp | 22 ++++++++++++++++++++++ src/ui/TabBarWidget.cpp | 2 ++ 4 files changed, 28 insertions(+) diff --git a/src/core/ActionsManager.cpp b/src/core/ActionsManager.cpp index 38c2fc89a2..df2df5ed96 100644 --- a/src/core/ActionsManager.cpp +++ b/src/core/ActionsManager.cpp @@ -305,6 +305,8 @@ ActionsManager::ActionsManager(QObject *parent) : QObject(parent), registerAction(SuspendTabAction, QT_TRANSLATE_NOOP("actions", "Suspend Tab"), QString(), QIcon(), ActionDefinition::WindowScope, ActionDefinition::NoFlags); registerAction(CloseTabAction, QT_TRANSLATE_NOOP("actions", "Close Tab"), QString(), ThemesManager::createIcon(QLatin1String("tab-close")), ActionDefinition::WindowScope); registerAction(CloseOtherTabsAction, QT_TRANSLATE_NOOP("actions", "Close Other Tabs"), QString(), ThemesManager::createIcon(QLatin1String("tab-close-other")), ActionDefinition::MainWindowScope); + registerAction(CloseTabsToTheLeftAction, QT_TRANSLATE_NOOP("actions", "Close Tabs to the Left"), QString(), QIcon(), ActionDefinition::MainWindowScope); + registerAction(CloseTabsToTheRightAction, QT_TRANSLATE_NOOP("actions", "Close Tabs to the Right"), QString(), QIcon(), ActionDefinition::MainWindowScope); registerAction(ClosePrivateTabsAction, QT_TRANSLATE_NOOP("actions", "Close All Private Tabs"), QT_TRANSLATE_NOOP("actions", "Close All Private Tabs in Current Window"), QIcon(), ActionDefinition::MainWindowScope, ActionDefinition::NoFlags); registerAction(ClosePrivateTabsPanicAction, QT_TRANSLATE_NOOP("actions", "Close Private Tabs and Windows"), QString(), QIcon(), ActionDefinition::ApplicationScope); registerAction(ReopenTabAction, QT_TRANSLATE_NOOP("actions", "Reopen Previously Closed Tab"), QString(), QIcon(), ActionDefinition::MainWindowScope); diff --git a/src/core/ActionsManager.h b/src/core/ActionsManager.h index cb5d7bcd81..8c5d0b9a92 100644 --- a/src/core/ActionsManager.h +++ b/src/core/ActionsManager.h @@ -104,6 +104,8 @@ class ActionsManager final : public QObject SuspendTabAction, CloseTabAction, CloseOtherTabsAction, + CloseTabsToTheLeftAction, + CloseTabsToTheRightAction, ClosePrivateTabsAction, ClosePrivateTabsPanicAction, ReopenTabAction, diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index f22234f9c4..01064767b4 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -960,6 +960,28 @@ void MainWindow::triggerAction(int identifier, const QVariantMap ¶meters) } } + break; + case ActionsManager::CloseTabsToTheLeftAction: + if (window) + { + for (int index=0; index < getWindowIndex(window->getIdentifier()); index++) + { + Window *leftWindow=getWindowByIndex(index); + if (!leftWindow->isPinned()) leftWindow->requestClose(); + } + } + + break; + case ActionsManager::CloseTabsToTheRightAction: + if (window) + { + for (int index=getWindowIndex(window->getIdentifier()) + 1; index < getWindowCount(); index++) + { + Window *rightWindow=getWindowByIndex(index); + if (!rightWindow->isPinned()) rightWindow->requestClose(); + } + } + break; case ActionsManager::ActivateTabAction: if (window) diff --git a/src/ui/TabBarWidget.cpp b/src/ui/TabBarWidget.cpp index c704555ad6..1e1e184b2d 100644 --- a/src/ui/TabBarWidget.cpp +++ b/src/ui/TabBarWidget.cpp @@ -721,6 +721,8 @@ void TabBarWidget::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator(); menu.addAction(new Action(ActionsManager::CloseTabAction, {}, windowExecutor, &menu)); menu.addAction(new Action(ActionsManager::CloseOtherTabsAction, {{QLatin1String("tab"), window->getIdentifier()}}, windowExecutor, &menu)); + menu.addAction(new Action(ActionsManager::CloseTabsToTheLeftAction, {{QLatin1String("tab"), window->getIdentifier()}}, windowExecutor, &menu)); + menu.addAction(new Action(ActionsManager::CloseTabsToTheRightAction, {{QLatin1String("tab"), window->getIdentifier()}}, windowExecutor, &menu)); menu.addAction(new Action(ActionsManager::ClosePrivateTabsAction, {}, mainWindowExecutor, &menu)); } }