]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
DolphinView: beginAnchoredSelection after setSelected in selectNextItem
[dolphin.git] / src / views / dolphinview.cpp
index 85e652ecf70baa14c8f412399b9f421d89d4c8a6..c12e3d5f7d080c9e3712ac5ec890af08af442cc1 100644 (file)
@@ -12,6 +12,9 @@
 #include "dolphinitemlistview.h"
 #include "dolphinnewfilemenuobserver.h"
 #include "draganddrophelper.h"
+#ifndef QT_NO_ACCESSIBILITY
+#include "kitemviews/accessibility/kitemlistviewaccessible.h"
+#endif
 #include "kitemviews/kfileitemlistview.h"
 #include "kitemviews/kfileitemmodel.h"
 #include "kitemviews/kitemlistcontainer.h"
@@ -50,6 +53,9 @@
 #include <kwidgetsaddons_version.h>
 
 #include <QAbstractItemView>
+#ifndef QT_NO_ACCESSIBILITY
+#include <QAccessible>
+#endif
 #include <QActionGroup>
 #include <QApplication>
 #include <QClipboard>
@@ -199,8 +205,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
     connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection);
     connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError);
     connect(m_model, &KFileItemModel::fileItemsChanged, this, &DolphinView::fileItemsChanged);
-    // #473377: Use a QueuedConnection to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns.
-    connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved, Qt::QueuedConnection);
+    connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved);
 
     connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel);
 
@@ -376,9 +381,8 @@ void DolphinView::setGroupedSorting(bool grouped)
 
     ViewProperties props(viewPropertiesUrl());
     props.setGroupedSorting(grouped);
-    props.save();
 
-    m_container->controller()->model()->setGroupedSorting(grouped);
+    m_model->setGroupedSorting(grouped);
 
     Q_EMIT groupedSortingChanged(grouped);
 }
@@ -758,7 +762,23 @@ void DolphinView::renameSelectedItems()
 
     } else {
         KIO::RenameFileDialog *dialog = new KIO::RenameFileDialog(items, this);
-        connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished);
+        connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, [this, items](const QList<QUrl> &urls) {
+            // The model may have already been updated, so it's possible that we don't find the old items.
+            for (int i = 0; i < items.count(); ++i) {
+                const int index = m_model->index(items[i]);
+                if (index >= 0) {
+                    QHash<QByteArray, QVariant> data;
+                    data.insert("text", urls[i].fileName());
+                    m_model->setData(index, data);
+                }
+            }
+
+            forceUrlsSelection(urls.first(), urls);
+            updateSelectionState();
+        });
+        connect(dialog, &KIO::RenameFileDialog::error, this, [this](KJob *job) {
+            KMessageBox::error(this, job->errorString());
+        });
 
         dialog->open();
     }
@@ -1120,7 +1140,7 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes)
 void DolphinView::slotItemMiddleClicked(int index)
 {
     const KFileItem &item = m_model->fileItem(index);
-    const QUrl &url = openItemAsFolderUrl(item);
+    const QUrl &url = openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
     const auto modifiers = QGuiApplication::keyboardModifiers();
     if (!url.isEmpty()) {
         // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
@@ -1861,6 +1881,7 @@ void DolphinView::selectNextItem()
         }
         if (nextItem >= 0) {
             selectionManager->setSelected(nextItem, 1);
+            selectionManager->beginAnchoredSelection(nextItem);
         }
         m_selectNextItem = false;
     }
@@ -2030,6 +2051,7 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con
 
             if (!newNameExistsAlready) {
                 forceUrlsSelection(newUrl, {newUrl});
+                updateSelectionState();
 
                 // Only connect the result signal if there is no item with the new name
                 // in the model yet, see bug 328262.
@@ -2273,11 +2295,6 @@ QUrl DolphinView::viewPropertiesUrl() const
     return url;
 }
 
-void DolphinView::slotRenameDialogRenamingFinished(const QList<QUrl> &urls)
-{
-    forceUrlsSelection(urls.first(), urls);
-}
-
 void DolphinView::forceUrlsSelection(const QUrl &current, const QList<QUrl> &selected)
 {
     clearSelection();
@@ -2323,6 +2340,12 @@ void DolphinView::showLoadingPlaceholder()
 {
     m_placeholderLabel->setText(i18n("Loading…"));
     m_placeholderLabel->setVisible(true);
+#ifndef QT_NO_ACCESSIBILITY
+    if (QAccessible::isActive()) {
+        auto accessibleViewInterface = static_cast<KItemListViewAccessible *>(QAccessible::queryAccessibleInterface(m_view));
+        accessibleViewInterface->announceOverallViewState(m_placeholderLabel->text());
+    }
+#endif
 }
 
 void DolphinView::updatePlaceholderLabel()
@@ -2372,6 +2395,12 @@ void DolphinView::updatePlaceholderLabel()
     }
 
     m_placeholderLabel->setVisible(true);
+#ifndef QT_NO_ACCESSIBILITY
+    if (QAccessible::isActive()) {
+        auto accessibleViewInterface = static_cast<KItemListViewAccessible *>(QAccessible::queryAccessibleInterface(m_view));
+        accessibleViewInterface->announceOverallViewState(m_placeholderLabel->text());
+    }
+#endif
 }
 
 bool DolphinView::tryShowNameToolTip(QHelpEvent *event)