# HG changeset patch
# User insilmaril
# Date 1161704198 0
# Node ID 67cfa6e6b863b54e326d365d5e5a1b54f8b12a5d
# Parent  053b8645e3e911a21e819c1c183e09679cbf5904
1.8.58 - More undoCommands, spanish translation of doc

diff -r 053b8645e3e9 -r 67cfa6e6b863 api.cpp
--- a/api.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/api.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -11,13 +11,13 @@
 {
 	com="";
 	paramList.clear();
-	errorString="";
-	noErr=true;
+	resetError();
 }
 
-void API::parseCommand (const QString &s)
+void API::parseInput (const QString &s)
 {
 	initCommand();
+	input=s;
 	QRegExp re;
 	int pos;
 
@@ -75,32 +75,76 @@
 	return paramList;
 }
 
-QString API::errorDesc()
+int API::paramCount()
 {
-	return errorString;
+	return paramList.count();
 }
 
-bool API::error()
+
+QString API::errorMessage()
 {
-	// invert noErr
-	return (noErr) ?false:true;
+	QString l;
+	switch (errLevel)
+	{
+		case NoError: l="No Error";
+		case Warning: l="Warning";
+		case Aborted: l="Aborted";
+	}
+	return QString ("Error Level: %1\n    Command: %2\nDescription: %3")
+		.arg(l).arg(com).arg(errDescription);
 }
 
-void API::setError(const QString &e)
+QString API::errorDescription()
 {
-	noErr=false;
-	errorString=e;
+	return errDescription;
+}
+
+ErrorLevel API::errorLevel()
+{
+	return errLevel;
+}
+
+void API::setError(ErrorLevel level, const QString &description)
+{
+	errDescription=description;
+	errLevel=level;
+}
+
+void API::resetError ()
+{
+	errMessage="";
+	errDescription="";
+	errLevel=NoError;
+}
+
+
+bool API::checkParamCount (QList <int> plist)
+{
+	QStringList expList;
+	QString expected;
+	for (int i=0; i<plist.count();i++)
+	{
+		if (checkParamCount (plist[i])) 
+		{
+			resetError();
+			return true;
+		}
+		expList.append(QString().setNum(plist[i]));
+	}	
+	expected=expList.join(",");	
+	errDescription=QString("Wrong number of parameters: Expected %1, but found %2").arg(expected).arg(paramList.count());
+	return false;
 }
 
 bool API::checkParamCount (const int &expected)
 {
 	if (paramList.count()!=expected)
 	{
-		errorString=QString("expected %1 parameters, but got %2").arg(expected).arg(paramList.count());
-		noErr=false;
-	} else 
-		noErr=true;
-	return noErr;	
+		errLevel=Aborted;
+		errDescription=QString("Wrong number of parameters: Expected %1, but found %2").arg(expected).arg(paramList.count());
+		return false;
+	} 
+	return true;	
 }
 
 bool API::checkParamIsInt(const int &index)
@@ -108,19 +152,20 @@
 	bool ok;
 	if (index > paramList.count())
 	{
-		errorString =QString("Parameter index %1 is outside of parameter list").arg(index);
-		noErr=false;
+		errLevel=Aborted;
+		errDescription=QString("Parameter index %1 is outside of parameter list").arg(index);
+		return false;
 	} else
 	{
 		paramList[index].toInt (&ok, 10);
 		if (!ok)
 		{
-			errorString=QString("Parameter %1 is not an integer").arg(index);
-			noErr=false;
-		} else
-			noErr=true;
+			errLevel=Aborted;
+			errDescription=QString("Parameter %1 is not an integer").arg(index);
+			return false;
+		} 
 	}	
-	return noErr;
+	return true;
 }
 
 int API::parInt (bool &ok,const uint &index)
@@ -145,3 +190,26 @@
 	ok=true;
 	return r;
 }
+
+bool API::parBool (bool &ok,const int &index)
+{
+	// return the bool at index, this could be also stored in
+	// a variable later
+	QString r;
+	ok=true;
+	/*
+	QRegExp re("\"(.*)\"");
+	int pos=re.search (paramList[index]);
+	if (pos>=0)
+		r=re.cap (1);
+	else	
+		r="";
+	*/	
+	if (paramList[index]=="true")
+		return true;
+	else if	(paramList[index]=="false")
+		return false;
+	ok=false;
+	return ok;
+}
+
diff -r 053b8645e3e9 -r 67cfa6e6b863 api.h
--- a/api.h	Wed Oct 18 10:45:00 2006 +0000
+++ b/api.h	Tue Oct 24 15:36:38 2006 +0000
@@ -1,28 +1,37 @@
 #ifndef API_H
 #define API_H
 
