]> cloud.milkyroute.net Git - dolphin.git/commitdiff
dolphinview: when rename dialog finishes, immediately update the model and the selection
authorJin Liu <m.liu.jin@gmail.com>
Fri, 11 Oct 2024 08:21:14 +0000 (16:21 +0800)
committerJin Liu <m.liu.jin@gmail.com>
Sat, 12 Oct 2024 13:23:46 +0000 (21:23 +0800)
On sucessful return of the rename dialog, we update
the model and the selection immediately to reflect
the new name. This is to avoid the short duration
after the rename during which the selection is lost.

Currently, after the rename dialog finishes, the selection
is briefly lost for about 1 second until the view
automatically refreshes.

This patch updates the model and selection immediately
after the dialog finishes, so the renamed file is still
selected.

BUG: 481717

src/views/dolphinview.cpp
src/views/dolphinview.h

index ab39173dacbed1c29fb8adb35e99418ea12e1aad..f9f32d35cbc28b6fda0e41667dfd06cccb94788c 100644 (file)
@@ -757,7 +757,20 @@ 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());
         });
@@ -2276,11 +2289,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();
index c985f4eb9616998c612504ac891e18e6560609a1..e78a9ca9d9a16b2022302e64851cdc41d9289005 100644 (file)
@@ -698,7 +698,6 @@ private Q_SLOTS:
     void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event);
     void slotModelChanged(KItemModelBase *current, KItemModelBase *previous);
     void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons);
-    void slotRenameDialogRenamingFinished(const QList<QUrl> &urls);
     void slotSelectedItemTextPressed(int index);
     void slotItemCreatedFromJob(KIO::Job *, const QUrl &, const QUrl &to);
     void slotItemLinkCreatedFromJob(KIO::Job *, const QUrl &, const QString &, const QUrl &to);