[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/kotext-undoRedo-PierreSt] /: tempo
From:       Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date:       2012-02-20 12:59:45
Message-ID: 20120220125945.A2FB3A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 511a393b4805c602e91b475ed846f782b188e7c5 by Pierre Stirnweiss.
Committed on 02/02/2012 at 18:28.
Pushed by pstirnweiss into branch 'kotext-undoRedo-PierreSt'.

tempo

M  +5    -0    libs/flake/KoShapeController.cpp
M  +6    -0    libs/flake/commands/KoShapeDeleteCommand.cpp
M  +27   -9    libs/kotext/KoTextEditor.cpp
M  +6    -0    libs/kotext/commands/DeleteAnchorsCommand.cpp
M  +26   -3    libs/kotext/commands/DeleteCommand.cpp
M  +9    -2    libs/kundo2/kundo2stack.cpp
M  +4    -0    libs/kundo2/kundo2stack.h
M  +3    -0    words/part/KWDocument.cpp

http://commits.kde.org/calligra/511a393b4805c602e91b475ed846f782b188e7c5

diff --git a/libs/flake/KoShapeController.cpp b/libs/flake/KoShapeController.cpp
index 817ba5e..be17e42 100644
--- a/libs/flake/KoShapeController.cpp
+++ b/libs/flake/KoShapeController.cpp
@@ -164,12 +164,17 @@ KUndo2Command* KoShapeController::addShapeDirect(KoShape \
*shape, KUndo2Command *  
 KUndo2Command* KoShapeController::removeShape(KoShape *shape, KUndo2Command *parent)
 {
+    kDebug() << "removeShape begin";
     KUndo2Command *cmd = new KoShapeDeleteCommand(d->shapeBasedDocument, shape, \
parent); +    kDebug() << "cmd created";
     QList<KoShape*> shapes;
     shapes.append(shape);
+    kDebug() << "shape appended";
     d->shapeBasedDocument->shapesRemoved(shapes, cmd);
+    kDebug() << "removed shape from doc";
     // detach shape from any attached connection shapes
     d->handleAttachedConnections(shape, cmd);
+    kDebug() << "will return";
     return cmd;
 }
 
diff --git a/libs/flake/commands/KoShapeDeleteCommand.cpp \
b/libs/flake/commands/KoShapeDeleteCommand.cpp index 519f047..3de1897 100644
--- a/libs/flake/commands/KoShapeDeleteCommand.cpp
+++ b/libs/flake/commands/KoShapeDeleteCommand.cpp
@@ -24,6 +24,8 @@
 
 #include <klocale.h>
 
+#include <KDebug>
+
 class KoShapeDeleteCommand::Private
 {
 public:
@@ -50,6 +52,7 @@ KoShapeDeleteCommand::KoShapeDeleteCommand(KoShapeBasedDocumentBase \
*controller,  : KUndo2Command(parent),
         d(new Private(controller))
 {
+    kDebug() << "shapeDelete cstr";
     d->shapes.append(shape);
     d->oldParents.append(shape->parent());
 
@@ -82,17 +85,20 @@ KoShapeDeleteCommand::~KoShapeDeleteCommand()
 
 void KoShapeDeleteCommand::redo()
 {
+    kDebug() << "shapeDeleteCommand begin";
     KUndo2Command::redo();
     if (! d->controller)
         return;
 
     for (int i = 0; i < d->shapes.count(); i++) {
         // the parent has to be there when it is removed from the \
KoShapeBasedDocumentBase +        kDebug() << "will remove shapes";
         d->controller->removeShape(d->shapes[i]);
         if (d->oldParents.at(i))
             d->oldParents.at(i)->removeShape(d->shapes[i]);
     }
     d->deleteShapes = true;
+    kDebug() << "shapeDeleteCommand end";
 }
 
 void KoShapeDeleteCommand::undo()
diff --git a/libs/kotext/KoTextEditor.cpp b/libs/kotext/KoTextEditor.cpp
index 3c141c7..d73272a 100644
--- a/libs/kotext/KoTextEditor.cpp
+++ b/libs/kotext/KoTextEditor.cpp
@@ -137,18 +137,19 @@ void KoTextEditor::Private::documentCommandAdded()
         KoTextEditor::Private *m_p;
     };
 
-    //kDebug() << "editor state: " << editorState << " headcommand: " << \
headCommand; +    kDebug() << "in new command recieved";
+    kDebug() << "editor state: " << editorState << " headcommand: " << headCommand;
     if (!headCommand || editorState == NoOp) {
         headCommand = new KUndo2Command(commandTitle);
         if (KoTextDocument(document).undoStack()) {
-            //kDebug() << "pushing head: " << headCommand->text();
+            kDebug() << "first condition. pushing head: " << headCommand->text();
             KoTextDocument(document).undoStack()->push(headCommand);
         }
     }
     else if ((editorState == KeyPress || editorState == Delete) && \
headCommand->childCount()) {  headCommand = new KUndo2Command(commandTitle);
         if (KoTextDocument(document).undoStack()) {
-            //kDebug() << "pushing head: " << headCommand->text();
+            kDebug() << "second condition. pushing head: " << headCommand->text();
             KoTextDocument(document).undoStack()->push(headCommand);
         }
     }
@@ -158,12 +159,15 @@ void KoTextEditor::Private::documentCommandAdded()
 
 void KoTextEditor::Private::updateState(KoTextEditor::Private::State newState, \
QString title)  {
-    if (editorState == Custom && newState !=NoOp)
+    kDebug() << "updateState. editorState: " << editorState << " newState: " << \
newState << " command title: " << title; +    if (editorState == Custom && newState \
!=NoOp) { +        kDebug() << "returning";
         return;
-    //kDebug() << "updateState from: " << editorState << " to: " << newState;
+    }
+    kDebug() << "updateState from: " << editorState << " to: " << newState;
     if (editorState != newState || commandTitle != title) {
         if (headCommand /*&& headCommand->childCount() && \
                KoTextDocument(document).undoStack()*/) {
-            //kDebug() << "reset headCommand";
+            kDebug() << "reset headCommand";
             //            KoTextDocument(document).undoStack()->push(headCommand);
             headCommand = 0;
         }
@@ -173,7 +177,7 @@ void \
KoTextEditor::Private::updateState(KoTextEditor::Private::State newState, Q  \
commandTitle = title;  else
         commandTitle = i18n("Text");
-    //kDebug() << "commandTitle is now: " << commandTitle;
+    kDebug() << "commandTitle is now: " << commandTitle;
 }
 
 bool KoTextEditor::Private::deleteInlineObjects(bool backwards)
@@ -361,12 +365,19 @@ void KoTextEditor::addCommand(KUndo2Command *command)
 
 void KoTextEditor::instantlyExecuteCommand(KUndo2Command *command)
 {
+    kDebug() << "instantlyexecute commend: " << command << " titled: " << \
                command->text();
     d->updateState(KoTextEditor::Private::Custom, \
(!command->text().isEmpty())?command->text():i18n("Text"));  //kDebug() << "will push \
                the custom command: " << command->text();
     d->headCommand = command; // So any text it does is store as sub commands
     command->redo();
     // instant replay done let's not keep it dangling
-    d->updateState(KoTextEditor::Private::NoOp);
+    kDebug() << "done executing, will reset the state to NoOp";
+    kDebug() << "command: " << command << " hasParent: " << command->hasParent();
+    if (!command->hasParent()) {
+        kDebug() << "resetting now";
+//        d->updateState(KoTextEditor::Private::NoOp);
+    }
+    kDebug() << "end execute instant";
 }
 
 void KoTextEditor::registerTrackedChange(QTextCursor &selection, KoGenChange::Type \
changeType, QString title, QTextFormat& format, QTextFormat& prevFormat, bool \
applyToWholeBlock) @@ -1163,6 +1174,7 @@ void \
KoTextEditor::updateInlineObjectPosition(int start, int end)  void \
KoTextEditor::removeAnchors(const QList<KoTextAnchor*> &anchors, KUndo2Command \
*parent)  {
     Q_ASSERT(parent);
+    kDebug() << "will remove anchor";
     instantlyExecuteCommand(new DeleteAnchorsCommand(anchors, d->document, parent));
 }
 
@@ -1294,6 +1306,7 @@ bool KoTextEditor::paste(KoTextEditor *editor,
 
 void KoTextEditor::deleteChar(MoveOperation direction, KoShapeController \
*shapeController)  {
+    kDebug() << "deleteChar begin";
     if (isEditProtected()) {
         return;
     }
@@ -1344,6 +1357,7 @@ void KoTextEditor::deleteChar(MoveOperation direction, \
KoShapeController *shapeC  shapeController));
         }
     }
+    kDebug() << "end deleteChar";
 }
 
 void KoTextEditor::toggleListNumbering(bool numberingEnabled)
@@ -1484,7 +1498,7 @@ void KoTextEditor::deleteChar()
     }
 
     if (!d->deleteInlineObjects(false) || d->caret.hasSelection()) {
-        d->updateState(KoTextEditor::Private::Delete, i18n("Delete"));
+        d->updateState(KoTextEditor::Private::Delete, i18n("DeleteChar"));
 
         QTextCharFormat charFormat = d->caret.charFormat();
 
@@ -2377,14 +2391,18 @@ const QTextTable *KoTextEditor::currentTable () const
 
 void KoTextEditor::beginEditBlock()
 {
+    kDebug() << "beginEditBlock";
     d->updateState(KoTextEditor::Private::Custom);
     d->caret.beginEditBlock();
 }
 
 void KoTextEditor::endEditBlock()
 {
+    kDebug() << "endEditBlock";
     d->caret.endEditBlock();
+    kDebug() << "doc end edit done";
     d->updateState(KoTextEditor::Private::NoOp);
+    kDebug() << "done reseting style to 0. endEditBlock finished";
 }
 
 #include <KoTextEditor.moc>
diff --git a/libs/kotext/commands/DeleteAnchorsCommand.cpp \
b/libs/kotext/commands/DeleteAnchorsCommand.cpp index 621829f..54111b6 100644
--- a/libs/kotext/commands/DeleteAnchorsCommand.cpp
+++ b/libs/kotext/commands/DeleteAnchorsCommand.cpp
@@ -24,6 +24,8 @@
 #include "KoTextDocument.h"
 #include "KoInlineTextObjectManager.h"
 
+#include <KDebug>
+
 bool sortAnchor(KoTextAnchor *a1, KoTextAnchor *a2)
 {
     return a1->positionInDocument() > a2->positionInDocument();
@@ -52,6 +54,7 @@ DeleteAnchorsCommand::~DeleteAnchorsCommand()
 
 void DeleteAnchorsCommand::redo()
 {
+    kDebug() << "DeleteAnchorCommands redo begin";
     KUndo2Command::redo();
     m_deleteAnchors = true;
     if (m_first) {
@@ -59,7 +62,9 @@ void DeleteAnchorsCommand::redo()
         foreach (KoTextAnchor *anchor, m_anchors) {
             QTextCursor cursor(m_document);
             cursor.setPosition(anchor->positionInDocument());
+            kDebug() << "about to delete the char";
             cursor.deleteChar();
+            kDebug() << "char deleted";
         }
     }
     KoInlineTextObjectManager *manager = \
KoTextDocument(m_document).inlineTextObjectManager(); @@ -69,6 +74,7 @@ void \
DeleteAnchorsCommand::redo()  manager->removeInlineObject(anchor);
         }
     }
+    kDebug() << "deleteAnchorCommand redo end";
 }
 
 void DeleteAnchorsCommand::undo()
diff --git a/libs/kotext/commands/DeleteCommand.cpp \
b/libs/kotext/commands/DeleteCommand.cpp index 2a4527d..e6105c4 100644
--- a/libs/kotext/commands/DeleteCommand.cpp
+++ b/libs/kotext/commands/DeleteCommand.cpp
@@ -61,6 +61,7 @@ void DeleteCommand::undo()
 
 void DeleteCommand::redo()
 {
+    kDebug() << "deleteCommand redo begin";
     m_undone = false;
     if (!m_first) {
         foreach (KUndo2Command *command, m_shapeDeleteCommands)
@@ -69,20 +70,26 @@ void DeleteCommand::redo()
         KoTextCommandBase::redo();
         UndoRedoFinalizer finalizer(this);
     } else {
+        kDebug() << "first time";
         m_first = false;
         if (m_document) {
             KoTextEditor *textEditor = KoTextDocument(m_document).textEditor();
             if (textEditor) {
+                kDebug() << "will start delete actions";
                 textEditor->beginEditBlock();
+                kDebug() << "macro started";
                 doDelete();
                 textEditor->endEditBlock();
+                kDebug() << "macro end";
             }
         }
     }
+    kDebug() << "redo finished";
 }
 
 void DeleteCommand::doDelete()
 {
+    kDebug() << "do delete start";
     KoTextEditor *textEditor = KoTextDocument(m_document).textEditor();
     Q_ASSERT(textEditor);
     QTextCursor *caret = textEditor->cursor();
@@ -118,18 +125,26 @@ void DeleteCommand::doDelete()
         m_format = caret->charFormat();;
 
     //Delete any inline objects present within the selection
+    kDebug() << "before handling inlineObjects";
     deleteInlineObjects();
+    kDebug() << "after handling inline objects";
 
     //Now finally Delete the selected text. Don't use selection.deleteChar() direct
     //cause the Texteditor needs to know about the changes too.
-    if (m_mode == PreviousChar)
+    if (m_mode == PreviousChar) {
         textEditor->deletePreviousChar();
-    else
+    }
+    else {
+        kDebug() << "will delete the char";
         textEditor->deleteChar();
+        kDebug() << "char deleted";
+    }
+    kDebug() << "dodelete end";
  }
 
 void DeleteCommand::deleteInlineObjects()
 {
+    kDebug() << "deleteInline start";
     KoTextDocument textDocument(m_document);
     KoTextEditor *textEditor = textDocument.textEditor();
     Q_ASSERT(textEditor);
@@ -147,7 +162,9 @@ void DeleteCommand::deleteInlineObjects()
             if (data->unicode() == QChar::ObjectReplacementCharacter) {
                 cursor.setPosition(position + i);
                 object = manager->inlineTextObject(cursor);
+                kDebug() << "there is an object, will delete the anchor";
                 deleteTextAnchor(object);
+                kDebug() << "anchor deleted";
                 m_invalidInlineObjects.insert(object);
             }
             data++;
@@ -160,19 +177,25 @@ void DeleteCommand::deleteInlineObjects()
         deleteTextAnchor(object);
         m_invalidInlineObjects.insert(object);
     }
+    kDebug() << "delete inline end";
 }
 
 void DeleteCommand::deleteTextAnchor(KoInlineObject *object)
 {
+    kDebug() << "will delete the anchor";
     if (object) {
         KoTextAnchor *anchor = dynamic_cast<KoTextAnchor *>(object);
         if (anchor) {
             KoShape *shape = anchor->shape();
-            KUndo2Command *shapeDeleteCommand = \
m_shapeController->removeShape(shape); +            kDebug() << "will create the \
shapeDeleteCommand"; +            KUndo2Command *shapeDeleteCommand = \
m_shapeController->removeShape(shape, this); +            kDebug() << \
"shapeDeleteCommand created, will call redo on it";  shapeDeleteCommand->redo();
+            kDebug() << "redo called";
             m_shapeDeleteCommands.push_back(shapeDeleteCommand);
         }
     }
+    kDebug() << "deleteAnchor end";
 }
 
 int DeleteCommand::id() const
diff --git a/libs/kundo2/kundo2stack.cpp b/libs/kundo2/kundo2stack.cpp
index 48d6625..bf63eea 100644
--- a/libs/kundo2/kundo2stack.cpp
+++ b/libs/kundo2/kundo2stack.cpp
@@ -111,11 +111,13 @@
     \sa ~KUndo2Command()
 */
 
-KUndo2Command::KUndo2Command(const QString &text, KUndo2Command *parent)
+KUndo2Command::KUndo2Command(const QString &text, KUndo2Command *parent):
+    m_hasParent(parent != 0)
 {
     d = new KUndo2CommandPrivate;
-    if (parent != 0)
+    if (parent != 0) {
         parent->d->child_list.append(this);
+    }
     setText(text);
 }
 
@@ -310,6 +312,11 @@ const KUndo2Command *KUndo2Command::child(int index) const
     return d->child_list.at(index);
 }
 
