From: Peter Penz Date: Sun, 17 Dec 2006 11:52:26 +0000 (+0000) Subject: Reanimated cut-, copy- and paste- functionality as preparation for moving to KonqUndo... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/c28c72619cef1edaf6ca732d293b321f5ac220e5 Reanimated cut-, copy- and paste- functionality as preparation for moving to KonqUndoManager. svn path=/trunk/playground/utils/dolphin/; revision=614325 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 0c527bb51..dd985fc1d 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -657,33 +657,33 @@ void DolphinMainWindow::cut() // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData // in libkonq m_clipboardContainsCutData = true; - /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(), - widget()); - QApplication::clipboard()->setData(data);*/ + + QMimeData* mimeData = new QMimeData(); + const KUrl::List selectedUrls = m_activeView->selectedUrls(); + selectedUrls.populateMimeData(mimeData); + + QApplication::clipboard()->setMimeData(mimeData); } void DolphinMainWindow::copy() { m_clipboardContainsCutData = false; - /* KDE4-TODO: - Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(), - widget()); - QApplication::clipboard()->setData(data);*/ + + QMimeData* mimeData = new QMimeData(); + const KUrl::List selectedUrls = m_activeView->selectedUrls(); + selectedUrls.populateMimeData(mimeData); + + QApplication::clipboard()->setMimeData(mimeData); } void DolphinMainWindow::paste() { - /* KDE4-TODO: - see KonqOperations::doPaste QClipboard* clipboard = QApplication::clipboard(); - QMimeSource* data = clipboard->data(); - if (!KUrlDrag::canDecode(data)) { - return; - } + const QMimeData* mimeData = clipboard->mimeData(); clearStatusBar(); - KUrl::List sourceUrls; - KUrlDrag::decode(data, sourceUrls); + const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData); // per default the pasting is done into the current Url of the view KUrl destUrl(m_activeView->url()); @@ -702,8 +702,12 @@ void DolphinMainWindow::paste() } } - - updateViewProperties(sourceUrls); + // TODO #1: use libkonq commands (see doPaste() implementation + // KIO::Job* job = KIO::pasteClipboard(destUrl, this, false); + // ... + // TODO #2: this boolean doesn't work between instances of dolphin or with konqueror or with other + // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData + // in libkonq if (m_clipboardContainsCutData) { moveUrls(sourceUrls, destUrl); m_clipboardContainsCutData = false; @@ -711,7 +715,7 @@ void DolphinMainWindow::paste() } else { copyUrls(sourceUrls, destUrl); - }*/ + } } void DolphinMainWindow::updatePasteAction() @@ -723,13 +727,12 @@ void DolphinMainWindow::updatePasteAction() QString text(i18n("Paste")); QClipboard* clipboard = QApplication::clipboard(); - const QMimeData* data = clipboard->mimeData(); - /* KDE4-TODO: - if (KUrlDrag::canDecode(data)) { + const QMimeData* mimeData = clipboard->mimeData(); + + KUrl::List urls = KUrl::List::fromMimeData(mimeData); + if (!urls.isEmpty()) { pasteAction->setEnabled(true); - KUrl::List urls; - KUrlDrag::decode(data, urls); const int count = urls.count(); if (count == 1) { pasteAction->setText(i18n("Paste 1 File")); @@ -738,10 +741,10 @@ void DolphinMainWindow::updatePasteAction() pasteAction->setText(i18n("Paste %1 Files").arg(count)); } } - else {*/ + else { pasteAction->setEnabled(false); pasteAction->setText(i18n("Paste")); - //} + } if (pasteAction->isEnabled()) { KUrl::List urls = m_activeView->selectedUrls(); @@ -1597,9 +1600,9 @@ void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest) } void DolphinMainWindow::addPendingUndoJob(KIO::Job* job, - DolphinCommand::Type commandType, - const KUrl::List& source, - const KUrl& dest) + DolphinCommand::Type commandType, + const KUrl::List& source, + const KUrl& dest) { connect(job, SIGNAL(result(KJob*)), this, SLOT(addUndoOperation(KJob*))); diff --git a/src/undomanager.cpp b/src/undomanager.cpp index e6946cfe3..30e0dba35 100644 --- a/src/undomanager.cpp +++ b/src/undomanager.cpp @@ -76,13 +76,15 @@ void UndoManager::addCommand(const DolphinCommand& command) { ++m_historyIndex; + QList::iterator it = m_history.begin(); + it += m_historyIndex; if (m_recordMacro) { DolphinCommand macroCommand = command; macroCommand.m_macroIndex = m_macroCounter; - m_history.insert(m_history.at(m_historyIndex), macroCommand); + m_history.insert(it, macroCommand); } else { - m_history.insert(m_history.at(m_historyIndex), command); + m_history.insert(it, command); } emit undoAvailable(true); @@ -125,7 +127,7 @@ void UndoManager::undo(DolphinMainWindow* mainWindow) calcStepsCount(macroCount, progressCount); /* - * KDE4, ### TODO Only here to avoid possible crash + * KDE4, ### TODO Only here to avoid possible crash */ ProgressIndicator progressIndicator(mainWindow, i18n("Executing undo operation..."), i18n("Executed undo operation."), diff --git a/src/undomanager.h b/src/undomanager.h index c3cfda56e..baed41947 100644 --- a/src/undomanager.h +++ b/src/undomanager.h @@ -21,9 +21,10 @@ #ifndef UNDOMANAGER_H #define UNDOMANAGER_H -#include +#include #include -#include +#include + #include #include @@ -127,7 +128,7 @@ public slots: /** * Performs a redo operation on the last command where an undo * operation has been applied. - * + * * @param mainwindow The mainwindow where to show progress */ void redo(DolphinMainWindow* mainwindow); @@ -182,7 +183,7 @@ private: bool m_recordMacro; int m_historyIndex; int m_macroCounter; - Q3ValueList m_history; + QList m_history; /** * Dependent from the current history index \a m_historyIndex