r21931 by jghali - #12276: Undo deletion of more than one paragraph doesn't restore style

scribus-commit scribus-commit at lists.scribus.net
Wed Apr 19 10:53:45 UTC 2017


Author: jghali
Date: Wed Apr 19 10:53:44 2017
New Revision: 21931

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21931
Log:
#12276: Undo deletion of more than one paragraph doesn't restore style

Modified:
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/pageitem_noteframe.cpp
    trunk/Scribus/scribus/pageitem_noteframe.h
    trunk/Scribus/scribus/pageitem_textframe.cpp
    trunk/Scribus/scribus/scribusdoc.cpp

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21931&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp	(original)
+++ trunk/Scribus/scribus/pageitem.cpp	Wed Apr 19 10:53:44 2017
@@ -4908,6 +4908,8 @@
 				restoreLineShade(ss, isUndo);
 			else if (ss->contains("DELETE_FRAMETEXT"))
 				restoreDeleteFrameText(ss, isUndo);
+			else if (ss->contains("DELETE_FRAMEPARA"))
+				restoreDeleteFrameParagraph(ss, isUndo);
 			else if (ss->contains("INSERT_FRAMETEXT"))
 				restoreInsertFrameText(ss,isUndo);
 			else if (ss->contains("LOREM_FRAMETEXT"))
@@ -6654,6 +6656,27 @@
 	update();
 }
 
+void PageItem::restoreDeleteFrameParagraph(SimpleState *ss, bool isUndo)
+{
+	ScItemState<ParagraphStyle> *is = dynamic_cast<ScItemState<ParagraphStyle> *>(ss);
+	if (!is)
+		qFatal("PageItem::restoreDeleteFrameParagraph: dynamic cast failed");
+	int start = is->getInt("START");
+	if (isUndo)
+	{
+		itemText.insertChars(start, SpecialChars::PARSEP);
+		itemText.applyStyle(start, is->getItem());
+		invalid = true;
+		invalidateLayout();
+	}
+	else
+	{
+		itemText.select(start, 1);
+		asTextFrame()->deleteSelectedTextFromFrame();
+	}
+	update();
+}
+
 void PageItem::restoreInsertFrameText(SimpleState *ss, bool isUndo)
 {
 	QString text = ss->get("TEXT_STR");

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21931&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h	(original)
+++ trunk/Scribus/scribus/pageitem.h	Wed Apr 19 10:53:44 2017
@@ -1514,6 +1514,7 @@
 	void restoreCustomLineStyle(SimpleState *state, bool isUndo);
 	void restoreDefaultParagraphStyle(SimpleState *state, bool isUndo);
 	void restoreDeleteFrameText(SimpleState *state, bool isUndo);
+	void restoreDeleteFrameParagraph(SimpleState *state, bool isUndo);
 	void restoreDropLinks(UndoState *state, bool isUndo);
 	void restoreEndArrowScale(SimpleState *state, bool isUndo);
 	void restoreFill(SimpleState *state, bool isUndo);

Modified: trunk/Scribus/scribus/pageitem_noteframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21931&path=/trunk/Scribus/scribus/pageitem_noteframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_noteframe.cpp	Wed Apr 19 10:53:44 2017
@@ -378,6 +378,12 @@
 	updateNotesText();
 }
 
