]> cloud.milkyroute.net Git - dolphin.git/commitdiff
The paste operation should ignore the current selection to behave similar as Konquero...
authorPeter Penz <peter.penz19@gmail.com>
Sat, 29 Mar 2008 07:44:03 +0000 (07:44 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 29 Mar 2008 07:44:03 +0000 (07:44 +0000)
Some internal cleanups are still required (see TODO comments), so that after finishing the operation an indication can be given to the user in the statusbar (must go for breakfast now, otherwise I'll eat my keyboard...).

BUG: 159862

svn path=/trunk/KDE/kdebase/apps/; revision=791354

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h
src/dolphinview.cpp

index 008212bea56108b3698d4c6519992c4fde4f9402..e17987fdd0c399d9d4774bb8cb0dca2976fe6583 100644 (file)
@@ -95,6 +95,24 @@ void DolphinContextMenu::open()
     }
 }
 
+void DolphinContextMenu::pasteIntoFolder()
+{
+    // TODO: this method should go into DolphinView (see DolphinContextMenu::createPasteAction())
+    Q_ASSERT(m_selectedItems.count() == 1);
+    Q_ASSERT(m_fileInfo.isDir());
+
+    QClipboard* clipboard = QApplication::clipboard();
+    const QMimeData* mimeData = clipboard->mimeData();
+
+    const KUrl::List source = KUrl::List::fromMimeData(mimeData);
+    const KUrl& dest = m_fileInfo.url();
+    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
+        KonqOperations::copy(m_mainWindow, KonqOperations::MOVE, source, dest);
+        clipboard->clear();
+    } else {
+        KonqOperations::copy(m_mainWindow, KonqOperations::COPY, source, dest);
+    }
+}
 
 void DolphinContextMenu::openTrashContextMenu()
 {
@@ -230,7 +248,7 @@ void DolphinContextMenu::openViewportContextMenu()
     popup->addMenu(newMenu->menu());
     popup->addSeparator();
 
-    QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
+    QAction* pasteAction = createPasteAction();
     popup->addAction(pasteAction);
 
     // setup 'View Mode' menu
@@ -281,7 +299,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     // insert 'Cut', 'Copy' and 'Paste'
     QAction* cutAction = collection->action(KStandardAction::name(KStandardAction::Cut));
     QAction* copyAction  = collection->action(KStandardAction::name(KStandardAction::Copy));
-    QAction* pasteAction = collection->action(KStandardAction::name(KStandardAction::Paste));
+    QAction* pasteAction = createPasteAction();
 
     popup->addAction(cutAction);
     popup->addAction(copyAction);
@@ -415,4 +433,21 @@ QString DolphinContextMenu::placesName(const KUrl& url) const
     return name;
 }
 
+QAction* DolphinContextMenu::createPasteAction()
+{
+    // TODO: move this method as QAction* action pasteAction() into DolphinMainWindow
+    QAction* action = 0;
+    if ((m_selectedItems.count() == 1) && m_fileInfo.isDir()) {
+        action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
+        const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+        const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
+        action->setEnabled(!pasteData.isEmpty());
+        connect(action, SIGNAL(triggered()), this, SLOT(pasteIntoFolder()));
+    } else {
+        action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
+    }
+
+    return action;
+}
+
 #include "dolphincontextmenu.moc"
index a7cd9c01da420fe70c37ee2b6be6a90d8311af27..0b4d2bf5395e73a8cc5f4f2ca636a8c3dcfa0caf 100644 (file)
@@ -69,6 +69,9 @@ public:
     /** Opens the context menu model. */
     void open();
 
+private slots:
+    void pasteIntoFolder();
+
 private:
     void openTrashContextMenu();
     void openTrashItemContextMenu();
@@ -108,6 +111,8 @@ private:
      */
     QString placesName(const KUrl& url) const;
 
+    QAction* createPasteAction();
+
 private:
     struct Entry
     {
index 3f8933bd31b1b6f28470957bb3a1a34651312069..d905e5cabf0dd207f0b0584a200521fc7254e273 100644 (file)
@@ -1102,41 +1102,12 @@ void DolphinView::paste()
     const QMimeData* mimeData = clipboard->mimeData();
 
     const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
-
-    // per default the pasting is done into the current URL of the view
-    KUrl destUrl = url();
-
-    // check whether the pasting should be done into a selected directory
-    const KUrl::List selectedUrls = this->selectedUrls();
-    if (selectedUrls.count() == 1) {
-        const KFileItem fileItem(S_IFDIR,
-                                 KFileItem::Unknown,
-                                 selectedUrls.first(),
-                                 true);
-        if (fileItem.isDir()) {
-            // only one item is selected which is a directory, hence paste
-            // into this directory
-            destUrl = selectedUrls.first();
-            if (sourceUrls.contains(destUrl)) {
-                const QString text = i18nc("@info", "The folder <filename>%1</filename> is pasted into itself. Is this intended?", fileItem.name());
-                int result = KMessageBox::questionYesNo(window(),
-                                                        text,
-                                                        i18nc("@title:window", "Paste into Folder"),
-                                                        KGuiItem(i18nc("@action:button", "Paste"), "dialog-ok"),
-                                                        KGuiItem(i18nc("@action:button", "Cancel"), "dialog-cancel"));
-                if (result == KMessageBox::No) {
-                    return;
-                }
-            }
-        }
-    }
-
     if (KonqMimeData::decodeIsCutSelection(mimeData)) {
-        KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, destUrl);
+        KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url());
         emit doingOperation(KonqFileUndoManager::MOVE);
         clipboard->clear();
     } else {
-        KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, destUrl);
+        KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url());
         emit doingOperation(KonqFileUndoManager::COPY);
     }
 }
@@ -1163,19 +1134,6 @@ QPair<bool, QString> DolphinView::pasteInfo() const
         ret.second = i18nc("@action:inmenu", "Paste");
     }
 
-    if (ret.first) {
-        const KFileItemList items = selectedItems();
-        const uint count = items.count();
-        if (count > 1) {
-            // pasting should not be allowed when more than one file
-            // is selected
-            ret.first = false;
-        } else if (count == 1) {
-            // Only one file is selected. Pasting is only allowed if this
-            // file is a directory.
-            ret.first = items.first().isDir();
-        }
-    }
     return ret;
 }