r17641 by craig - #10805 / Chelen: Text undo for 1.5

scribus-commit scribus-commit at lists.scribus.net
Tue Jun 26 20:48:09 UTC 2012


Author: craig
Date: Tue Jun 26 20:48:09 2012
New Revision: 17641

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17641
Log:
#10805 / Chelen: Text undo for 1.5

Modified:
    trunk/Scribus/scribus/canvasmode.cpp
    trunk/Scribus/scribus/canvasmode.h
    trunk/Scribus/scribus/canvasmode_edit.cpp
    trunk/Scribus/scribus/gtaction.cpp
    trunk/Scribus/scribus/gtaction.h
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/pageitem_textframe.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/ui/loremipsum.cpp
    trunk/Scribus/scribus/ui/loremipsum.h
    trunk/Scribus/scribus/ui/propertywidget_distance.cpp
    trunk/Scribus/scribus/undomanager.cpp
    trunk/Scribus/scribus/undomanager.h

Modified: trunk/Scribus/scribus/canvasmode.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/canvasmode.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode.cpp (original)
+++ trunk/Scribus/scribus/canvasmode.cpp Tue Jun 26 20:48:09 2012
@@ -76,7 +76,8 @@
 	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);

Modified: trunk/Scribus/scribus/canvasmode.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/canvasmode.h
==============================================================================
--- trunk/Scribus/scribus/canvasmode.h (original)
+++ trunk/Scribus/scribus/canvasmode.h Tue Jun 26 20:48:09 2012
@@ -36,6 +36,7 @@
 class QKeyEvent;
 class QPainter;
 
+class  UndoManager;
 class  Canvas;
 struct CanvasViewMode;
 class  PanGesture;
@@ -140,6 +141,7 @@
 	
 
 protected:
+	UndoManager* undoManager;
 	ScribusView * const m_view;	
 	Canvas * const m_canvas;
 	ScribusDoc * const m_doc;

Modified: trunk/Scribus/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/canvasmode_edit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edit.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_edit.cpp Tue Jun 26 20:48:09 2012
@@ -487,6 +487,12 @@
 
 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());

Modified: trunk/Scribus/scribus/gtaction.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/gtaction.cpp
==============================================================================
--- trunk/Scribus/scribus/gtaction.cpp (original)
+++ trunk/Scribus/scribus/gtaction.cpp Tue Jun 26 20:48:09 2012
@@ -43,6 +43,8 @@
 #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 @@
 	doAppend = append;
 	updateParagraphStyles = false;
 	overridePStyleFont = true;
+	undoManager = UndoManager::instance();
 }
 
 void gtAction::setProgressInfo()
@@ -108,42 +111,54 @@
 
 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();
-		}
-	}
-
-	QChar ch0(0), ch5(5), ch10(10), ch13(13); 
-	for (int a = 0; a < text.length(); ++a)
-	{
-		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));
-	}
-	
+			it->itemText.selectAll();
+			it->asTextFrame()->deleteSelectedTextFromFrame();
+		}
+	}
+
+	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())
+	{
+		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)

Modified: trunk/Scribus/scribus/gtaction.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/gtaction.h
==============================================================================
--- trunk/Scribus/scribus/gtaction.h (original)
+++ trunk/Scribus/scribus/gtaction.h Tue Jun 26 20:48:09 2012
@@ -41,6 +41,7 @@
 class ParagraphStyle;
 class ScribusDoc;
 class ScribusMainWindow;
+class UndoManager;
 
 class gtStyle;
 class gtParagraphStyle;
@@ -52,6 +53,7 @@
 class SCRIBUS_API gtAction
 {
 private:
+	UndoManager* undoManager;
 	ScribusMainWindow* m_ScMW;
 	PageItem *textFrame;
 	PageItem *it;

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Tue Jun 26 20:48:09 2012
@@ -1376,34 +1376,83 @@
 
 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::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 @@
 			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 @@
 			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);
 	}
@@ -4472,6 +4573,191 @@
 	m_Doc->setMasterPageMode(oldMPMode);
 	m_Doc->useRaster = useRasterBackup;
 	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)
@@ -7348,6 +7634,13 @@
 {
 	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;
 	}
 }

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h (original)
+++ trunk/Scribus/scribus/pageitem.h Tue Jun 26 20:48:09 2012
@@ -1209,6 +1209,23 @@
 	 * @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);

Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp Tue Jun 26 20:48:09 2012
@@ -3301,7 +3301,10 @@
 		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 @@
 	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 @@
 		break;
 	default:
 		bool doUpdate = false;
+		UndoTransaction* activeTransaction = NULL;
 		if (itemText.lengthOfSelection() > 0) //(kk < 0x1000)
 		{
 			bool x11Hack=false;
@@ -3795,6 +3805,9 @@
 #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 @@
 		//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 @@
 		}
 		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 @@
 		}
 		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::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;

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Tue Jun 26 20:48:09 2012
@@ -1173,9 +1173,33 @@
 				{
 					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 @@
 							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 @@
 				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 @@
 				doc->maxCanvasCoordinate = maxSize;
 				if (outlinePalette->isVisible())
 					outlinePalette->BuildTree();
+				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);
-				undoManager->setUndoEnabled(true);
 				doc->m_Selection->delaySignalsOff();
 				inlinePalette->unsetDoc();
 				inlinePalette->setDoc(doc);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Tue Jun 26 20:48:09 2012
