r21964 by jghali - improve undo of paragraph separator insertion

scribus-commit scribus-commit at lists.scribus.net
Sat Apr 22 10:39:30 UTC 2017


Author: jghali
Date: Sat Apr 22 10:39:30 2017
New Revision: 21964

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21964
Log:
improve undo of paragraph separator insertion

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=21964&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp	(original)
+++ trunk/Scribus/scribus/pageitem.cpp	Sat Apr 22 10:39:30 2017
@@ -4909,33 +4909,35 @@
 			else if (ss->contains("DELETE_FRAMEPARA"))
 				restoreDeleteFrameParagraph(ss, isUndo);
 			else if (ss->contains("INSERT_FRAMETEXT"))
-				restoreInsertFrameText(ss,isUndo);
+				restoreInsertFrameText(ss, isUndo);
+			else if (ss->contains("INSERT_FRAMEPARA"))
+				restoreInsertFrameParagraph(ss, isUndo);
 			else if (ss->contains("LOREM_FRAMETEXT"))
-				restoreInsertFrameText(ss,isUndo);
+				restoreInsertFrameText(ss, isUndo);
 			else if (ss->contains("APPLY_CHARSTYLE"))
-				restoreCharStyle(ss,isUndo);
+				restoreCharStyle(ss, isUndo);
 			else if (ss->contains("SET_CHARSTYLE"))
-				restoreSetCharStyle(ss,isUndo);
+				restoreSetCharStyle(ss, isUndo);
 			else if (ss->contains("SET_PARASTYLE"))
-				restoreSetParagraphStyle(ss,isUndo);
+				restoreSetParagraphStyle(ss, isUndo);
 			else if (ss->contains("APPLY_PARASTYLE"))
-				restoreParagraphStyle(ss,isUndo);
+				restoreParagraphStyle(ss, isUndo);
 			else if (ss->contains("APPLY_DEFAULTPARASTYLE"))
-				restoreDefaultParagraphStyle(ss,isUndo);
+				restoreDefaultParagraphStyle(ss, isUndo);
 			else if (ss->contains("LEFT_TEXTFRAMEDIST"))
-				restoreLeftTextFrameDist(ss,isUndo);
+				restoreLeftTextFrameDist(ss, isUndo);
 			else if (ss->contains("RIGHT_TEXTFRAMEDIST"))
-				restoreRightTextFrameDist(ss,isUndo);
+				restoreRightTextFrameDist(ss, isUndo);
 			else if (ss->contains("TOP_TEXTFRAMEDIST"))
-				restoreTopTextFrameDist(ss,isUndo);
+				restoreTopTextFrameDist(ss, isUndo);
 			else if (ss->contains("BOTTOM_TEXTFRAMEDIST"))
-				restoreBottomTextFrameDist(ss,isUndo);
+				restoreBottomTextFrameDist(ss, isUndo);
 			else if (ss->contains("FIRSTLINEOFFSET"))
-				restoreFirstLineOffset(ss,isUndo);
+				restoreFirstLineOffset(ss, isUndo);
 			else if (ss->contains("PASTE_TEXT"))
-				restorePasteText(ss,isUndo);
+				restorePasteText(ss, isUndo);
 			else if (ss->contains("CORNER_RADIUS"))
-				restoreCornerRadius(ss,isUndo);
+				restoreCornerRadius(ss, isUndo);
 			else if (ss->contains("IMAGEFLIPH"))
 			{
 				select();
@@ -5069,15 +5071,15 @@
 			else if (ss->contains("APPLY_IMAGE_EFFECTS"))
 				restoreImageEffects(ss, isUndo);
 			else if (ss->contains("DROP_LINKS"))
-				restoreDropLinks(ss,isUndo);
+				restoreDropLinks(ss, isUndo);
 			else if (ss->contains("LINK_TEXT_FRAME"))
-				restoreLinkTextFrame(ss,isUndo);
+				restoreLinkTextFrame(ss, isUndo);
 			else if (ss->contains("UNLINK_TEXT_FRAME"))
-				restoreUnlinkTextFrame(ss,isUndo);
+				restoreUnlinkTextFrame(ss, isUndo);
 			else if (ss->contains("CLEAR_IMAGE"))
-				restoreClearImage(ss,isUndo);
+				restoreClearImage(ss, isUndo);
 			else if (ss->contains("PASTE_INLINE"))
-				restorePasteInline(ss,isUndo);
+				restorePasteInline(ss, isUndo);
 			else if (ss->contains("TRANSFORM"))
 				restoreTransform(ss, isUndo);
 			else if (ss->contains("PATH_OPERATION"))
@@ -6687,6 +6689,27 @@
 	}
 	else
 		itemText.insertChars(start, text);
+}
+
+void PageItem::restoreInsertFrameParagraph(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.select(start, 1);
+		asTextFrame()->deleteSelectedTextFromFrame();
+		itemText.applyStyle(start, is->getItem());
+	}
+	else
+	{
+		itemText.insertChars(start, SpecialChars::PARSEP);
+		invalid = true;
+		invalidateLayout();
+	}
+	update();
 }
 
 void PageItem::restoreCornerRadius(SimpleState *state, bool isUndo)

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21964&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h	(original)
+++ trunk/Scribus/scribus/pageitem.h	Sat Apr 22 10:39:30 2017
@@ -1580,6 +1580,7 @@
 	void restoreImageScaleChange(SimpleState *state, bool isUndo);
 	void restoreImageScaleMode(SimpleState *state, bool isUndo);
 	void restoreInsertFrameText(SimpleState *state, bool isUndo);
