View Issue Details

IDProjectCategoryView StatusLast Update
0010805ScribusUndo/Redopublic2012-07-01 20:34
ReporterChelen Assigned ToChelen  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.5.0 
Target Version1.5.0Fixed in Version1.5.0svn 
Summary0010805: Text Undo
Descriptionundo/redo for :

delete text
insert text
replace text
paste text
paste inline frame
insert lorem ipsum
insert special char
import text
append text
clean content of a textframe
change char style
change paragraph style
change first line offset policy
erase style
columns and text distance in text frame
tabs length
...
TagsNo tags attached.
Patch

Relationships

related to 0010216 closedChelen Insert inline Frame Undo + Redone gives different anchoring relative position 
related to 0010310 closedChelen No Undo on Style change 
related to 0009802 closedChelen Undo for text frames 

Activities

Chelen

2012-06-26 20:27

reporter  

Patch.diff (51,216 bytes)   
diff --git a/Scribus/scribus/canvasmode.cpp b/Scribus/scribus/canvasmode.cpp
index 4f2b9c2..f7e6fb6 100644
--- a/Scribus/scribus/canvasmode.cpp
+++ b/Scribus/scribus/canvasmode.cpp
@@ -76,7 +76,8 @@ CanvasMode::CanvasMode (ScribusView* view) :
 	m_view(view),
 	m_canvas(view->m_canvas),
 	m_doc(view->Doc),
-	m_panGesture(NULL)
+	m_panGesture(NULL),
+	undoManager(UndoManager::instance())
 {
 	m_pen["outline"]	= QPen(Qt::gray, 1.0 , Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 	m_pen["outline"].setCosmetic(true);
diff --git a/Scribus/scribus/canvasmode.h b/Scribus/scribus/canvasmode.h
index 98b7a26..29d2354 100644
--- a/Scribus/scribus/canvasmode.h
+++ b/Scribus/scribus/canvasmode.h
@@ -36,6 +36,7 @@ class QMouseEvent;
 class QKeyEvent;
 class QPainter;
 
+class  UndoManager;
 class  Canvas;
 struct CanvasViewMode;
 class  PanGesture;
@@ -140,6 +141,7 @@ public:
 	
 
 protected:
+	UndoManager* undoManager;
 	ScribusView * const m_view;	
 	Canvas * const m_canvas;
 	ScribusDoc * const m_doc;
diff --git a/Scribus/scribus/canvasmode_edit.cpp b/Scribus/scribus/canvasmode_edit.cpp
index afac8d4..7eeca1c 100644
--- a/Scribus/scribus/canvasmode_edit.cpp
+++ b/Scribus/scribus/canvasmode_edit.cpp
@@ -487,6 +487,12 @@ void CanvasMode_Edit::mouseMoveEvent(QMouseEvent *m)
 
 void CanvasMode_Edit::mousePressEvent(QMouseEvent *m)
 {
+	if (UndoManager::undoEnabled())
+	{
+		SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+		if(ss)
+			ss->set("ETEA",QString(""));
+	}
 // 	const double mouseX = m->globalX();
 // 	const double mouseY = m->globalY();
 	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
diff --git a/Scribus/scribus/gtaction.cpp b/Scribus/scribus/gtaction.cpp
index 16877f0..d9a34b0 100644
--- a/Scribus/scribus/gtaction.cpp
+++ b/Scribus/scribus/gtaction.cpp
@@ -43,6 +43,8 @@ for which a new license (GPL+exception) is in place.
 #include "selection.h"
 #include "sccolorengine.h"
 #include "scribus.h"
+#include "undomanager.h"
+#include "pageitem_textframe.h"
 
 #include "util_icon.h"
 #include "ui/propertiespalette.h"
@@ -80,6 +82,7 @@ gtAction::gtAction(bool append, PageItem* pageitem)
 	doAppend = append;
 	updateParagraphStyles = false;
 	overridePStyleFont = true;
+	undoManager = UndoManager::instance();
 }
 
 void gtAction::setProgressInfo()
@@ -108,42 +111,54 @@ void gtAction::clearFrame()
 
 void gtAction::writeUnstyled(const QString& text)
 {
+	UndoTransaction* activeTransaction = NULL;
 	if (isFirstWrite)
 	{
 		if (!doAppend)
 		{
+			if (UndoManager::undoEnabled())
+				activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ImportText, "", Um::IDelete));
 			if (it->nextInChain() != 0)
 			{
 				PageItem *nextItem = it->nextInChain();
 				while (nextItem != 0)
 				{
-					nextItem->itemText.clear();
+					nextItem->itemText.selectAll();
+					nextItem->asTextFrame()->deleteSelectedTextFromFrame();
 					nextItem = nextItem->nextInChain();
 				}
 			}
-			it->itemText.clear();
+			it->itemText.selectAll();
+			it->asTextFrame()->deleteSelectedTextFromFrame();
 		}
 	}
 
-	QChar ch0(0), ch5(5), ch10(10), ch13(13); 
-	for (int a = 0; a < text.length(); ++a)
+	QChar ch0(0), ch5(5), ch10(10), ch13(13);
+	QString textStr = text;
+	textStr.remove(ch0);
+	textStr.remove(ch13);
+	textStr.replace(ch10,ch13);
+	textStr.replace(ch5,ch13);
+	textStr.replace(QString(0x2028),SpecialChars::LINEBREAK);
+	textStr.replace(QString(0x2029),SpecialChars::PARSEP);
+	int pos = it->itemText.length();
+	if (UndoManager::undoEnabled())
 	{
-		if ((text.at(a) == ch0) || (text.at(a) == ch13))
-			continue;
-		QChar ch = text.at(a);
-		if ((ch == ch10) || (ch == ch5))
-			ch = ch13;
-		else if (ch.unicode() == 0x2028)
-			ch = SpecialChars::LINEBREAK;
-		else if (ch.unicode() == 0x2029)
-			ch = SpecialChars::PARSEP;
-		
-		int pos = it->itemText.length();
-		it->itemText.insertChars(pos, QString(ch));
+		SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate);
+			ss->set("INSERT_FRAMETEXT", "insert_frametext");
+			ss->set("TEXT_STR",textStr);
+			ss->set("START", pos);
+			undoManager->action(it, ss);
 	}
-	
+	it->itemText.insertChars(pos, textStr);
 	lastCharWasLineChange = text.right(1) == "\n";
 	isFirstWrite = false;
+	if (activeTransaction)
+	{
+		activeTransaction->commit();
+		delete activeTransaction;
+		activeTransaction = NULL;
+	}
 }
 
 void gtAction::write(const QString& text, gtStyle *style)
diff --git a/Scribus/scribus/gtaction.h b/Scribus/scribus/gtaction.h
index 1ace66c..a8949ee 100644
--- a/Scribus/scribus/gtaction.h
+++ b/Scribus/scribus/gtaction.h
@@ -41,6 +41,7 @@ class CharStyle;
 class ParagraphStyle;
 class ScribusDoc;
 class ScribusMainWindow;
+class UndoManager;
 
 class gtStyle;
 class gtParagraphStyle;
@@ -52,6 +53,7 @@ typedef QMap<QString, QString> FontFamilyMap;
 class SCRIBUS_API gtAction
 {
 private:
+	UndoManager* undoManager;
 	ScribusMainWindow* m_ScMW;
 	PageItem *textFrame;
 	PageItem *it;
diff --git a/Scribus/scribus/pageitem.cpp b/Scribus/scribus/pageitem.cpp
index a8acc92..fb7e695 100644
--- a/Scribus/scribus/pageitem.cpp
+++ b/Scribus/scribus/pageitem.cpp
@@ -1376,34 +1376,83 @@ void PageItem::currentTextProps(ParagraphStyle& parStyle) const
 
 void PageItem::setTextToFrameDistLeft(double newLeft)
 {
+	if(Extra==newLeft)
+		return;
+	if (UndoManager::undoEnabled())
+	{
+		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
+		ss->set("LEFT_TEXTFRAMEDIST", "left_textframedist");
+		ss->set("OLD_DIST",Extra);
+		ss->set("NEW_DIST",newLeft);
+		undoManager->action(this, ss);
+	}
 	Extra=newLeft;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDistRight(double newRight)
 {
+	if(RExtra==newRight)
+		return;
+	if (UndoManager::undoEnabled())
+	{
+		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
+		ss->set("RIGHT_TEXTFRAMEDIST", "right_textframedist");
+		ss->set("OLD_DIST",RExtra);
+		ss->set("NEW_DIST",newRight);
+		undoManager->action(this, ss);
+	}
 	RExtra=newRight;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDistTop(double newTop)
 {
+	if(TExtra==newTop)
+		return;
+	if (UndoManager::undoEnabled())
+	{
+		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
+		ss->set("TOP_TEXTFRAMEDIST", "top_textframedist");
+		ss->set("OLD_DIST",TExtra);
+		ss->set("NEW_DIST",newTop);
+		undoManager->action(this, ss);
+	}
 	TExtra=newTop;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDistBottom(double newBottom)
 {
+	if(BExtra==newBottom)
+		return;
+	if (UndoManager::undoEnabled())
+	{
+		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
+		ss->set("BOTTOM_TEXTFRAMEDIST", "bottom_textframedist");
+		ss->set("OLD_DIST",BExtra);
+		ss->set("NEW_DIST",newBottom);
+		undoManager->action(this, ss);
+	}
 	BExtra=newBottom;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDist(double newLeft, double newRight, double newTop, double newBottom)
 {
-	Extra=newLeft;
-	RExtra=newRight;
-	TExtra=newTop;
-	BExtra=newBottom;
+	UndoTransaction* activeTransaction = NULL;
+	if (UndoManager::undoEnabled())
+		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::TextFrame, Um::IDocument, Um::TextFrameDist, "", Um::ITextFrame));
+	setTextToFrameDistLeft(newLeft);
+	setTextToFrameDistRight(newRight);
+	setTextToFrameDistTop(newTop);
+	setTextToFrameDistBottom(newBottom);
+	if (activeTransaction)
+	{
+		activeTransaction->commit();
+		delete activeTransaction;
+		activeTransaction = NULL;
+	}
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
@@ -1414,11 +1463,29 @@ void PageItem::setGridOffset(double) { } // FIXME
 void PageItem::setGridDistance(double) { } // FIXME
 void PageItem::setColumns(int n) 
 {
-	Cols = qMax(1, n); //FIXME: undo
+	if(Cols==n)
+		return;
+	if(UndoManager::undoEnabled()){
+		SimpleState *ss = new SimpleState(Um::Columns, "", Um::IBorder);
+		ss->set("COLUMNS", "columns");
+		ss->set("OLD_COLUMNS", Cols);
+		ss->set("NEW_COLUMNS",n);
+		undoManager->action(this, ss);
+	}
+	Cols = qMax(1, n);
 }
 void PageItem::setColumnGap(double gap)
 {
-	ColGap = gap; //FIXME: undo
+	if(ColGap==gap)
+		return;
+	if(UndoManager::undoEnabled()){
+		SimpleState *ss = new SimpleState(Um::Columns, "", Um::IBorder);
+		ss->set("COLUMNSGAP", "columnsgap");
+		ss->set("OLD_COLUMNS", ColGap);
+		ss->set("NEW_COLUMNS",gap);
+		undoManager->action(this, ss);
+	}
+	ColGap = gap;
 }
 
 void PageItem::setCornerRadius(double newRadius)
@@ -4361,8 +4428,40 @@ void PageItem::restore(UndoState *state, bool isUndo)
 			restoreShade(ss, isUndo);
 		else if (ss->contains("LINE_COLOR"))
 			restoreLineColor(ss, isUndo);
+		else if (ss->contains("COLUMNS"))
+			restoreColumns(ss, isUndo);
+		else if (ss->contains("COLUMNSGAP"))
+			restoreColumnsGap(ss, isUndo);
 		else if (ss->contains("LINE_SHADE"))
 			restoreLineShade(ss, isUndo);
+		else if (ss->contains("DELETE_FRAMETEXT"))
+			restoreDeleteFrameText(ss, isUndo);
+		else if (ss->contains("INSERT_FRAMETEXT"))
+			restoreInsertFrameText(ss,isUndo);
+		else if (ss->contains("LOREM_FRAMETEXT"))
+			restoreLoremIpsum(ss,isUndo);
+		else if (ss->contains("APPLY_CHARSTYLE"))
+			restoreCharStyle(ss,isUndo);
+		else if (ss->contains("SET_CHARSTYLE"))
+			restoreSetCharStyle(ss,isUndo);
+		else if (ss->contains("SET_PARASTYLE"))
+			restoreSetParagraphStyle(ss,isUndo);
+		else if (ss->contains("APPLY_PARASTYLE"))
+			restoreParagraphStyle(ss,isUndo);
+		else if (ss->contains("APPLY_DEFAULTPARASTYLE"))
+			restoreDefaultParagraphStyle(ss,isUndo);
+		else if (ss->contains("LEFT_TEXTFRAMEDIST"))
+			restoreLeftTextFrameDist(ss,isUndo);
+		else if (ss->contains("RIGHT_TEXTFRAMEDIST"))
+			restoreRightTextFrameDist(ss,isUndo);
+		else if (ss->contains("TOP_TEXTFRAMEDIST"))
+			restoreTopTextFrameDist(ss,isUndo);
+		else if (ss->contains("BOTTOM_TEXTFRAMEDIST"))
+			restoreBottomTextFrameDist(ss,isUndo);
+		else if (ss->contains("FIRSTLINEOFFSET"))
+			restoreFirstLineOffset(ss,isUndo);
+		else if (ss->contains("PASTE_TEXT"))
+			restorePasteText(ss,isUndo);
 		else if (ss->contains("IMAGEFLIPH"))
 		{
 			select();
@@ -4464,6 +4563,8 @@ void PageItem::restore(UndoState *state, bool isUndo)
 			restoreReverseText(ss, isUndo);
 		else if (ss->contains("CLEAR_IMAGE"))
 			restoreClearImage(ss,isUndo);
+		else if (ss->contains("PASTE_INLINE"))
+			restorePasteInline(ss,isUndo);
 		else if (ss->contains("PATH_OPERATION"))
 			restorePathOperation(ss, isUndo);
 	}
@@ -4474,6 +4575,191 @@ void PageItem::restore(UndoState *state, bool isUndo)
 	m_Doc->SnapGuides = SnapGuidesBackup;
 }
 
+void PageItem::restorePasteInline(SimpleState *is, bool isUndo)
+{
+	int start = is->getInt("START");
+	if(isUndo){
+		itemText.select(start,1);
+		asTextFrame()->deleteSelectedTextFromFrame();
+	} else {
+		itemText.insertObject(is->getInt("INDEX"));
+	}
+}
+
+void PageItem::restorePasteText(SimpleState *ss, bool isUndo)
+{
+	ScItemState<StoryText> *is = dynamic_cast<ScItemState<StoryText>*>(ss);
+	int start = is->getInt("START");
+	if(isUndo){
+		itemText.select(start,is->getItem().length());
+		asTextFrame()->deleteSelectedTextFromFrame();
+	} else {
+		itemText.insert(is->getItem());
+	}
+}
+
+void PageItem::restoreColumnsGap(SimpleState *ss, bool isUndo)
+{
+	if(isUndo){
+		ColGap = ss->getInt("OLD_COLUMNS");
+	} else {
+		ColGap = ss->getInt("NEW_COLUMNS");
+	}
+	update();
+}
+
+void PageItem::restoreLeftTextFrameDist(SimpleState *ss, bool isUndo)
+{
+	if(isUndo){
+		Extra = ss->getInt("OLD_DIST");
+	} else {
+		Extra = ss->getInt("NEW_DIST");
+	}
+	update();
+}
+
+void PageItem::restoreRightTextFrameDist(SimpleState *ss, bool isUndo)
+{
+	if(isUndo){
+		RExtra = ss->getInt("OLD_DIST");
+	} else {
+		RExtra = ss->getInt("NEW_DIST");
+	}
+	update();
+}
+
+void PageItem::restoreTopTextFrameDist(SimpleState *ss, bool isUndo)
+{
+	if(isUndo){
+		TExtra = ss->getInt("OLD_DIST");
+	} else {
+		TExtra = ss->getInt("NEW_DIST");
+	}
+	update();
+}
+
+void PageItem::restoreBottomTextFrameDist(SimpleState *ss, bool isUndo)
+{
+	if(isUndo){
+		BExtra = ss->getInt("OLD_DIST");
+	} else {
+		BExtra = ss->getInt("NEW_DIST");
+	}
+	update();
+}
+
+void PageItem::restoreColumns(SimpleState *ss, bool isUndo)
+{
+	if(isUndo){
+		Cols = ss->getInt("OLD_COLUMNS");
+	} else {
+		Cols = ss->getInt("NEW_COLUMNS");
+	}
+	update();
+}
+
+void PageItem::restoreFirstLineOffset(SimpleState *ss, bool isUndo)
+{
+	ScItemState<QPair<FirstLineOffsetPolicy, FirstLineOffsetPolicy > > *is = dynamic_cast<ScItemState<QPair<FirstLineOffsetPolicy, FirstLineOffsetPolicy> >*>(ss);
+	if(isUndo){
+		firstLineOffsetP = is->getItem().first;
+	} else {
+		firstLineOffsetP = is->getItem().second;
+	}
+	update();
+}
+
+void PageItem::restoreDefaultParagraphStyle(SimpleState *ss, bool isUndo)
+{
+	ScItemState<QPair<ParagraphStyle, ParagraphStyle > > *is = dynamic_cast<ScItemState<QPair<ParagraphStyle, ParagraphStyle> >*>(ss);
+	if(isUndo){
+		itemText.setDefaultStyle(is->getItem().second);
+	} else {
+		itemText.setDefaultStyle(is->getItem().first);
+	}
+}
+
+void PageItem::restoreParagraphStyle(SimpleState *ss, bool isUndo)
+{
+	ScItemState<QPair<ParagraphStyle, ParagraphStyle > > *is = dynamic_cast<ScItemState<QPair<ParagraphStyle, ParagraphStyle> >*>(ss);
+	int pos = is->getInt("POS");
+	if(isUndo){
+		itemText.eraseStyle(pos,is->getItem().first);
+		itemText.applyStyle(pos,is->getItem().second);
+	} else {
+		itemText.applyStyle(pos,is->getItem().first);
+	}
+}
+
+void PageItem::restoreCharStyle(SimpleState *ss, bool isUndo)
+{
+	ScItemState<QPair<CharStyle, CharStyle > > *is = dynamic_cast<ScItemState<QPair<CharStyle, CharStyle> >*>(ss);
+	int length = is->getInt("LENGTH");
+	int start = is->getInt("START");
+	if(isUndo){
+		itemText.eraseCharStyle(start,length,is->getItem().first);
+		itemText.applyCharStyle(start,length,is->getItem().second);
+	} else {
+		itemText.applyCharStyle(start,length,is->getItem().first);
+	}
+}
+
+void PageItem::restoreSetCharStyle(SimpleState *ss, bool isUndo)
+{
+	ScItemState<QPair<CharStyle, CharStyle > > *is = dynamic_cast<ScItemState<QPair<CharStyle, CharStyle> >*>(ss);
+	int length = is->getInt("LENGTH");
+	int start = is->getInt("START");
+	if(isUndo){
+		itemText.setCharStyle(start,length,is->getItem().second);
+	} else {
+		itemText.setCharStyle(start,length,is->getItem().first);
+	}
+}
+
+void PageItem::restoreSetParagraphStyle(SimpleState *ss, bool isUndo)
+{
+	ScItemState<QPair<ParagraphStyle, ParagraphStyle > > *is = dynamic_cast<ScItemState<QPair<ParagraphStyle, ParagraphStyle> >*>(ss);
+	int pos = is->getInt("POS");
+	if(isUndo){
+		itemText.setStyle(pos,is->getItem().second);
+	} else {
+		itemText.setStyle(pos,is->getItem().first);
+	}
+}
+
+void PageItem::restoreLoremIpsum(SimpleState *ss, bool isUndo)
+{
+	QString sampleText = ss->get("TEXT_STR");
+	if(isUndo){
+		itemText.selectAll();
+		asTextFrame()->deleteSelectedTextFromFrame();
+	} else {
+		itemText.insertChars(0,sampleText);
+	}
+}
+
+void PageItem::restoreDeleteFrameText(SimpleState *ss, bool isUndo){
+	QString text = ss->get("TEXT_STR");
+	int start = ss->getInt("START");
+	if(isUndo){
+		itemText.insertChars(start,text);
+	} else {
+		itemText.select(start,text.length());
+		asTextFrame()->deleteSelectedTextFromFrame();
+	}
+}
+
+void PageItem::restoreInsertFrameText(SimpleState *ss, bool isUndo){
+	QString text = ss->get("TEXT_STR");
+	int start = ss->getInt("START");
+	if(isUndo){
+		itemText.select(start,text.length());
+		asTextFrame()->deleteSelectedTextFromFrame();
+	} else {
+		itemText.insertChars(start,text);
+	}
+}
+
 void PageItem::restoreMove(SimpleState *state, bool isUndo)
 {
 	double ox = state->getDouble("OLD_XPOS");
@@ -7348,6 +7634,13 @@ void PageItem::setFirstLineOffset(FirstLineOffsetPolicy flop)
 {
 	if(firstLineOffsetP != flop)
 	{
+		if (UndoManager::undoEnabled())
+		{
+			ScItemState<QPair<FirstLineOffsetPolicy,FirstLineOffsetPolicy> > *is = new ScItemState<QPair <FirstLineOffsetPolicy,FirstLineOffsetPolicy> >(Um::FirstLineOffset);
+			is->set("FIRSTLINEOFFSET", "fisrtlineoffset");
+			is->setItem(QPair<FirstLineOffsetPolicy,FirstLineOffsetPolicy>(firstLineOffsetP, flop));
+			undoManager->action(this, is);
+		}
 		firstLineOffsetP = flop;
 	}
 }
diff --git a/Scribus/scribus/pageitem.h b/Scribus/scribus/pageitem.h
index ea07fe7..d0fba00 100644
--- a/Scribus/scribus/pageitem.h
+++ b/Scribus/scribus/pageitem.h
@@ -1209,6 +1209,23 @@ protected:
 	 * @author Riku Leino
 	 */
 	/*@{*/
+	void restorePasteInline(SimpleState *state, bool isUndo);
+	void restorePasteText(SimpleState *state, bool isUndo);
+	void restoreFirstLineOffset(SimpleState *state, bool isUndo);
+	void restoreParagraphStyle(SimpleState *state, bool isUndo);
+	void restoreDefaultParagraphStyle(SimpleState *state, bool isUndo);
+	void restoreCharStyle(SimpleState *state, bool isUndo);
+	void restoreLeftTextFrameDist(SimpleState *state, bool isUndo);
+	void restoreRightTextFrameDist(SimpleState *state, bool isUndo);
+	void restoreTopTextFrameDist(SimpleState *state, bool isUndo);
+	void restoreBottomTextFrameDist(SimpleState *state, bool isUndo);
+	void restoreSetCharStyle(SimpleState *state, bool isUndo);
+	void restoreColumns(SimpleState *state, bool isUndo);
+	void restoreColumnsGap(SimpleState *state, bool isUndo);
+	void restoreSetParagraphStyle(SimpleState *state, bool isUndo);
+	void restoreLoremIpsum(SimpleState *state, bool isUndo);
+	void restoreDeleteFrameText(SimpleState *state, bool isUndo);
+	void restoreInsertFrameText(SimpleState *state, bool isUndo);
 	void restoreMove(SimpleState *state, bool isUndo);
 	void restoreResize(SimpleState *state, bool isUndo);
 	void restoreRotate(SimpleState *state, bool isUndo);
diff --git a/Scribus/scribus/pageitem_textframe.cpp b/Scribus/scribus/pageitem_textframe.cpp
index 833e3c9..5386071 100644
--- a/Scribus/scribus/pageitem_textframe.cpp
+++ b/Scribus/scribus/pageitem_textframe.cpp
@@ -3301,7 +3301,10 @@ void PageItem_TextFrame::clearContents()
 		nextItem = nextItem->prevInChain();
 
 	ParagraphStyle defaultStyle = nextItem->itemText.defaultStyle();
-	nextItem->itemText.clear();
+	nextItem->itemText.selectAll();
+	nextItem->asTextFrame()->deleteSelectedTextFromFrame();
+	if(UndoManager::undoEnabled())
+		undoManager->getLastUndo()->setName(Um::ClearText);
 	nextItem->itemText.setDefaultStyle(defaultStyle);
 
 	while (nextItem != 0)
@@ -3387,6 +3390,12 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 	case Qt::Key_Down:
 		if ( (buttonModifiers & Qt::ShiftModifier) == 0 )
 			deselectAll();
+		if (UndoManager::undoEnabled())
+		{
+			SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+			if(ss)
+				ss->set("ETEA",QString(""));
+		}
 	}
 
 	if (unicodeTextEditMode)
@@ -3780,6 +3789,7 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 		break;
 	default:
 		bool doUpdate = false;
+		UndoTransaction* activeTransaction = NULL;
 		if (itemText.lengthOfSelection() > 0) //(kk < 0x1000)
 		{
 			bool x11Hack=false;
@@ -3795,6 +3805,9 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 #endif
 			if (!controlCharHack && !x11Hack && !k->text().isEmpty())
 			{
+				if (UndoManager::undoEnabled())
+					activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ReplaceText, "", Um::IDelete));
+
 				deleteSelectedTextFromFrame();
 				doUpdate = true;
 			}
@@ -3811,6 +3824,20 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 		//if ((kk == Qt::Key_Tab) || ((kk == Qt::Key_Return) && (buttonState & Qt::ShiftButton)))
 		if (kk == Qt::Key_Tab)
 		{
+			if (UndoManager::undoEnabled())
+			{
+				SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+				if(ss && ss->get("ETEA") == "insert_frametext")
+						ss->set("TEXT_STR",ss->get("TEXT_STR") + QString(SpecialChars::TAB));
+				else {
+					ss = new SimpleState(Um::InsertText,"",Um::ICreate);
+					ss->set("INSERT_FRAMETEXT", "insert_frametext");
+					ss->set("ETEA", QString("insert_frametext"));
+					ss->set("TEXT_STR", QString(SpecialChars::TAB));
+					ss->set("START", itemText.cursorPosition());
+					undoManager->action(this, ss);
+				}
+			}
 			itemText.insertChars(QString(SpecialChars::TAB), true);
 //			Tinput = true;
 //			view->RefreshItem(this);
@@ -3818,6 +3845,20 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 		}
 		else if ((uc[0] > QChar(31) && m_Doc->currentStyle.charStyle().font().canRender(uc[0])) || (as == 13) || (as == 30))
 		{
+			if (UndoManager::undoEnabled())
+			{
+				SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+				if(ss && ss->get("ETEA") == "insert_frametext")
+						ss->set("TEXT_STR",ss->get("TEXT_STR") + uc);
+				else {
+					ss = new SimpleState(Um::InsertText,"",Um::ICreate);
+					ss->set("INSERT_FRAMETEXT", "insert_frametext");
+					ss->set("ETEA", QString("insert_frametext"));
+					ss->set("TEXT_STR",uc);
+					ss->set("START", itemText.cursorPosition());
+					undoManager->action(this, ss);
+				}
+			}
 			itemText.insertChars(uc, true);
 			if ((m_Doc->docHyphenator->AutoCheck) && (itemText.cursorPosition() > 1))
 			{
@@ -3845,6 +3886,12 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 		}
 		if (doUpdate)
 		{
+			if (activeTransaction)
+			{
+				activeTransaction->commit();
+				delete activeTransaction;
+				activeTransaction = NULL;
+			}
 			// update layout immediately, we need MaxChars to be correct to detect 
 			// if we need to move to next frame or not
 			updateLayout();
@@ -3873,6 +3920,24 @@ void PageItem_TextFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
 void PageItem_TextFrame::deleteSelectedTextFromFrame()
 {
 	if (itemText.lengthOfSelection() > 0) {
+		if (UndoManager::undoEnabled())
+		{
+			SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+			if(ss && ss->get("ETEA") == "delete_frametext"){
+				if(itemText.startOfSelection()<ss->getInt("START")){
+					ss->set("START",itemText.startOfSelection());
+					ss->set("TEXT_STR",itemText.text(itemText.startOfSelection(),itemText.lengthOfSelection()) + ss->get("TEXT_STR"));
+				} else
+					ss->set("TEXT_STR",ss->get("TEXT_STR") + itemText.text(itemText.startOfSelection(),itemText.lengthOfSelection()));
+			}else {
+				ss = new SimpleState(Um::DeleteText,"",Um::IDelete);
+				ss->set("DELETE_FRAMETEXT", "delete_frametext");
+				ss->set("ETEA", QString("delete_frametext"));
+				ss->set("TEXT_STR",itemText.text(itemText.startOfSelection(),itemText.lengthOfSelection()));
+				ss->set("START", itemText.startOfSelection());
+				undoManager->action(this, ss);
+			}
+		}
 		itemText.setCursorPosition( itemText.startOfSelection() );
 		itemText.removeSelection();
 		HasSel = false;
diff --git a/Scribus/scribus/scribus.cpp b/Scribus/scribus/scribus.cpp
index 7274e67..47011bd 100644
--- a/Scribus/scribus/scribus.cpp
+++ b/Scribus/scribus/scribus.cpp
@@ -1173,9 +1173,33 @@ void ScribusMainWindow::specialActionKeyEvent(const QString& actionName, int uni
 				{
 					if (unicodevalue!=-1)
 					{
-						if (currItem->HasSel)
+						UndoTransaction* activeTransaction = NULL;
+						if (currItem->HasSel){
+							if (UndoManager::undoEnabled())
+								activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ReplaceText, "", Um::IDelete));
 							currItem->deleteSelectedTextFromFrame();
+						}
+						if (UndoManager::undoEnabled())
+						{
+							SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+							if(ss && ss->get("ETEA") == "insert_frametext")
+									ss->set("TEXT_STR",ss->get("TEXT_STR") + QString(QChar(unicodevalue)));
+							else {
+								ss = new SimpleState(Um::InsertText,"",Um::ICreate);
+								ss->set("INSERT_FRAMETEXT", "insert_frametext");
+								ss->set("ETEA", QString("insert_frametext"));
+								ss->set("TEXT_STR", QString(QChar(unicodevalue)));
+								ss->set("START", currItem->itemText.cursorPosition());
+								undoManager->action(currItem, ss);
+							}
+						}
 						currItem->itemText.insertChars(QString(QChar(unicodevalue)), true);
+						if (activeTransaction)
+						{
+							activeTransaction->commit();
+							delete activeTransaction;
+							activeTransaction = NULL;
+						}
 					}
 					else if (actionName=="unicodeSoftHyphen") //ignore the char as we use an attribute if the text item, for now.
 					{
@@ -1188,6 +1212,20 @@ void ScribusMainWindow::specialActionKeyEvent(const QString& actionName, int uni
 							fl |= ScStyle_HyphenationPossible;
 							currItem->itemText.item(qMax(currItem->CPos-1,0))->setEffects(fl);
 #else
+							if (UndoManager::undoEnabled())
+							{
+								SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
+								if(ss && ss->get("ETEA") == "insert_frametext")
+										ss->set("TEXT_STR",ss->get("TEXT_STR") + QString(SpecialChars::SHYPHEN));
+								else {
+									ss = new SimpleState(Um::InsertText,"",Um::ICreate);
+									ss->set("INSERT_FRAMETEXT", "insert_frametext");
+									ss->set("ETEA", QString("insert_frametext"));
+									ss->set("TEXT_STR", QString(SpecialChars::SHYPHEN));
+									ss->set("START", currItem->itemText.cursorPosition());
+									undoManager->action(currItem, ss);
+								}
+							}
 							currItem->itemText.insertChars(QString(SpecialChars::SHYPHEN), true);
 #endif
 						}
@@ -5111,7 +5149,14 @@ void ScribusMainWindow::slotEditPaste()
 				dig.parseMemory(xml, xml.length());
 
 				StoryText* story = dig.result<StoryText>();
-
+				if (UndoManager::undoEnabled())
+				{
+					ScItemState<StoryText> *is = new ScItemState<StoryText>(Um::Paste);
+					is->set("PASTE_TEXT", "paste_text");
+					is->set("START",currItem->itemText.cursorPosition());
+					is->setItem(*story);
+					undoManager->action(currItem, is);
+				}
 				currItem->itemText.insert(*story);
 
 				delete story;
@@ -5178,8 +5223,16 @@ void ScribusMainWindow::slotEditPaste()
 				doc->maxCanvasCoordinate = maxSize;
 				if (outlinePalette->isVisible())
 					outlinePalette->BuildTree();
-				currItem->itemText.insertObject(fIndex);
 				undoManager->setUndoEnabled(true);
+				if (UndoManager::undoEnabled())
+				{
+					SimpleState *is = new SimpleState(Um::Paste,"",Um::IPaste);
+					is->set("PASTE_INLINE", "paste_inline");
+					is->set("START",currItem->itemText.cursorPosition());
+					is->set("INDEX",fIndex);
+					undoManager->action(currItem, is);
+				}
+				currItem->itemText.insertObject(fIndex);
 				doc->m_Selection->delaySignalsOff();
 				inlinePalette->unsetDoc();
 				inlinePalette->setDoc(doc);
diff --git a/Scribus/scribus/scribusdoc.cpp b/Scribus/scribus/scribusdoc.cpp
index d816fdb..3cde579 100644
--- a/Scribus/scribus/scribusdoc.cpp
+++ b/Scribus/scribus/scribusdoc.cpp
@@ -8400,8 +8400,8 @@ void ScribusDoc::itemSelection_SetParagraphStyle(const ParagraphStyle & newStyle
 	if (selectedItemCount == 0)
 		return;
 	UndoTransaction* activeTransaction = NULL;
-	if (selectedItemCount > 1)
-		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::ApplyTextStyle, newStyle.displayName(), Um::IFont));
+	if (UndoManager::undoEnabled())
+		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::SetStyle, newStyle.displayName(), Um::IFont));
 	for (uint aa = 0; aa < selectedItemCount; ++aa)
 	{
 		PageItem *currItem = itemSelection->itemAt(aa);
@@ -8454,8 +8454,8 @@ void ScribusDoc::itemSelection_EraseParagraphStyle(Selection* customSelection)
 	if (selectedItemCount == 0)
 		return;
 	UndoTransaction* activeTransaction = NULL;
-	if (selectedItemCount > 1)
-		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::ApplyTextStyle, tr( "remove direct paragraph formatting" ), Um::IFont));
+	if (UndoManager::undoEnabled())
+		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::RemoveTextStyle, tr( "remove direct paragraph formatting" ), Um::IFont));
 	for (uint aa = 0; aa < selectedItemCount; ++aa)
 	{
 		PageItem *currItem = itemSelection->itemAt(aa);
@@ -8479,17 +8479,40 @@ void ScribusDoc::itemSelection_EraseParagraphStyle(Selection* customSelection)
 				{
 					ParagraphStyle newStyle;
 					newStyle.setParent(currItem->itemText.paragraphStyle(pos).parent());
+					if (UndoManager::undoEnabled())
+					{
+						ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+						is->set("SET_PARASTYLE", "set_parastyle");
+						is->set("POS",pos);
+						is->setItem(QPair<ParagraphStyle,ParagraphStyle>(newStyle, currItem->itemText.paragraphStyle(pos)));
+						undoManager->action(currItem, is);
+					}
 					currItem->itemText.setStyle(pos, newStyle);
 				}
 			}
 			ParagraphStyle newStyle2;
 			newStyle2.setParent(currItem->itemText.paragraphStyle(stop).parent());
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("SET_PARASTYLE", "set_parastyle");
+				is->set("POS",stop);
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(newStyle2, currItem->itemText.paragraphStyle(stop)));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.setStyle(stop, newStyle2);
 		}
 		else
 		{
 			ParagraphStyle newStyle;
 			newStyle.setParent(currItem->itemText.defaultStyle().parent());
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("APPLY_DEFAULTPARASTYLE", "apply_defaultparastyle");
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(newStyle, currItem->itemText.defaultStyle()));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.setDefaultStyle(newStyle);
 		}
 		currItem->invalid = true;
@@ -8524,6 +8547,13 @@ void ScribusDoc::itemSelection_ApplyParagraphStyle(const ParagraphStyle & newSty
 		{
 			ParagraphStyle dstyle(currItem->itemText.defaultStyle());
 			dstyle.applyStyle(newStyle);
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("APPLY_DEFAULTPARASTYLE", "apply_defaultparastyle");
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(dstyle, currItem->itemText.defaultStyle()));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.setDefaultStyle(dstyle);
 		}
 		if (currItemTextCount > 0)
@@ -8541,9 +8571,25 @@ void ScribusDoc::itemSelection_ApplyParagraphStyle(const ParagraphStyle & newSty
 			{
 				if (currItem->itemText.text(pos) == SpecialChars::PARSEP)
 				{
+					if (UndoManager::undoEnabled())
+					{
+						ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+						is->set("APPLY_PARASTYLE", "apply_parastyle");
+						is->set("POS",pos);
+						is->setItem(QPair<ParagraphStyle,ParagraphStyle>(newStyle, currItem->itemText.paragraphStyle(pos)));
+						undoManager->action(currItem, is);
+					}
 					currItem->itemText.applyStyle(pos, newStyle, rmDirectFormatting);
 				}
 			}
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("APPLY_PARASTYLE", "apply_parastyle");
+				is->set("POS",stop);
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(newStyle, currItem->itemText.paragraphStyle(stop)));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.applyStyle(stop, newStyle, rmDirectFormatting);
 			currItem->invalid = true;
 		}