+bool KUndo2Command::hasParent()
+{
+    return m_hasParent;
+}
+
 #endif // QT_NO_UNDOCOMMAND
 
 #ifndef QT_NO_UNDOSTACK
diff --git a/libs/kundo2/kundo2stack.h b/libs/kundo2/kundo2stack.h
index c0539fe..30ff215 100644
--- a/libs/kundo2/kundo2stack.h
+++ b/libs/kundo2/kundo2stack.h
@@ -78,9 +78,13 @@ public:
     int childCount() const;
     const KUndo2Command *child(int index) const;
 
+    bool hasParent();
+
 private:
     Q_DISABLE_COPY(KUndo2Command)
     friend class KUndo2QStack;
+
+    bool m_hasParent;
 };
 
 #endif // QT_NO_UNDOCOMMAND
diff --git a/words/part/KWDocument.cpp b/words/part/KWDocument.cpp
index 8e00cb6..c294f2e 100644
--- a/words/part/KWDocument.cpp
+++ b/words/part/KWDocument.cpp
@@ -191,6 +191,7 @@ void KWDocument::removeShape(KoShape *shape)
 
 void KWDocument::shapesRemoved(const QList<KoShape*> &shapes, KUndo2Command \
*command)  {
+    kDebug() << "in removeShapes KW";
     QMap<KoTextEditor *, QList<KoTextAnchor *> > anchors;
     foreach (KoShape *shape, shapes) {
         KWFrame *frame = dynamic_cast<KWFrame*>(shape->applicationData());
@@ -205,7 +206,9 @@ void KWDocument::shapesRemoved(const QList<KoShape*> &shapes, \
KUndo2Command *com  }
     QMap<KoTextEditor *, QList<KoTextAnchor *> >::const_iterator \
it(anchors.begin());  for (; it != anchors.end(); ++it) {
+        kDebug() << "will call the textEditor remove anchor";
         it.key()->removeAnchors(it.value(), command);
+        kDebug() << "done";
     }
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic