From: Holger Freyther Date: Wed, 29 Nov 2006 09:30:41 +0000 (+0000) Subject: Changes to Undo/Redo in regard to ProgressIndicator X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/9a4a17dd4d7f3d195ab4393e057e8eb90b0a3422 Changes to Undo/Redo in regard to ProgressIndicator It was not important to know where the operation was executed, it is important where undo/redo was clicked and this solely indicates where the progress should be shown. Now undo/redo get the MainWindow and can pass that to ProgressIndicator. I'm about to revive m_progressIndicator again svn path=/trunk/playground/utils/dolphin/; revision=609020 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 0d4667db7..af9bd0a01 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -313,6 +313,16 @@ void DolphinMainWindow::slotSelectionChanged() emit selectionChanged(); } +void DolphinMainWindow::slotRedo() +{ + UndoManager::instance().redo(this); +} + +void DolphinMainWindow::slotUndo() +{ + UndoManager::instance().undo(this); +} + void DolphinMainWindow::closeEvent(QCloseEvent* event) { // KDE4-TODO @@ -417,7 +427,7 @@ void DolphinMainWindow::createFolder() statusBar->setMessage(i18n("Created folder %1.",url.path()), DolphinStatusBar::OperationCompleted); - DolphinCommand command(DolphinCommand::CreateFolder, KUrl::List(), url, this); + DolphinCommand command(DolphinCommand::CreateFolder, KUrl::List(), url); UndoManager::instance().addCommand(command); } else { @@ -524,7 +534,7 @@ void DolphinMainWindow::createFile() KUrl::List list; list.append(sourceUrl); - DolphinCommand command(DolphinCommand::CreateFile, list, destUrl, this); + DolphinCommand command(DolphinCommand::CreateFile, list, destUrl); UndoManager::instance().addCommand(command); } @@ -1233,16 +1243,16 @@ void DolphinMainWindow::setupActions() // setup 'Edit' menu UndoManager& undoManager = UndoManager::instance(); - KStdAction::undo(&undoManager, - SLOT(undo()), + KStdAction::undo(this, + SLOT(slotUndo()), actionCollection()); connect(&undoManager, SIGNAL(undoAvailable(bool)), this, SLOT(slotUndoAvailable(bool))); connect(&undoManager, SIGNAL(undoTextChanged(const QString&)), this, SLOT(slotUndoTextChanged(const QString&))); - KStdAction::redo(&undoManager, - SLOT(redo()), + KStdAction::redo(this, + SLOT(slotRedo()), actionCollection()); connect(&undoManager, SIGNAL(redoAvailable(bool)), this, SLOT(slotRedoAvailable(bool))); @@ -1625,7 +1635,7 @@ void DolphinMainWindow::addPendingUndoJob(KIO::Job* job, UndoInfo undoInfo; undoInfo.id = job->progressId(); - undoInfo.command = DolphinCommand(commandType, source, dest, this); + undoInfo.command = DolphinCommand(commandType, source, dest); m_pendingUndoJobs.append(undoInfo); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 6e9f75b7f..dbe6ed4e0 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -163,6 +163,12 @@ public slots: /** Updates the state of the 'Edit' menu actions. */ void slotSelectionChanged(); + /** Executes Redo operation */ + void slotRedo(); + + /** @see slotUndo() */ + void slotUndo(); + protected: /** @see QMainWindow::closeEvent */ virtual void closeEvent(QCloseEvent* event); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 7dbebeab5..e60f6f655 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -263,7 +263,7 @@ void DolphinView::renameSelectedItems() else if (KIO::NetAccess::file_move(source, dest)) { // TODO: From the users point of view he executed one 'rename n files' operation, // but internally we store it as n 'rename 1 file' operations for the undo mechanism. - DolphinCommand command(DolphinCommand::Rename, source, dest, mainWindow()); + DolphinCommand command(DolphinCommand::Rename, source, dest); undoMan.addCommand(command); } } @@ -569,7 +569,7 @@ void DolphinView::rename(const KUrl& source, const QString& newName) m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.",source.fileName(), dest.fileName()), DolphinStatusBar::OperationCompleted); - DolphinCommand command(DolphinCommand::Rename, source, dest, mainWindow()); + DolphinCommand command(DolphinCommand::Rename, source, dest); UndoManager::instance().addCommand(command); } else { diff --git a/src/undomanager.cpp b/src/undomanager.cpp index 1a705f395..e6946cfe3 100644 --- a/src/undomanager.cpp +++ b/src/undomanager.cpp @@ -30,8 +30,7 @@ DolphinCommand::DolphinCommand() : m_type(Copy), - m_macroIndex(-1), - m_mainWindow(0) + m_macroIndex(-1) { // Implementation note: DolphinCommands are stored in a QValueList, whereas // QValueList requires a default constructor of the added class. @@ -44,13 +43,11 @@ DolphinCommand::DolphinCommand() : DolphinCommand::DolphinCommand(Type type, const KUrl::List& source, - const KUrl& dest, - DolphinMainWindow* mainWindow) : + const KUrl& dest) : m_type(type), m_macroIndex(-1), m_source(source), - m_dest(dest), - m_mainWindow(mainWindow) + m_dest(dest) { } @@ -63,7 +60,6 @@ DolphinCommand& DolphinCommand::operator = (const DolphinCommand& command) m_type = command.m_type; m_source = command.m_source; m_dest = command.m_dest; - m_mainWindow = command.m_mainWindow; return *this; } @@ -114,7 +110,7 @@ void UndoManager::endMacro() // KDE4 TODO: consider switching to KCommandHistory (kdeui) for the command history, and to // KonqCommandRecorder etc. from libkonq/konq_undo.* -void UndoManager::undo() +void UndoManager::undo(DolphinMainWindow* mainWindow) { if (m_recordMacro) { endMacro(); @@ -128,16 +124,16 @@ void UndoManager::undo() int macroCount = 1; calcStepsCount(macroCount, progressCount); + /* + * KDE4, ### TODO Only here to avoid possible crash + */ + ProgressIndicator progressIndicator(mainWindow, i18n("Executing undo operation..."), + i18n("Executed undo operation."), + progressCount); for (int i = 0; i < macroCount; ++i) { const DolphinCommand command = m_history[m_historyIndex]; - /* - * KDE4, ### TODO Only here to avoid possible crash - */ - ProgressIndicator progressIndicator(command.mainWindow(), i18n("Executing undo operation..."), - i18n("Executed undo operation."), - progressCount); --m_historyIndex; if (m_historyIndex < 0) { emit undoAvailable(false); @@ -209,7 +205,7 @@ void UndoManager::undo() case DolphinCommand::CreateFolder: case DolphinCommand::CreateFile: { - KIO::NetAccess::del(command.destination(), command.mainWindow() ); + KIO::NetAccess::del(command.destination(), mainWindow); break; } } @@ -219,14 +215,14 @@ void UndoManager::undo() // information to the Dolphin statusbar. connect(job, SIGNAL(percent(KIO::Job*, unsigned long)), this, SLOT(slotPercent(KIO::Job*, unsigned long))); - KIO::NetAccess::synchronousRun(job, command.mainWindow() ); + KIO::NetAccess::synchronousRun(job, mainWindow); } progressIndicator.execOperation(); } } -void UndoManager::redo() +void UndoManager::redo(DolphinMainWindow *mainWindow) { if (m_recordMacro) { endMacro(); @@ -242,13 +238,12 @@ void UndoManager::redo() int macroCount = 1; calcStepsCount(macroCount, progressCount); + ProgressIndicator progressIndicator(mainWindow, i18n("Executing redo operation..."), + i18n("Executed redo operation."), + progressCount); for (int i = 0; i < macroCount; ++i) { const DolphinCommand command = m_history[m_historyIndex]; -#warning "TOUGH" - ProgressIndicator progressIndicator(0, i18n("Executing redo operation..."), - i18n("Executed redo operation."), - progressCount); if (m_historyIndex >= maxHistoryIndex) { emit redoAvailable(false); emit redoTextChanged(i18n("Redo")); @@ -290,7 +285,7 @@ void UndoManager::redo() const QString originalFileName((*it).fileName().section('-', 1)); KUrl originalSourceUrl(destUrl + "/" + originalFileName); KIO::Job* moveToTrashJob = KIO::trash(originalSourceUrl); - KIO::NetAccess::synchronousRun(moveToTrashJob, command.mainWindow() ); + KIO::NetAccess::synchronousRun(moveToTrashJob, mainWindow); ++it; progressIndicator.execOperation(); @@ -299,7 +294,7 @@ void UndoManager::redo() } case DolphinCommand::CreateFolder: { - KIO::NetAccess::mkdir(command.destination(), command.mainWindow()); + KIO::NetAccess::mkdir(command.destination(), mainWindow); break; } @@ -319,7 +314,7 @@ void UndoManager::redo() // information to the Dolphin statusbar. connect(job, SIGNAL(percent(KJob*, unsigned long)), this, SLOT(slotPercent(KJob*, unsigned long))); - KIO::NetAccess::synchronousRun(job, command.mainWindow()); + KIO::NetAccess::synchronousRun(job, mainWindow); } ++m_historyIndex; diff --git a/src/undomanager.h b/src/undomanager.h index 9e2094fe3..c3cfda56e 100644 --- a/src/undomanager.h +++ b/src/undomanager.h @@ -55,7 +55,7 @@ public: }; DolphinCommand(); - DolphinCommand(Type type, const KUrl::List& source, const KUrl& dest, DolphinMainWindow* mainWindow); + DolphinCommand(Type type, const KUrl::List& source, const KUrl& dest); ~DolphinCommand(); // non-virtual DolphinCommand& operator = (const DolphinCommand& command); @@ -63,14 +63,12 @@ public: void setSource(const KUrl::List source) { m_source = source; } const KUrl::List& source() const { return m_source; } const KUrl& destination() const { return m_dest; } - DolphinMainWindow* mainWindow() const { return m_mainWindow; } private: Type m_type; int m_macroIndex; KUrl::List m_source; KUrl m_dest; - QPointer m_mainWindow; friend class UndoManager; // allow to modify m_macroIndex }; @@ -121,14 +119,18 @@ public slots: /** * Performs an undo operation on the last command which has * been added by UndoManager::addCommand(). + * + * @param mainwindow The mainwindow where to show progress */ - void undo(); + void undo(DolphinMainWindow* mainwindow); /** * 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(); + void redo(DolphinMainWindow* mainwindow); signals: /**