# HG changeset patch
# User insilmaril
# Date 1161168300 0
# Node ID 053b8645e3e911a21e819c1c183e09679cbf5904
# Parent  18f824bd3070b96350fc760c09aca4a1559cd2c1
undo/redo for delete BranchObj. Added calling commands in testmenu

diff -r 18f824bd3070 -r 053b8645e3e9 branchobj.cpp
--- a/branchobj.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/branchobj.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -1242,6 +1242,7 @@
 	int th = bboxTotal.height();	
 // TODO testing
 /*
+*/
 	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
 	cout << "  d="<<depth<<
 		"  ref="<<ref<<
@@ -1253,7 +1254,6 @@
 //		"  hidden="<<hidden<<
 //		"  th="<<th<<
 		endl;
-*/
 
 	setOrientation();
 	//updateLink();
diff -r 18f824bd3070 -r 053b8645e3e9 demos/todo.vym
Binary file demos/todo.vym has changed
diff -r 18f824bd3070 -r 053b8645e3e9 exports.cpp
--- a/exports.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/exports.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -1,7 +1,7 @@
-#include <q3filedialog.h>
-#include <QMessageBox>
-#include <QProcess>
-#include <QTextStream>
+//#include <q3filedialog.h>
+//#include <QMessageBox>
+//#include <QProcess>
+//#include <QTextStream>
 
 #include "exports.h"
 #include "file.h"
@@ -19,7 +19,7 @@
 {
 	indentPerDepth="  ";
 	bool ok;
-    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-XXXXXX"));
+    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-export-XXXXXX"));
 	if (!tmpDir.exists() || !ok)
 		QMessageBox::critical( 0, QObject::tr( "Error" ),
 					   QObject::tr("Couldn't access temporary directory\n"));
diff -r 18f824bd3070 -r 053b8645e3e9 file.h
--- a/file.h	Mon Oct 16 12:42:54 2006 +0000
+++ b/file.h	Wed Oct 18 10:45:00 2006 +0000
@@ -1,7 +1,7 @@
 #ifndef FILE_H
 #define FILE_H
 
-#include <qdir.h>
+#include <QDir>
 
 enum LoadMode {NewMap,ImportAdd,ImportReplace};
 enum SaveMode {PartOfMap,CompleteMap,UndoCommand};
@@ -20,9 +20,9 @@
 bool saveStringToDisk (const QString &, const QString &s);
 
 /////////////////////////////////////////////////////////////////////////////
-#include <qlabel.h>
+#include <QLabel>
 #include <q3filedialog.h>
-#include <qpixmap.h>
+#include <QPixmap>
 
 class ImagePreview : public QLabel, public Q3FilePreview
 {
diff -r 18f824bd3070 -r 053b8645e3e9 historywindow.cpp
--- a/historywindow.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/historywindow.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -1,6 +1,8 @@
 #include "historywindow.h"
 #include "mapeditor.h"
 
+extern QString iconPath;
+
 HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
 {
 	ui.setupUi (this);
@@ -21,6 +23,9 @@
 
 	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
 
+	ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
+	ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
+
 	connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
 	connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
 	connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
diff -r 18f824bd3070 -r 053b8645e3e9 imports.cpp
--- a/imports.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/imports.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -1,7 +1,3 @@
-#include <QMessageBox>
-//Added by qt3to4:
-#include <QTextStream>
-
 #include "file.h"
 #include "imports.h"
 #include "linkablemapobj.h"
@@ -15,7 +11,7 @@
 ImportBase::ImportBase()
 {
 	bool ok;
-    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-XXXXXX"));
+    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-import-XXXXXX"));
 	if (!tmpDir.exists() || !ok)
 		QMessageBox::critical( 0, QObject::tr( "Error" ),
 					   QObject::tr("Couldn't access temporary directory\n"));
@@ -82,8 +78,7 @@
 			lines += stream.readLine(); // line of text excluding '\n'
 		file.close();
 	}
-	// FIXME
-	// Generate vym from broken bookmarks above...
+	// TODO Generate vym from broken bookmarks above...
 
 	return true;
 }
diff -r 18f824bd3070 -r 053b8645e3e9 linkablemapobj.cpp
--- a/linkablemapobj.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/linkablemapobj.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -538,21 +538,7 @@
 
 
 	setDockPos(); // Call overloaded method
-/* FIXME not needed?
-	LinkOrient orientOld=orientation;
-	if ((orientation!=orientOld) && (orientOld!= OrientUndef))
-	{
-		// Orientation just changed. Reorient this subbranch, because move is called
-		// before updateLink => Position is still the old one, which could lead to 
-		// linking of subranch to itself => segfault
-		//
-		// Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
-		// no need to reposition now
-		cout <<"Trying to reorientate...   orient="<<orientation<<endl;
-		reposition();
-	}
-	
-*/
+	setOrientation();
 
 	double p1x=parPos.x();	// Link is drawn from P1 to P2
 	double p1y=parPos.y();
diff -r 18f824bd3070 -r 053b8645e3e9 mainwindow.cpp
--- a/mainwindow.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/mainwindow.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -161,7 +161,7 @@
 
 	// Connect TextEditor, so that we can update flags if text changes
 	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
-	connect (textEditor, SIGNAL (textClosed() ), this, SLOT (updateActions()));
+	connect (textEditor, SIGNAL (textEditorClosed() ), this, SLOT (updateActions()));
 
 	updateGeometry();
 }
@@ -681,8 +681,6 @@
     connect( a, SIGNAL( triggered() ), this, SLOT( editMapInfo() ) );
 	actionEditMapInfo=a;
 
-	editMenu->addSeparator();
-
 	// Import at selection (adding to selection)
     a = new QAction( tr( "Add map (insert)" ),this);
 	a->setStatusTip (tr( "Add map at selection" ));
@@ -1393,10 +1391,16 @@
     QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
 
     QAction *a;
-    a = new QAction( tr( "test flag" ), this);
+    a = new QAction( tr( "Test function" ), this);
     a->setStatusTip( tr( "Call test function" ));
+	a->setShortcut (Qt::Key_F4 );
     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction() ) );
 	testMenu->addAction (a);