-#include <qstringlist.h>
+#include <QStringList>
+
+enum ErrorLevel {NoError,Warning,Aborted};
 
 class API
 {
 public:
 	API();
 	void initCommand();
-	void parseCommand (const QString&);
+	void parseInput (const QString &input);
 	QString command();
 	QStringList parameters();
-	QString errorDesc();
-	bool error();
-	void setError (const QString &);
-	bool checkParamCount (const int &);
-	bool checkParamIsInt (const int &);
-	int parInt (bool &,const uint&);
-	QString parString(bool &,const int &);
+	int paramCount();
+	QString errorMessage();
+	QString errorDescription();
+	ErrorLevel errorLevel();
+	void setError (ErrorLevel level,const QString &description);
+	void resetError();
+	bool checkParamCount (QList <int> plist);
+	bool checkParamCount (const int &index);
+	bool checkParamIsInt (const int &index);
+	int parInt (bool &,const uint &index);
+	QString parString(bool &ok,const int &index);
+	bool parBool (bool &ok, const int &index);
 private:
+	QString input;
 	QString com;
 	QStringList paramList;
-	QString errorString;
-	bool noErr;
+	QString errMessage;
+	QString errDescription;
+	ErrorLevel errLevel;
 };
 
 #endif
diff -r 053b8645e3e9 -r 67cfa6e6b863 branchobj.cpp
--- a/branchobj.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/branchobj.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -1242,7 +1242,6 @@
 	int th = bboxTotal.height();	
 // TODO testing
 /*
-*/
 	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
 	cout << "  d="<<depth<<
 		"  ref="<<ref<<
@@ -1254,6 +1253,7 @@
 //		"  hidden="<<hidden<<
 //		"  th="<<th<<
 		endl;
+*/
 
 	setOrientation();
 	//updateLink();
diff -r 053b8645e3e9 -r 67cfa6e6b863 demos/todo.vym
Binary file demos/todo.vym has changed
diff -r 053b8645e3e9 -r 67cfa6e6b863 doc/vym_es.pdf
Binary file doc/vym_es.pdf has changed
diff -r 053b8645e3e9 -r 67cfa6e6b863 historywindow.cpp
--- a/historywindow.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/historywindow.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -103,6 +103,8 @@
 	item->setBackgroundColor (c);
 	ui.historyTable->setItem(undosAvail, 1, item);
 
+	// Show "now" row
+	ui.historyTable->scrollToItem (item);
 
 	// Update Redos in table
 	s=curStep;
diff -r 053b8645e3e9 -r 67cfa6e6b863 linkablemapobj.cpp
--- a/linkablemapobj.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/linkablemapobj.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -535,8 +535,6 @@
 		p2y=QPoint( parObj->getParPos() ).y();
 	} 
 
-
-
 	setDockPos(); // Call overloaded method
 	setOrientation();
 
diff -r 053b8645e3e9 -r 67cfa6e6b863 main.cpp
--- a/main.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/main.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -1,8 +1,8 @@
 #include <QApplication>
-#include <QPixmap>
-#include <QTranslator>
-#include <QDir>
-#include <QTextCodec>
+//#include <QPixmap>
+//#include <QTranslator>
+//#include <QDir>
+//#include <QTextCodec>
 #include <q3network.h>
 //#include <QActionGroup>
 
@@ -35,9 +35,9 @@
 
 int statusbarTime=3500;
 
-int main(int argc, char** argv)
+int main(int argc, char* argv[])
 {
-//FIXME	Q_INIT_RESOURCE (application);
+	//Q_INIT_RESOURCE (application);
 
     QApplication app(argc,argv);
 
@@ -84,7 +84,7 @@
 	// ok, let's find my way on my own
 	{
 		#if defined (Q_OS_MACX)
-			vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents");
+			vymBaseDir.setPath(vymBaseDir.currentDirPath() +"/vym.app/Contents/Resources");
 
 		#else
 			vymBaseDir.setPath ("/usr/share/vym");
diff -r 053b8645e3e9 -r 67cfa6e6b863 mainwindow.cpp
--- a/mainwindow.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/mainwindow.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -70,6 +70,9 @@
 	move   (settings.value( "/mainwindow/geometry/pos", QPoint(300,100)).toPoint());
 
 
+	// Sometimes we may need to remember old selections
+	prevSelection="";
+
 	// Create unique temporary directory
 	bool ok;
 	tmpVymDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX");
@@ -480,16 +483,16 @@
 	a->setShortcut (Qt::ALT + Qt::Key_Insert );
 	a->setShortcutContext (Qt::WindowShortcut);
 	addAction (a);
-    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchHere() ) );
+    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
 	a->setEnabled (false);
 	actionListBranches.append(a);
