]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Using the "document-properties" icon for the Properties entry of the RMB context...
[dolphin.git] / src / dolphinview.cpp
index 4fc3248c81a5085ee2e58224ba10f557ff3f6d5b..8b914de4079819ab9cdcdf265526cd8c5153f3bd 100644 (file)
@@ -88,6 +88,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_tabsForFiles(false),
     m_isContextMenuOpen(false),
     m_ignoreViewProperties(false),
+    m_assureVisibleCurrentIndex(false),
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_controller(0),
@@ -142,6 +143,8 @@ DolphinView::DolphinView(QWidget* parent,
             this, SIGNAL(redirection(KUrl, KUrl)));
     connect(m_dirLister, SIGNAL(completed()),
             this, SLOT(restoreCurrentItem()));
+    connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
+            this, SLOT(slotRefreshItems()));
 
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
@@ -149,7 +152,6 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
-    kDebug() << "Deleted view " << m_expandedDragSource;
     delete m_expandedDragSource;
     m_expandedDragSource = 0;
 }
@@ -315,7 +317,10 @@ bool DolphinView::hasSelection() const
 
 void DolphinView::clearSelection()
 {
-    itemView()->selectionModel()->clear();
+    QItemSelectionModel* selModel = itemView()->selectionModel();
+    const QModelIndex currentIndex = selModel->currentIndex();
+    selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
+                                            QItemSelectionModel::Clear);
 }
 
 KFileItemList DolphinView::selectedItems() const
@@ -627,30 +632,31 @@ void DolphinView::renameSelectedItems()
         const QString newName = dialog.newName();
         if (newName.isEmpty()) {
             emit errorMessage(dialog.errorString());
-        } else {
-            // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
-            // as one operation instead of n rename operations like it is done now...
-            Q_ASSERT(newName.contains('#'));
-
-            // currently the items are sorted by the selection order, resort
-            // them by the file name
-            qSort(items.begin(), items.end(), lessThan);
-
-            // iterate through all selected items and rename them...
-            int index = 1;
-            foreach (const KFileItem& item, items) {
-                const KUrl& oldUrl = item.url();
-                QString number;
-                number.setNum(index++);
-
-                QString name = newName;
-                name.replace('#', number);
-
-                if (oldUrl.fileName() != name) {
-                    KUrl newUrl = oldUrl;
-                    newUrl.setFileName(name);
-                    KonqOperations::rename(this, oldUrl, newUrl);
-                }
+            return;
+        }
+
+        // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
+        // as one operation instead of n rename operations like it is done now...
+        Q_ASSERT(newName.contains('#'));
+
+        // currently the items are sorted by the selection order, resort
+        // them by the file name
+        qSort(items.begin(), items.end(), lessThan);
+
+        // iterate through all selected items and rename them...
+        int index = 1;
+        foreach (const KFileItem& item, items) {
+            const KUrl& oldUrl = item.url();
+            QString number;
+            number.setNum(index++);
+
+            QString name = newName;
+            name.replace('#', number);
+
+            if (oldUrl.fileName() != name) {
+                KUrl newUrl = oldUrl;
+                newUrl.setFileName(name);
+                KonqOperations::rename(this, oldUrl, newUrl);
             }
         }
     } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
@@ -674,13 +680,18 @@ void DolphinView::renameSelectedItems()
         const QString& newName = dialog.newName();
         if (newName.isEmpty()) {
             emit errorMessage(dialog.errorString());
-        } else {
-            const KUrl& oldUrl = items.first().url();
-            KUrl newUrl = oldUrl;
-            newUrl.setFileName(newName);
-            KonqOperations::rename(this, oldUrl, newUrl);
+            return;
         }
+
+        const KUrl& oldUrl = items.first().url();
+        KUrl newUrl = oldUrl;
+        newUrl.setFileName(newName);
+        KonqOperations::rename(this, oldUrl, newUrl);
     }
