diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 9a00f5251..c5186cd25 100644 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -176,6 +176,10 @@ void FormMain::createConnections() { this, SLOT(loadWebBrowserMenu(int))); connect(m_ui->m_actionCloseCurrentTab, SIGNAL(triggered()), m_ui->m_tabWidget, SLOT(closeCurrentTab())); + connect(m_ui->m_actionAddBrowser, SIGNAL(triggered()), + m_ui->m_tabWidget, SLOT(addEmptyBrowser())); + connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()), + m_ui->m_tabWidget, SLOT(closeAllTabsExceptCurrent())); } void FormMain::loadWebBrowserMenu(int index) { diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index e726c8627..5adc7d44e 100644 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -76,14 +76,50 @@ void TabWidget::setupIcons() { m_cornerButton->setIcon(IconThemeFactory::getInstance()->fromTheme("list-add")); } -void TabWidget::closeTab(int index) { +bool TabWidget::closeTab(int index) { if (tabBar()->tabType(index) == TabBar::Closable) { removeTab(index); + return true; + } + else { + return false; } } -void TabWidget::closeCurrentTab() { - closeTab(currentIndex()); +bool TabWidget::closeCurrentTab() { + return closeTab(currentIndex()); +} + +void TabWidget::closeAllTabsExceptCurrent() { + // Close tabs after active tab. + int index_of_active = currentIndex(); + int total_count = count(); + int iterative_index = 0; + + while (total_count-- > 0) { + if (iterative_index < index_of_active) { + // Deleting tab on the left from the active one. + if (closeTab(iterative_index)) { + // We successfully deleted that LEFT tab. + index_of_active--; + } + else { + // We reached "non-closable" tab, go forward. + iterative_index++; + } + } + else if (iterative_index > index_of_active) { + // Deleting tab on the right from the active one. + if (!closeTab(iterative_index)) { + // We reached "non-closable" tab, go forward. + iterative_index++; + } + } + else { + // We iterate through active tab now, no deleting; + iterative_index++; + } + } } void TabWidget::removeTab(int index) { diff --git a/src/gui/tabwidget.h b/src/gui/tabwidget.h index 913cb83d4..9a7ef01fd 100644 --- a/src/gui/tabwidget.h +++ b/src/gui/tabwidget.h @@ -59,8 +59,11 @@ class TabWidget : public QTabWidget { void changeIcon(int index, const QIcon &new_icon); // Closes tab with given index and deletes contained widget. - void closeTab(int index); - void closeCurrentTab(); + bool closeTab(int index); + bool closeCurrentTab(); + + // Closes all "closable" tabs except the active tab. + void closeAllTabsExceptCurrent(); // Adds new WebBrowser tab to global TabWidget. int addEmptyBrowser();