+    a = new QAction( tr( "Command" ), this);
+    a->setStatusTip( tr( "Enter command to call in editor" ));
+	a->setShortcut (Qt::Key_F5 );
+    connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
+	testMenu->addAction (a);
 }
 
 // Help Actions
@@ -3090,7 +3094,7 @@
 	if (!me) return;
 
 	// updateActions is also called when NoteEditor is closed
-	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
+	actionViewToggleNoteEditor->setOn (textEditor->showWithMain());
 
 	QAction *a;
 	if (me->getLinkColorHint()==HeadingColor) 
@@ -3333,9 +3337,19 @@
 
 void Main::testFunction()
 {
+	if (!currentMapEditor()) return;
 	currentMapEditor()->testFunction();
 }
 
+void Main::testCommand()
+{
+	if (!currentMapEditor()) return;
+	bool ok;
+	QString com = QInputDialog::getText(
+			__VYM, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
+	if (ok) currentMapEditor()->parseAtom(com);
+}
+
 void Main::helpDoc()
 {
 	QString docpath;
diff -r 18f824bd3070 -r 053b8645e3e9 mainwindow.h
--- a/mainwindow.h	Mon Oct 16 12:42:54 2006 +0000
+++ b/mainwindow.h	Wed Oct 18 10:45:00 2006 +0000
@@ -173,6 +173,7 @@
 	void standardFlagChanged();
 
     void testFunction();
+    void testCommand();
 
     void helpDoc();
     void helpAbout();
diff -r 18f824bd3070 -r 053b8645e3e9 mapeditor.cpp
--- a/mapeditor.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/mapeditor.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -372,7 +372,7 @@
 		mapCenter);
 }
 
-void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
+void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, const QString &comment)
 {
 	// save the selected part of the map, Undo will replace part of map 
 	QString undoSelection="";
@@ -385,6 +385,25 @@
 		undoSel);
 }
 
+void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
+{
+	if (!redoSel  ||typeid(*redoSel) != typeid(BranchObj) ) 
+	{
+		qWarning ("MapEditor::saveStateRemovingPart  no undoSel given!");
+		return;
+	}
+
+	// save the selected part of the map, Undo will insert part of map 
+	QString undoSelection=redoSel->getParObj()->getSelectString();
+	QString redoSelection=redoSel->getSelectString();
+
+	saveState (PartOfMap,
+		undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
+		redoSelection, "delete ()", 
+		comment, 
+		redoSel);
+}
+
 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
 {
 	// selection does not change during action,
@@ -401,22 +420,6 @@
 		NULL);
 }
 
-/* FIXME not used
-void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) 
-{
-	QString redoSelection="";
-	if (redoSel) redoSelection=redoSel->getSelectString();
-	QString undoSelection="";
-	if (undoSel) undoSelection=undoSel->getSelectString();
-
-	saveState (UndoCommand,
-		undoSelection, uc,
-		redoSelection, "FIXME-redoCom",	//FIXME
-		comment, 
-		saveSel);
-}
-*/
-
 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) 
 {
 	// "Normal" savestate: save commands, selections and comment
@@ -491,7 +494,8 @@
 	}	
 	else if (savemode==PartOfMap )
 	{
-		undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
+		undoCommand=undoCom;
+		undoCommand.replace ("PATH",bakMapPath);
 	} else
 	{
 		undoCommand="undoMap (\""+bakMapPath+"\")";
@@ -501,7 +505,7 @@
 		saveStringToDisk (QString(bakMapPath),backupXML);
 
 	// We would have to save all actions in a tree, to keep track of 
-	// possible redos after a action. Too complex, forget about redos.
+	// possible redos after a action. Possible, but we are too lazy: forget about redos.
 	redosAvail=0;
 
 	// Write the current state to disk
@@ -545,51 +549,38 @@
 	QString com=api.command();
 	
 	// External commands
-	if (com=="moveBranchUp")
-		moveBranchUp();
-	else if (com=="moveBranchDown")
-		moveBranchDown();
-	else if (com=="move")
-	{
-		if (api.checkParamCount(2) && selection )
-		{	
-			x=api.parInt (ok,0);
-			if (ok)
-			{
-				y=api.parInt (ok,1);
-				if (ok) move (x,y);
-			}
-		}	
-	}
-	else if (com=="moveRel")
-	{
-		if (api.checkParamCount(2) && selection )
-		{	
-			x=api.parInt (ok,0);
-			if (ok)
-			{
-				y=api.parInt (ok,1);
-				if (ok) moveRel (x,y);
-			}
-		}	
-	}
-	else if (com=="delete")
-	{
-		if (api.checkParamCount(1) && selection )
-		{	
-			s=api.parString(ok,0);
-			if (ok &&select (s)) deleteSelection();
-		}	
-	}	
-	else if (com=="addBranch")
+	if (com=="addBranch")
 	{
 		if (api.checkParamCount(1) && selection )
 		{	
 			y=api.parInt (ok,0);
 			if (ok ) addNewBranchInt (y);
 		}	
-	}	
-	else if (com=="linkBranchToPos")
+	} else if (com==QString("addMapReplace"))
+	{
+		if (api.checkParamCount(2))
+		{
+			s=api.parString (ok,0);	// selection
+			t=api.parString (ok,1);	// path to map
+			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
+			addMapReplace(s,t);	
+		}
+	} else if (com==QString("addMapInsert"))
+	{
+		if (api.checkParamCount(2))
+		{
+			t=api.parString (ok,0);	// path to map
+			y=api.parInt(ok,1);		// position
+			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
+			addMapInsert(t,y);	
+		}
+	} else if (com=="delete")
+	{
+		if (api.checkParamCount(0) && selection )
+		{	
+			deleteSelection();
+		}	
+	} else if (com=="linkBranchToPos")
 	{
 		if (selection && typeid(*selection) == typeid(BranchObj) ) 
 		{
@@ -622,6 +613,33 @@
 				}	
 			}
 		}
+	} else if (com=="moveBranchUp")
+		moveBranchUp();
+	else if (com=="moveBranchDown")
+		moveBranchDown();
+	else if (com=="move")
+	{
+		if (api.checkParamCount(2) && selection )
+		{	
+			x=api.parInt (ok,0);
+			if (ok)
+			{
+				y=api.parInt (ok,1);
+				if (ok) move (x,y);
+			}
+		}	
+	}
+	else if (com=="moveRel")
+	{
+		if (api.checkParamCount(2) && selection )
+		{	
+			x=api.parInt (ok,0);
+			if (ok)
+			{
+				y=api.parInt (ok,1);
+				if (ok) moveRel (x,y);
+			}
+		}	
 	} else if (com=="setHeading")
 	{
 		if (api.checkParamCount(1))
@@ -676,22 +694,11 @@
 				}	
 			}	
 		}
-	}	
-	// Internal commands, used for undo etc.	
-	else if (com==QString("undoMap"))
+	// Internal commands
+	} else if (com==QString("undoMap"))
 	{
 		if (api.checkParamCount(1))
-			undoXML("",api.parString (ok,0));
-	} else if (com==QString("undoPart"))
-	{
-		if (api.checkParamCount(2))
-		{
-			s=api.parString (ok,0);	// undo selection
-			t=api.parString (ok,1);	// backup dir
-			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
-			cout <<t.ascii()<<endl;
-			undoXML(s,t);	
-		}
+			addMapReplace("",api.parString (ok,0));
 	} else if (com=="select")
 	{
 		if (api.checkParamCount(1))
@@ -824,7 +831,7 @@
 		// (map state is set later at end of load...)
 	} else
 	{
-		saveStatePart(selection,"Load map");
+		saveStateChangingPart(selection,"Load map");
 	}	
 	
     
@@ -1279,7 +1286,7 @@
 
 bool MapEditor::isRedoAvailable()
 {
-	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
+	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
 		return true;
 	else	
 		return false;
@@ -1381,11 +1388,11 @@
 	// And ignore clicking the current row ;-)	
 }
 
-void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
+void MapEditor::addMapReplace(const QString &undoSel, const QString &path)
 {
-	QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
-	QDir d(bakMapDir);
-	QFile file (bakMapPath);
+	QString pathDir=path.left(path.findRev("/"));
+	QDir d(pathDir);
+	QFile file (path);
 
 	if (d.exists() )
 	{
@@ -1396,7 +1403,7 @@
 		reader.setContentHandler( &handler );
 		reader.setErrorHandler( &handler );
 		handler.setMapEditor( this );
-		handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
+		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
 		if (undoSel.isEmpty())
 		{
 			unselect();
@@ -1413,18 +1420,59 @@
 		if (! ok ) 
 		{	
 			// This should never ever happen
-			QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
-								   tr( handler.errorProtocol() )+" in "+bakMapDir );
+			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
+								    handler.errorProtocol());
 		}
 	} else	
+		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
+}
+
+void MapEditor::addMapInsert(const QString &path, int pos)
+{
+	if (selection && (typeid(*selection) == typeid(BranchObj) ||
+				      typeid(*selection) == typeid(MapCenterObj))) 
 	{
-		QMessageBox::critical( 0, tr( "Critical Error" ),
-			tr("Temporary directory %1 used for undo is gone. \n"
-			"I will create a new one, but at the moment no undo is available.\n"
-			"Maybe you want to reload your original data.\n\n"
-			"Sorry for any inconveniences.").arg(bakMapDir) );
-		makeTmpDirs();	
-	}							
+		QString pathDir=path.left(path.findRev("/"));
+		QDir d(pathDir);
+		QFile file (path);
+
+		BranchObj *bo=addNewBranchInt (pos);
+		if (!bo)
+		{
+			
+			QMessageBox::critical( 0, tr( "Critical Error" ), 
+				tr("Could insert branch at position %1\n in branch %2").arg(pos)
+				.arg(((BranchObj*)selection)->getHeading()));
+			return;	
+		}
+		unselect();
+		selection=bo;
+		selection->select();
+
+		
+		if (d.exists() )
+		{
+			// We need to parse saved XML data
+			mapBuilderHandler handler;
+			QXmlInputSource source( file);
+			QXmlSimpleReader reader;
+			reader.setContentHandler( &handler );
+			reader.setErrorHandler( &handler );
+			handler.setMapEditor( this );
+			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
+			handler.setLoadMode (ImportReplace);
+			blockReposition=true;
+			bool ok = reader.parse( source );
+			blockReposition=false;
+			if (! ok ) 
+			{	
+				// This should never ever happen
+				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
+										handler.errorProtocol());
+			}
+		} else	
+			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
+	}		
 }
 
 void MapEditor::pasteNoSave()
@@ -1443,7 +1491,7 @@
 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
 				      typeid(*selection) == typeid(MapCenterObj))) 
 	{
-		saveStatePart(selection,QString("Paste to %1").arg( getName(selection)));
+		saveStateChangingPart(selection,QString("Paste to %1").arg( getName(selection)));
 		pasteNoSave();
 		mapCenter->reposition();
 		adjustCanvasSize();
@@ -1452,7 +1500,7 @@
 
 void MapEditor::cut()
 {
-	saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
+	saveStateChangingPart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
 	copy();
 	cutNoSave();
 	mapCenter->reposition();
@@ -1658,7 +1706,8 @@
 		if (newbo)
 		{
 			saveStateConstSelection (
-				QString ("delete (\"%1\")").arg(newbo->getSelectString()),
+				//QString ("delete (\"%1\")").arg(newbo->getSelectString()),
+				"delete ()",
 				QString ("addBranch (%1)").arg(pos-2),
 				QString ("Add new branch to %1").arg(getName(bo)));	//TODO undoCommand
 
@@ -1695,7 +1744,7 @@
 		 (typeid(*selection) == typeid(BranchObj) ) )
 	{
 		BranchObj* bo1 = (BranchObj*) selection;
-		saveStatePart(selection, QString("Add new branch here").arg(getName(bo1)));
+		saveStateChangingPart(selection, QString("Add new branch here").arg(getName(bo1)));
 
 		bool wasScrolled=false;
 		BranchObj *newbo=NULL;
@@ -1739,12 +1788,10 @@
 		bo->unselect();
 		if (selection->getDepth()>1)
 			// Normal branch, save parent with childs
-			saveStatePart(par,QString("Delete %1").arg(getName(bo)));
-		//	naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
+			saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
 		else
 			// Mainbranch, save whole map
-			// TODO Better would be to insert mainbranch again at pos
-			// But undoCommand is missing right now
+			// TODO Better would be to insert mainbranch again at pos But undoCommand is missing right now
 			saveStateComplete(QString("Delete %1").arg(getName(bo)));
 		selection=NULL;
 		par->removeBranch(bo);
@@ -1758,7 +1805,7 @@
 	{
 		FloatImageObj* fio=(FloatImageObj*)selection;
 		BranchObj* par=(BranchObj*)(fio->getParObj());
-		saveStatePart(par, QString("Delete %1").arg(getName(fio)));
+		saveStateChangingPart(par, QString("Delete %1").arg(getName(fio)));
 		fio->unselect();
 		selection=NULL;
 		par->removeFloatImage(fio);
@@ -2226,7 +2273,7 @@
 			typeid(*selection) == typeid(MapCenterObj))
 		{
 			BranchObj *bo=(BranchObj*)selection;
-			saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
+			saveStateChangingPart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
 			bo->setColor(actColor); // color branch
 		}    
 	}
@@ -2240,7 +2287,7 @@
 			typeid(*selection) == typeid(MapCenterObj))
 		{
 			BranchObj *bo=(BranchObj*)selection;
-			saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
+			saveStateChangingPart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
 			bo->setColorChilds(actColor); // color links, color childs
 		}    
 	}
@@ -2541,7 +2588,7 @@
 		if (bo->getDepth()==1)
 			saveStateComplete(s);
 		else	
-			saveStatePart(selection->getParObj(),s);	// TODO undoCommand
+			saveStateChangingPart(selection->getParObj(),s);	// TODO undoCommand
 		QString sel=selection->getSelectString();
 		unselect();
 		par->removeBranchHere(bo);
@@ -2554,7 +2601,7 @@
 {
 	if (selection && (typeid(*selection) == typeid(BranchObj) ))
 	{		
-		saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
+		saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
 		((BranchObj*)selection)->removeChilds();
 		mapCenter->reposition();
 	}	
@@ -2729,7 +2776,7 @@
 			s="Unscroll";
 		else	
 			s="Scroll";
-		saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
+		saveStateChangingPart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
 		bo->toggleScroll();
 		adjustCanvasSize();
 		canvas()->update();
@@ -2769,7 +2816,7 @@
 		QString fn;
 		if ( fd->exec() == QDialog::Accepted )
 		{
-			saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection)));
+			saveStateChangingPart(selection, QString("Add floatimage to %1").arg(getName(selection)));
 			// FIXME in QT4 use:	lastImageDir=fd->directory();
 			lastImageDir=QDir (fd->dirPath());
 			QStringList flist = fd->selectedFiles();