@@ -8569,7 +8615,7 @@ void ScribusDoc::itemSelection_ApplyCharStyle(const CharStyle & newStyle, Select
 	if (selectedItemCount == 0)
 		return;
 	UndoTransaction* activeTransaction = NULL;
-	if (selectedItemCount > 1)
+	if (UndoManager::undoEnabled())
 		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::ApplyTextStyle, newStyle.asString(), Um::IFont));
 	for (uint aa = 0; aa < selectedItemCount; ++aa)
 	{
@@ -8595,6 +8641,15 @@ void ScribusDoc::itemSelection_ApplyCharStyle(const CharStyle & newStyle, Select
 					length = start < currItem->itemText.length() ? 1 : 0;
 				}
 			}
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<CharStyle,CharStyle> > *is = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+				is->set("APPLY_CHARSTYLE", "apply_charstyle");
+				is->set("START",start);
+				is->set("LENGTH",qMax(0,length));
+				is->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(start)));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.applyCharStyle(start, qMax(0, length), newStyle);
 			currItem->invalid = true;
 		}
@@ -8602,6 +8657,20 @@ void ScribusDoc::itemSelection_ApplyCharStyle(const CharStyle & newStyle, Select
 		{
 			ParagraphStyle dstyle(currItem->itemText.defaultStyle());
 			dstyle.charStyle().applyCharStyle(newStyle);
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("APPLY_DEFAULTPARASTYLE", "apply_defaultparastyle");
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(dstyle, currItem->itemText.defaultStyle()));
+				undoManager->action(currItem, is);
+
+				ScItemState<QPair<CharStyle,CharStyle> > *ist = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+				ist->set("APPLY_CHARSTYLE", "apply_charstyle");
+				ist->set("START",0);
+				ist->set("LENGTH",currItem->itemText.length());
+				ist->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(0)));
+				undoManager->action(currItem, ist);
+			}
 			currItem->itemText.setDefaultStyle(dstyle);
 //			if (currItem->asPathText())
 			currItem->itemText.applyCharStyle(0, currItem->itemText.length(), newStyle);
