]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Changes to Undo/Redo in regard to ProgressIndicator
authorHolger Freyther <holger+kde@freyther.de>
Wed, 29 Nov 2006 09:30:41 +0000 (09:30 +0000)
committerHolger Freyther <holger+kde@freyther.de>
Wed, 29 Nov 2006 09:30:41 +0000 (09:30 +0000)
    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

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/undomanager.cpp
src/undomanager.h

index 0d4667db705b4fd19c3ad7e95f340bc55e162116..af9bd0a011b818726b08b000f89b5c4074689089 100644 (file)
@@ -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);
 }
 
index 6e9f75b7fa88bfa7152bbe55c631c5b98bcda993..dbe6ed4e02820ac4f768be745c156efd30fe0a08 100644 (file)
@@ -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);
index 7dbebeab588ffec8cbbb1b2f46fbab61e4c0e285..e60f6f655a7b52321b8c899dfd60691132d52df3 100644 (file)
@@ -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 {
index 1a705f39586627783424cdea32173390e3a18c96..e6946cfe31af4209493d04730e6a190b39f95452 100644 (file)
@@ -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;
index 9e2094fe386a2f2966c757070ba21e0dfe4181ab..c3cfda56ecc1f3aaaf4f3fbf99b8f0a64b2d259c 100644 (file)
@@ -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<DolphinMainWindow> 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:
     /**