r17646 by craig - #10807: Changing paragraph style properties produce undo step for each selected paragraph

scribus-commit scribus-commit at lists.scribus.net
Wed Jun 27 20:01:37 UTC 2012


Author: craig
Date: Wed Jun 27 20:01:37 2012
New Revision: 17646

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17646
Log:
#10807: Changing paragraph style properties produce undo step for each selected paragraph

Modified:
    trunk/Scribus/scribus/canvasmode_edit.cpp
    trunk/Scribus/scribus/pageitem_textframe.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/undomanager.cpp
    trunk/Scribus/scribus/undomanager.h
    trunk/Scribus/scribus/undostate.h

Modified: trunk/Scribus/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/canvasmode_edit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edit.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_edit.cpp Wed Jun 27 20:01:37 2012
@@ -492,6 +492,14 @@
 		SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
 		if(ss)
 			ss->set("ETEA",QString(""));
+		else
+		{
+			TransactionState *ts = dynamic_cast<TransactionState*>(undoManager->getLastUndo());
+			if(ts)
+				ss = dynamic_cast<SimpleState*>(ts->at(0));
+			if(ss)
+				ss->set("ETEA",QString(""));
+		}
 	}
 // 	const double mouseX = m->globalX();
 // 	const double mouseY = m->globalY();

Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp Wed Jun 27 20:01:37 2012
@@ -3395,6 +3395,14 @@
 			SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
 			if(ss)
 				ss->set("ETEA",QString(""));
+			else
+			{
+				TransactionState *ts = dynamic_cast<TransactionState*>(undoManager->getLastUndo());
+				if(ts)
+					ss = dynamic_cast<SimpleState*>(ts->at(0));
+				if(ss)
+					ss->set("ETEA",QString(""));
+			}
 		}
 	}
 

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Wed Jun 27 20:01:37 2012
@@ -7312,7 +7312,7 @@
 {
 	CharStyle newStyle;
 	newStyle.setFont((*AllFonts)[fon]);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "FONT");
 }
 
 
@@ -7321,7 +7321,7 @@
 {
 	CharStyle newStyle;
 	newStyle.setParent(name.isEmpty()? Style::INHERIT_PARENT : name);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "NAMED_STYLE");
 }
 
 
@@ -7401,14 +7401,14 @@
 		farbe = CommonStrings::None;
 	CharStyle newStyle;
 	newStyle.setFillColor(farbe);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "FILL_COLOR");
 }
 
 void ScribusDoc::itemSelection_SetFillShade(int sha, Selection* customSelection)
 {
 	CharStyle newStyle;
 	newStyle.setFillShade(sha);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "FILL_SHADE");
 }
 
 void ScribusDoc::itemSelection_SetStrokeColor(QString farbe, Selection* customSelection)
@@ -7417,28 +7417,28 @@
 		farbe = CommonStrings::None;
 	CharStyle newStyle;
 	newStyle.setStrokeColor(farbe);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "STROKE_COLOR");
 }
 
 void ScribusDoc::itemSelection_SetStrokeShade(int sha, Selection* customSelection)
 {
 	CharStyle newStyle;
 	newStyle.setStrokeShade(sha);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "STROKE_SHADE");
 }
 
 void ScribusDoc::itemSelection_SetScaleV(int scale, Selection* customSelection)
 {
 	CharStyle newStyle;
 	newStyle.setScaleV(scale);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "SCALE_V");
 }
 
 void ScribusDoc::itemSelection_SetScaleH(int scale, Selection* customSelection)
 {
 	CharStyle newStyle;
 	newStyle.setScaleH(scale);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "SCALE_H");
 }
 
 void ScribusDoc::itemSelection_SetShadowOffsets(int shx, int shy, Selection* customSelection)
@@ -7446,7 +7446,7 @@
 	CharStyle newStyle;
 	newStyle.setShadowXOffset(shx);
 	newStyle.setShadowYOffset(shy);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "SHADOW_OFFSET");
 }
 
 void ScribusDoc::itemSelection_SetUnderline(int pos, int wid, Selection* customSelection)
@@ -7454,7 +7454,7 @@
 	CharStyle newStyle;
 	newStyle.setUnderlineOffset(pos);
 	newStyle.setUnderlineWidth(wid);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "UNDERLINE");
 }
 
 void ScribusDoc::itemSelection_SetStrikethru(int pos, int wid, Selection* customSelection)
@@ -7462,21 +7462,21 @@
 	CharStyle newStyle;
 	newStyle.setStrikethruOffset(pos);
 	newStyle.setStrikethruWidth(wid);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "STRIKE_THRU");
 }
 
 void ScribusDoc::itemSelection_SetBaselineOffset(int sha, Selection* customSelection)
 {
 	CharStyle newStyle;
 	newStyle.setBaselineOffset(sha);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "BASELINE_OFFSET");
 }
 
 void ScribusDoc::itemSelection_SetOutlineWidth(int wid, Selection* customSelection)
 {
 	CharStyle newStyle;
 	newStyle.setOutlineWidth(wid);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "OUTLINE_WIDTH");
 }
 
 void ScribusDoc::itemSelection_SetItemBrush(QString farbe)
@@ -8263,10 +8263,10 @@
 {
 	CharStyle newStyle;
 	newStyle.setFeatures(static_cast<StyleFlag>(s).featureList());
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "EFFECTS");
 	return;
 	
-	uint selectedItemCount=m_Selection->count();
+	/*uint selectedItemCount=m_Selection->count();
 	if (selectedItemCount != 0 && s != ScStyle_None)
 	{
 		UndoTransaction* activeTransaction = NULL;
@@ -8316,7 +8316,7 @@
 		}
 		m_updateManager.setUpdatesEnabled();
 		changed();
-	}
+	}*/
 }
 
 void ScribusDoc::itemSelection_SetOpticalMargins(int i, Selection* customSelection)
@@ -8339,7 +8339,7 @@
 {
 	CharStyle newStyle;
 	newStyle.setTracking(kern);
-	itemSelection_ApplyCharStyle(newStyle, customSelection);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "TRACKING");
 }
 
 void ScribusDoc::itemSelection_SetLineSpacingMode(int m, Selection* customSelection)
@@ -8351,12 +8351,12 @@
 
 void ScribusDoc::itemSelection_SetFontSize(int size, Selection* customSelection)
 {
-	if (true || ((appMode == modeEdit) || (appMode == modeEditTable)))
-	{
+	//if (true || ((appMode == modeEdit) || (appMode == modeEditTable)))
+	//{
 		CharStyle newStyle;
 		newStyle.setFontSize(size);
-		itemSelection_ApplyCharStyle(newStyle, customSelection);
-	}
+		itemSelection_ApplyCharStyle(newStyle, customSelection, "FONT_SIZE");
+	/*}
 	else
 	{
 		ParagraphStyle storyStyle;
@@ -8374,7 +8374,7 @@
 			storyStyle.setLineSpacing(docPrefsData.guidesPrefs.valueBaselineGrid-1);
 		}
 		itemSelection_ApplyParagraphStyle(storyStyle, customSelection);
-	}
+	}*/
 }
 
 void ScribusDoc::itemSelection_SetParagraphStyle(const ParagraphStyle & newStyle, Selection* customSelection)
@@ -8592,7 +8592,7 @@
 	regionsChanged()->update(QRectF());
 }
 
