r19356 by jghali - #12536: It is possible to delete Normal master page

scribus-commit scribus-commit at lists.scribus.net
Sat Jul 19 00:57:23 UTC 2014


Author: jghali
Date: Sat Jul 19 00:57:22 2014
New Revision: 19356

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19356
Log:
#12536: It is possible to delete Normal master page
#12537: Crash when clicking in Windows > Outline

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

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19356&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sat Jul 19 00:57:22 2014
@@ -1841,10 +1841,12 @@
 			changeLayerName(ss->getInt("ACTIVE"), name);
 			layersUndo=true;
 		}
+		else if (ss->contains("MASTERPAGE_ADD"))
+			restoreAddMasterPage(ss, isUndo);
+		else if (ss->contains("MASTERPAGE_RENAME"))
+			restoreMasterPageRenaming(ss, isUndo);
 		else if (ss->contains("OLD_MASTERPAGE"))
 			restoreMasterPageApplying(ss, isUndo);
-		else if (ss->contains("MASTERPAGE_ADD"))
-			restoreAddMasterPage(ss, isUndo);
 		else if (ss->contains("PAGE_COPY"))
 			restoreCopyPage(ss, isUndo);
 		else if (ss->contains("PAGE_MOVE"))
@@ -2326,7 +2328,9 @@
 	QString pageName = ss->get("MASTERPAGE_NAME");
 	int pageNr = ss->getInt("MASTERPAGE_NBR");
 
-	bool oldMPMode = masterPageMode();
+	bool oldMPMode  = masterPageMode();
+	ScPage* oldPage = currentPage();
+
 	setMasterPageMode(true);
 	if (isUndo)
 	{
@@ -2347,6 +2351,8 @@
 		delete tmp;
 	}
 	setMasterPageMode(oldMPMode);
+	if (!oldMPMode)
+		setCurrentPage(oldPage);
 	scMW()->pagePalette->updateMasterPageList();
 	m_View->reformPages();
 }
@@ -2666,33 +2672,40 @@
 bool ScribusDoc::renameMasterPage(const QString& oldPageName, const QString& newPageName)
 {
 	Q_ASSERT(oldPageName!=CommonStrings::masterPageNormal && oldPageName!=CommonStrings::trMasterPageNormal);
-	if (MasterNames.contains(oldPageName) && !MasterNames.contains(newPageName))
-	{
-		//Rename our master page lists
-		int number=MasterNames[oldPageName];
-		MasterNames.insert(newPageName, number);
-		MasterNames.remove(oldPageName);
-		Q_ASSERT(MasterPages.at(number)->pageName()==oldPageName);
-		MasterPages.at(number)->setPageName(newPageName);
-		//Update any pages that were linking to our old name
-		ScPage* docPage=NULL;
-		for (int i=0; i < DocPages.count(); ++i )
-		{
-			docPage=DocPages[i];
-			if (docPage->MPageNam == oldPageName)
-				docPage->MPageNam = newPageName;
-		}
-		//Update any items that were linking to our old name
-		uint masterItemsCount=MasterItems.count();
-		for (uint i = 0; i < masterItemsCount; ++i)
-		{
-			if (MasterItems.at(i)->OnMasterPage == oldPageName)
-				MasterItems.at(i)->OnMasterPage = newPageName;
-		}
-		changed();
-		return true;
-	}
-	return false;
+	if (!MasterNames.contains(oldPageName) || MasterNames.contains(newPageName))
+		return false;
+
+	//Rename our master page lists
+	int number = MasterNames[oldPageName];
+	MasterNames.insert(newPageName, number);
+	MasterNames.remove(oldPageName);
+	Q_ASSERT(MasterPages.at(number)->pageName()==oldPageName);
+	MasterPages.at(number)->setPageName(newPageName);
+	//Update any pages that were linking to our old name
+	ScPage* docPage=NULL;
+	for (int i=0; i < DocPages.count(); ++i )
+	{
+		docPage=DocPages[i];
+		if (docPage->MPageNam == oldPageName)
+			docPage->MPageNam = newPageName;
+	}
+	//Update any items that were linking to our old name
+	uint masterItemsCount=MasterItems.count();
+	for (uint i = 0; i < masterItemsCount; ++i)
+	{
+		if (MasterItems.at(i)->OnMasterPage == oldPageName)
+			MasterItems.at(i)->OnMasterPage = newPageName;
+	}
+	changed();
+	if (UndoManager::undoEnabled())
+	{
+		SimpleState *ss = new SimpleState(Um::RenameMasterPage, "", Um::IDocument);
+		ss->set("MASTERPAGE_RENAME", "masterpage_rename");
+		ss->set("OLD_MASTERPAGE", oldPageName);
+		ss->set("NEW_MASTERPAGE", newPageName);
+		undoManager->action(this, ss);
+	}
+	return true;
 }
 
 