+	void restoreInsertFrameParagraph(SimpleState *state, bool isUndo);
 	void restoreLayer(SimpleState *state, bool isUndo);
 	void restoreLeftTextFrameDist(SimpleState *state, bool isUndo);
 	void restoreLineColor(SimpleState *state, bool isUndo);

Modified: trunk/Scribus/scribus/pageitem_noteframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21964&path=/trunk/Scribus/scribus/pageitem_noteframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_noteframe.cpp	Sat Apr 22 10:39:30 2017
@@ -390,6 +390,12 @@
 	updateNotesText();
 }
 
+void PageItem_NoteFrame::restoreInsertNoteParagraph(SimpleState *state, bool isUndo)
+{
+	PageItem::restoreInsertFrameParagraph(state, isUndo);
+	updateNotesText();
+}
+
 void PageItem_NoteFrame::unWeld(bool doUndo)
 {
 	if (doUndo)

Modified: trunk/Scribus/scribus/pageitem_noteframe.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21964&path=/trunk/Scribus/scribus/pageitem_noteframe.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.h	(original)
+++ trunk/Scribus/scribus/pageitem_noteframe.h	Sat Apr 22 10:39:30 2017
@@ -52,6 +52,7 @@
 	void restoreDeleteNoteText(SimpleState *state, bool isUndo);
 	void restoreDeleteNoteParagraph(SimpleState *state, bool isUndo);
 	void restoreInsertNoteText(SimpleState *state, bool isUndo);
+	void restoreInsertNoteParagraph(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=21964&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp	Sat Apr 22 10:39:30 2017
@@ -4006,16 +4006,38 @@
 					conv = 32;
 				if (UndoManager::undoEnabled())
 				{
+					ScItemState<ParagraphStyle> *ip = 0;
 					SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
-					if (ss && ss->get("ETEA") == "insert_frametext")
-						ss->set("TEXT_STR",ss->get("TEXT_STR") + QString(QChar(conv)));
+					UndoObject *undoTarget = this;
+					int cursorPos = itemText.cursorPosition();
+					if (conv == SpecialChars::PARSEP.unicode())
+					{
+						ip = new ScItemState<ParagraphStyle>(Um::InsertText, "", Um::ICreate);
+						ip->set("INSERT_FRAMEPARA");
+						ip->set("ETEA", "insert_framepara");
+						ip->set("START", cursorPos);
+						ip->setItem(itemText.paragraphStyle(cursorPos));
+						if (isNoteFrame())
+						{
+							undoTarget = dynamic_cast<UndoObject*>(m_Doc);
+							ip->set("noteframeName", getUName());
+						}
+						undoManager->action(undoTarget, ip);
+					}
+					else if (ss && ss->get("ETEA") == "insert_frametext")
+						ss->set("TEXT_STR", ss->get("TEXT_STR") + QString(QChar(conv)));
 					else {
 						ss = new SimpleState(Um::InsertText,"",Um::ICreate);
 						ss->set("INSERT_FRAMETEXT");
 						ss->set("ETEA", QString("insert_frametext"));
 						ss->set("TEXT_STR", QString(QChar(conv)));
 						ss->set("START", itemText.cursorPosition());
-						undoManager->action(this, ss);
+						if (isNoteFrame())
+						{
+							undoTarget = dynamic_cast<UndoObject*>(m_Doc);
+							ss->set("noteframeName", getUName());
+						}
+						undoManager->action(undoTarget, ss);
 					}
 				}
 				itemText.insertChars(QString(QChar(conv)), true);
@@ -4475,20 +4497,36 @@
 		{
 			if (UndoManager::undoEnabled())
 			{
+				ScItemState<ParagraphStyle> *ip = 0;
 				SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo());
-				if (ss && ss->get("ETEA") == "insert_frametext")
+				UndoObject *undoTarget = this;
+				int cursorPos = itemText.cursorPosition();
+				if (uc[0] == SpecialChars::PARSEP)
+				{
+					ip = new ScItemState<ParagraphStyle>(Um::InsertText, "", Um::ICreate);
+					ip->set("INSERT_FRAMEPARA");
+					ip->set("ETEA", "insert_framepara");
+					ip->set("START", cursorPos);
+					ip->setItem(itemText.paragraphStyle(cursorPos));
+					if (isNoteFrame())
+					{
+						undoTarget = dynamic_cast<UndoObject*>(m_Doc);
+						ip->set("noteframeName", getUName());
+					}
+					undoManager->action(undoTarget, ip);
+				}
+				else 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 = new SimpleState(Um::InsertText, "", Um::ICreate);
 					ss->set("INSERT_FRAMETEXT");
 					ss->set("ETEA", QString("insert_frametext"));
 					ss->set("TEXT_STR", uc);
-					ss->set("START", itemText.cursorPosition());
-					UndoObject * undoTarget = this;
+					ss->set("START", cursorPos);
 					if (isNoteFrame())
 					{
-						undoTarget = m_Doc;
+						undoTarget = dynamic_cast<UndoObject*>(m_Doc);
 						ss->set("noteframeName", getUName());
 					}
 					undoManager->action(undoTarget, ss);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21964&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Sat Apr 22 10:39:30 2017
@@ -1890,6 +1890,12 @@
 			PageItem * nF = getItemFromName(ss->get("noteframeName"));
 			Q_ASSERT(nF != NULL);
 			nF->asNoteFrame()->restoreInsertNoteText(ss,isUndo);
+		}
+		else if (ss->contains("INSERT_FRAMEPARA"))
+		{
+			PageItem * nF = getItemFromName(ss->get("noteframeName"));
+			Q_ASSERT(nF != NULL);
+			nF->asNoteFrame()->restoreInsertNoteParagraph(ss,isUndo);
 		}
 		else if (ss->contains("NSTYLE"))
 		{




More information about the scribus-commit mailing list