]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Keep renamed file(s) in view
authorEmirald Mateli <aldo.mateli@gmail.com>
Sun, 17 Sep 2017 09:07:44 +0000 (11:07 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 17 Sep 2017 09:12:46 +0000 (11:12 +0200)
When renaming a file, if its new name causes it to scroll out of view,
Dolphin will not scroll to the location of the new file.
This patch aims to address that. This affects all view modes.

CCBUG: 354330

Test Plan:
1. Have many files in a directory (or several files, just zoom in a lot)
2. Rename a file so that it will move out of view

Differential Revision: https://phabricator.kde.org/D6312

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

index 5fcec9241217e9d1d950eecb63d827873471186b..2ca51f52dc8dc07988d4899c2a16ac7243a559af 100644 (file)
@@ -635,6 +635,9 @@ void DolphinView::renameSelectedItems()
                 this, &DolphinView::slotRoleEditingFinished);
     } else {
         RenameDialog* dialog = new RenameDialog(this, items);
+
+        connect(dialog, &RenameDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished);
+
         dialog->setAttribute(Qt::WA_DeleteOnClose);
         dialog->show();
         dialog->raise();
@@ -1308,9 +1311,7 @@ QUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh
 void DolphinView::observeCreatedItem(const QUrl& url)
 {
     if (m_active) {
-        clearSelection();
-        markUrlAsCurrent(url);
-        markUrlsAsSelected({url});
+        forceUrlsSelection(url, {url});
     }
 }
 
@@ -1541,6 +1542,8 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
             KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job);
             job->uiDelegate()->setAutoErrorHandlingEnabled(true);
 
+            forceUrlsSelection(newUrl, {newUrl});
+
             if (!newNameExistsAlready) {
                 // Only connect the result signal if there is no item with the new name
                 // in the model yet, see bug 328262.
@@ -1747,3 +1750,16 @@ QUrl DolphinView::viewPropertiesUrl() const
     url.setPath(m_viewPropertiesContext);
     return url;
 }
+
+void DolphinView::slotRenameDialogRenamingFinished(const QList<QUrl>& urls)
+{
+    forceUrlsSelection(urls.first(), urls);
+}
+
+void DolphinView::forceUrlsSelection(const QUrl& current, const QList<QUrl>& selected)
+{
+    clearSelection();
+    m_clearSelectionBeforeSelectingNewItems = true;
+    markUrlAsCurrent(current);
+    markUrlsAsSelected(selected);
+}
index 5c832efd1fe8acc813366ca41f02f07a312c0a3a..911103b5d70bfd62ce4c39bb55fd7d7d6aa918ca 100644 (file)
@@ -576,6 +576,7 @@ private 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);
 
     /*
      * Is called when new items get pasted or dropped.
@@ -760,6 +761,14 @@ private:
      */
     QUrl viewPropertiesUrl() const;
 
+    /**
+     * Clears the selection and updates current item and selection according to the parameters
+     *
+     * @param current URL to be set as current
+     * @param selected list of selected items
+     */
+    void forceUrlsSelection(const QUrl& current, const QList<QUrl>& selected);
+
 private:
     void updatePalette();
 
index df4827b3a5a4ba2d8703f490a842f80e675d4cfd..6309bfbdfecf6b4c95b4e996ecd3d58c2416bbe1 100644 (file)
@@ -162,6 +162,11 @@ void RenameDialog::renameItem(const KFileItem &item, const QString& newName)
     KIO::Job * job = KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo);
     KJobWidgets::setWindow(job, widget);
     KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job);
+
+    if (!job->error()) {
+        m_renamedItems << newUrl;
+    }
+
     job->uiDelegate()->setAutoErrorHandlingEnabled(true);
 }
 
@@ -223,6 +228,10 @@ void RenameDialog::renameItems()
             renameItem(item, newName);
         }
     }
+
+    if (!m_items.empty()) {
+        emit renamingFinished(m_renamedItems);
+    }
 }
 
 QString RenameDialog::indexedName(const QString& name, int index, const QChar& indexPlaceHolder)
index 3964c0a5c4fe05e14db941dedb22131f60189118..7ead0ca9f8531dd2ca156329706b18c6afd6469b 100644 (file)
@@ -41,6 +41,9 @@ public:
     explicit RenameDialog(QWidget* parent, const KFileItemList& items);
     virtual ~RenameDialog();
 
+signals:
+    void renamingFinished(const QList<QUrl>& urls);
+
 private slots:
     void slotAccepted();
     void slotTextChanged(const QString& newName);
@@ -63,6 +66,7 @@ private:
 
 private:
     bool m_renameOneItem;
+    QList<QUrl> m_renamedItems;
     QString m_newName;
     QLineEdit* m_lineEdit;
     KFileItemList m_items;