#include "viewproperties.h"
#include "zoomlevelinfo.h"
+#include <kdebug.h>
+
/**
* Helper function for sorting items with qSort() in
* DolphinView::renameSelectedItems().
m_isContextMenuOpen(false),
m_ignoreViewProperties(false),
m_assureVisibleCurrentIndex(false),
- m_selectClipboardItems(false),
m_mode(DolphinView::IconsView),
m_topLayout(0),
m_controller(0),
m_currentItemUrl(),
m_createdItemUrl(),
m_selectedItems(),
+ m_newFileNames(),
m_expandedDragSource(0)
{
m_topLayout = new QVBoxLayout(this);
void DolphinView::setUrl(const KUrl& url)
{
+ m_newFileNames.clear();
+
// remember current item candidate (see slotDirListerCompleted())
- m_selectClipboardItems = false;
m_currentItemUrl = url;
updateView(url, KUrl());
}
const KUrl& destPath,
QDropEvent* event)
{
+ addNewFileNames(event->mimeData());
DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
}
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());
- }
-
+ 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();
}
}
void DolphinView::pasteToUrl(const KUrl& url)
{
- m_selectClipboardItems = true;
+ addNewFileNames(QApplication::clipboard()->mimeData());
KonqOperations::doPaste(this, url);
}
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"
#include <QKeyEvent>
#include <QLinkedList>
#include <QListView>
+#include <QSet>
#include <QWidget>
typedef KIO::FileUndoManager::CommandType CommandType;
*/
QMimeData* selectionMimeData() const;
+ /**
+ * Is invoked after a paste operation or a drag & drop
+ * operation and adds the filenames of all URLs from \a mimeData to
+ * m_newFileNames. This allows to select all newly added
+ * items in slotDirListerCompleted().
+ */
+ void addNewFileNames(const QMimeData* mimeData);
+
private:
bool m_active : 1;
bool m_showPreview : 1;
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;
KUrl m_rootUrl;
KUrl m_currentItemUrl;
KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
- KFileItemList m_selectedItems; //this is used for making the View to remember selections after F5
+ KFileItemList m_selectedItems; // this is used for making the View to remember selections after F5
+
+ /**
+ * Remembers the filenames that have been added by a paste operation
+ * or a drag & drop operation. Allows to select the items in
+ * slotDirListerCompleted().
+ */
+ QSet<QString> m_newFileNames;
QAbstractItemView* m_expandedDragSource;
};