]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
dolphinview: after inline renaming, immediately update the selection
[dolphin.git] / src / dolphinviewcontainer.cpp
index 3fedef6fc9f220db1e28ae3089d4d6fc4ec666eb..62c29a1fc684eb4fc5a4c4cbeca2c0a9578bb9c9 100644 (file)
@@ -33,6 +33,9 @@
 #include <KShell>
 #include <kio_version.h>
 
+#ifndef QT_NO_ACCESSIBILITY
+#include <QAccessible>
+#endif
 #include <QApplication>
 #include <QDesktopServices>
 #include <QDropEvent>
@@ -41,6 +44,7 @@
 #include <QRegularExpression>
 #include <QTimer>
 #include <QUrl>
+#include <QUrlQuery>
 
 // An overview of the widgets contained by this ViewContainer
 struct LayoutStructure {
@@ -435,6 +439,14 @@ void DolphinViewContainer::showMessage(const QString &message, KMessageWidget::M
         m_messageWidget->hide();
     }
     m_messageWidget->animatedShow();
+
+#ifndef QT_NO_ACCESSIBILITY
+    if (QAccessible::isActive() && isActive()) {
+        // To announce the new message keyboard focus must be moved to the message label. However, we do not have direct access to the label that is internal
+        // to the KMessageWidget. Instead we setFocus() on the KMessageWidget and trust that it has set correct focus handling.
+        m_messageWidget->setFocus();
+    }
+#endif
 }
 
 void DolphinViewContainer::readSettings()
@@ -533,6 +545,15 @@ QString DolphinViewContainer::captionWindowTitle() const
 
 QString DolphinViewContainer::caption() const
 {
+    // see KUrlNavigatorPrivate::firstButtonText().
+    if (url().path().isEmpty() || url().path() == QLatin1Char('/')) {
+        QUrlQuery query(url());
+        const QString title = query.queryItemValue(QStringLiteral("title"));
+        if (!title.isEmpty()) {
+            return title;
+        }
+    }
+
     if (isSearchModeEnabled()) {
         if (currentSearchText().isEmpty()) {
             return i18n("Search");
@@ -542,12 +563,11 @@ QString DolphinViewContainer::caption() const
     }
 
     KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
-    const QString pattern = url().adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/?");
-    const auto &matchedPlaces =
-        placesModel->match(placesModel->index(0, 0), KFilePlacesModel::UrlRole, QRegularExpression::anchoredPattern(pattern), 1, Qt::MatchRegularExpression);
 
-    if (!matchedPlaces.isEmpty()) {
-        return placesModel->text(matchedPlaces.first());
+    QModelIndex url_index = placesModel->closestItem(url());
+
+    if (url_index.isValid() && placesModel->url(url_index).matches(url(), QUrl::StripTrailingSlash)) {
+        return placesModel->text(url_index);
     }
 
     if (!url().isLocalFile()) {
@@ -741,6 +761,18 @@ void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item)
         job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
         connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished);
         job->start();
+    } else {
+        // If no 2nd service available, try to open archives in new tabs, regardless of the "Open archives as folder" setting.
+        const QUrl &url = DolphinView::openItemAsFolderUrl(item);
+        const auto modifiers = QGuiApplication::keyboardModifiers();
+        if (!url.isEmpty()) {
+            // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
+            if (modifiers & Qt::ShiftModifier) {
+                Q_EMIT activeTabRequested(url);
+            } else {
+                Q_EMIT tabRequested(url);
+            }
+        }
     }
 }
 
@@ -954,10 +986,13 @@ void DolphinViewContainer::slotCurrentDirectoryRemoved()
         const QString dirPath = url().toLocalFile();
         const QString newPath = getNearestExistingAncestorOfPath(dirPath);
         const QUrl newUrl = QUrl::fromLocalFile(newPath);
-        setUrl(newUrl);
-    }
-
-    showMessage(xi18n("Current location changed, <filename>%1</filename> is no longer accessible.", location), KMessageWidget::Warning);
+        // #473377: Delay changing the url to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns.
+        QTimer::singleShot(0, this, [&, newUrl, location] {
+            setUrl(newUrl);
+            showMessage(xi18n("Current location changed, <filename>%1</filename> is no longer accessible.", location), KMessageWidget::Warning);
+        });
+    } else
+        showMessage(xi18n("Current location changed, <filename>%1</filename> is no longer accessible.", location), KMessageWidget::Warning);
 }
 
 void DolphinViewContainer::slotOpenUrlFinished(KJob *job)