X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/44a21ea51a055c7429ddee866e35b0a5a21c072b..d6c086ad04:/src/dolphintabwidget.cpp diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 600974f56..73c275242 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -116,7 +116,7 @@ void DolphinTabWidget::refreshViews() { const int tabCount = count(); for (int i = 0; i < tabCount; ++i) { - tabBar()->setTabText(i, tabName()); + tabBar()->setTabText(i, tabName(tabPageAt(i))); tabPageAt(i)->refreshViews(); } } @@ -135,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) @@ -151,7 +147,7 @@ void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& s setCurrentIndex(count() - 1); } -void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl) +void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement) { QWidget* focusWidget = QApplication::focusWidget(); @@ -161,7 +157,11 @@ 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()); + int newTabIndex = -1; + if (tabPlacement == AfterCurrentTab) { + newTabIndex = currentIndex() + 1; + } + insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage)); if (focusWidget) { // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened @@ -226,7 +226,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; } @@ -306,7 +307,7 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url) { const int index = indexOf(qobject_cast(sender())); if (index >= 0) { - tabBar()->setTabText(index, tabName()); + 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. @@ -354,12 +355,12 @@ void DolphinTabWidget::tabRemoved(int index) emit tabCountChanged(count()); } -QString DolphinTabWidget::tabName() const +QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const { - if (currentTabPage() == nullptr) { + if (!tabPage) { return QString(); } - QString name = currentTabPage()->activeViewContainer()->getCaption(); + 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("&&"));