@@ -8409,8 +8409,8 @@
 	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);
@@ -8463,8 +8463,8 @@
 	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);
@@ -8488,17 +8488,40 @@
 				{
 					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;
@@ -8533,6 +8556,13 @@
 		{
 			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)
@@ -8550,8 +8580,24 @@
 			{
 				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;
@@ -8578,7 +8624,7 @@
 	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)
 	{
@@ -8604,6 +8650,15 @@
 					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;
 		}
@@ -8611,6 +8666,20 @@
 		{
 			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);
@@ -8638,7 +8707,7 @@
 	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)
 	{
@@ -8664,6 +8733,15 @@
 					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;
 		}
@@ -8671,6 +8749,20 @@
 		{
 			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);
@@ -8697,8 +8789,8 @@
 	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);
@@ -8735,6 +8827,15 @@
 					{
 						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;
 					}
@@ -8745,6 +8846,15 @@
 			{
 				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);
 			}
 		}
@@ -8754,6 +8864,13 @@
 			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())

Modified: trunk/Scribus/scribus/ui/loremipsum.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/ui/loremipsum.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/loremipsum.cpp (original)
+++ trunk/Scribus/scribus/ui/loremipsum.cpp Tue Jun 26 20:48:09 2012
@@ -46,6 +46,7 @@
 #include "commonstrings.h"
 #include "hyphenator.h"
 #include "util_icon.h"
+#include "undomanager.h"
 
 QString getLoremLocation(QString fname)
 {
@@ -135,6 +136,7 @@
 
 LoremManager::LoremManager(ScribusDoc* doc, QWidget* parent) : QDialog( parent )
 {
+	undoManager = UndoManager::instance();
 	m_Doc=doc;
 	setModal(true);
 	setWindowTitle( tr( "Lorem Ipsum" ) );
@@ -285,11 +287,17 @@
 			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 @@
 #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);

Modified: trunk/Scribus/scribus/ui/loremipsum.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/ui/loremipsum.h
==============================================================================
--- trunk/Scribus/scribus/ui/loremipsum.h (original)
+++ trunk/Scribus/scribus/ui/loremipsum.h Tue Jun 26 20:48:09 2012
@@ -35,6 +35,7 @@
 class QVBoxLayout;
 
 class ScribusDoc;
+class UndoManager;
 // class LanguageManager;
 
 
@@ -122,6 +123,7 @@
 	QHBoxLayout* layout1;
 	QSpacerItem* buttonSpacer;
 	QString standardloremtext;
+	UndoManager* undoManager;
 
 	//! all lorems with Public Name -> filename structure
 	QMap<QString,QString> availableLorems;

Modified: trunk/Scribus/scribus/ui/propertywidget_distance.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/ui/propertywidget_distance.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertywidget_distance.cpp (original)
+++ trunk/Scribus/scribus/ui/propertywidget_distance.cpp Tue Jun 26 20:48:09 2012
@@ -44,6 +44,7 @@
 	rightLabel->setBuddy(rightDistance);
 
 	columns->setDecimals(0);
+	columns->setSuffix("");
 
 	languageChange();
 
@@ -281,9 +282,10 @@
 
 	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 @@
 		{
 			columnGap->setEnabled(true);
 			columnGapLabel->setEnabled(true);
-		}
+		}*/
 		textItem->update();
 		if (m_doc->appMode == modeEditTable)
 			m_item->asTable()->update();
@@ -311,7 +313,7 @@
 	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 @@
 			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 @@
 			{
 				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 @@
 	topDistance->blockSignals(false);
 	bottomDistance->blockSignals(false);
 	rightDistance->blockSignals(false);
-}
+}

Modified: trunk/Scribus/scribus/undomanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/undomanager.cpp
==============================================================================
--- trunk/Scribus/scribus/undomanager.cpp (original)
+++ trunk/Scribus/scribus/undomanager.cpp Tue Jun 26 20:48:09 2012
@@ -524,6 +524,13 @@
 		target->setUName(targetName);
 	action(target, state, targetPixmap);
 	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)
@@ -928,7 +935,10 @@
 	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 @@
 	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 @@
 	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::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::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::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::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       = "";

Modified: trunk/Scribus/scribus/undomanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17641&path=/trunk/Scribus/scribus/undomanager.h
==============================================================================
--- trunk/Scribus/scribus/undomanager.h (original)
+++ trunk/Scribus/scribus/undomanager.h Tue Jun 26 20:48:09 2012
@@ -352,6 +352,8 @@
 	 * @return true if in global mode and false if in object specific mode
 	 */
 	bool isGlobalMode();
+
+	UndoState* getLastUndo();
 
 private:
 	/**
@@ -563,6 +565,14 @@
 	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 @@
 	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;




More information about the scribus-commit mailing list