@@ -8629,7 +8698,7 @@ void ScribusDoc::itemSelection_SetCharStyle(const CharStyle & newStyle, Selectio
 	if (selectedItemCount == 0)
 		return;
 	UndoTransaction* activeTransaction = NULL;
-	if (selectedItemCount > 1)
+	if (UndoManager::undoEnabled())
 		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::ApplyTextStyle, newStyle.asString(), Um::IFont));
 	for (uint aa = 0; aa < selectedItemCount; ++aa)
 	{
@@ -8655,6 +8724,15 @@ void ScribusDoc::itemSelection_SetCharStyle(const CharStyle & newStyle, Selectio
 					length = start < currItem->itemText.length() ? 1 : 0;
 				}
 			}
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<CharStyle,CharStyle> > *is = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+				is->set("SET_CHARSTYLE", "set_charstyle");
+				is->set("START",start);
+				is->set("LENGTH",length);
+				is->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(start)));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.setCharStyle(start, length, newStyle);
 			currItem->invalid = true;
 		}
@@ -8662,6 +8740,20 @@ void ScribusDoc::itemSelection_SetCharStyle(const CharStyle & newStyle, Selectio
 		{
 			ParagraphStyle dstyle(currItem->itemText.defaultStyle());
 			dstyle.charStyle().setStyle(newStyle);
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("APPLY_DEFAULTPARASTYLE", "apply_defaultparastyle");
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(dstyle, currItem->itemText.defaultStyle()));
+				undoManager->action(currItem, is);
+
+				ScItemState<QPair<CharStyle,CharStyle> > *ist = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+				ist->set("SET_CHARSTYLE", "set_charstyle");
+				ist->set("START",0);
+				ist->set("LENGTH",currItem->itemText.length());
+				ist->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(0)));
+				undoManager->action(currItem, ist);
+			}
 			currItem->itemText.setDefaultStyle(dstyle);
 //			if (currItem->asPathText())
 			currItem->itemText.setCharStyle(0, currItem->itemText.length(), newStyle);