@@ -4876,6 +4889,16 @@
 	scMW()->pagePalette->rebuildPages();
 }
 
+void ScribusDoc::restoreMasterPageRenaming(SimpleState *state, bool isUndo)
+{
+	QString oldName = state->get("OLD_MASTERPAGE");
+	QString newName = state->get("NEW_MASTERPAGE");
+	if (isUndo)
+		renameMasterPage(newName, oldName);
+	else
+		renameMasterPage(oldName, newName);
+	scMW()->pagePalette->updateMasterPageList();
+}
 
 void ScribusDoc::restoreCopyPage(SimpleState *state, bool isUndo)
 {

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19356&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Sat Jul 19 00:57:22 2014
@@ -739,6 +739,7 @@
 	 * @brief Undo function for applying a master page
 	 */
 	void restoreMasterPageApplying(SimpleState *state, bool isUndo);
+	void restoreMasterPageRenaming(SimpleState *state, bool isUndo);
 	void restoreCopyPage(SimpleState *state, bool isUndo);
 	void restoreMovePage(SimpleState *state, bool isUndo);
 	void restoreAddMasterPage(SimpleState *state, bool isUndo);

Modified: trunk/Scribus/scribus/undomanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19356&path=/trunk/Scribus/scribus/undomanager.cpp
==============================================================================
--- trunk/Scribus/scribus/undomanager.cpp (original)
+++ trunk/Scribus/scribus/undomanager.cpp Sat Jul 19 00:57:22 2014
@@ -870,6 +870,8 @@
 	UndoManager::DelMasterPage      = tr("Del master page");
 	UndoManager::ImportMasterPage   = tr("Import master page");
 	UndoManager::DuplicateMasterPage= tr("Duplicate master page");
+	UndoManager::ApplyMasterPage    = tr("Apply Master Page");
+	UndoManager::RenameMasterPage   = tr("Rename Master Page");
 	UndoManager::UniteItem          = tr("Combine Polygons");
 	UndoManager::SplitItem          = tr("Split Polygons");
 	UndoManager::Resize             = tr("Resize");
@@ -912,7 +914,6 @@
 	UndoManager::Delete             = tr("Delete");
 	UndoManager::Rename             = tr("Rename");
 	UndoManager::FromTo             = tr("From %1\nto %2");
-	UndoManager::ApplyMasterPage    = tr("Apply Master Page");
 	UndoManager::Paste              = tr("Paste");
 	UndoManager::Cut                = tr("Cut");
 	UndoManager::RoundCorner        = tr("Change round corner");
@@ -1162,6 +1163,8 @@
 QString UndoManager::ImportMasterPage   = "";
 QString UndoManager::DuplicateMasterPage= "";
 QString UndoManager::DelMasterPage      = "";
+QString UndoManager::ApplyMasterPage    = "";
+QString UndoManager::RenameMasterPage   = "";
 QString UndoManager::Resize             = "";
 QString UndoManager::Rotate             = "";
 QString UndoManager::MoveFromTo         = "";
@@ -1208,7 +1211,6 @@
 QString UndoManager::Delete             = "";
 QString UndoManager::Rename             = "";
 QString UndoManager::FromTo             = "";
-QString UndoManager::ApplyMasterPage    = "";
 QString UndoManager::Paste              = "";
 QString UndoManager::Cut                = "";
 QString UndoManager::Transparency       = "";

Modified: trunk/Scribus/scribus/undomanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19356&path=/trunk/Scribus/scribus/undomanager.h
==============================================================================
--- trunk/Scribus/scribus/undomanager.h (original)
+++ trunk/Scribus/scribus/undomanager.h Sat Jul 19 00:57:22 2014
@@ -467,6 +467,8 @@
 	static QString DelMasterPage;
 	static QString ImportMasterPage;
 	static QString DuplicateMasterPage;
+	static QString ApplyMasterPage;
+	static QString RenameMasterPage;
 	static QString Resize;
 	static QString Rotate;
 	static QString MoveFromTo;
@@ -503,7 +505,6 @@
 	static QString Rename;
 	static QString FromTo;
 	static QString Mode;
-	static QString ApplyMasterPage;
 	static QString Paste;
 	static QString Cut;
 	static QString Transparency;




More information about the scribus-commit mailing list