X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/82b2dbd3ec568a6e6fe01a8e75739b25cae25f15..b7ceb51b44da394089689a2649cc8529c1f74669:/src/dolphintabwidget.cpp diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index d9b7d7e13..c708c6494 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -23,17 +23,18 @@ #include "dolphintabpage.h" #include "dolphinviewcontainer.h" -#include -#include #include +#include #include #include -#include + +#include +#include DolphinTabWidget::DolphinTabWidget(QWidget* parent) : QTabWidget(parent), m_placesSelectorVisible(true), - m_previousTab(0) + m_lastViewedTab(0) { connect(this, &DolphinTabWidget::tabCloseRequested, this, static_cast(&DolphinTabWidget::closeTab)); @@ -60,6 +61,18 @@ DolphinTabPage* DolphinTabWidget::currentTabPage() const return tabPageAt(currentIndex()); } +DolphinTabPage* DolphinTabWidget::nextTabPage() const +{ + const int index = currentIndex() + 1; + return tabPageAt(index < count() ? index : 0); +} + +DolphinTabPage* DolphinTabWidget::prevTabPage() const +{ + const int index = currentIndex() - 1; + return tabPageAt(index >= 0 ? index : (count() - 1)); +} + DolphinTabPage* DolphinTabWidget::tabPageAt(const int index) const { return static_cast(widget(index)); @@ -103,6 +116,7 @@ void DolphinTabWidget::refreshViews() { const int tabCount = count(); for (int i = 0; i < tabCount; ++i) { + tabBar()->setTabText(i, tabName(tabPageAt(i))); tabPageAt(i)->refreshViews(); } } @@ -121,14 +135,10 @@ void DolphinTabWidget::openNewActivatedTab() // The URL navigator of the new tab should have the same editable state // as the current tab - KUrlNavigator* navigator = newActiveViewContainer->urlNavigator(); - navigator->setUrlEditable(isUrlEditable); + newActiveViewContainer->urlNavigator()->setUrlEditable(isUrlEditable); - if (isUrlEditable) { - // If a new tab is opened and the URL is editable, assure that - // the user can edit the URL without manually setting the focus - navigator->setFocus(); - } + // Always focus the new tab's view + newActiveViewContainer->view()->setFocus(); } void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl) @@ -147,7 +157,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU this, &DolphinTabWidget::activeViewChanged); connect(tabPage, &DolphinTabPage::activeViewUrlChanged, this, &DolphinTabWidget::tabUrlChanged); - addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(primaryUrl)); + addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage)); if (focusWidget) { // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened @@ -212,7 +222,8 @@ void DolphinTabWidget::closeTab(const int index) Q_ASSERT(index < count()); if (count() < 2) { - // Never close the last tab. + // Close Dolphin when closing the last tab. + parentWidget()->close(); return; } @@ -292,7 +303,7 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url) { const int index = indexOf(qobject_cast(sender())); if (index >= 0) { - tabBar()->setTabText(index, tabName(url)); + tabBar()->setTabText(index, tabName(tabPageAt(index))); tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); // Emit the currentUrlChanged signal if the url of the current tab has been changed. @@ -304,8 +315,8 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url) void DolphinTabWidget::currentTabChanged(int index) { - // previous tab deactivation - if (DolphinTabPage* tabPage = tabPageAt(m_previousTab)) { + // last-viewed tab deactivation + if (DolphinTabPage* tabPage = tabPageAt(m_lastViewedTab)) { tabPage->setActive(false); } DolphinTabPage* tabPage = tabPageAt(index); @@ -313,7 +324,7 @@ void DolphinTabWidget::currentTabChanged(int index) emit activeViewChanged(viewContainer); emit currentUrlChanged(viewContainer->url()); tabPage->setActive(true); - m_previousTab = index; + m_lastViewedTab = index; } void DolphinTabWidget::tabInserted(int index) @@ -340,20 +351,13 @@ void DolphinTabWidget::tabRemoved(int index) emit tabCountChanged(count()); } -QString DolphinTabWidget::tabName(const QUrl& url) const +QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const { - QString name; - if (url == QUrl(QStringLiteral("file:///"))) { - name = '/'; - } else { - name = url.adjusted(QUrl::StripTrailingSlash).fileName(); - if (name.isEmpty()) { - name = url.scheme(); - } else { - // Make sure that a '&' inside the directory name is displayed correctly - // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() - name.replace('&', QLatin1String("&&")); - } + if (!tabPage) { + return QString(); } - return name; + QString name = tabPage->activeViewContainer()->caption(); + // Make sure that a '&' inside the directory name is displayed correctly + // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() + return name.replace('&', QLatin1String("&&")); }