-	actionEditAddBranchHere=a;
+	actionEditAddBranchBefore=a;
 	a = new QAction(tr( "Add branch (insert)" ),this);
 	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
 	a->setShortcut ( Qt::ALT + Qt::Key_A );
 	a->setShortcutContext (Qt::WindowShortcut);
 	addAction (a);
-    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchHere() ) );
+    connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
 	actionListBranches.append(a);
 
 	// Add branch above
@@ -1437,7 +1440,7 @@
 		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
 		branchAddContextMenu->addAction (actionEditPaste );
 		branchAddContextMenu->addAction ( actionEditAddBranch );
-		branchAddContextMenu->addAction ( actionEditAddBranchHere );
+		branchAddContextMenu->addAction ( actionEditAddBranchBefore );
 		branchAddContextMenu->addAction ( actionEditAddBranchAbove);
 		branchAddContextMenu->addAction ( actionEditAddBranchBelow );
 		branchAddContextMenu->addSeparator();	
@@ -2607,24 +2610,33 @@
 	    currentMapEditor()->editFATE2URL();
 }
 
+void Main::editHeadingFinished()
+{
+	// only called from editHeading(), so there is a currentME
+	MapEditor *me=currentMapEditor();
+
+#if defined(Q_OS_MACX)
+#else
+	me->setHeading(lineedit->text());
+		
+	lineedit->releaseKeyboard();
+	lineedit->hide();
+	setFocus();
+#endif	
+	if (!prevSelection.isEmpty()) me->select(prevSelection);
+	prevSelection="";
+}
+
 void Main::editHeading()
 {
-	if (lineedit->isVisible())
+	if (currentMapEditor())
 	{
-		if (currentMapEditor())
-		{	
-			MapEditor *me=currentMapEditor();
-			QString oldSel=me->getSelectString();
-			if (me->select (editSel))
-				me->setHeading(lineedit->text());
-			me->select (oldSel);
-		}	
-		lineedit->releaseKeyboard();
-		lineedit->hide();
-		setFocus();
-	} else
-	{
-		if (currentMapEditor())
+		MapEditor *me=currentMapEditor();
+		QString oldSel=me->getSelectString();
+
+		if (lineedit->isVisible())
+			editHeadingFinished();
+		else
 		{
 			bool ok;
 			QPoint p;
@@ -2637,30 +2649,30 @@
 				QDialog *d =new QDialog(NULL);
 				QLineEdit *le=new QLineEdit (d);
 				d->setWindowFlags (Qt::FramelessWindowHint);
-				d->setGeometry(p.x(),p.y(),200,25);
-				le->resize (d->size());
+				d->setGeometry(p.x(),p.y(),230,25);
+				le->resize (d->width()-10,d->height());
 				le->setText (s);
 				le->selectAll();
 				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
 				d->activateWindow();
 				d->exec();
 				currentMapEditor()->setHeading (le->text());
+				delete (le);
+				delete (d);
+				editHeadingFinished();
 #else
 				p = currentMapEditor()->mapTo(this, currentMapEditor()->worldMatrix().map( p));
-				lineedit->setGeometry(p.x(),p.y(),200,25);
+				lineedit->setGeometry(p.x(),p.y(),230,25);
 				lineedit->setText(s);
 				lineedit->setCursorPosition(1);
 				lineedit->selectAll();
 				lineedit->show();
 				lineedit->grabKeyboard();
 				lineedit->setFocus();
-
-				editSel=currentMapEditor()->getSelectString();
 #endif
-
 			}
 		}
-	}
+	} // currentMapEditor()	
 }
 
 void Main::openVymLinks(const QStringList &vl)
@@ -2764,34 +2776,95 @@
 void Main::editUnScrollAll()
 {
 	if (currentMapEditor())
+		currentMapEditor()->unScrollAll();	
+}
+
+void Main::editNewBranch()
+{
+	MapEditor *me=currentMapEditor();
+	if (!lineedit->isVisible() && me)
 	{
-		currentMapEditor()->unScrollAll();	
+		BranchObj *bo=(BranchObj*)me->getSelection();
+		BranchObj *newbo=me->addNewBranch(0);
+
+		if (newbo) 
+			me->select (newbo->getSelectString());
+		else
+			return;
+
+		if (actionSettingsAutoEdit->isOn())
+		{
+			if (!actionSettingsAutoSelectHeading->isOn())
+				prevSelection=bo->getSelectString();
+			editHeading();
+		}
 	}	
 }
 
