r16490 by craig - #9875: Add in undo/redo for text frame linking and unlinking

scribus-commit scribus-commit at lists.scribus.net
Thu Mar 24 12:39:50 CET 2011


Author: craig
Date: Thu Mar 24 11:39:50 2011
New Revision: 16490

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16490
Log:
#9875: Add in undo/redo for text frame linking and unlinking

Modified:
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/undomanager.cpp
    trunk/Scribus/scribus/undomanager.h

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16490&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Thu Mar 24 11:39:50 2011
@@ -1132,12 +1132,20 @@
 		nxt->firstChar = 0;
 		nxt = nxt->NextBox;
 	}
+	if (UndoManager::undoEnabled())
+	{
+		ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >(UndoManager::LinkTextFrame);
+		is->set("LINK_TEXT_FRAME", "linkTextFrame");
+		is->setItem(std::pair<PageItem*, PageItem*>(this, NextBox));
+		undoManager->action(this, is);
+	}
 }
 
 void PageItem::unlink()
 {
 	if( NextBox )
 	{
+		PageItem *undoNextBox=NextBox;
 		// make sure lastInFrame is valid
 		layout();
 		/*
@@ -1175,6 +1183,13 @@
 		}
 		// NextBox == NULL now
 		NextBox = NULL;
+		if (UndoManager::undoEnabled())
+		{
+			ItemState<std::pair<PageItem*, PageItem*> > *is = new ItemState<std::pair<PageItem*, PageItem*> >(UndoManager::UnlinkTextFrame);
+			is->set("UNLINK_TEXT_FRAME", "unlinkTextFrame");
+			is->setItem(std::pair<PageItem*, PageItem*>(this, undoNextBox));
+			undoManager->action(this, is);
+		}
 	}
 }
 
@@ -4089,6 +4104,10 @@
 			restoreShapeContour(ss, isUndo);
 		else if (ss->contains("APPLY_IMAGE_EFFECTS"))
 			restoreImageEffects(ss, isUndo);
+		else if (ss->contains("LINK_TEXT_FRAME"))
+			restoreLinkTextFrame(ss,isUndo);
+		else if (ss->contains("UNLINK_TEXT_FRAME"))
+			restoreUnlinkTextFrame(ss,isUndo);
 	}
 	if (!OnMasterPage.isEmpty())
 		m_Doc->setCurrentPage(oldCurrentPage);
@@ -4411,6 +4430,36 @@
 		m_Doc->itemSelection_SetImageOffset(x, y, &tempSelection);
 	else
 		m_Doc->itemSelection_SetImageOffset(ox, oy, &tempSelection);
+}
+
+void PageItem::restoreLinkTextFrame(UndoState *state, bool isUndo)
+{
+	if (!isTextFrame())
+		return;
+	if (isUndo)
+	{
+		unlink();
+	}
+	else
+	{
+		ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state);
+		asTextFrame()->link(is->getItem().second->asTextFrame());
+	}
+}
+
+void PageItem::restoreUnlinkTextFrame(UndoState *state, bool isUndo)
+{
+	if (!isTextFrame())
+		return;
+	if (isUndo)
+	{
+		ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state);
+		asTextFrame()->link(is->getItem().second->asTextFrame());
+	}
+	else
+	{
+		unlink();
+	}
 }
 
 void PageItem::restorePoly(SimpleState *state, bool isUndo, bool isContour)
@@ -6369,6 +6418,20 @@
 	}
 }
 
+void PageItem::restoreLinkTextFrame(UndoState *state, bool isUndo)
+{
+	if (!isTextFrame())
+		return;
+	if (isUndo)
+	{
+		unlink();
+	}
+	else
+	{
+		ItemState<std::pair<PageItem*, PageItem*> > *is = dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(state);
+		asTextFrame()->link(is->getItem().second->asTextFrame());
+	}
+}
 
 
 void PageItem::convertClip()

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16490&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h (original)
+++ trunk/Scribus/scribus/pageitem.h Thu Mar 24 11:39:50 2011
@@ -1219,6 +1219,7 @@
 
 	void restoreShapeContour(UndoState *state, bool isUndo);
 	void restoreImageEffects(UndoState *state, bool isUndo);
+	void restoreLinkTextFrame(UndoState *state, bool isUndo);
 	/*@}*/
 
 	/**

Modified: trunk/Scribus/scribus/undomanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16490&path=/trunk/Scribus/scribus/undomanager.cpp
==============================================================================
--- trunk/Scribus/scribus/undomanager.cpp (original)
+++ trunk/Scribus/scribus/undomanager.cpp Thu Mar 24 11:39:50 2011
@@ -960,6 +960,8 @@
 	UndoManager::Copy               = tr("Copy");
 	UndoManager::CopyPage           = tr("Copy page");
 	UndoManager::ToOutlines         = tr("Convert to outlines");
+	UndoManager::LinkTextFrame		= tr("Link text frame");
+	UndoManager::UnlinkTextFrame	= tr("Unlink text frame");
 }
 
 void UndoManager::initIcons()

Modified: trunk/Scribus/scribus/undomanager.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16490&path=/trunk/Scribus/scribus/undomanager.h
==============================================================================
--- trunk/Scribus/scribus/undomanager.h (original)
+++ trunk/Scribus/scribus/undomanager.h Thu Mar 24 11:39:50 2011
@@ -586,6 +586,8 @@
 	static QString Copy;
 	static QString CopyPage;
 	static QString ToOutlines;
+	static QString LinkTextFrame;
+	static QString UnlinkTextFrame;
 	/*@}*/
 
 	/**




More information about the scribus-commit mailing list