X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/90dec129f5586dfe1415a53a1bcd64b547a2f3ac..232dcda76c486a8d4f0b021bd32b8eef01880595:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 0450eb460..e59f9b282 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -67,6 +67,8 @@ #include "viewproperties.h" #include "zoomlevelinfo.h" +#include + /** * Helper function for sorting items with qSort() in * DolphinView::renameSelectedItems(). @@ -90,7 +92,6 @@ 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), @@ -108,6 +109,7 @@ DolphinView::DolphinView(QWidget* parent, m_currentItemUrl(), m_createdItemUrl(), m_selectedItems(), + m_newFileNames(), m_expandedDragSource(0) { m_topLayout = new QVBoxLayout(this); @@ -158,10 +160,6 @@ 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()); } @@ -611,8 +609,9 @@ QString DolphinView::statusBarText() const void DolphinView::setUrl(const KUrl& url) { + m_newFileNames.clear(); + // remember current item candidate (see slotDirListerCompleted()) - m_selectClipboardItems = false; m_currentItemUrl = url; updateView(url, KUrl()); } @@ -985,6 +984,7 @@ void DolphinView::dropUrls(const KFileItem& destItem, const KUrl& destPath, QDropEvent* event) { + addNewFileNames(event->mimeData()); DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this); } @@ -1147,15 +1147,6 @@ 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: @@ -1211,29 +1202,21 @@ void DolphinView::slotDirListerCompleted() 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 fileNames; - foreach (const KUrl& url, copiedUrls) { - fileNames.insert(url.fileName()); - } - + if (!m_newFileNames.isEmpty()) { + // select all newly added items created by a paste operation or + // a drag & drop operation 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())) { + if (m_newFileNames.contains(url.fileName())) { selectionModel->select(proxyIndex, QItemSelectionModel::Select); } } + + m_newFileNames.clear(); } } @@ -1513,6 +1496,7 @@ QAbstractItemView* DolphinView::itemView() const void DolphinView::pasteToUrl(const KUrl& url) { + addNewFileNames(QApplication::clipboard()->mimeData()); KonqOperations::doPaste(this, url); } @@ -1546,5 +1530,12 @@ QMimeData* DolphinView::selectionMimeData() const return m_dolphinModel->mimeData(selection.indexes()); } +void DolphinView::addNewFileNames(const QMimeData* mimeData) +{ + const KUrl::List urls = KUrl::List::fromMimeData(mimeData); + foreach (const KUrl& url, urls) { + m_newFileNames.insert(url.fileName()); + } +} #include "dolphinview.moc"