-void Main::editNewBranch()
+void Main::editNewBranchBefore()
 {
-
-	if (!lineedit->isVisible() && currentMapEditor())
-		currentMapEditor()->addNewBranch(0);
-}
-
-void Main::editNewBranchHere()
-{
-	if (currentMapEditor())
-		currentMapEditor()->addNewBranchHere();
+	MapEditor *me=currentMapEditor();
+	if (!lineedit->isVisible() && me)
+	{
+		BranchObj *bo=(BranchObj*)me->getSelection();
+		BranchObj *newbo=me->addNewBranchBefore();
+
+		if (newbo) 
+			me->select (newbo->getSelectString());
+		else
+			return;
+
+		if (actionSettingsAutoEdit->isOn())
+		{
+			if (!actionSettingsAutoSelectHeading->isOn())
+				prevSelection=bo->getSelectString();
+			editHeading();
+		}
+	}	
 }
 
 void Main::editNewBranchAbove()
 {
-	if (currentMapEditor())
-		currentMapEditor()->addNewBranch(-1);
+	MapEditor *me=currentMapEditor();
+	if (!lineedit->isVisible() && me)
+	{
+		BranchObj *bo=(BranchObj*)me->getSelection();
+		BranchObj *newbo=me->addNewBranch (-1);
+
+		if (newbo) 
+			me->select (newbo->getSelectString());
+		else
+			return;
+
+		if (actionSettingsAutoEdit->isOn())
+		{
+			if (!actionSettingsAutoSelectHeading->isOn())
+				prevSelection=bo->getSelectString();
+			editHeading();
+		}
+	}	
 }
 
 void Main::editNewBranchBelow()
 {
-	if (currentMapEditor())
-		currentMapEditor()->addNewBranch(1);
+	MapEditor *me=currentMapEditor();
+	if (!lineedit->isVisible() && me)
+	{
+		BranchObj *bo=(BranchObj*)me->getSelection();
+		BranchObj *newbo=me->addNewBranch (1);
+
+		if (newbo) 
+			me->select (newbo->getSelectString());
+		else
+			return;
+
+		if (actionSettingsAutoEdit->isOn())
+		{
+			if (!actionSettingsAutoSelectHeading->isOn())
+				prevSelection=bo->getSelectString();
+			editHeading();
+		}
+	}	
 }
 
 void Main::editImportAdd()
diff -r 053b8645e3e9 -r 67cfa6e6b863 mainwindow.h
--- a/mainwindow.h	Wed Oct 18 10:45:00 2006 +0000
+++ b/mainwindow.h	Tue Oct 24 15:36:38 2006 +0000
@@ -96,6 +96,7 @@
 	void openVymLinks(const QStringList &);
 	void editVymLink();
 	void editOpenMultipleVymLinks();
+    void editHeadingFinished();
 public slots:
     void editHeading();
 	void editOpenVymLink();
@@ -108,7 +109,7 @@
     void editToggleScroll();
     void editUnScrollAll();
     void editNewBranch();
-    void editNewBranchHere();
+    void editNewBranchBefore();
     void editNewBranchAbove();
     void editNewBranchBelow();
     void editImportAdd();
@@ -189,7 +190,7 @@
 	QStringList imageTypes;
 
 	QLineEdit *lineedit;	// to enter headings of branches
-	QString editSel;
+	QString prevSelection;
 
 	Q3PtrList <QAction> actionListBranches;
 
@@ -219,7 +220,7 @@
 	QAction *actionEditHeading;
 	QAction *actionEditDelete;
 	QAction *actionEditAddBranch;
-	QAction *actionEditAddBranchHere;
+	QAction *actionEditAddBranchBefore;
 	QAction *actionEditAddBranchAbove;
 	QAction *actionEditAddBranchBelow;
 	QAction *actionEditRemoveBranchKeepChilds;