@@ -3728,7 +3775,7 @@
       (typeid(*selection) == typeid(MapCenterObj))  )
   {
     BranchObj *bo=((BranchObj*)selection);
-    saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo)));
+    saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
     //QString fn=fd->selectedFile();
     //lastImageDir=fn.left(fn.findRev ("/"));
     bo->addFloatImage();
diff -r 18f824bd3070 -r 053b8645e3e9 mapeditor.h
--- a/mapeditor.h	Mon Oct 16 12:42:54 2006 +0000
+++ b/mapeditor.h	Wed Oct 18 10:45:00 2006 +0000
@@ -32,13 +32,15 @@
 	void makeTmpDirs();		// create temporary directories
     QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
     void saveStateComplete       (const QString &);					
-    void saveStatePart           (LinkableMapObj *, const QString &);
+    void saveStateChangingPart (LinkableMapObj *, const QString &);
+    void saveStateRemovingPart (LinkableMapObj *, const QString &);
     void saveStateConstSelection (const QString &, const QString &, const QString &);
     void saveState(LinkableMapObj *, const QString &, LinkableMapObj *, const QString &, const QString &);
     void saveState(const QString &, const QString &, const QString &, const QString &, const QString &);
     void saveState(const SaveMode&, const QString &, const QString &, const QString &, const QString &, const QString &, LinkableMapObj *);
+public:	
     void parseAtom(const QString &);	
-
+private:
     void addFloatImage(const QPixmap &img);
 
   private slots:
@@ -82,18 +84,19 @@
     void undo();		// undo last action
 	bool isUndoAvailable();
 	void gotoStep (int);// goto a step in history
+    void addMapReplace(const QString & undoSel, const QString & path);
+    void addMapInsert (const QString & path, int pos);
 private:	
-    void undoXML(const QString &, const QString &);
     void pasteNoSave();		// paste clipboard to branch
     void cutNoSave();	// cut to clipboard
 public:	
     void paste();		// paste clipboard to branch and backup
     void cut();			// cut to clipboard and backup
-    void move    (const int &,const int&);
-    void moveRel (const int &,const int&);
+    void move    (const int &x, const int &y);
+    void moveRel (const int &x, const int &y);
     void moveBranchUp();
     void moveBranchDown();
-	QString getHeading (bool &,QPoint &);	// Get heading, ok if selection is branch
+	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
 	void setHeading(const QString &);
 private:
 	void setHeadingInt(const QString &);
@@ -230,7 +233,7 @@
 	bool printFooter;			// Print footer below map
 
 	bool zipped;				// should map be zipped
-static	int mapNum;				// unique number for Editor
+	static	int mapNum;			// unique number for Editor
 	QString fileName;			// short name of file (for tab)
 	QString filePath;			// path to file which will be saved
 	QString fileDir;			// dir where file is saved
diff -r 18f824bd3070 -r 053b8645e3e9 texteditor.cpp
--- a/texteditor.cpp	Mon Oct 16 12:42:54 2006 +0000
+++ b/texteditor.cpp	Wed Oct 18 10:45:00 2006 +0000
@@ -496,9 +496,8 @@
 void TextEditor::closeEvent( QCloseEvent* ce )
 {
     ce->accept();	// TextEditor can be reopened with show()
+    showwithmain=false;
 	emit (textEditorClosed() );
-	cout << "TE closed\n";
-    showwithmain=false;
     return;
 }
 
diff -r 18f824bd3070 -r 053b8645e3e9 version.h
--- a/version.h	Mon Oct 16 12:42:54 2006 +0000
+++ b/version.h	Wed Oct 18 10:45:00 2006 +0000
@@ -3,6 +3,6 @@
 
 #define __VYM "VYM"
 #define __VYM_VERSION "1.8.57"
-#define __BUILD_DATE "October 13, 2006"
+#define __BUILD_DATE "October 16, 2006"
 
 #endif