]> cloud.milkyroute.net Git - dolphin.git/commitdiff
implemented functionality for closing tabs
authorPeter Penz <peter.penz19@gmail.com>
Sun, 13 Apr 2008 20:20:30 +0000 (20:20 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 13 Apr 2008 20:20:30 +0000 (20:20 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=796587

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h

index 74d93329cf7b3a2e15f4d03630b186ff21d025a1..2de0f29a70bc172d73c11d5176e044aa3276f0d1 100644 (file)
@@ -268,6 +268,7 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
         // Only one view is open currently and hence no tab is shown at
         // all. Before creating a tab for 'url', provide a tab for the current URL.
         m_tabBar->addTab(KIcon("folder"), m_activeViewContainer->url().fileName());
+        m_tabBar->blockSignals(false);
     }
 
     m_tabBar->addTab(KIcon("folder"), url.fileName());
@@ -693,6 +694,46 @@ void DolphinMainWindow::setActiveTab(int index)
                                                          viewTab.secondaryView);
 }
 
+void DolphinMainWindow::closeTab(int index)
+{
+    Q_ASSERT(index >= 0);
+    Q_ASSERT(index < m_viewTab.count());
+    if (m_viewTab.count() == 1) {
+          // the last tab may never get closed
+        return;
+    }
+
+    if (index == m_tabIndex) {
+        // The tab that should be closed is the active tab. Activate the
+        // previous tab before closing the tab.
+        setActiveTab((index > 0) ? index - 1 : 1);
+    }
+
+    // delete tab
+    m_viewTab[index].primaryView->deleteLater();
+    if (m_viewTab[index].secondaryView != 0) {
+        m_viewTab[index].secondaryView->deleteLater();
+    }
+    m_viewTab[index].splitter->deleteLater();
+    m_viewTab.erase(m_viewTab.begin() + index);
+
+    m_tabBar->blockSignals(true);
+    m_tabBar->removeTab(index);
+
+    if (m_tabIndex > index) {
+        m_tabIndex--;
+        Q_ASSERT(m_tabIndex >= 0);
+    }
+
+    // if only one tab is left, also remove the tab entry so that
+    // closing the last tab is not possible
+    if (m_viewTab.count() == 1) {
+        m_tabBar->removeTab(0);
+    } else {
+        m_tabBar->blockSignals(false);
+    }
+}
+
 void DolphinMainWindow::init()
 {
     DolphinSettings& settings = DolphinSettings::instance();
@@ -729,8 +770,12 @@ void DolphinMainWindow::init()
 
     m_tabBar = new KTabBar(this);
     m_tabBar->setHoverCloseButton(true);
+    m_tabBar->setHoverCloseButtonDelayed(false);
     connect(m_tabBar, SIGNAL(currentChanged(int)),
             this, SLOT(setActiveTab(int)));
+    connect(m_tabBar, SIGNAL(closeRequest(int)),
+           this, SLOT(closeTab(int)));
+    m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open
 
     QWidget* centralWidget = new QWidget(this);
     m_centralWidgetLayout = new QVBoxLayout(centralWidget);
index fa02f082132af0adad0a2cc1aa807407a59abdd1..3ac766d7713bac30263d2c913d5aa846efac5931 100644 (file)
@@ -331,6 +331,11 @@ private slots:
      */
     void setActiveTab(int index);
 
+    /**
+     * Closes the tab with the index \index and activates the tab with index - 1.
+     */
+    void closeTab(int index);
+
 private:
     DolphinMainWindow(int id);
     void init();