diff -r 053b8645e3e9 -r 67cfa6e6b863 mapeditor.cpp
--- a/mapeditor.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/mapeditor.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -387,21 +387,33 @@
 
 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
 {
-	if (!redoSel  ||typeid(*redoSel) != typeid(BranchObj) ) 
+	if (!redoSel)
 	{
-		qWarning ("MapEditor::saveStateRemovingPart  no undoSel given!");
+		qWarning ("MapEditor::saveStateRemovingPart  no redoSel 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);
+	if (typeid(*redoSel) == typeid(BranchObj) && redoSel->getDepth()>1 ) 
+	{
+		// save the selected branch of the map, Undo will insert part of map 
+		saveState (PartOfMap,
+			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
+			redoSelection, "delete ()", 
+			comment, 
+			redoSel);
+	} else if (typeid(*redoSel) == typeid(BranchObj) )
+	{
+		// save the selected mainbranch of the map, Undo will insert part of map 
+		saveState (PartOfMap,
+			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
+//			undoSelection, QString("addMapInsert (\"PATH\",%1,%2)").arg(((BranchObj*)redoSel)->getNum())
+//				.arg(((BranchObj*)redoSel)->x()).arg(((BranchObj*)redoSel)->y()),
+			redoSelection, "delete ()", 
+			comment, 
+			redoSel);
+		
+	}
 }
 
 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
@@ -545,81 +557,185 @@
 	bool ok;
 
 	// Split string s into command and parameters
-	api.parseCommand (atom);
+	api.parseInput (atom);
 	QString com=api.command();
 	
 	// External commands
 	if (com=="addBranch")
 	{
-		if (api.checkParamCount(1) && selection )
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else 
 		{	
-			y=api.parInt (ok,0);
-			if (ok ) addNewBranchInt (y);
-		}	
+			QList <int> pl;
+			pl << 0 <<1;
+			if (api.checkParamCount(pl))
+			{
+				if (api.paramCount()==0)
+					addNewBranchInt (-2);
+				else
+				{
+					y=api.parInt (ok,0);
+					if (ok ) addNewBranchInt (y);
+				}
+			}
+		}
+	} else if (com=="addBranchBefore")
+	{
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else 
+		{	
+			if (api.paramCount()==0)
+			{
+				addNewBranchBefore ();
+			}	
+		}
 	} else if (com==QString("addMapReplace"))
 	{
-		if (api.checkParamCount(2))
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else 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);	
+			addMapReplaceInt(s,t);	
 		}
 	} else if (com==QString("addMapInsert"))
 	{
-		if (api.checkParamCount(2))
+		if (!selection)
 		{
-			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);	
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else 
+		{	
+			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);
+				addMapInsertInt(t,y);	
+			}
 		}
 	} else if (com=="delete")
 	{
-		if (api.checkParamCount(0) && selection )
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(0))
 		{	
 			deleteSelection();
 		}	
