]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Select copied/moved items automatically if no item is already selected. This gives...
authorPeter Penz <peter.penz19@gmail.com>
Fri, 8 May 2009 16:44:51 +0000 (16:44 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 8 May 2009 16:44:51 +0000 (16:44 +0000)
BUG: 191723

svn path=/trunk/KDE/kdebase/apps/; revision=965344

src/dolphinview.cpp
src/dolphinview.h

index bddd4b5bf57f552c0287e952eb1c6d4fc01cd7ba..ec675455896749846a20dd2394653c5b2375a30d 100644 (file)
@@ -90,6 +90,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_isContextMenuOpen(false),
     m_ignoreViewProperties(false),
     m_assureVisibleCurrentIndex(false),
+    m_selectClipboardItems(false),
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_controller(0),
@@ -147,7 +148,7 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
             this, SIGNAL(redirection(KUrl, KUrl)));
     connect(m_dirLister, SIGNAL(completed()),
-            this, SLOT(restoreCurrentItem()));
+            this, SLOT(slotDirListerCompleted()));
     connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
             this, SLOT(slotRefreshItems()));
 
@@ -157,6 +158,10 @@ DolphinView::DolphinView(QWidget* parent,
     connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
             this, SLOT(observeCreatedItem(const KUrl&)));
 
+    // when a copy/move-operation has been finished, the pasted items should get selected
+    connect(KIO::FileUndoManager::self(), SIGNAL(jobRecordingFinished(CommandType)),
+           this, SLOT(slotJobRecordingFinished(CommandType)));
+
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
 }
@@ -606,7 +611,7 @@ QString DolphinView::statusBarText() const
 
 void DolphinView::setUrl(const KUrl& url)
 {
-    // remember current item candidate (see restoreCurrentItem())
+    // remember current item candidate (see slotDirListerCompleted())
     m_currentItemUrl = url;
     updateView(url, KUrl());
 }
@@ -1141,6 +1146,15 @@ void DolphinView::restoreSelection()
     changeSelection(m_selectedItems);
 }
 
+void DolphinView::slotJobRecordingFinished(CommandType command)
+{
+    // Assure that the pasted items get selected. This must be done
+    // asynchronously in slotDirListerCompleted().
+    m_selectClipboardItems = ((command == KIO::FileUndoManager::Copy) ||
+                              (command == KIO::FileUndoManager::Move)) &&
+                             !hasSelection();
+}
+
 void DolphinView::emitContentsMoved()
 {
     // only emit the contents moved signal if:
@@ -1179,9 +1193,10 @@ void DolphinView::slotRequestUrlChange(const KUrl& url)
     m_controller->setUrl(url);
 }
 
-void DolphinView::restoreCurrentItem()
+void DolphinView::slotDirListerCompleted()
 {
     if (!m_currentItemUrl.isEmpty()) {
+        // assure that the current item remains visible
         const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
         if (dirIndex.isValid()) {
             const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
@@ -1194,6 +1209,31 @@ void DolphinView::restoreCurrentItem()
         }
         m_currentItemUrl.clear();
     }
+
+    if (m_selectClipboardItems) {
+        m_selectClipboardItems = false;
+
+        // select all items that have been pasted from the clipboard to
+        // the current directory
+        const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+        const KUrl::List copiedUrls = KUrl::List::fromMimeData(mimeData);
+
+        QSet<QString> fileNames;
+        foreach (const KUrl& url, copiedUrls) {
+            fileNames.insert(url.fileName());
+        }
+
+        QItemSelectionModel* selectionModel = itemView()->selectionModel();
+        const int rowCount = m_proxyModel->rowCount();
+        for (int row = 0; row < rowCount; ++row) {
+            const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
+            const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
+            const KUrl url = m_dolphinModel->itemForIndex(dirIndex).url();
+            if (fileNames.contains(url.fileName())) {
+                selectionModel->select(proxyIndex, QItemSelectionModel::Select);
+            }
+        }
+    }
 }
 
 void DolphinView::slotRefreshItems()
index 7014aeb02f595f29b07f81cf80139c619cae6030..cb48caf5679a381c4d94be7b7d0242eaaed8ca7b 100644 (file)
@@ -38,6 +38,8 @@
 #include <QListView>
 #include <QWidget>
 
+typedef KIO::FileUndoManager::CommandType CommandType;
+
 class DolphinController;
 class DolphinColumnView;
 class DolphinDetailsView;
@@ -643,10 +645,10 @@ private slots:
     void slotRequestUrlChange(const KUrl& url);
 
     /**
-     * Restores the current item (= item that has the keyboard focus)
-     * to m_currentItemUrl.
+     * Invoked when the directory lister has completed the loading of
+     * items. Assures that pasted items and renamed items get seleced.
      */
-    void restoreCurrentItem();
+    void slotDirListerCompleted();
 
     /**
      * Is invoked when the KDirLister indicates refreshed items.
@@ -680,6 +682,12 @@ private slots:
      */
     void restoreSelection();
 
+    /**
+     * Invoked when the undo manager indicates a finished operation.
+     * If a copy/move-operation has been done, the pasted items get selected.
+     */
+    void slotJobRecordingFinished(CommandType command);
+
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
@@ -754,6 +762,7 @@ private:
     bool m_isContextMenuOpen : 1;   // TODO: workaround for Qt-issue 207192
     bool m_ignoreViewProperties : 1;
     bool m_assureVisibleCurrentIndex : 1;
+    bool m_selectClipboardItems : 1;
 
     Mode m_mode;