X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/90dec129f5586dfe1415a53a1bcd64b547a2f3ac..dcf397ae512850805dbe37fc03ece82be2660bd0:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 0450eb460..aa0bb9619 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -64,6 +64,7 @@ #include "renamedialog.h" #include "tooltips/tooltipmanager.h" #include "settings/dolphinsettings.h" +#include "versioncontrolobserver.h" #include "viewproperties.h" #include "zoomlevelinfo.h" @@ -90,7 +91,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), @@ -99,15 +99,18 @@ DolphinView::DolphinView(QWidget* parent, m_columnView(0), m_fileItemDelegate(0), m_selectionModel(0), + m_selectionChangedTimer(0), m_dolphinModel(dolphinModel), m_dirLister(dirLister), m_proxyModel(proxyModel), m_previewGenerator(0), m_toolTipManager(0), + m_versionControlObserver(0), m_rootUrl(), - m_currentItemUrl(), + m_activeItemUrl(), m_createdItemUrl(), m_selectedItems(), + m_newFileNames(), m_expandedDragSource(0) { m_topLayout = new QVBoxLayout(this); @@ -158,10 +161,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()); } @@ -192,7 +191,7 @@ void DolphinView::setActive(bool active) QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); if (active) { - emit selectionChanged(selectedItems()); + emitSelectionChangedSignal(); } else { color.setAlpha(150); } @@ -333,6 +332,7 @@ void DolphinView::clearSelection() const QModelIndex currentIndex = selModel->currentIndex(); selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current | QItemSelectionModel::Clear); + m_selectedItems.clear(); } KFileItemList DolphinView::selectedItems() const @@ -379,7 +379,7 @@ int DolphinView::selectedItemsCount() const return m_columnView->selectedItems().count(); } - return itemView()->selectionModel()->selection().count(); + return itemView()->selectionModel()->selectedIndexes().count(); } void DolphinView::setContentsPosition(int x, int y) @@ -522,6 +522,10 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl) loadDirectory(url); } + // When changing the URL there is no need to keep the version + // data of the previous URL. + m_dolphinModel->clearVersionData(); + emit startedPathLoading(url); } @@ -609,11 +613,16 @@ QString DolphinView::statusBarText() const return text; } +QList DolphinView::versionControlActions(const KFileItemList& items) const +{ + return items.isEmpty() + ? m_versionControlObserver->contextMenuActions(url().path(KUrl::AddTrailingSlash)) + : m_versionControlObserver->contextMenuActions(items); +} + void DolphinView::setUrl(const KUrl& url) { - // remember current item candidate (see slotDirListerCompleted()) - m_selectClipboardItems = false; - m_currentItemUrl = url; + m_newFileNames.clear(); updateView(url, KUrl()); } @@ -649,16 +658,23 @@ void DolphinView::renameSelectedItems() if (itemCount > 1) { // More than one item has been selected for renaming. Open // a rename dialog and rename all items afterwards. - RenameDialog dialog(this, items); - if (dialog.exec() == QDialog::Rejected) { + QPointer dialog = new RenameDialog(this, items); + if (dialog->exec() == QDialog::Rejected) { + delete dialog; return; } - const QString newName = dialog.newName(); + const QString newName = dialog->newName(); if (newName.isEmpty()) { - emit errorMessage(dialog.errorString()); + emit errorMessage(dialog->errorString()); + delete dialog; return; } + delete dialog; + + // the selection would be invalid after renaming the items, so just clear + // it before + clearSelection(); // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations // as one operation instead of n rename operations like it is done now... @@ -697,16 +713,19 @@ void DolphinView::renameSelectedItems() } else { Q_ASSERT(itemCount == 1); - RenameDialog dialog(this, items); - if (dialog.exec() == QDialog::Rejected) { + QPointer dialog = new RenameDialog(this, items); + if (dialog->exec() == QDialog::Rejected) { + delete dialog; return; } - const QString& newName = dialog.newName(); + const QString newName = dialog->newName(); if (newName.isEmpty()) { - emit errorMessage(dialog.errorString()); + emit errorMessage(dialog->errorString()); + delete dialog; return; } + delete dialog; const KUrl& oldUrl = items.first().url(); KUrl newUrl = oldUrl; @@ -953,6 +972,14 @@ void DolphinView::triggerItem(const KFileItem& item) emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart } +void DolphinView::emitDelayedSelectionChangedSignal() +{ + // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures + // that fast selection changes don't result in expensive operations to + // collect all file items for the signal (see DolphinView::selectedItems()). + m_selectionChangedTimer->start(); +} + void DolphinView::emitSelectionChangedSignal() { emit selectionChanged(DolphinView::selectedItems()); @@ -985,6 +1012,7 @@ void DolphinView::dropUrls(const KFileItem& destItem, const KUrl& destPath, QDropEvent* event) { + addNewFileNames(event->mimeData()); DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this); } @@ -1096,6 +1124,11 @@ bool DolphinView::isTabsForFilesEnabled() const return m_tabsForFiles; } +void DolphinView::activateItem(const KUrl& url) +{ + m_activeItemUrl = url; +} + bool DolphinView::itemsExpandable() const { return (m_detailsView != 0) && m_detailsView->itemsExpandable(); @@ -1147,15 +1180,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: @@ -1196,9 +1220,9 @@ void DolphinView::slotRequestUrlChange(const KUrl& url) void DolphinView::slotDirListerCompleted() { - if (!m_currentItemUrl.isEmpty()) { + if (!m_activeItemUrl.isEmpty()) { // assure that the current item remains visible - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl); + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_activeItemUrl); if (dirIndex.isValid()) { const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); QAbstractItemView* view = itemView(); @@ -1207,33 +1231,26 @@ void DolphinView::slotDirListerCompleted() if (clearSelection) { view->clearSelection(); } + m_activeItemUrl.clear(); } - 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()); - } - - QItemSelectionModel* selectionModel = itemView()->selectionModel(); + if (!m_newFileNames.isEmpty()) { + // select all newly added items created by a paste operation or + // a drag & drop operation const int rowCount = m_proxyModel->rowCount(); + QItemSelection selection; 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); + if (m_newFileNames.contains(url.fileName())) { + selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select); } } + itemView()->selectionModel()->select(selection, QItemSelectionModel::Select); + + m_newFileNames.clear(); } } @@ -1441,6 +1458,12 @@ void DolphinView::createView() m_selectionModel = view->selectionModel(); } + m_selectionChangedTimer = new QTimer(this); + m_selectionChangedTimer->setSingleShot(true); + m_selectionChangedTimer->setInterval(300); + connect(m_selectionChangedTimer, SIGNAL(timeout()), + this, SLOT(emitSelectionChangedSignal())); + // reparent the selection model, as it should not be deleted // when deleting the model m_selectionModel->setParent(this); @@ -1450,6 +1473,14 @@ void DolphinView::createView() m_previewGenerator = new KFilePreviewGenerator(view); m_previewGenerator->setPreviewShown(m_showPreview); + m_versionControlObserver = new VersionControlObserver(view); + connect(m_versionControlObserver, SIGNAL(infoMessage(const QString&)), + this, SIGNAL(infoMessage(const QString&))); + connect(m_versionControlObserver, SIGNAL(errorMessage(const QString&)), + this, SIGNAL(errorMessage(const QString&))); + connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(const QString&)), + this, SIGNAL(operationCompletedMessage(const QString&))); + if (DolphinSettings::instance().generalSettings()->showToolTips()) { m_toolTipManager = new ToolTipManager(view, m_proxyModel); connect(m_controller, SIGNAL(hideToolTip()), @@ -1459,7 +1490,7 @@ void DolphinView::createView() m_topLayout->insertWidget(1, view); connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, SLOT(emitSelectionChangedSignal())); + this, SLOT(emitDelayedSelectionChangedSignal())); connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(emitContentsMoved())); connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)), @@ -1513,6 +1544,7 @@ QAbstractItemView* DolphinView::itemView() const void DolphinView::pasteToUrl(const KUrl& url) { + addNewFileNames(QApplication::clipboard()->mimeData()); KonqOperations::doPaste(this, url); } @@ -1546,5 +1578,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"