+	} else if (com=="deleteKeepChilds")
+	{
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(0))
+		{	
+			removeBranchKeepChilds();
+		}	
 	} else if (com=="linkBranchToPos")
 	{
-		if (selection && typeid(*selection) == typeid(BranchObj) ) 
+		if (!selection)
 		{
-			if (api.checkParamCount(4))
-			{
-				// 0	selectstring of parent
-				// 1	num in parent (for branches)
-				// 2,3	x,y of mainbranch or mapcenter
-				s=api.parString(ok,0);
-				LinkableMapObj *dst=mapCenter->findObjBySelect (s);
-				if (dst)
-				{	
-					if (typeid(*dst) == typeid(BranchObj) ) 
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(4))
+		{
+			// 0	selectstring of parent
+			// 1	num in parent (for branches)
+			// 2,3	x,y of mainbranch or mapcenter
+			s=api.parString(ok,0);
+			LinkableMapObj *dst=mapCenter->findObjBySelect (s);
+			if (dst)
+			{	
+				if (typeid(*dst) == typeid(BranchObj) ) 
+				{
+					// Get number in parent
+					x=api.parInt (ok,1);
+					if (ok)
+						((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
+				} else if (typeid(*dst) == typeid(MapCenterObj) ) 
+				{
+					((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
+					// Get coordinates of mainbranch
+					x=api.parInt (ok,2);
+					if (ok)
 					{
-						// Get number in parent
-						x=api.parInt (ok,1);
-						if (ok)
-							((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
-					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
-					{
-						((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
-						// Get coordinates of mainbranch
-						x=api.parInt (ok,2);
-						if (ok)
-						{
-							y=api.parInt (ok,3);
-							if (ok) ((BranchObj*)selection)->move (x,y);
-						}
-					}	
+						y=api.parInt (ok,3);
+						if (ok) ((BranchObj*)selection)->move (x,y);
+					}
 				}	
-			}
+			}	
 		}
 	} else if (com=="moveBranchUp")
-		moveBranchUp();
-	else if (com=="moveBranchDown")
-		moveBranchDown();
-	else if (com=="move")
 	{
-		if (api.checkParamCount(2) && selection )
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(0))
+		{
+			moveBranchUp();
+		}	
+	} else if (com=="moveBranchDown")
+	{
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(0))
+		{
+			moveBranchDown();
+		}	
+	} else if (com=="move")
+	{
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( typeid(*selection) != typeid(BranchObj) && 
+					typeid(*selection) != typeid(MapCenterObj) &&
+					typeid(*selection) != typeid(FloatImageObj) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch or floatimage");
+		} else if (api.checkParamCount(2))
 		{	
 			x=api.parInt (ok,0);
 			if (ok)
@@ -631,7 +747,15 @@
 	}
 	else if (com=="moveRel")
 	{
-		if (api.checkParamCount(2) && selection )
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( typeid(*selection) != typeid(BranchObj) && 
+					typeid(*selection) != typeid(MapCenterObj) &&
+					typeid(*selection) != typeid(FloatImageObj) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch or floatimage");
+		} else if (api.checkParamCount(2))
 		{	
 			x=api.parInt (ok,0);
 			if (ok)
@@ -642,7 +766,14 @@
 		}	
 	} else if (com=="setHeading")
 	{
-		if (api.checkParamCount(1))
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(1))
 		{
 			s=api.parString (ok,0);
 			if (ok) 
@@ -650,55 +781,98 @@
 		}	
 	} else if (com=="setURL")
 	{
-		if (api.checkParamCount(1))
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(1))
 		{
 			s=api.parString (ok,0);
 			if (ok) setURLInt(s);
 		}	
 	} else if (com=="setVymLink")
 	{
-		if (api.checkParamCount(1))
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(1))
 		{
 			s=api.parString (ok,0);
 			if (ok) setVymLinkInt(s);
 		}	
 	}
+	else if (com=="setHideExport")
+	{
+		if (!selection)
+		{
+			api.setError (Aborted,"Nothing selected");
+		} else if ( typeid(*selection) != typeid(BranchObj) && 
+					typeid(*selection) != typeid(MapCenterObj) &&
+					typeid(*selection) != typeid(FloatImageObj) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch or floatimage");
+		} else if (api.checkParamCount(2))
+		{
+			s=api.parString(ok,0);
+			if (ok) 
+			{
+				BranchObj* bo=(BranchObj*)selection;
+				bo->activateStandardFlag(s);
+				bo->updateFlagsToolbar();
+			}	
+		}
+	}	
 	else if (com=="setFlag")
 	{
-		if (selection && typeid(*selection) == typeid(BranchObj) ) 
+		if (!selection)
 		{
-			if (api.checkParamCount(1) )
-			{	
-				s=api.parString(ok,0);
-				if (ok) 
-				{
-					BranchObj* bo=(BranchObj*)selection;
-					bo->activateStandardFlag(s);
-					bo->updateFlagsToolbar();
-				}	
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(1))
+		{
+			s=api.parString(ok,0);
+			if (ok) 
+			{
+				BranchObj* bo=(BranchObj*)selection;
+				bo->activateStandardFlag(s);
+				bo->updateFlagsToolbar();
 			}	
 		}
 	}	
 	else if (com=="unsetFlag")
 	{
-		if (selection && typeid(*selection) == typeid(BranchObj) ) 
+		if (!selection)
 		{
-			if (api.checkParamCount(1) )
-			{	
-				s=api.parString(ok,0);
-				if (ok) 
-				{
-					BranchObj* bo=(BranchObj*)selection;
-					bo->deactivateStandardFlag(s);
-					bo->updateFlagsToolbar();
-				}	
+			api.setError (Aborted,"Nothing selected");
+		} else if ( (typeid(*selection) != typeid(BranchObj) && 
+					 typeid(*selection) != typeid(MapCenterObj)) )
+		{				  
+			api.setError (Aborted,"Type of selection is not a branch");
+		} else if (api.checkParamCount(1))
+		{
+			s=api.parString(ok,0);
+			if (ok) 
+			{
+				BranchObj* bo=(BranchObj*)selection;
+				bo->deactivateStandardFlag(s);
+				bo->updateFlagsToolbar();
 			}	
 		}
 	// Internal commands
 	} else if (com==QString("undoMap"))
 	{
 		if (api.checkParamCount(1))
-			addMapReplace("",api.parString (ok,0));
+			addMapReplaceInt("",api.parString (ok,0));
 	} else if (com=="select")
 	{
 		if (api.checkParamCount(1))
@@ -709,16 +883,18 @@
 	}	
 	else
 	{
-		api.setError ("Unknown command in: "+atom);
+		api.setError (Aborted,"Unknown command");
 	}
 
 	// Any errors?
-	if (api.error())
+	if (api.errorLevel()==NoError)
+		setChanged();
+	else	
 	{
 		// TODO Error handling
 		qWarning("MapEditor::parseAtom: Error!");
-		qWarning(api.errorDesc());
-	}	
+		qWarning(api.errorMessage());
+	} 
 }
 
 void MapEditor::toggleHistoryWindow()
@@ -1388,7 +1564,7 @@
 	// And ignore clicking the current row ;-)	
 }
 
-void MapEditor::addMapReplace(const QString &undoSel, const QString &path)
+void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
 {
 	QString pathDir=path.left(path.findRev("/"));
 	QDir d(pathDir);
@@ -1427,7 +1603,7 @@
 		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
 }
 
-void MapEditor::addMapInsert(const QString &path, int pos)
+void MapEditor::addMapInsertInt (const QString &path, int pos)
 {
 	if (selection && (typeid(*selection) == typeid(BranchObj) ||
 				      typeid(*selection) == typeid(MapCenterObj))) 
@@ -1436,20 +1612,6 @@
 		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
@@ -1460,7 +1622,7 @@
 			reader.setErrorHandler( &handler );
 			handler.setMapEditor( this );
 			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
-			handler.setLoadMode (ImportReplace);
+			handler.setLoadMode (ImportAdd);
 			blockReposition=true;
 			bool ok = reader.parse( source );
 			blockReposition=false;
@@ -1470,6 +1632,8 @@
 				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
 										handler.errorProtocol());
 			}
+			if (selection!=mapCenter)
+				((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos);
 		} else	
 			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
 	}		
@@ -1689,18 +1853,19 @@
 	return newbo;
 }	
 
-void MapEditor::addNewBranch(int pos)
+BranchObj* MapEditor::addNewBranch(int pos)
 {
 	// Different meaning than num in addNewBranchInt!
 	// -1	add above
 	//  0	add as child
 	// +1	add below
+	BranchObj *bo = (BranchObj*) selection;
+	BranchObj *newbo=NULL;
+
 	if (selection  &&  
 		 (typeid(*selection) == typeid(BranchObj) || 
 		  typeid(*selection) == typeid(MapCenterObj) ) ) 
 	{
-		BranchObj *bo = (BranchObj*) selection;
-		BranchObj *newbo;
 		newbo=addNewBranchInt (pos-2);
 
 		if (newbo)
@@ -1711,72 +1876,44 @@
 				QString ("addBranch (%1)").arg(pos-2),
 				QString ("Add new branch to %1").arg(getName(bo)));	//TODO undoCommand
 
-			LinkableMapObj *oldselection=selection;
-
 			mapCenter->reposition();
 			adjustCanvasSize();
-
-
-			if (mainWindow->autoEdit() ||
-				mainWindow->autoSelectHeading() )
-			{
-				selection->unselect();
-				selection=newbo;
-				selection->select();
-				if (mainWindow->autoEdit() )
-					mainWindow->editHeading();
-				if (!mainWindow->autoSelectHeading()
-					)//&& !wasScrolled)  //FIXME wasScrolled was moved to addNewBranchInt
-				{
-					selection->unselect();
-					selection=oldselection;
-					selection->select();
-				}
-			}	
 		}
 	}	