+
+    // assure that the current index remains visible when KDirLister
+    // will notify the view about changed items
+    m_assureVisibleCurrentIndex = true;
 }
 
 void DolphinView::trashSelectedItems()
@@ -849,14 +860,12 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         break;
 
     case QEvent::MouseButtonPress:
-        kDebug() << "m_expandedDragSource = " << m_expandedDragSource;
         if ((watched == itemView()->viewport()) && (m_expandedDragSource != 0)) {
             // Listening to a mousebutton press event to delete expanded views is a
             // workaround, as it seems impossible for the FolderExpander to know when
             // a dragging outside a view has been finished. However it works quite well:
             // A mousebutton press event indicates that a drag operation must be
             // finished already.
-            kDebug() << "Deleted view " << m_expandedDragSource;
             m_expandedDragSource->deleteLater();
             m_expandedDragSource = 0;
         }
@@ -869,8 +878,16 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         break;
 
     case QEvent::KeyPress:
-        if ((watched == itemView()) && (m_toolTipManager != 0)) {
-            m_toolTipManager->hideTip();
+        if (watched == itemView()) {
+            if (m_toolTipManager != 0) {
+                m_toolTipManager->hideTip();
+            }
+
+            // clear the selection when Escape has been pressed
+            QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
+            if (keyEvent->key() == Qt::Key_Escape) {
+                clearSelection();
+            }
         }
         break;
 
@@ -1026,30 +1043,7 @@ void DolphinView::updateAdditionalInfoActions(KActionCollection* collection)
 
 QPair<bool, QString> DolphinView::pasteInfo() const
 {
-    QPair<bool, QString> ret;
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-
-    KUrl::List urls = KUrl::List::fromMimeData(mimeData);
-    if (!urls.isEmpty()) {
-        // disable the paste action if no writing is supported
-        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url());
-        ret.first = KonqFileItemCapabilities(KFileItemList() << item).supportsWriting();
-
-        if (urls.count() == 1) {
-            const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, urls.first(), true);
-            ret.second = item.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
-                                        i18nc("@action:inmenu", "Paste One File");
-
-        } else {
-            ret.second = i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls.count());
-        }
-    } else {
-        ret.first = false;
-        ret.second = i18nc("@action:inmenu", "Paste");
-    }
-
-    return ret;
+    return KonqOperations::pasteInfo(url());
 }
 
 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles)
@@ -1073,11 +1067,9 @@ void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
         return;
 
     if (DragAndDropHelper::instance().isDragSource(view)) {
-        kDebug() << "Is current drag source";
         // We must store for later deletion.
         if (m_expandedDragSource != 0) {
             // The old stored view is obviously not the drag source anymore.
-            kDebug() << "Deleted old view " << m_expandedDragSource;
             m_expandedDragSource->deleteLater();
             m_expandedDragSource = 0;
         }
@@ -1085,7 +1077,6 @@ void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
         m_expandedDragSource = view;
     }
     else {
-        kDebug() << "Deleted new view " << view;
         view->deleteLater();
     }
 }
@@ -1142,6 +1133,14 @@ void DolphinView::restoreCurrentItem()
     }
 }
 
+void DolphinView::slotRefreshItems()
+{
+    if (m_assureVisibleCurrentIndex) {
+        m_assureVisibleCurrentIndex = false;
+        itemView()->scrollTo(itemView()->currentIndex());
+    }
+}
+
 void DolphinView::loadDirectory(const KUrl& url, bool reload)
 {
     if (!url.isValid()) {
@@ -1417,16 +1416,7 @@ bool DolphinView::isCutItem(const KFileItem& item) const
 
 void DolphinView::pasteToUrl(const KUrl& url)
 {
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-
-    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
-    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
-        KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url);
-        clipboard->clear();
-    } else {
-        KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url);
-    }
+    KonqOperations::doPaste(this, url);
 }
 
 void DolphinView::updateZoomLevel(int oldZoomLevel)