+void PageItem_NoteFrame::restoreDeleteNoteParagraph(SimpleState *state, bool isUndo)
+{
+	PageItem::restoreDeleteFrameParagraph(state, isUndo);
+	updateNotesText();
+}
+
 void PageItem_NoteFrame::restoreInsertNoteText(SimpleState *state, bool isUndo)
 {
 	PageItem::restoreInsertFrameText(state, isUndo);

Modified: trunk/Scribus/scribus/pageitem_noteframe.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21931&path=/trunk/Scribus/scribus/pageitem_noteframe.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.h	(original)
+++ trunk/Scribus/scribus/pageitem_noteframe.h	Wed Apr 19 10:53:44 2017
@@ -15,6 +15,7 @@
 	PageItem_NoteFrame(ScribusDoc *doc, double x, double y, double w, double h, double w2, QString fill, QString outline);
 	PageItem_NoteFrame(PageItem_TextFrame* inFrame, NotesStyle *nStyle);
 	~PageItem_NoteFrame() { }
+
 public:
 	virtual PageItem_NoteFrame * asNoteFrame() { return this; }
 	virtual bool isNoteFrame() const { return true; }
@@ -49,6 +50,7 @@
 	void removeNote(TextNote* note) { l_notes.removeOne(note); }
 
 	void restoreDeleteNoteText(SimpleState *state, bool isUndo);
+	void restoreDeleteNoteParagraph(SimpleState *state, bool isUndo);
 	void restoreInsertNoteText(SimpleState *state, bool isUndo);
 	//overloaded PageItem::unWeld()
 	void unWeld(bool doUndo=true);

Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21931&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp	Wed Apr 19 10:53:44 2017
@@ -4568,10 +4568,12 @@
 	int start = itemText.startOfSelection();
 	int stop = itemText.endOfSelection();
 	int marksNum = 0;
-	if (UndoManager::undoEnabled()) {
+	if (UndoManager::undoEnabled()) 
+	{
 		int lastPos = start;
 		CharStyle lastParent = itemText.charStyle(start);
 		UndoState* state = undoManager->getLastUndo();
+		ScItemState<ParagraphStyle> *ip = NULL;
 		ScItemState<CharStyle> *is = NULL;
 		TransactionState *ts = NULL;
 		bool added = false;
@@ -4608,30 +4610,33 @@
 		//delete text
 		for (int i=start; i <= stop; ++i)
 		{
-			Mark* mark = i < itemText.length() && itemText.hasMark(i)? itemText.mark(i) : NULL;
+			Mark* mark = i < itemText.length() && itemText.hasMark(i) ? itemText.mark(i) : NULL;
 			const CharStyle& curParent = itemText.charStyle(i);
-			if (i==stop || !curParent.equiv(lastParent) || (mark!=NULL && mark->isType(MARKNoteFrameType)))
+			bool needParaAction = ((i < stop) && (itemText.text(i) == SpecialChars::PARSEP));
+			if (i==stop || !curParent.equiv(lastParent) || (mark && mark->isType(MARKNoteFrameType)) || needParaAction)
 			{
 				added = false;
 				lastIsDelete = false;
 				if (is && ts && is->get("ETEA") == "delete_frametext" && lastPos < is->getInt("START"))
 				{
-					if (is->getItem().equiv(lastParent))
+					int oldStart = is->getInt("START");
+					if (is->getItem().equiv(lastParent) && (i - lastPos > 0) && (start + i - lastPos == oldStart))
 					{
 						is->set("START", start);
 						is->set("TEXT_STR", itemText.text(lastPos, i - lastPos) + is->get("TEXT_STR"));
 						added = true;
-					}
-					lastIsDelete = true;
+						lastIsDelete = true;
+					}
 				}
 				else if (is && ts && is->get("ETEA") == "delete_frametext"  && lastPos >= is->getInt("START"))
 				{
-					if (is->getItem().equiv(lastParent))
+					int oldStart = is->getInt("START");
+					if (is->getItem().equiv(lastParent) && (i - lastPos > 0) && (oldStart == start))
 					{
 						is->set("TEXT_STR", is->get("TEXT_STR") + itemText.text(lastPos, i - lastPos));
 						added = true;
-					}
-					lastIsDelete = true;
+						lastIsDelete = true;
+					}
 				}
 				if (!added)
 				{
@@ -4697,6 +4702,25 @@
 				}
 				lastPos = i;
 				lastParent = curParent;
+			}
+			if (needParaAction)
+			{
+				UndoObject * undoTarget = this;
+				if (isNoteFrame())
+					undoTarget = m_Doc;
+				ip = new ScItemState<ParagraphStyle>(Um::DeleteText, "", Um::IDelete);
+				ip->set("DELETE_FRAMEPARA");
+				ip->set("START", start);
+				ip->setItem(itemText.paragraphStyle(i));
+				lastPos = i + 1;
+				if (lastPos < itemText.length())
+					lastParent = itemText.charStyle(lastPos);
+				if (ts)
+					ts->pushBack(undoTarget, ip);
+				else
+					undoManager->action(undoTarget, ip);
+				is = NULL;
+				ts = NULL;
 			}
 		}
 		if (trans)

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21931&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Wed Apr 19 10:53:44 2017
@@ -1878,6 +1878,12 @@
 			PageItem * nF = getItemFromName(ss->get("noteframeName"));
 			Q_ASSERT(nF != NULL);
 			nF->asNoteFrame()->restoreDeleteNoteText(ss, isUndo);
+		}
+		else if (ss->contains("DELETE_FRAMEPARA"))
+		{
+			PageItem * nF = getItemFromName(ss->get("noteframeName"));
+			Q_ASSERT(nF != NULL);
+			nF->asNoteFrame()->restoreDeleteNoteParagraph(ss, isUndo);
 		}
 		else if (ss->contains("INSERT_FRAMETEXT"))
 		{




More information about the scribus-commit mailing list