+	return newbo;
 }
 
 
-void MapEditor::addNewBranchHere()
+BranchObj* MapEditor::addNewBranchBefore()
 {
+	BranchObj *newbo=NULL;
 	if (selection  &&  
 		 (typeid(*selection) == typeid(BranchObj) ) )
+		 // We accept no MapCenterObj here, so we _have_ a parent
 	{
-		BranchObj* bo1 = (BranchObj*) selection;
-		saveStateChangingPart(selection, QString("Add new branch here").arg(getName(bo1)));
-
-		bool wasScrolled=false;
-		BranchObj *newbo=NULL;
+		BranchObj* bo = (BranchObj*) selection;
+		QPoint p=bo->getRelPos();
+
+
 		BranchObj *parbo=(BranchObj*)(selection->getParObj());
-		if (parbo)
+
+		// add below selection
+		newbo=parbo->insertBranch(bo->getNum()+1);
+		if (newbo)
 		{
-			// add below selection
-			newbo=parbo->insertBranch(bo1->getNum()+1);
-		} 
-
-		LinkableMapObj *oldselection=selection;
-		((BranchObj*)selection)->moveBranchTo (newbo,-1);
-
-		mapCenter->reposition();
-		adjustCanvasSize();
-		if (mainWindow->autoEdit() ||
-			mainWindow->autoSelectHeading() )
-		{
-			selection->unselect();
-			selection=newbo;
-			selection->select();
-			if (mainWindow->autoEdit() )
-				mainWindow->editHeading();
-			if (!mainWindow->autoSelectHeading()
-				&& !wasScrolled)
-			{
-				selection->unselect();
-				selection=oldselection;
-				selection->select();
-			}
-		}	
+			newbo->move2RelPos (p);
+
+			// Move selection to new branch
+			((BranchObj*)selection)->moveBranchTo (newbo,-1);
+
+			saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", 
+				QString ("Add branch before %1").arg(getName(bo)));
+
+			mapCenter->reposition();
+			adjustCanvasSize();
+		}
 	}	
+	return newbo;
 }
 
 void MapEditor::deleteSelection()
@@ -1786,13 +1923,7 @@
 		BranchObj* bo=(BranchObj*)selection;
 		BranchObj* par=(BranchObj*)(bo->getParObj());
 		bo->unselect();