@@ -8688,8 +8780,8 @@ void ScribusDoc::itemSelection_EraseCharStyle(Selection* customSelection)
 	if (selectedItemCount == 0)
 		return;
 	UndoTransaction* activeTransaction = NULL;
-	if (selectedItemCount > 1)
-		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::ApplyTextStyle, tr( "remove direct char formatting" ), Um::IFont));
+	if (UndoManager::undoEnabled())
+		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::RemoveTextStyle, tr( "remove direct char formatting" ), Um::IFont));
 	for (uint aa = 0; aa < selectedItemCount; ++aa)
 	{
 		PageItem *currItem = itemSelection->itemAt(aa);
@@ -8726,6 +8818,15 @@ void ScribusDoc::itemSelection_EraseCharStyle(Selection* customSelection)
 					{
 						CharStyle newStyle;
 						newStyle.setParent(lastParent);
+						if (UndoManager::undoEnabled())
+						{
+							ScItemState<QPair<CharStyle,CharStyle> > *is = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+							is->set("SET_CHARSTYLE", "set_charstyle");
+							is->set("START",lastPos);
+							is->set("LENGTH",i-lastPos);
+							is->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(lastPos)));
+							undoManager->action(currItem, is);
+						}
 						currItem->itemText.setCharStyle(lastPos, i-lastPos, newStyle);
 						lastPos = i;
 					}
@@ -8736,6 +8837,15 @@ void ScribusDoc::itemSelection_EraseCharStyle(Selection* customSelection)
 			{
 				CharStyle newStyle2;
 				newStyle2.setParent(lastParent);
+				if (UndoManager::undoEnabled())
+				{
+					ScItemState<QPair<CharStyle,CharStyle> > *is = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+					is->set("SET_CHARSTYLE", "set_charstyle");
+					is->set("START",lastPos);
+					is->set("LENGTH",stop-lastPos);
+					is->setItem(QPair<CharStyle,CharStyle>(newStyle2, currItem->itemText.charStyle(lastPos)));
+					undoManager->action(currItem, is);
+				}
 				currItem->itemText.setCharStyle(lastPos, stop-lastPos, newStyle2);
 			}
 		}
@@ -8745,6 +8855,13 @@ void ScribusDoc::itemSelection_EraseCharStyle(Selection* customSelection)
 			CharStyle newStyle;
 			newStyle.setParent(defStyle.charStyle().parent());
 			defStyle.charStyle() = newStyle;