-void ScribusDoc::itemSelection_ApplyCharStyle(const CharStyle & newStyle, Selection* customSelection)
+void ScribusDoc::itemSelection_ApplyCharStyle(const CharStyle & newStyle, Selection* customSelection, QString ETEA)
 {
 	Selection* itemSelection = (customSelection!=0) ? customSelection : m_Selection;
 	assert(itemSelection!=0);
@@ -8636,12 +8636,29 @@
 				{
 					if (UndoManager::undoEnabled())
 					{
-						ScItemState<QPair<CharStyle,CharStyle> > *is = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
-						is->set("APPLY_CHARSTYLE", "apply_charstyle");
-						is->set("START",lastPos);
-						is->set("LENGTH",i-lastPos);
-						is->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(lastPos)));
-						undoManager->action(currItem, is);
+						UndoState* state = undoManager->getLastUndo();
+						ScItemState<QPair<CharStyle,CharStyle> > *is = NULL;
+						SimpleState *ss = NULL;
+						TransactionState *ts = dynamic_cast<TransactionState*>(state);
+						if(state && state->isTransaction())
+							ss = dynamic_cast<SimpleState*>(ts->at(0));
+						if(ss && ss->get("ETEA") == ETEA)
+						{
+							for(int i=0;i<ts->sizet();i++){
+								is = dynamic_cast<ScItemState<QPair<CharStyle,CharStyle> > *>(ts->at(i));
+								is->setItem(QPair<CharStyle,CharStyle>(newStyle, is->getItem().second));
+							}
+						}
+						else
+						{
+							is = new ScItemState<QPair <CharStyle,CharStyle> >(Um::ApplyTextStyle);
+							is->set("APPLY_CHARSTYLE", "apply_charstyle");
+							is->set("START",lastPos);
+							is->set("LENGTH",i-lastPos);
+							is->set("ETEA", ETEA);
+							is->setItem(QPair<CharStyle,CharStyle>(newStyle, currItem->itemText.charStyle(lastPos)));
+							undoManager->action(currItem, is);
+						}
 					}
 					lastPos = i;
 					lastParent = curParent;

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Wed Jun 27 20:01:37 2012
@@ -1022,7 +1022,7 @@
 
 	void itemSelection_ApplyParagraphStyle(const ParagraphStyle & newstyle, Selection* customSelection=0, bool rmDirectFormatting = false);
 	void itemSelection_SetParagraphStyle(const ParagraphStyle & newstyle, Selection* customSelection=0);
-	void itemSelection_ApplyCharStyle(const CharStyle & newstyle, Selection* customSelection=0);
+	void itemSelection_ApplyCharStyle(const CharStyle & newstyle, Selection* customSelection=0, QString ETEA = "");
 	void itemSelection_SetCharStyle(const CharStyle & newstyle, Selection* customSelection=0);
 	void itemSelection_EraseParagraphStyle(Selection* customSelection=0);
 	void itemSelection_EraseCharStyle(Selection* customSelection=0);

Modified: trunk/Scribus/scribus/undomanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/undomanager.cpp
==============================================================================
--- trunk/Scribus/scribus/undomanager.cpp (original)
+++ trunk/Scribus/scribus/undomanager.cpp Wed Jun 27 20:01:37 2012
@@ -527,10 +527,8 @@
 }
 
 UndoState* UndoManager::getLastUndo(){
-	if(stacks_[currentDoc_].undoActions_.size()>0)
-		return stacks_[currentDoc_].undoActions_[0];
-	else
-		return 0;
+	UndoState* state = stacks_[currentDoc_].getNextUndo(currentUndoObjectId_);
+	return state;
 }
 
 void UndoManager::undo(int steps)

Modified: trunk/Scribus/scribus/undomanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/undomanager.h
==============================================================================
--- trunk/Scribus/scribus/undomanager.h (original)
+++ trunk/Scribus/scribus/undomanager.h Wed Jun 27 20:01:37 2012
@@ -73,6 +73,8 @@
 	TransactionState();
 	/** @brief Destroys the TransactionState instance */
 	~TransactionState();
+	/** @brief To know if the state is a Transaction */
+	bool isTransaction(){return true;};
 	
 	/**
 	 * @brief Add a new <code>UndoState</code> object to the transaction.

Modified: trunk/Scribus/scribus/undostate.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17646&path=/trunk/Scribus/scribus/undostate.h
==============================================================================
--- trunk/Scribus/scribus/undostate.h (original)
+++ trunk/Scribus/scribus/undostate.h Wed Jun 27 20:01:37 2012
@@ -108,7 +108,8 @@
 	/** @brief redo the state described by this UndoState,
 	 *  @brief requires the related UndoObject */
 	virtual void redo();
-
+	/** @brief To know if the state is a transaction */
+	virtual bool isTransaction(){ return false;};
 	/** @brief Set the UndoObject this state belongs to */
 	virtual void setUndoObject(UndoObject *object);
 	/** @brief return the UndoObject this state belongs to */




More information about the scribus-commit mailing list