-		if (selection->getDepth()>1)
-			// Normal branch, save parent with childs
-			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
-			saveStateComplete(QString("Delete %1").arg(getName(bo)));
+		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
 		selection=NULL;
 		par->removeBranch(bo);
 		selection=par;
@@ -2584,16 +2715,21 @@
 	{		
 		BranchObj* bo=(BranchObj*)selection;
 		BranchObj* par=(BranchObj*)(bo->getParObj());
+		QPoint p=bo->getRelPos();
 		QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
 		if (bo->getDepth()==1)
 			saveStateComplete(s);
 		else	
 			saveStateChangingPart(selection->getParObj(),s);	// TODO undoCommand
+
 		QString sel=selection->getSelectString();
 		unselect();
 		par->removeBranchHere(bo);
 		mapCenter->reposition();
 		select (sel);
+		((BranchObj*)selection)->move2RelPos (p);
+		mapCenter->reposition();
+		adjustCanvasSize();
 	}	
 }
 
@@ -2601,6 +2737,7 @@
 {
 	if (selection && (typeid(*selection) == typeid(BranchObj) ))
 	{		
+		// TODO undoCommand
 		saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
 		((BranchObj*)selection)->removeChilds();
 		mapCenter->reposition();
@@ -3048,6 +3185,15 @@
 {
 	cout << "MapEditor::testFunction() called\n";
 
+	if (selection && 
+		(typeid(*selection) == typeid(BranchObj)) || 
+		(typeid(*selection) == typeid(MapCenterObj))  )
+	{
+		BranchObj* bo=(BranchObj*)selection;
+		cout << bo->getHeading().ascii() <<" is scrolled: "<<bo->isScrolled()<<endl;
+	}
+	return;
+	
 	WarningDialog dia;
 	dia.showCancelButton (true);
 	dia.setText("This is a longer \nWarning");
diff -r 053b8645e3e9 -r 67cfa6e6b863 mapeditor.h
--- a/mapeditor.h	Wed Oct 18 10:45:00 2006 +0000
+++ b/mapeditor.h	Tue Oct 24 15:36:38 2006 +0000
@@ -84,9 +84,9 @@
     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 addMapReplaceInt(const QString & undoSel, const QString & path);
+    void addMapInsertInt (const QString & path, int pos);
     void pasteNoSave();		// paste clipboard to branch
     void cutNoSave();	// cut to clipboard
 public:	
@@ -104,8 +104,8 @@
 	void setVymLinkInt(const QString &);	// Set vymLink for selection
     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
 public:	
-    void addNewBranch(int);			// pos allows to add above/below selection
-    void addNewBranchHere();		// insert and make selection its
+    BranchObj* addNewBranch(int);			// pos allows to add above/below selection
+    BranchObj* addNewBranchBefore();		// insert and make selection its
     void deleteSelection();
 	LinkableMapObj* getSelection();	// returns selection
 	void unselect();				// before changing current noteedit
diff -r 053b8645e3e9 -r 67cfa6e6b863 tex/vym.changelog
--- a/tex/vym.changelog	Wed Oct 18 10:45:00 2006 +0000
+++ b/tex/vym.changelog	Tue Oct 24 15:36:38 2006 +0000
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Tue Oct 24 17:24:22 CEST 2006 - uwedr
+
+- Version: 1.8.58
+- Feature: More undo commands (and fixes there)
+
 -------------------------------------------------------------------
 Mon Oct 16 14:41:03 CEST 2006 - uwedr
 
diff -r 053b8645e3e9 -r 67cfa6e6b863 version.h
--- a/version.h	Wed Oct 18 10:45:00 2006 +0000
+++ b/version.h	Tue Oct 24 15:36:38 2006 +0000
@@ -2,7 +2,7 @@
 #define VERSION_H
 
 #define __VYM "VYM"
-#define __VYM_VERSION "1.8.57"
-#define __BUILD_DATE "October 16, 2006"
+#define __VYM_VERSION "1.8.58"
+#define __BUILD_DATE "October 24, 2006"
 
 #endif
diff -r 053b8645e3e9 -r 67cfa6e6b863 xml.cpp
--- a/xml.cpp	Wed Oct 18 10:45:00 2006 +0000
+++ b/xml.cpp	Tue Oct 24 15:36:38 2006 +0000
@@ -463,7 +463,7 @@
 	{
 		bool okx,oky;
 		int x,y;
-		if (!a.value( "relPosX").isEmpty() && loadMode==NewMap && branchDepth<2) 
+		if (!a.value( "relPosX").isEmpty() ) 
 		{
 			if (!a.value( "relPosY").isEmpty() ) 
 			{