+			if (UndoManager::undoEnabled())
+			{
+				ScItemState<QPair<ParagraphStyle,ParagraphStyle> > *is = new ScItemState<QPair <ParagraphStyle,ParagraphStyle> >(Um::SetStyle);
+				is->set("APPLY_DEFAULTPARASTYLE", "apply_defaultparastyle");
+				is->setItem(QPair<ParagraphStyle,ParagraphStyle>(defStyle, currItem->itemText.defaultStyle()));
+				undoManager->action(currItem, is);
+			}
 			currItem->itemText.setDefaultStyle(defStyle);
 		}
 		if (currItem->asPathText())
diff --git a/Scribus/scribus/ui/loremipsum.cpp b/Scribus/scribus/ui/loremipsum.cpp
index bd84fcc..acdb3f7 100644
--- a/Scribus/scribus/ui/loremipsum.cpp
+++ b/Scribus/scribus/ui/loremipsum.cpp
@@ -46,6 +46,7 @@ for which a new license (GPL+exception) is in place.
 #include "commonstrings.h"
 #include "hyphenator.h"
 #include "util_icon.h"
+#include "undomanager.h"
 
 QString getLoremLocation(QString fname)
 {
@@ -135,6 +136,7 @@ QString LoremParser::createLorem(uint parCount, bool random)
 
 LoremManager::LoremManager(ScribusDoc* doc, QWidget* parent) : QDialog( parent )
 {
+	undoManager = UndoManager::instance();
 	m_Doc=doc;
 	setModal(true);
 	setWindowTitle( tr( "Lorem Ipsum" ) );
@@ -285,11 +287,17 @@ void LoremManager::insertLoremIpsum(QString name, int paraCount, bool random)
 			i2 = currItem->asTable()->activeCell().textFrame();
 		if (!i2->asTextFrame())
 			continue;
+		UndoTransaction* activeTransaction = NULL;
 		if (i2->itemText.length() != 0)
 		{
-			Selection tempSelection(this, false);
-			tempSelection.addItem(i2, true);
-			m_Doc->itemSelection_ClearItem(&tempSelection);
+			if (UndoManager::undoEnabled())
+				activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::AddLoremIpsum, "", Um::ICreate));
+			i2->itemText.selectAll();
+			i2->asTextFrame()->deleteSelectedTextFromFrame();
+			//We don't need to open a dialog box as the user can undo this action.
+			//Selection tempSelection(this, false);
+			//tempSelection.addItem(i2, true);
+			//m_Doc->itemSelection_ClearItem(&tempSelection);
 			/* ClearItem() doesn't return true or false so
 			the following test has to be done */
 			if (i2->itemText.length() != 0)
@@ -320,7 +328,21 @@ void LoremManager::insertLoremIpsum(QString name, int paraCount, bool random)
 #endif
 		
 		// K.I.S.S.:
-		i2->itemText.insertChars(0, lp->createLorem(paraCount, random));
+		QString sampleText = lp->createLorem(paraCount, random);
+		if (UndoManager::undoEnabled())
+		{
+			SimpleState *ss = new SimpleState(Um::AddLoremIpsum,"",Um::ICreate);
+			ss->set("LOREM_FRAMETEXT", "lorem_frametext");
+			ss->set("TEXT_STR",sampleText);
+			undoManager->action(i2, ss);
+		}
+		if (activeTransaction)
+		{
+			activeTransaction->commit();
+			delete activeTransaction;
+			activeTransaction = NULL;
+		}
+		i2->itemText.insertChars(0, sampleText);
 		delete lp;
 		if (m_Doc->docHyphenator->AutoCheck)
 			m_Doc->docHyphenator->slotHyphenate(i2);
diff --git a/Scribus/scribus/ui/loremipsum.h b/Scribus/scribus/ui/loremipsum.h
index 8e9f5a1..aeccf4c 100644
--- a/Scribus/scribus/ui/loremipsum.h
+++ b/Scribus/scribus/ui/loremipsum.h
@@ -35,6 +35,7 @@ class QTreeWidget;
 class QVBoxLayout;
 
 class ScribusDoc;
+class UndoManager;
 // class LanguageManager;
 
 
@@ -122,6 +123,7 @@ private:
 	QHBoxLayout* layout1;
 	QSpacerItem* buttonSpacer;
 	QString standardloremtext;
+	UndoManager* undoManager;
 
 	//! all lorems with Public Name -> filename structure
 	QMap<QString,QString> availableLorems;
diff --git a/Scribus/scribus/ui/propertywidget_distance.cpp b/Scribus/scribus/ui/propertywidget_distance.cpp
index a866566..f3a6f9c 100644
--- a/Scribus/scribus/ui/propertywidget_distance.cpp
+++ b/Scribus/scribus/ui/propertywidget_distance.cpp
@@ -44,6 +44,7 @@ PropertyWidget_Distance::PropertyWidget_Distance(QWidget* parent) : QFrame(paren
 	rightLabel->setBuddy(rightDistance);
 
 	columns->setDecimals(0);
+	columns->setSuffix("");
 
 	languageChange();
 
@@ -281,9 +282,10 @@ void PropertyWidget_Distance::handleColumns()
 
 	if (textItem)
 	{
-		textItem->Cols = static_cast<int>(columns->value());
+		textItem->setColumns(static_cast<int>(columns->value()));
 		displayColumns(textItem->Cols, textItem->ColGap);
-		if (static_cast<int>(columns->value()) == 1)
+		//this is already done in displayColumns()
+		/*if (static_cast<int>(columns->value()) == 1)
 		{
 			columnGap->setEnabled(false);
 			columnGapLabel->setEnabled(false);
@@ -292,7 +294,7 @@ void PropertyWidget_Distance::handleColumns()
 		{
 			columnGap->setEnabled(true);
 			columnGapLabel->setEnabled(true);
-		}
+		}*/
 		textItem->update();
 		if (m_doc->appMode == modeEditTable)
 			m_item->asTable()->update();
@@ -311,7 +313,7 @@ void PropertyWidget_Distance::handleColumnGap()
 	if (!textItem) return;
 
 	if (columnGapLabel->currentIndex() == 0)
-		textItem->ColGap = columnGap->value() / m_unitRatio;
+		textItem->setColumnGap(columnGap->value() / m_unitRatio);
 	else
 	{
 		double lineCorr;
@@ -321,7 +323,7 @@ void PropertyWidget_Distance::handleColumnGap()
 			lineCorr = 0;
 		double newWidth = columnGap->value() / m_unitRatio;
 		double newGap = qMax(((textItem->width() - textItem->textToFrameDistLeft() - textItem->textToFrameDistRight() - lineCorr) - (newWidth * textItem->Cols)) / (textItem->Cols - 1), 0.0);
-		textItem->ColGap = newGap;
+		textItem->setColumnGap(newGap);
 	}
 	textItem->update();
 	if (m_doc->appMode == modeEditTable)
@@ -358,7 +360,9 @@ void PropertyWidget_Distance::handleTabs()
 			{
 				ParagraphStyle newStyle(m_item->itemText.defaultStyle());
 				newStyle.setTabValues(dia->tmpTab);
-				m_item->itemText.setDefaultStyle(newStyle);
+				Selection tempSelection(this, false);
+				tempSelection.addItem(m_item, true);
+				m_doc->itemSelection_ApplyParagraphStyle(newStyle, &tempSelection);
 			}
 			else
 			{
@@ -467,4 +471,4 @@ void PropertyWidget_Distance::unitChange()
 	topDistance->blockSignals(false);
 	bottomDistance->blockSignals(false);
 	rightDistance->blockSignals(false);
-}
\ No newline at end of file
+}
diff --git a/Scribus/scribus/undomanager.cpp b/Scribus/scribus/undomanager.cpp
index 6358cd4..6d3282e 100644
--- a/Scribus/scribus/undomanager.cpp
+++ b/Scribus/scribus/undomanager.cpp
@@ -526,6 +526,13 @@ void UndoManager::action(UndoObject* target, UndoState* state,
 	target->setUName(oldName);
 }
 
+UndoState* UndoManager::getLastUndo(){
+	if(stacks_[currentDoc_].undoActions_.size()>0)
+		return stacks_[currentDoc_].undoActions_[0];
+	else
+		return 0;
+}
+
 void UndoManager::undo(int steps)
 {
 	if (!undoEnabled_)
@@ -928,7 +935,10 @@ void UndoManager::languageChange()
 	UndoManager::ImportOOoDraw      = tr("Import OpenOffice.org Draw image");
 	UndoManager::ImportAI           = tr("Import AI drawing");
 	UndoManager::ImportXfig         = tr("Import XFig drawing");
+	UndoManager::Columns            = tr("Change columns");
+	UndoManager::ColumnsGap         = tr("Change columns gap");
 	UndoManager::ImportWMF          = tr("Import WMF drawing");
+	UndoManager::TextFrameDist      = tr("Change text to frame distance");
 	UndoManager::ScratchSpace       = tr("Scratch space");
 	//UndoManager::TextFlow           = tr("Text flows around the frame");
 	UndoManager::ObjectFrame        = tr("Text flows around the frame");
@@ -951,6 +961,14 @@ void UndoManager::languageChange()
 	UndoManager::ResetContourLine   = tr("Reset contour line");
 	UndoManager::AddPage            = tr("Add page");
 	UndoManager::AddPages           = tr("Add pages");
+	UndoManager::ReplaceText        = tr("Replace text");
+	UndoManager::FirstLineOffset    = tr("Change First Line Offset");
+	UndoManager::DeleteText         = tr("Delete text");
+	UndoManager::InsertText         = tr("Insert text");
+	UndoManager::AppendText         = tr("Append text");
+	UndoManager::ImportText         = tr("Import text");
+	UndoManager::ClearText          = tr("Clear text");
+	UndoManager::AddLoremIpsum      = tr("Add Lorem Ipsum");
 	UndoManager::DeletePage         = tr("Delete page");
 	UndoManager::DeletePages        = tr("Delete pages");
 	UndoManager::ChangePageProps    = tr("Change page properties");
@@ -974,6 +992,7 @@ void UndoManager::languageChange()
 	UndoManager::ChangeFormula      = tr("Change formula");
 	UndoManager::MultipleDuplicate  = tr("Multiple duplicate");
 	UndoManager::ApplyTextStyle     = tr("Apply text style");
+	UndoManager::RemoveTextStyle    = tr("Remove text style");
 	UndoManager::MenuUndo           = tr("&Undo: %1", "f.e. Undo: Move");
 	UndoManager::MenuUndoEmpty      = tr("&Undo");
 	UndoManager::MenuRedo           = tr("&Redo: %1", "f.e. Redo: Move");
@@ -1087,6 +1106,7 @@ QString UndoManager::ItemsInvolved      = "";
 QString UndoManager::ItemsInvolved2     = "";
 uint    UndoManager::ItemsInvolvedLimit = 20;
 QString UndoManager::Cancel             = "";
+QString UndoManager::TextFrameDist      = "";
 QString UndoManager::SetFill            = "";
 QString UndoManager::ColorFromTo        = "";
 QString UndoManager::SetShade           = "";
@@ -1114,6 +1134,7 @@ QString UndoManager::Cut                = "";
 QString UndoManager::Transparency       = "";
 QString UndoManager::LineTransparency   = "";
 QString UndoManager::LineStyle          = "";
+QString UndoManager::FirstLineOffset    = "";
 QString UndoManager::LineEnd            = "";
 QString UndoManager::LineJoin           = "";
 QString UndoManager::LineWidth          = "";
@@ -1176,6 +1197,13 @@ QString UndoManager::ChangeShapeType    = "";
 QString UndoManager::ResetContourLine   = "";
 QString UndoManager::AddPage            = "";
 QString UndoManager::AddPages           = "";
+QString UndoManager::DeleteText         = "";
+QString UndoManager::AppendText         = "";
+QString UndoManager::ImportText         = "";
+QString UndoManager::ClearText          = "";
+QString UndoManager::ReplaceText        = "";
+QString UndoManager::InsertText         = "";
+QString UndoManager::AddLoremIpsum      = "";
 QString UndoManager::DeletePage         = "";
 QString UndoManager::DeletePages        = "";
 QString UndoManager::ChangePageProps    = "";
@@ -1199,11 +1227,14 @@ QString UndoManager::GetImage           = "";
 QString UndoManager::ChangeFormula      = "";
 QString UndoManager::MultipleDuplicate  = "";
 QString UndoManager::ApplyTextStyle     = "";
+QString UndoManager::RemoveTextStyle    = "";
 QString UndoManager::MenuUndo           = "";
 QString UndoManager::MenuUndoEmpty      = "";
 QString UndoManager::MenuRedo           = "";
 QString UndoManager::MenuRedoEmpty      = "";
 QString UndoManager::EditContour        = "";
+QString UndoManager::Columns            = "";
+QString UndoManager::ColumnsGap         = "";
 QString UndoManager::ResetControlPoint  = "";
 QString UndoManager::ResetControlPoints = "";
 QString UndoManager::ImageEffects       = "";
diff --git a/Scribus/scribus/undomanager.h b/Scribus/scribus/undomanager.h
index fd4fe2e..9d5a898 100644
--- a/Scribus/scribus/undomanager.h
+++ b/Scribus/scribus/undomanager.h
@@ -353,6 +353,8 @@ public:
 	 */
 	bool isGlobalMode();
 
+	UndoState* getLastUndo();
+
 private:
 	/**
 	 * @brief The only instance of UndoManager available.
@@ -563,6 +565,14 @@ public:
 	static QString ResetContourLine;
 	static QString AddPage;
 	static QString AddPages;
+	static QString ReplaceText;
+	static QString FirstLineOffset;
+	static QString AppendText;
+	static QString ImportText;
+	static QString ClearText;
+	static QString AddLoremIpsum;
+	static QString DeleteText;
+	static QString InsertText;
 	static QString DeletePage;
 	static QString DeletePages;
 	static QString ChangePageProps;
@@ -586,6 +596,10 @@ public:
 	static QString ChangeFormula;
 	static QString MultipleDuplicate;
 	static QString ApplyTextStyle;
+	static QString RemoveTextStyle;
+	static QString Columns;
+	static QString ColumnsGap;
+	static QString TextFrameDist;
 	static QString MenuUndo;
 	static QString MenuUndoEmpty;
 	static QString MenuRedo;
Patch.diff (51,216 bytes)   

Issue History

Date Modified Username Field Change
2012-06-26 20:27 Chelen New Issue
2012-06-26 20:27 Chelen Status new => assigned
2012-06-26 20:27 Chelen Assigned To => Chelen
2012-06-26 20:27 Chelen File Added: Patch.diff
2012-06-26 20:54 cbradney Status assigned => resolved
2012-06-26 20:54 cbradney Fixed in Version => 1.5.0svn
2012-06-26 20:54 cbradney Resolution open => fixed
2012-06-26 22:34 Chelen Relationship added related to 0010216
2012-06-26 22:34 Chelen Relationship added related to 0010310
2012-06-26 22:35 Chelen Relationship added related to 0009802
2012-07-01 20:34 cbradney Status resolved => closed