]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / dolphinview.cpp
index bddd4b5bf57f552c0287e952eb1c6d4fc01cd7ba..e947508f07f8ecd5e9fc69ac117eca3afa58113f 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()));
 
@@ -606,7 +607,8 @@ QString DolphinView::statusBarText() const
 
 void DolphinView::setUrl(const KUrl& url)
 {
-    // remember current item candidate (see restoreCurrentItem())
+    // remember current item candidate (see slotDirListerCompleted())
+    m_selectClipboardItems = false;
     m_currentItemUrl = url;
     updateView(url, KUrl());
 }
@@ -1179,9 +1181,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 +1197,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()
@@ -1472,6 +1500,7 @@ QAbstractItemView* DolphinView::itemView() const
 
 void DolphinView::pasteToUrl(const KUrl& url)
 {
+    m_selectClipboardItems = true;
     KonqOperations::doPaste(this, url);
 }