]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
DolphinMainWindowTest: Add unit test for autosave session feature
[dolphin.git] / src / dolphintabwidget.cpp
index edc1cb7d84f87f12f1d2c03998db3a51c6a119fd..f274ffa2abbb4b7f64555ae9daa329a4b4e6bee7 100644 (file)
@@ -35,12 +35,12 @@ DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidg
     connect(tabBar, &DolphinTabBar::openNewActivatedTab, this, QOverload<int>::of(&DolphinTabWidget::openNewActivatedTab));
     connect(tabBar, &DolphinTabBar::tabDropEvent, this, &DolphinTabWidget::tabDropEvent);
     connect(tabBar, &DolphinTabBar::tabDetachRequested, this, &DolphinTabWidget::detachTab);
-    tabBar->hide();
 
     setTabBar(tabBar);
     setDocumentMode(true);
     setElideMode(Qt::ElideRight);
     setUsesScrollButtons(true);
+    setTabBarAutoHide(true);
 }
 
 DolphinTabPage *DolphinTabWidget::currentTabPage() const
@@ -104,11 +104,17 @@ void DolphinTabWidget::refreshViews()
 
     const int tabCount = count();
     for (int i = 0; i < tabCount; ++i) {
-        tabBar()->setTabText(i, tabName(tabPageAt(i)));
+        updateTabName(i);
         tabPageAt(i)->refreshViews();
     }
 }
 
+void DolphinTabWidget::updateTabName(int index)
+{
+    Q_ASSERT(index >= 0);
+    tabBar()->setTabText(index, tabName(tabPageAt(index)));
+}
+
 bool DolphinTabWidget::isUrlOpen(const QUrl &url) const
 {
     return viewOpenAtDirectory(url).has_value();
@@ -163,9 +169,7 @@ void DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryU
     connect(tabPage, &DolphinTabPage::activeViewChanged, this, &DolphinTabWidget::activeViewChanged);
     connect(tabPage, &DolphinTabPage::activeViewUrlChanged, this, &DolphinTabWidget::tabUrlChanged);
     connect(tabPage->activeViewContainer(), &DolphinViewContainer::captionChanged, this, [this, tabPage]() {
-        const int tabIndex = indexOf(tabPage);
-        Q_ASSERT(tabIndex >= 0);
-        tabBar()->setTabText(tabIndex, tabName(tabPage));
+        updateTabName(indexOf(tabPage));
     });
 
     if (position == NewTabPosition::FollowSetting) {
@@ -407,7 +411,7 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url)
 {
     const int index = indexOf(qobject_cast<QWidget *>(sender()));
     if (index >= 0) {
-        tabBar()->setTabText(index, tabName(tabPageAt(index)));
+        updateTabName(index);
         tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
         if (tabBar()->isVisible()) {
             // ensure the path url ends with a slash to have proper folder icon for remote folders
@@ -422,6 +426,8 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url)
         if (index == currentIndex()) {
             Q_EMIT currentUrlChanged(url);
         }
+
+        Q_EMIT urlChanged(url);
     }
 }
 
@@ -451,7 +457,7 @@ void DolphinTabWidget::tabInserted(int index)
 {
     QTabWidget::tabInserted(index);
 
-    if (count() > 1) {
+    if (tabBar()->isVisible()) {
         // Resolve all pending tab icons
         for (int i = 0; i < count(); ++i) {
             const QUrl url = tabPageAt(i)->activeViewContainer()->url();
@@ -464,8 +470,6 @@ void DolphinTabWidget::tabInserted(int index)
                 tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
             }
         }
-
-        tabBar()->show();
     }
 
     Q_EMIT tabCountChanged(count());
@@ -475,12 +479,6 @@ void DolphinTabWidget::tabRemoved(int index)
 {
     QTabWidget::tabRemoved(index);
 
-    // If only one tab is left, then remove the tab entry so that
-    // closing the last tab is not possible.
-    if (count() < 2) {
-        tabBar()->hide();
-    }
-
     Q_EMIT tabCountChanged(count());
 }