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

List:       kde-commits
Subject:    [calligra] /: Make sure cut doesn't produce two undo steps
From:       C. Boemann <cbo () boemann ! dk>
Date:       2012-05-31 23:39:06
Message-ID: 20120531233906.61A8FA60A9 () git ! kde ! org
[Download RAW message or body]

Git commit 43de093956051c98abc814ede335bb317dce3f08 by C. Boemann.
Committed on 01/06/2012 at 01:37.
Pushed by boemann into branch 'master'.

Make sure cut doesn't produce two undo steps

BUG: 260162

M  +10   -11   libs/kotext/KoTextEditor.h
M  +0    -1    plugins/textshape/CMakeLists.txt
M  +6    -2    plugins/textshape/TextTool.cpp
D  +0    -53   plugins/textshape/commands/TextCutCommand.cpp
D  +0    -42   plugins/textshape/commands/TextCutCommand.h

http://commits.kde.org/calligra/43de093956051c98abc814ede335bb317dce3f08

diff --git a/libs/kotext/KoTextEditor.h b/libs/kotext/KoTextEditor.h
index 363b279..afc1e0d 100644
--- a/libs/kotext/KoTextEditor.h
+++ b/libs/kotext/KoTextEditor.h
@@ -318,14 +318,19 @@ public slots:
 
     const QTextDocument *document() const;
 
-    //Starts a new custom command. Everything between these two is one custom \
                command. These should not be called from whithin a KUndo2Command
-//    void beginCustomCommand();
-//    void endCustomCommand();
-
-    //Same as Qt, only to be used inside KUndo2Commands
+    /// Same as Qt, only to be used inside KUndo2Commands
     KUndo2Command *beginEditBlock(QString title = QString());
     void endEditBlock();
 
+    /**
+     * Delete one character in the specified direction or a selection.
+     * Warning: From the outside this method should only be used with a parent \
command +     * and only if there is a selection
+     * @param previous should be true if act like backspace
+     */
+    void deleteChar(bool previous, KUndo2Command *parent = 0);
+
+
     bool hasComplexSelection() const;
 
     /**
@@ -475,12 +480,6 @@ signals:
     void textFormatChanged();
 
 protected:
-    /**
-     * Delete one character in the specified direction or a selection.
-     * @param previous should be true if act like backspace
-     */
-    void deleteChar(bool previous, KUndo2Command *parent = 0);
-
     void recursivelyVisitSelection(QTextFrame::iterator it, KoTextVisitor &visitor) \
const;  
 private:
diff --git a/plugins/textshape/CMakeLists.txt b/plugins/textshape/CMakeLists.txt
index 911c632..6253323 100644
--- a/plugins/textshape/CMakeLists.txt
+++ b/plugins/textshape/CMakeLists.txt
@@ -89,7 +89,6 @@ SET ( textshape_SRCS
     dialogs/ListLevelChooser.cpp
 
     commands/ChangeListLevelCommand.cpp
-    commands/TextCutCommand.cpp
     commands/ShowChangesCommand.cpp
     commands/AcceptChangeCommand.cpp
     commands/RejectChangeCommand.cpp
diff --git a/plugins/textshape/TextTool.cpp b/plugins/textshape/TextTool.cpp
index 9c11f39..330a1b5 100644
--- a/plugins/textshape/TextTool.cpp
+++ b/plugins/textshape/TextTool.cpp
@@ -34,7 +34,6 @@
 #include "dialogs/FontDia.h"
 #include "dialogs/TableDialog.h"
 #include "dialogs/SimpleTableWidget.h"
-#include "commands/TextCutCommand.h"
 #include "commands/AutoResizeCommand.h"
 #include "commands/ChangeListLevelCommand.h"
 #include "FontSizeAction.h"
@@ -1099,7 +1098,12 @@ bool TextTool::paste()
 
 void TextTool::cut()
 {
-    m_textEditor.data()->addCommand(new TextCutCommand(this));
+    if (m_textEditor.data()->hasSelection()) {
+        copy();
+        KUndo2Command *topCmd = \
m_textEditor.data()->beginEditBlock(i18nc("(qtundo-format)", "Cut")); +        \
m_textEditor.data()->deleteChar(false, topCmd); +        \
m_textEditor.data()->endEditBlock(); +    }
 }
 
 QStringList TextTool::supportedPasteMimeTypes() const
diff --git a/plugins/textshape/commands/TextCutCommand.cpp \
b/plugins/textshape/commands/TextCutCommand.cpp deleted file mode 100644
index b2c68e6..0000000
--- a/plugins/textshape/commands/TextCutCommand.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- This file is part of the KDE project
- * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.*/
-
-#include "TextCutCommand.h"
-
-#include <KoTextEditor.h>
-#include <TextTool.h>
-#include <KAction>
-#include <klocale.h>
-
-TextCutCommand::TextCutCommand(TextTool *tool, KUndo2Command *parent) :
-    KUndo2Command (parent),
-    m_tool(tool),
-    m_first(true)
-{
-    setText(i18nc("(qtundo-format)", "Cut"));
-}
-
-void TextCutCommand::undo()
-{
-    KUndo2Command::undo();
-}
-
-void TextCutCommand::redo()
-{
-    if (!m_first) {
-        KUndo2Command::redo();
-    } else {
-        m_first = false;
-        m_tool->copy();
-        KoTextEditor *te = m_tool->m_textEditor.data();
-        if (te == 0)
-            return;
-
-        te->deleteChar();
-    }
-}
diff --git a/plugins/textshape/commands/TextCutCommand.h \
b/plugins/textshape/commands/TextCutCommand.h deleted file mode 100644
index ebad6f8..0000000
--- a/plugins/textshape/commands/TextCutCommand.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- This file is part of the KDE project
- * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.*/
-
-#ifndef TEXTCUTCOMMAND_H
-#define TEXTCUTCOMMAND_H
-
-#include <kundo2qstack.h>
-
-class TextTool;
-
-class TextCutCommand : public KUndo2Command
-{
-public:
-
-    TextCutCommand(TextTool *tool, KUndo2Command* parent = 0);
-
-    virtual void undo();
-    virtual void redo();
-
-private:
-
-    TextTool *m_tool;
-    bool m_first;
-};
-
-#endif // TEXTCUTCOMMAND_H


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

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