diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index 01852e266..b621c2392 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -127,6 +127,7 @@ void TabBar::overflowChanged(bool overflowed) } } +//TODO: replace these 3 w/ preferencable mbox void TabBar::closeAllButCurrent() { QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close other tabs?"), @@ -137,6 +138,26 @@ void TabBar::closeAllButCurrent() } } +void TabBar::closeToRight() +{ + QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close all tabs to the right?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + + if (button == QMessageBox::Yes) { + emit closeToRight(m_clickedTab); + } +} + +void TabBar::closeToLeft() +{ + QMessageBox::StandardButton button = QMessageBox::question(this, tr("Close Tabs"), tr("Do you really want to close all tabs to the left?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + + if (button == QMessageBox::Yes) { + emit closeToLeft(m_clickedTab); + } +} + QSize TabBar::tabSizeHint(int index, bool fast) const { if (!m_window->isVisible()) { @@ -341,6 +362,8 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event) menu.addAction(m_window->action(QSL("Other/RestoreClosedTab"))); menu.addSeparator(); menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); + menu.addAction(tr("Close Tabs To The Right"), this, SLOT(closeToRight())); + menu.addAction(tr("Close Tabs To The Left"), this, SLOT(closeToLeft())); menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab())); menu.addSeparator(); } diff --git a/src/lib/tabwidget/tabbar.h b/src/lib/tabwidget/tabbar.h index 397c44b66..07ce56493 100644 --- a/src/lib/tabwidget/tabbar.h +++ b/src/lib/tabwidget/tabbar.h @@ -52,6 +52,8 @@ signals: void reloadTab(int index); void stopTab(int index); void closeAllButCurrent(int index); + void closeToRight(int index); + void closeToLeft(int index); void duplicateTab(int index); void detachTab(int index); @@ -73,6 +75,8 @@ private slots: void closeCurrentTab(); void closeAllButCurrent(); + void closeToRight(); + void closeToLeft(); void closeTabFromButton(); private: diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index 41dc4d008..76ed0593a 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -128,6 +128,8 @@ TabWidget::TabWidget(BrowserWindow* window, QWidget* parent) connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int))); connect(m_tabBar, SIGNAL(stopTab(int)), this, SLOT(stopTab(int))); connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int))); + connect(m_tabBar, SIGNAL(closeToRight(int)), this, SLOT(closeToRight(int))); + connect(m_tabBar, SIGNAL(closeToLeft(int)), this, SLOT(closeToLeft(int))); connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int))); connect(m_tabBar, SIGNAL(detachTab(int)), this, SLOT(detachTab(int))); connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int))); @@ -618,6 +620,37 @@ void TabWidget::closeAllButCurrent(int index) } } +void TabWidget::closeToRight(int index) +{ + if (!validIndex(index)) { + return; + } + + foreach (WebTab* tab, allTabs(false)) { + int tabIndex = tab->tabIndex(); + if (index >= tabIndex) { + continue; + } + requestCloseTab(tabIndex); + } +} + + +void TabWidget::closeToLeft(int index) +{ + if (!validIndex(index)) { + return; + } + + foreach (WebTab* tab, allTabs(false)) { + int tabIndex = tab->tabIndex(); + if (index <= tabIndex) { + continue; + } + requestCloseTab(tabIndex); + } +} + void TabWidget::detachTab(int index) { WebTab* tab = weTab(index); diff --git a/src/lib/tabwidget/tabwidget.h b/src/lib/tabwidget/tabwidget.h index 467b9278f..21a09e2e2 100644 --- a/src/lib/tabwidget/tabwidget.h +++ b/src/lib/tabwidget/tabwidget.h @@ -117,6 +117,8 @@ public slots: void reloadAllTabs(); void stopTab(int index); void closeAllButCurrent(int index); + void closeToRight(int index); + void closeToLeft(int index); void detachTab(int index); void restoreClosedTab(QObject* obj = 0); void restoreAllClosedTabs();