X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/37327c9b0aae112c5890703cba1f0157043007e0..9b5f56980bc4d2f399a6b828c94b23f3626c9d21:/src/dolphintabwidget.cpp diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index a09a769d3..254e654a7 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -8,7 +8,6 @@ #include "dolphin_generalsettings.h" #include "dolphintabbar.h" -#include "dolphintabpage.h" #include "dolphinviewcontainer.h" #include @@ -88,15 +87,8 @@ void DolphinTabWidget::readProperties(const KConfigGroup& group) if (i >= count()) { openNewActivatedTab(); } - if (group.hasKey("Tab Data " % QString::number(i))) { - // Tab state created with Dolphin > 4.14.x - const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray()); - tabPageAt(i)->restoreState(state); - } else { - // Tab state created with Dolphin <= 4.14.x - const QByteArray state = group.readEntry("Tab " % QString::number(i), QByteArray()); - tabPageAt(i)->restoreStateV1(state); - } + const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray()); + tabPageAt(i)->restoreState(state); } const int index = group.readEntry("Active Tab Index", 0); @@ -128,12 +120,9 @@ bool DolphinTabWidget::isUrlOpen(const QUrl &url) const void DolphinTabWidget::openNewActivatedTab() { std::unique_ptr oldNavigatorState; - if (currentTabPage()->primaryViewActive()) { + if (currentTabPage()->primaryViewActive() || !m_navigatorsWidget->secondaryUrlNavigator()) { oldNavigatorState = m_navigatorsWidget->primaryUrlNavigator()->visualState(); } else { - if (!m_navigatorsWidget->secondaryUrlNavigator()) { - m_navigatorsWidget->createSecondaryUrlNavigator(); - } oldNavigatorState = m_navigatorsWidget->secondaryUrlNavigator()->visualState(); } @@ -156,10 +145,14 @@ void DolphinTabWidget::openNewActivatedTab() void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl) { openNewTab(primaryUrl, secondaryUrl); - setCurrentIndex(count() - 1); + if (GeneralSettings::openNewTabAfterLastTab()) { + setCurrentIndex(count() - 1); + } else { + setCurrentIndex(currentIndex() + 1); + } } -void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement) +void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl) { QWidget* focusWidget = QApplication::focusWidget(); @@ -169,10 +162,17 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU 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)); + }); + int newTabIndex = -1; - if (tabPlacement == AfterCurrentTab) { + if (!GeneralSettings::openNewTabAfterLastTab()) { newTabIndex = currentIndex() + 1; } + insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage)); if (focusWidget) { @@ -186,14 +186,20 @@ void DolphinTabWidget::openDirectories(const QList& dirs, bool splitView) { Q_ASSERT(dirs.size() > 0); + bool somethingWasAlreadyOpen = false; + QList::const_iterator it = dirs.constBegin(); while (it != dirs.constEnd()) { const QUrl& primaryUrl = *(it++); const QPair indexInfo = indexByUrl(primaryUrl); const int index = indexInfo.first; const bool isInPrimaryView = indexInfo.second; + + // When the user asks for a URL that's already open, activate it instead + // of opening a second copy if (index >= 0) { - setCurrentIndex(index); + somethingWasAlreadyOpen = true; + activateTab(index); const auto tabPage = tabPageAt(index); if (isInPrimaryView) { tabPage->primaryViewContainer()->setActive(true); @@ -204,13 +210,19 @@ void DolphinTabWidget::openDirectories(const QList& dirs, bool splitView) // Required for updateViewState() call in openFiles() to work as expected // If there is a selection, updateViewState() calls are effectively a no-op tabPage->activeViewContainer()->view()->clearSelection(); - continue; - } - if (splitView && (it != dirs.constEnd())) { + } else if (splitView && (it != dirs.constEnd())) { const QUrl& secondaryUrl = *(it++); - openNewActivatedTab(primaryUrl, secondaryUrl); + if (somethingWasAlreadyOpen) { + openNewTab(primaryUrl, secondaryUrl); + } else { + openNewActivatedTab(primaryUrl, secondaryUrl); + } } else { - openNewActivatedTab(primaryUrl); + if (somethingWasAlreadyOpen) { + openNewTab(primaryUrl); + } else { + openNewActivatedTab(primaryUrl); + } } } } @@ -378,7 +390,9 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url) tabBar()->setTabText(index, tabName(tabPageAt(index))); tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile)); if (tabBar()->isVisible()) { - tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); + // ensure the path url ends with a slash to have proper folder icon for remote folders + const QUrl pathUrl = QUrl(url.adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/")); + tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(pathUrl))); } else { // Mark as dirty, actually load once the tab bar actually gets shown tabBar()->setTabIcon(index, QIcon()); @@ -401,13 +415,16 @@ void DolphinTabWidget::currentTabChanged(int index) m_lastViewedTab->disconnectNavigators(); m_lastViewedTab->setActive(false); } + if (tabPage->splitViewEnabled() && !m_navigatorsWidget->secondaryUrlNavigator()) { + m_navigatorsWidget->createSecondaryUrlNavigator(); + } DolphinViewContainer* viewContainer = tabPage->activeViewContainer(); Q_EMIT activeViewChanged(viewContainer); Q_EMIT currentUrlChanged(viewContainer->url()); tabPage->setActive(true); tabPage->connectNavigators(m_navigatorsWidget); m_navigatorsWidget->setSecondaryNavigatorVisible(tabPage->splitViewEnabled()); - m_lastViewedTab = tabPageAt(index); + m_lastViewedTab = tabPage; } void DolphinTabWidget::tabInserted(int index) @@ -419,7 +436,9 @@ void DolphinTabWidget::tabInserted(int index) for (int i = 0; i < count(); ++i) { const QUrl url = tabPageAt(i)->activeViewContainer()->url(); if (tabBar()->tabIcon(i).isNull()) { - tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(url))); + // ensure the path url ends with a slash to have proper folder icon for remote folders + const QUrl pathUrl = QUrl(url.adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/")); + tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(pathUrl))); } if (tabBar()->tabToolTip(i).isEmpty()) { tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));