# HG changeset patch
# User insilmaril
# Date 1276089248 0
# Node ID 43268373032d0a14deedf089f8da3938460bc1d5
# Parent  f0fe7c36ec5cfd25f8bcec10f6e2631a789a0533
1.13.4 Various fixes

diff -r f0fe7c36ec5c -r 43268373032d adaptormodel.cpp
--- a/adaptormodel.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/adaptormodel.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -36,7 +36,7 @@
 	m_caption=newCaption;
 }
 
-QDBusVariant AdaptorModel::query(const QString &query)
+QDBusVariant AdaptorModel::query(const QString &)
 {
 	QString s;
 	if (model)
diff -r f0fe7c36ec5c -r 43268373032d adaptormodel.h
--- a/adaptormodel.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/adaptormodel.h	Wed Jun 09 13:14:08 2010 +0000
@@ -27,7 +27,7 @@
 	QString caption();
 	void setCaption(const QString &newCaption);
 public slots: // METHODS
-   QDBusVariant query(const QString &query);
+   QDBusVariant query(const QString &);
    QDBusVariant getCurrentModelID();
    QDBusVariant getHeading();
    void setHeading (const QString &s);
diff -r f0fe7c36ec5c -r 43268373032d animpoint.cpp
--- a/animpoint.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/animpoint.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -124,6 +124,13 @@
 	return animated;
 }
 
+void AnimPoint::stop()
+{
+	animated=false;
+	setX (destPos.x());
+	setY (destPos.y());
+}
+
 void AnimPoint::initVector()
 {
 	vector.setX (destPos.x()-startPos.x() );
diff -r f0fe7c36ec5c -r 43268373032d animpoint.h
--- a/animpoint.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/animpoint.h	Wed Jun 09 13:14:08 2010 +0000
@@ -22,6 +22,7 @@
 	void setAnimated(bool);
 	bool isAnimated ();
 	bool animate();
+	void stop();
 
 private:
 	void initVector();
diff -r f0fe7c36ec5c -r 43268373032d branchitem.cpp
--- a/branchitem.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/branchitem.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -1,13 +1,13 @@
+#include "branchitem.h"
+
 #include "attributeitem.h"
-#include "branchitem.h"
 #include "branchobj.h"
 #include "vymmodel.h"
+#include "xlink.h"
 #include "xlinkitem.h"
 
 #include <QDir>
 
-using namespace std;
-
 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
 {
 	//qDebug()<< "Constr. BranchItem";
@@ -31,7 +31,7 @@
 
 BranchItem::~BranchItem()
 {
-	qDebug()<< "Destr. BranchItem "<<getHeading();
+	//qDebug()<< "Destr. BranchItem this="<<this<<"  "<<getHeading();
 	if (lmo) 
 	{
 		delete lmo;
@@ -69,7 +69,7 @@
 	branchCounter++;
 }
 
-QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
+QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset, QList <Link*> &tmpLinks ) //FIXME-3 Check if everything is saved...
 {
 	// Cloudy stuff can be hidden during exports
 	if (hidden) return QString();
@@ -140,27 +140,15 @@
 	TreeItem *ti=getBranchNum(i);
 	while (ti)
 	{
-		s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
+		s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset,tmpLinks);
 		i++;
 		ti=getBranchNum(i);
 	}	
 
-	// Save XLinks 
-	QString ol;	// old link
-	QString cl;	// current link
+	// Mark Links for save
 	for (int i=0; i<xlinkCount(); ++i)
-	{
-		cl=getXLinkNum(i)->saveToDir();
-		if (cl!=ol)
-		{
-			s+=cl;
-			ol=cl;
-		} else
-		{
-			qWarning (QString("BranchItem::saveToDir  Ignoring of duplicate xLink in %1").arg(getHeading()));
-			qWarning ()<<"this="<<this<< " i="<<i<<" "<<getXLinkNum(i)<<"  "<<getXLinkNum(i-1);
-		}
-	}	
+		if (!tmpLinks.contains (getXLinkNum (i)->getLink() )) 
+			tmpLinks.append (getXLinkNum(i)->getLink() );
 
     decIndent();
     s+=endElement   (elementName);
diff -r f0fe7c36ec5c -r 43268373032d branchitem.h
--- a/branchitem.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/branchitem.h	Wed Jun 09 13:14:08 2010 +0000
@@ -2,11 +2,14 @@
 #define BRANCHITEM_H
 
 #include "mapitem.h"
+//#include "xlink.h"
 
+#include <QList>
 
 class QString;
 class QGraphicsScene;
 class BranchObj;
+class Link;
 class XLinkItem;
 
 class BranchItem:public MapItem
@@ -19,7 +22,7 @@
 
 	virtual void insertBranch (int pos,BranchItem *branch);
 
-	virtual QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset);
+	virtual QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset,QList <Link*> &tmpLinks);
 
 	virtual void updateVisibility();
 
diff -r f0fe7c36ec5c -r 43268373032d branchobj.cpp
--- a/branchobj.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/branchobj.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -29,7 +29,7 @@
 
 BranchObj::~BranchObj ()
 {
-//	cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
+	//qDebug()<< "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading()<<")";
 
 	// If I'm animated, I need to un-animate myself first
 	if (anim.isAnimated() )
@@ -63,9 +63,6 @@
 void BranchObj::clear() 
 {
 	//setVisibility (true); //FIXME-4 needed?
-
-	while (!xlink.isEmpty())
-		delete xlink.takeFirst();
 }
 
 void BranchObj::setParObjTmp(LinkableMapObj* dst, QPointF m, int off)	
@@ -251,7 +248,7 @@
 	// set the frame
 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
 
-	//Update links to other branches
+	//Update links to other branches	
 	XLinkObj *xlo;
 	for (int i=0; i<treeItem->xlinkCount(); ++i)	
 	{
@@ -738,22 +735,24 @@
 	anim=ap;
 }
 
+void BranchObj::stopAnimation()
+{
+	anim.stop();
+	if (useRelPos)
+		setRelPos (anim);
+	else
+		move (anim);
+}
+
 bool BranchObj::animate()
 {
 	anim.animate ();
 	if ( anim.isAnimated() )
 	{
-		//if (((MapItem*)treeItem)->getPositionMode()==MapItem::Relative) 
 		if (useRelPos)
-		{
 			setRelPos (anim);
-			//cout<<"Animating rel "<<treeItem->getHeading().toStdString()<<" "<<anim<<" "<<anim.getStart()<<"->"<<anim.getDest()<<"  "<<relPos<<endl;
-		}
 		else
-		{
 			move (anim);
-			//cout<<"Animating abs "<<treeItem->getHeading().toStdString()<<" "<<anim<<" "<<anim.getStart()<<"->"<<anim.getDest()<<"  "<<absPos<<endl;
-		}
 		return true;
 	}
 	/*FIXME-3 reposition in BO:animate nearly never reached? needed?	
diff -r f0fe7c36ec5c -r 43268373032d branchobj.h
--- a/branchobj.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/branchobj.h	Wed Jun 09 13:14:08 2010 +0000
@@ -51,11 +51,10 @@
 	virtual void calcBBoxSizeWithChildren();	// calc size of  BBox including children recursivly
 
 	virtual void setAnimation(const AnimPoint &ap);
+	virtual void stopAnimation();
 	virtual bool animate();
 
 protected:
-	QList<XLinkObj*> xlink;			// xlinks to other branches
-
 	AnimPoint anim;
 };
 
diff -r f0fe7c36ec5c -r 43268373032d editxlinkdialog.cpp
--- a/editxlinkdialog.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/editxlinkdialog.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -10,7 +10,7 @@
 	ui.setupUi (this);
 
 	delink=false;
-	xli=NULL;
+	link=NULL;
 	selbi=NULL;
 
 	connect ( ui.widthBox, SIGNAL (valueChanged( int)), this, SLOT (widthChanged (int)));
@@ -33,14 +33,14 @@
 
 void EditXLinkDialog::widthChanged( int  w)
 {
-	xli->setWidth(w);
+	link->setWidth(w);
 }
 
-void EditXLinkDialog::setXLink( XLinkItem * xi)
+void EditXLinkDialog::setLink( Link * l)
 {
-	xli=xi;
-	ui.colorButton->setPaletteBackgroundColor (xli->getColor() );
-	ui.widthBox->setValue(xli->getWidth());
+	link=l;
+	ui.colorButton->setPaletteBackgroundColor (link->getColor() );
+	ui.widthBox->setValue(link->getWidth());
 }
 
 void EditXLinkDialog::setSelection(BranchItem *bi)
@@ -50,23 +50,23 @@
 
 void EditXLinkDialog::colorButtonPressed()
 {
-	if (xli)
+	if (link)
 	{	
-		QColor col = QColorDialog::getColor(xli->getColor(), this );
+		QColor col = QColorDialog::getColor(link->getColor(), this );
 		if ( !col.isValid() ) return;
-		xli->setColor( col );
+		link->setColor( col );
 		ui.colorButton->setPaletteBackgroundColor (col);
 	}
 }
 
 void EditXLinkDialog::setColorHeadingButtonPressed()	
 {
-	if (xli)
+	if (link)
 	{	
 		if (selbi)
 		{
 			QColor col=selbi->getHeadingColor();
-			xli->setColor(col);
+			link->setColor(col);
 			ui.colorButton->setPaletteBackgroundColor (col);
 		}
 	}
diff -r f0fe7c36ec5c -r 43268373032d editxlinkdialog.h
--- a/editxlinkdialog.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/editxlinkdialog.h	Wed Jun 09 13:14:08 2010 +0000
@@ -17,7 +17,7 @@
 	Q_OBJECT
 public:
 	EditXLinkDialog (QWidget *parent=0);
-	void setXLink (XLinkItem *);
+	void setLink (Link *);
 	void setSelection (BranchItem*);
 	bool useSettingsGlobal();
 	bool deleteXLink();
@@ -31,7 +31,7 @@
 private:
 	Ui::EditXLinkDialog ui;
 	bool delink;
-	XLinkItem *xli;
+	Link *link;
 	BranchItem *selbi;
 };
 
diff -r f0fe7c36ec5c -r 43268373032d exports.cpp
--- a/exports.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/exports.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -156,6 +156,8 @@
 	// Main loop over all branches
 	QString s;
 	QString curIndent;
+	QString dashIndent;
+
 	int i;
 	BranchItem *cur=NULL;
 	BranchItem *prev=NULL;
@@ -183,6 +185,8 @@
 					colString="[G]";
 				else  	
 					colString="[?]";
+
+				dashIndent="";	
 				switch (cur->depth())
 				{
 					case 0:
@@ -218,9 +222,14 @@
 					default:
 						ts << (curIndent + "- " + cur->getHeading());
 						ts << "\n";
+						dashIndent="  ";
 						break;
 				}
 
+				// If necessary, write URL
+				if (!cur->getURL().isEmpty())
+					ts << (curIndent + dashIndent + cur->getURL()) +"\n";
+
 				// If necessary, write note
 				if (!cur->getNoteObj().isEmpty())
 				{
@@ -263,6 +272,7 @@
 	// Main loop over all branches
 	QString s;
 	QString curIndent;
+	QString dashIndent;
 	int i;
 	BranchItem *cur=NULL;
 	BranchItem *prev=NULL;
@@ -279,6 +289,8 @@
 			if (!cur->hasHiddenExportParent() )
 			{
 				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
+
+				dashIndent="";
 				switch (cur->depth())
 				{
 					case 0:
@@ -294,17 +306,24 @@
 						ts << "\n";
 						ts << (curIndent + "* " + cur->getHeading());
 						ts << "\n";
+						dashIndent="  ";
 						break;
 					case 3:
 						ts << (curIndent + "- " + cur->getHeading());
 						ts << "\n";
+						dashIndent="  ";
 						break;
 					default:
 						ts << (curIndent + "- " + cur->getHeading());
 						ts << "\n";
+						dashIndent="  ";
 						break;
 				}
 
+				// If necessary, write URL
+				if (!cur->getURL().isEmpty())
+					ts << (curIndent + dashIndent + cur->getURL()) +"\n";
+
 				// If necessary, write note
 				if (!cur->getNoteObj().isEmpty())
 				{
@@ -512,10 +531,11 @@
 			.arg(col)
 			.arg(id);
 		QString url=current->getURL();	
+		QString heading=quotemeta(current->getHeading());
 		if (!url.isEmpty())
 		{
 			s+=QString ("<a href=\"%1\">").arg(url);
-			s+=QString ("<img src=\"flags/flag-url-16x16.png\">%1</a>").arg(quotemeta(current->getHeading()));
+			s+=QString ("<img src=\"flags/flag-url-16x16.png\">%1</a>").arg(heading);
 			s+="</a>";
 			
 			QRectF fbox=current->getBBoxURLFlag ();
@@ -664,7 +684,9 @@
 	model->setExportMode (true);
 
 	// Write header
-	ts<<"<html><title>"+model->getMapName()<<"</title><body>";
+	ts<<"<html>";
+	ts<<"<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"> ";
+	ts<<"<title>"+model->getMapName()<<"</title><body>";
 	ts<<" <link rel='stylesheet' id='css.stylesheet' href='"<<cssFileName<<"' />\n";
 
 	// Include image
diff -r f0fe7c36ec5c -r 43268373032d findresultitem.cpp
--- a/findresultitem.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/findresultitem.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -11,7 +11,7 @@
 	orgID=-1;
 	orgIndex=-1;
 	orgModel=NULL;
-	itemData.append(QVariant("empty"));
+	if (data.isEmpty()) itemData.append(QVariant("empty"));
 }
 
 FindResultItem::~FindResultItem()
diff -r f0fe7c36ec5c -r 43268373032d historywindow.cpp
--- a/historywindow.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/historywindow.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -155,6 +155,7 @@
 
 void HistoryWindow::closeEvent (QCloseEvent *)
 {
+	hide();
 	emit (windowClosed() );
 }
 
diff -r f0fe7c36ec5c -r 43268373032d linkablemapobj.cpp
--- a/linkablemapobj.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/linkablemapobj.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -32,8 +32,12 @@
 
 LinkableMapObj::~LinkableMapObj()
 {
-	//cout << "Destructor LMO\n";
-    delete (bottomline);
+	//cout<< "Destructor LMO style="<<style<<" l="<<l<<"  p="<<p<<"  segment="<<segment.count()<<endl;
+    if (bottomline)
+	{
+		delete (bottomline);
+		bottomline=NULL;
+	}	
 	delLink();
 }
 
diff -r f0fe7c36ec5c -r 43268373032d main.cpp
--- a/main.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/main.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -79,7 +79,6 @@
 	options.add ("run", Option::String, "r", "run");
 	options.add ("shortcuts", Option::Switch, "s", "shortcuts");
 	options.add ("shortcutsLaTeX", Option::Switch, "sl", "shortcutsLaTeX");
-	options.add ("test", Option::String, "t", "test");
 	options.add ("version", Option::Switch, "v","version");
 	options.setHelpText (
 		"VYM - View Your Mind\n"
@@ -87,7 +86,19 @@
 		"Information about vym can be found in vym.pdf,\n"
 		"which should be part of the vym package.\n"
 		"It is also available at the project homepage:\n\n"
-		"http://www.InSilmaril.de/vym\n");
+		"http://www.InSilmaril.de/vym\n\n"
+		"Usage: vym [OPTION]... [FILE]... \n"
+		"Open FILEs with vym\n\n"
+		"-d           debug       Show debugging output\n"
+		"-h           help        Show this help text\n"
+		"-l           local       Run with ressources in current directory\n"
+		"-n  STRING   name        Set name of instance for DBus access\n"
+		"-q           quit        Quit immediatly after start for benchmarking\n"
+		"-r  FILE     run         Run script\n"
+		"-s           shortcuts   Show Keyboard shortcuts on start\n"
+		"-sl          LaTeX       Show Keyboard shortcuts in LaTeX format on start\n"
+		"-v           version     Show vym version\n"
+	);
 	if (options.parse())
 	{
 		cout << endl << qPrintable( options.getHelpText())<<endl;
@@ -98,7 +109,7 @@
 
 	if (options.isOn ("version"))
 	{
-		cout << "VYM - View Your Mind (c) 2004-2009 Uwe Drechsel "  << endl
+		cout << "VYM - View Your Mind (c) 2004-2010 Uwe Drechsel "  << endl
 			<<"   Version: "<<__VYM_VERSION <<endl
 			<<"Build date: "<<__VYM_BUILD_DATE << endl
 			<<"  "<<__VYM_CODENAME<<endl;
diff -r f0fe7c36ec5c -r 43268373032d mainwindow.cpp
--- a/mainwindow.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/mainwindow.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -720,7 +720,7 @@
 
 	a = new QAction(QPixmap(iconPath+"up.png" ), tr( "Move up","Edit menu" ), this);
 	a->setStatusTip ( tr( "Move branch up" ) );
-	a->setShortcut (Qt::Key_PageUp );				// Move branch up	//FIXME-2 If already on top, GraphicsView scrolls up, probably because this action is disabled?!
+	a->setShortcut (Qt::Key_PageUp );				// Move branch up	
 	a->setEnabled (false);
 	switchboard.addConnection(a,tr("Edit","Shortcut group"));
 	tb->addAction (a);
@@ -2001,7 +2001,7 @@
 		fileNew();
 		VymModel *dstModel=vymViews.last()->getModel();
 		dstModel->select("mc:");
-		dstModel->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
+		dstModel->loadMap (clipboardDir+"/"+clipboardFile,ImportReplace);
 	}
 }
 
@@ -2116,7 +2116,7 @@
 
 			// Finally load map into mapEditor
 			vm->setFilePath (fn);
-			err=vm->load(fn,lmode,ftype);
+			err=vm->loadMap(fn,lmode,true,ftype);
 
 			// Restore old (maybe empty) filepath, if this is an import
 			if (lmode!=NewMap)
@@ -2571,11 +2571,12 @@
 	}
 }
 
-void Main::fileCloseMap()	
+bool Main::fileCloseMap()	
 {
 	VymModel *m=currentModel();
 	if (m)
 	{
+		//qDebug()<<"Main::fileCloseMap  currentIndex="<<tabWidget->currentIndex();
 		if (m->hasChanged())
 		{
 			QMessageBox mb( vymName,
@@ -2586,6 +2587,9 @@
 				QMessageBox::Cancel | QMessageBox::Escape );
 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
+			mb.setModal (true);
+			mb.show();
+			mb.setActiveWindow();
 			switch( mb.exec() ) 
 			{
 				case QMessageBox::Yes:
@@ -2597,7 +2601,7 @@
 					break;
 				case QMessageBox::Cancel:
 					// do nothing
-				return;
+					return true;
 			}
 		} 
 		// And here comes the segfault, because removeTab triggers 
@@ -2609,7 +2613,9 @@
 		//delete (m->getMapEditor());
 
 		updateActions();
+		return false;
 	}
+	return true; // Better don't exit vym if there is no currentModel()...
 }
 
 void Main::filePrint()
@@ -2618,41 +2624,16 @@
 		currentMapEditor()->print();
 }
 
-void Main::fileExitVYM()
+void Main::fileExitVYM()	
 {
 	// Check if one or more editors have changed
-	int i;
-	for (i=0;i<=vymViews.count() -1;i++)
+	int i=0;
+	while (vymViews.count()>0)
 	{
-		// If something changed, ask what to do
-		if (vymViews.at(i)->getModel()->hasChanged())
-		{
-			tabWidget->setCurrentPage(i);
-			QMessageBox mb( vymName,
-				tr("This map is not saved yet. Do you want to"),
-				QMessageBox::Warning,
-				QMessageBox::Yes | QMessageBox::Default,
-				QMessageBox::No,
-				QMessageBox::Cancel | QMessageBox::Escape );
-			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
-			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
-			mb.setModal (true);
-			mb.show();
-			mb.setActiveWindow();
-			switch( mb.exec() ) {
-				case QMessageBox::Yes:
-					// save (the changed editors) and exit
-					fileSave(currentModel(), CompleteMap);
-					break;
-				case QMessageBox::No:
-					// exit without saving
-					break;
-				case QMessageBox::Cancel:
-					// don't save and don't exit
-				return;
-			}
-		}
-	} // loop over all MEs	
+		//qDebug()<<"Main::fileExitVym  count="<<vymViews.count();
+		tabWidget->setCurrentPage(i);
+		if (fileCloseMap()) return;
+	} 
     qApp->quit();
 }
 
@@ -2784,12 +2765,6 @@
 				// Try to open new tab in existing konqueror started previously by vym
 				args.clear();
 
-/*	On KDE3 use DCOP
-				args<< QString("konqueror-%1").arg(procBrowser->pid())<<
-					"konqueror-mainwindow#1"<<
-					"newTab" <<
-					urls.at(i);
-*/					
 				args<< QString("org.kde.konqueror-%1").arg(*browserPID)<<
 					"/konqueror/MainWindow_1"<<
 					"newTab" <<
@@ -2837,7 +2812,7 @@
 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
 		args<<url;
 		QString workDir=QDir::currentDirPath();
-		if (!procBrowser->startDetached(browser,args))
+		if (!QProcess::startDetached(browser,args))
 		{
 			// try to set path to browser
 			QMessageBox::warning(0, 
@@ -3049,7 +3024,7 @@
 		m->nextBranch(cur,prev);
 	}
 
-    stats+=QString ("%1 xLinks \n").arg (xl,6);
+    stats+=QString ("%1 xLinks \n").arg (xl/2,6);
     stats+=QString ("%1 notes\n").arg (n,6);
     stats+=QString ("%1 images\n").arg (f,6);
     stats+=QString ("%1 branches\n").arg (m->branchCount(),6);
@@ -3671,7 +3646,7 @@
 
 void Main::updateActions()
 {
-	// updateActions is also called when satellites are closed	//FIXME-2 doesn't update immediatly, e.g. historyWindow is still visible, when "close" is pressed
+	// updateActions is also called when satellites are closed	
 	actionViewToggleNoteEditor->setChecked (textEditor->isVisible());
 	actionViewToggleHistoryWindow->setChecked (historyWindow->isVisible());
 	actionViewTogglePropertyWindow->setChecked (branchPropertyWindow->isVisible());
diff -r f0fe7c36ec5c -r 43268373032d mainwindow.h
--- a/mainwindow.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/mainwindow.h	Wed Jun 09 13:14:08 2010 +0000
@@ -109,7 +109,7 @@
     void fileExportKDE4Bookmarks();
     void fileExportTaskjuggler();
     void fileExportOOPresentation();
-    void fileCloseMap();
+    bool fileCloseMap();
     void filePrint();
     void fileExitVYM();
 
@@ -258,7 +258,6 @@
 
 private:
 	QTabWidget *tabWidget;
-	QProcess *procBrowser;		//FIXME-2 remove this...
 	qint64 *browserPID;
 
 	QStringList imageTypes;
diff -r f0fe7c36ec5c -r 43268373032d mapeditor.cpp
--- a/mapeditor.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/mapeditor.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -125,7 +125,7 @@
 	selectionColor =QColor (255,255,0);
 	
 
-	// Attributes	//FIXME-2 testing only...
+	// Attributes	//FIXME-3 testing only...
 	QString k;
 	AttributeDef *ad;
 	attrTable= new AttributeTable();
@@ -160,8 +160,7 @@
 
 MapEditor::~MapEditor()
 {
-	//qDebug() <<"Destructor MapEditor for "<<model->getMapName();
-	//model->unregisterEditor(this);
+	//qDebug ()<<"Destr MapEditor this="<<this;
 }
 
 VymModel* MapEditor::getModel()
@@ -1070,28 +1069,20 @@
 				if ((lmo->getOrientation()!=LinkableMapObj::RightOfCenter && p.x() < lmo->getBBox().left()+20)  ||
 				    (lmo->getOrientation()!=LinkableMapObj::LeftOfCenter && p.x() > lmo->getBBox().right()-20) ) 
 				{
-					// FIXME-4 if (ti->xlinkCount()>1)
-					if (true)
+					QMenu menu;
+					QList <QAction*> alist;
+					for (int i=0;i<ti->xlinkCount();i++)
+						alist.append (new QAction(ti->getXLinkNum(i)->getPartnerBranch()->getHeading(),&menu));
+					menu.addActions (alist);	
+					QAction *ra=menu.exec (e->globalPos() );
+					if (ra)
+						model->select (ti->getXLinkNum(alist.indexOf(ra))->getPartnerBranch ());
+					while (!alist.isEmpty())
 					{
-						QMenu menu;
-						QList <QAction*> alist;
-						for (int i=0;i<ti->xlinkCount();i++)
-							alist.append (new QAction(ti->getXLinkNum(i)->getOtherBranch(ti)->getHeading(),&menu));
-						menu.addActions (alist);	
-						QAction *ra=menu.exec (e->globalPos() );
-						if (ra)
-							model->select (ti->getXLinkNum(alist.indexOf(ra))->getOtherBranch (ti));
-						while (!alist.isEmpty())
-						{
-							QAction *a=alist.takeFirst();
-							delete a;
-						}	
-						return;
-					} else
-					{
-						model->select (ti->getXLinkNum(0)->getOtherBranch (ti));
-						return;
-					}
+						QAction *a=alist.takeFirst();
+						delete a;
+					}	
+					return;
 				}	
 			}
 		}
@@ -1112,11 +1103,13 @@
 			if (bi_begin)	
 			{
 				drawingLink=true;
-				tmpXLink=model->createXLink(bi_begin,true);
-				tmpXLink->setColor(model->getMapDefXLinkColor());
-				tmpXLink->setWidth(model->getMapDefXLinkWidth());
-				tmpXLink->setEnd   (p);
-				tmpXLink->updateXLink();
+				tmpLink=new Link (model);
+				tmpLink->setBeginBranch (bi_begin);
+				tmpLink->setColor(model->getMapDefXLinkColor());
+				tmpLink->setWidth(model->getMapDefXLinkWidth());
+				tmpLink->setEndPoint   (p);
+				tmpLink->createMapObj(mapScene);
+				tmpLink->updateLink();
 				return;
 			} 
 		}
@@ -1141,8 +1134,11 @@
 			movingObj_start.setY( p.y() - lmo->y() );	
 			movingObj_orgPos.setX (lmo->x() );
 			movingObj_orgPos.setY (lmo->y() );
-			lmo->setRelPos();
-			movingObj_orgRelPos=lmo->getRelPos();
+			if (ti->depth()>0)
+			{
+				lmo->setRelPos();	
+				movingObj_orgRelPos=lmo->getRelPos();
+			}
 
 			// If modMode==copy, then we want to "move" the _new_ object around
 			// then we need the offset from p to the _old_ selection, because of tmp
@@ -1204,11 +1200,10 @@
 		if (mainWindow->getModMode()!=Main::ModModeCopy)
 			setCursor (Qt::ArrowCursor);
 
+		// Scroll if needed
 		// To avoid jumping of the sceneView, only 
 		// show selection, if not tmp linked
-		/* FIXME-2 if (!lmosel->hasParObjTmp())
-			model->emitShowSelection();
-			*/
+		model->emitShowSelection();
 		
 		// Now move the selection, but add relative position 
 		// (movingObj_start) where selection was chosen with 
@@ -1275,6 +1270,7 @@
 						seli->getBranchObjNum(i)->setOrientation();
 					}
 				}	
+				lmosel->move   (p-movingObj_start);		
 			} else
 			{	
 				if (seli->depth()==1)
@@ -1326,8 +1322,8 @@
 	// Draw a link from one branch to another
 	if (drawingLink)
 	{
-		 tmpXLink->setEnd (p);
-		 tmpXLink->updateXLink();
+		 tmpLink->setEndPoint (p);
+		 tmpLink->updateLink();
 	}	 
 	
     // Move sceneView 
@@ -1380,18 +1376,20 @@
 		// Check if we are over another branch
 		if (dsti)
 		{	
-			tmpXLink->setEnd ( ((BranchItem*)dsti) );
-			tmpXLink->updateXLink();
-			tmpXLink->activate(); 
+			tmpLink->setEndBranch ( ((BranchItem*)dsti) );
+			tmpLink->updateLink();
+			model->createLink (tmpLink);
+			/* FIXME-2 Link savestate missing, segfaulting on undo
 			model->saveState(
 				tmpXLink,QString("delete ()"),
 				dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)),
 				QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti)) 
 			);	
+			*/
 		} else
 		{
-			model->deleteItem(tmpXLink);
-			tmpXLink=NULL;
+			delete (tmpLink);
+			tmpLink=NULL;
 		}
 		return;
 	}
@@ -1576,6 +1574,13 @@
 	}
 }
 
+void MapEditor::wheelEvent(QWheelEvent* e)
+{
+	//qDebug ()<<"ME::wheelEvent";	//FIXME-2 stop all animations in vymModel here
+	//model->stopAllAnimation();
+	QGraphicsView::wheelEvent (e);
+}
+
 void MapEditor::resizeEvent (QResizeEvent* e)
 {
 	QGraphicsView::resizeEvent( e );
diff -r f0fe7c36ec5c -r 43268373032d mapeditor.h
--- a/mapeditor.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/mapeditor.h	Wed Jun 09 13:14:08 2010 +0000
@@ -7,6 +7,7 @@
 #include <QPropertyAnimation>	
 
 #include "attribute.h"
+#include "xlink.h"
 #include "ornamentedobj.h"
 #include "settings.h"
 #include "vymmodel.h"
@@ -93,6 +94,8 @@
     virtual void mouseMoveEvent(QMouseEvent*);
     virtual void mouseReleaseEvent(QMouseEvent*);
     virtual void mouseDoubleClickEvent(QMouseEvent*);
+    virtual void wheelEvent(QWheelEvent*);
+
     virtual void resizeEvent( QResizeEvent * );
 
 	void dragEnterEvent (QDragEnterEvent *);
@@ -116,7 +119,7 @@
 	bool drawingLink;			// true while creating a link
 	bool copyingObj;			// true while modModeCopy
 	bool objectMoved;			// true if object was not clicked, but moved with mouse
-	XLinkItem* tmpXLink;
+	Link* tmpLink;
 
 	MapObj* movingObj;				// moving a MapObj
     QPointF movingObj_orgPos;		// org. pos of mouse before move
diff -r f0fe7c36ec5c -r 43268373032d noteobj.cpp
--- a/noteobj.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/noteobj.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -52,7 +52,7 @@
 	return getNoteASCII ("",80);
 }
 
-QString NoteObj::getNoteASCII(QString indent, const int &width)
+QString NoteObj::getNoteASCII(QString indent, const int &)	//FIXME-3 use width
 {
 	if (note.isEmpty()) return note;
 	QString r=note;
diff -r f0fe7c36ec5c -r 43268373032d treeitem.cpp
--- a/treeitem.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/treeitem.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -17,7 +17,7 @@
 
 TreeItem::TreeItem()
 {
-	cout << "Constr. TI  this="<<this<<endl;
+	//cout << "Constr. TI  this="<<this<<endl;
 	init();
 	itemData.clear();
 	rootItem=this;
@@ -38,13 +38,30 @@
 
 TreeItem::~TreeItem()
 {
-	//cout << "Destructor TreeItem "<<getHeadingStd()<<endl;
+	//qDebug()<<"Destr TreeItem this="<<this<<"  childcount="<<childItems.count();
+	/*
+	qDeleteAll(childItems);	// Call delete	//FIXME-3 use this instead of below
+	qDebug()<<"  ok1";
+	childItems.clear();		// and clear list
+	qDebug()<<"  ok2";use
+	*/
+
+	/*
+	if (this==rootItem)
+	{
+		qDebug()<<"  I'm rootItem, aborting";
+		return;
+	}
+	*/
+	//qDebug()<<"                   ="<<getHeading();
 	TreeItem *ti;
 	while (!childItems.isEmpty())
 	{
+		//qDebug()<<"    ="<<ti->getHeading();
 		ti=childItems.takeFirst();
+		//qDebug()<<"  ti="<<ti;
 		delete ti;
-	}	
+	}
 }
 
 
@@ -316,6 +333,7 @@
 void TreeItem::setHeading (const QString s)
 {
 	itemData[0]=s;
+	//qDebug()<<"TI::setHeading this="<<this<<"  "<<s;
 }
 
 QString TreeItem::getHeading () const
@@ -591,9 +609,17 @@
 {
 	if (n>=0 && n<branchCounter)
 	{
-		return (BranchObj*)(getBranchNum(n)->getLMO());
-	} else
-		return NULL;
+		BranchItem *bi=getBranchNum(n);
+		if (bi)
+		{
+			BranchObj *bo=(BranchObj*)(bi->getLMO());
+			if (bo)
+				return bo;
+			else
+				qDebug()<<"TI::getBONum bo=NULL";
+		}
+	} 
+	return NULL;
 }
 
 ImageItem* TreeItem::getImageNum (const int &n)
@@ -634,14 +660,10 @@
 	if (xlinkCounter>0 )
 	{
 		XLinkItem *xli=getXLinkNum (n);
-		if (!xli) return NULL;
-		if (xli->isBegin() )
-			return (XLinkObj*)(xli->getLMO());
-		else
+		if (xli)
 		{
-			xli=xli->getPartnerXLink();
-			if (!xli) return NULL;
-			return (XLinkObj*)(xli->getLMO());
+			Link *l=xli->getLink();
+			if (l) return l->getXLinkObj();
 		}
 	}
 	return NULL;
diff -r f0fe7c36ec5c -r 43268373032d treemodel.cpp
--- a/treemodel.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/treemodel.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -17,6 +17,7 @@
 
 TreeModel::~TreeModel()
 {
+	//qDebug()<<"Destr TreeModel  this="<<this;
     delete rootItem;
 }
 
diff -r f0fe7c36ec5c -r 43268373032d treemodel.h
--- a/treemodel.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/treemodel.h	Wed Jun 09 13:14:08 2010 +0000
@@ -8,6 +8,7 @@
 
 class BranchItem;
 class TreeItem;
+class Link;
 class LinkableMapObj;
 
 class TreeModel : public QAbstractItemModel
@@ -40,6 +41,10 @@
 
 protected:
     BranchItem *rootItem;
+
+	QList <Link*> xlinks;
+	QList <Link*> xlinks_obsolete;
+
 };
 
 #endif
diff -r f0fe7c36ec5c -r 43268373032d version.h
--- a/version.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/version.h	Wed Jun 09 13:14:08 2010 +0000
@@ -4,10 +4,10 @@
 #include <QString>
 
 #define __VYM_NAME "VYM"
-#define __VYM_VERSION "1.13.3"
+#define __VYM_VERSION "1.13.4"
 //#define __VYM_CODENAME "Codename: RC-1"
 #define __VYM_CODENAME "Codename: development version, not for production!"
-#define __VYM_BUILD_DATE "2010-04-09"
+#define __VYM_BUILD_DATE "2010-06-08"
 
 
 bool checkVersion(const QString &);
diff -r f0fe7c36ec5c -r 43268373032d vym.changelog
--- a/vym.changelog	Fri Apr 09 14:24:04 2010 +0000
+++ b/vym.changelog	Wed Jun 09 13:14:08 2010 +0000
@@ -1,3 +1,43 @@
+-------------------------------------------------------------------
+Tue Jun  8 17:17:41 CEST 2010 - vym@insilmaril.de
+
+- Version: 1.13.4   
+- Bugfix: ImportReplace of a map with multiple mapcenters 
+- Bugfix: Toolbar icon updated immediatly when history window is closed
+
+-------------------------------------------------------------------
+Mon Jun  7 10:40:15 CEST 2010 - vym@insilmaril.de
+
+- Bugfix: Umlauts in HTML export (set encoding to UTF-8)
+- Bugfix: xLink handling while deleting/restoring xLinks
+
+-------------------------------------------------------------------
+Tue Jun  1 15:50:44 CEST 2010 - vym@insilmaril.de
+
+- Version: 1.13.3   
+- Bugfix: Rewrote xlink engine in large parts to address 
+          several issues
+
+-------------------------------------------------------------------
+Fri Apr 30 10:26:59 CEST 2010 - vym@insilmaril.de
+
+- Bugfix: Don't reset zoomFactor after load
+
+-------------------------------------------------------------------
+Thu Apr 29 13:16:50 CEST 2010 - vym@insilmaril.de
+
+- Feature: Added some helptext about commandline options 
+
+-------------------------------------------------------------------
+Wed Apr 28 17:43:10 CEST 2010 - vym@insilmaril.de
+
+- Feature: ASCII exports show URLs now
+
+-------------------------------------------------------------------
+Thu Apr 22 16:07:44 CEST 2010 - vym@insilmaril.de
+
+- Bugfix: Removed empty field in findresults TreeView
+
 -------------------------------------------------------------------
 Fri Apr  9 16:12:55 CEST 2010 - vym@insilmaril.de
 
diff -r f0fe7c36ec5c -r 43268373032d vym.pro
--- a/vym.pro	Fri Apr 09 14:24:04 2010 +0000
+++ b/vym.pro	Wed Jun 09 13:14:08 2010 +0000
@@ -91,6 +91,7 @@
 	vymmodel.h \
 	vymview.h \
 	warningdialog.h \
+	xlink.h \
 	xlinkitem.h \
 	xlinkobj.h \
 	xml-base.h \
@@ -161,6 +162,7 @@
 	vymmodel.cpp \
 	vymview.cpp \
 	warningdialog.cpp \
+	xlink.cpp \
 	xlinkitem.cpp \
 	xlinkobj.cpp \
 	xml-base.cpp \
@@ -225,4 +227,4 @@
 INSTALLS += doc
 DEFINES += VYM_DOCDIR=\\\"$${DOCDIR}\\\"
 
-include(test/modeltest/modeltest.pri)
+#include(test/modeltest/modeltest.pri)
diff -r f0fe7c36ec5c -r 43268373032d vymmodel.cpp
--- a/vymmodel.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/vymmodel.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -12,14 +12,13 @@
 #include "exporthtmldialog.h"
 #include "file.h"
 #include "findresultmodel.h"
-#include "geometry.h"		// for addBBox
 #include "mainwindow.h"
 #include "misc.h"
 #include "parser.h"
 #include "process.h"
 
-#include "warningdialog.h"
 #include "xlinkitem.h"
+#include "xlinkobj.h"
 #include "xml-freemind.h"
 #include "xmlobj.h"
 #include "xml-vym.h"
@@ -54,7 +53,7 @@
 
 VymModel::VymModel()
 {
-    //cout << "Const VymModel\n";
+    //qDebug()<< "Const VymModel";
 	init();
 	rootItem->setModel (this);
 }
@@ -62,18 +61,20 @@
 
 VymModel::~VymModel() 
 {
-    //cout << "Destr VymModel\n";
+    //qDebug() << "Destr VymModel begin this="<<this;
 	autosaveTimer->stop();
 	fileChangedTimer->stop();
-	clear();
-	if (mapEditor) delete (mapEditor);
+	//qApp->processEvents();	// Update view (scene()->update() is not enough)
+    //qDebug() << "Destr VymModel end   this="<<this;
 }	
 
 void VymModel::clear() 
 {
-	unselect();
 	while (rootItem->childCount() >0)
+	{
+		//qDebug()<<"VM::clear  ri="<<rootItem<<"  ri->count()="<<rootItem->childCount();
 		deleteItem (rootItem->getChildNum(0) );
+	}
 }
 
 void VymModel::init () 
@@ -125,11 +126,11 @@
 	// find routine
 	findReset();
 
-	// animations	// FIXME-3 switch to new animation system 
-	animationUse=settings.readBoolEntry("/animation/use",false);	// FIXME-3 add options to control _what_ is animated
+	// animations	// FIXME-4 switch to new animation system 
+	animationUse=settings.readBoolEntry("/animation/use",false);	// FIXME-4 add options to control _what_ is animated
 	animationTicks=settings.readNumEntry("/animation/ticks",10);
 	animationInterval=settings.readNumEntry("/animation/interval",50);
-	animObjList.clear();
+	animObjList.clear();	
 	animationTimer=new QTimer (this);
 	connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
 
@@ -144,6 +145,9 @@
 
 	hidemode=TreeItem::HideNone;
 
+	// Avoid recursions later
+	cleaningUpLinks=false;
+
 	// Network
 	netstate=Offline;
 
@@ -236,21 +240,34 @@
 	// Find the used flags while traversing the tree	// FIXME-3 this can be done local to vymmodel maybe...
 	standardFlagsMaster->resetUsedCounter();
 	
+
+	// Temporary list of links
+	QList <Link*> tmpLinks;
+
 	// Build xml recursivly
 	if (!saveSel)
+	{
 		// Save all mapcenters as complete map, if saveSel not set
-		s+=saveTreeToDir(tmpdir,prefix,offset);
-	else
+			s+=saveTreeToDir(tmpdir,prefix,offset,tmpLinks);
+
+		// Save local settings
+		s+=settings.getDataXML (destPath);
+
+		// Save selection
+		if (getSelectedItem() && !saveSel ) 
+			s+=xml.valueElement("select",getSelectString());
+
+	} else
 	{
 		switch (saveSel->getType())
 		{
 			case TreeItem::Branch:
 				// Save Subtree
-				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
+				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset,tmpLinks);
 				break;
 			case TreeItem::MapCenter:
 				// Save Subtree
-				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
+				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset,tmpLinks);
 				break;
 			case TreeItem::Image:
 				// Save Image
@@ -262,12 +279,11 @@
 		}
 	}
 
-	// Save local settings
-	s+=settings.getDataXML (destPath);
-
-	// Save selection
-	if (getSelectedItem() && !saveSel ) 
-		s+=xml.valueElement("select",getSelectString());
+	// Save XLinks
+	for (int i=0; i<tmpLinks.count();++i)
+	{
+		s+=tmpLinks.at(i)->saveToDir();
+	}
 
 	xml.decIndent();
 	s+=xml.endElement("vymmap");
@@ -278,12 +294,11 @@
 	return s;
 }
 
-QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
+QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset, QList <Link*> &tmpLinks)
 {
     QString s;
-
 	for (int i=0; i<rootItem->branchCount(); i++)
-		s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
+		s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset,tmpLinks);
     return s;
 }
 
@@ -338,10 +353,22 @@
 	return destPath;
 }
 
-ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
+ErrorCode VymModel::loadMap (
+	QString fname, 
+	const LoadMode &lmode, 
+	bool saveStateFlag, 
+	const FileType &ftype,
+	int pos)
 {
 	ErrorCode err=success;
 
+	// Get updated zoomFactor, before applying one read from file in the end
+	if (mapEditor) zoomFactor=mapEditor->getZoomFactorTarget();
+
+	// For ImportReplace let's insert a new branch and replace that
+	BranchItem *selbi=getSelectedBranch();
+	BranchItem *newbi=NULL;
+
 	parseBaseHandler *handler;
 	fileType=ftype;
 	switch (fileType)
@@ -361,20 +388,23 @@
 		selModel->clearSelection();
 	} else
 	{
-		BranchItem *bi=getSelectedBranch();
-		if (!bi) return aborted;
+		if (!selbi) return aborted;
 		if (lmode==ImportAdd)
-			saveStateChangingPart(
-				bi,
-				bi,
+			if (saveStateFlag) saveStateChangingPart(
+				selbi,
+				selbi,
 				QString("addMapInsert (%1)").arg(fname),
-				QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
-		else	
-			saveStateChangingPart(
-				bi,
-				bi,
+				QString("Add map %1 to %2").arg(fname).arg(getObjectName(selbi)));
+		if (lmode==ImportReplace)
+		{
+			if (saveStateFlag) saveStateChangingPart(
+				selbi,
+				selbi,
 				QString("addMapReplace(%1)").arg(fname),
-				QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
+				QString("Add map %1 to %2").arg(fname).arg(getObjectName(selbi)));
+			newbi=addNewBranchInt (selbi,-1);	// Add below selection	
+			select (newbi);
+		}
 	}	
     
 
@@ -465,7 +495,11 @@
 			tmpdir=fname.left(fname.findRev("/",-1));	
 		handler->setTmpDir (tmpdir);
 		handler->setInputFile (file.name());
-		handler->setLoadMode (lmode);
+		if (lmode==ImportReplace)
+			handler->setLoadMode (ImportAdd,pos);
+		else	
+			handler->setLoadMode (lmode,pos);
+
 		bool ok = reader.parse( source );
 		blockReposition=false;
 		blockSaveState=blockSaveStateOrg;
@@ -473,18 +507,27 @@
 		file.close();
 		if ( ok ) 
 		{
-			reposition();	
-			emitSelectionChanged();
 			if (lmode==NewMap)
 			{
 				mapDefault=false;
 				mapChanged=false;
 				mapUnsaved=false;
 				autosaveTimer->stop();
+
+				// Reset timestamp to check for later updates of file
+				fileChangedTime=QFileInfo (destPath).lastModified();
 			}
 
-			// Reset timestamp to check for later updates of file
-			fileChangedTime=QFileInfo (destPath).lastModified();
+	
+
+			if (lmode==ImportReplace)
+			{
+				deleteItem (selbi);
+				select (newbi);
+				deleteKeepChildren (false);
+			}
+			reposition();	
+			emitSelectionChanged();
 		} else 
 		{
 			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
@@ -640,96 +683,6 @@
 	return err;
 }
 
-void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)	
-{
-	QString pathDir=path.left(path.findRev("/"));
-	QDir d(pathDir);
-	QFile file (path);
-
-	if (d.exists() )
-	{
-		// We need to parse saved XML data
-		parseVYMHandler handler;
-		QXmlInputSource source( file);
-		QXmlSimpleReader reader;
-		reader.setContentHandler( &handler );
-		reader.setErrorHandler( &handler );
-		handler.setModel ( this);
-		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
-		if (undoSel.isEmpty())
-		{
-			unselect();
-			clear();
-			handler.setLoadMode (NewMap);
-		} else	
-		{
-			select (undoSel);
-			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));
-}
-
-bool VymModel::addMapInsertInt (const QString &path)
-{
-	QString pathDir=path.left(path.findRev("/"));
-	QDir d(pathDir);
-	QFile file (path);
-
-	if (d.exists() )
-	{
-		// We need to parse saved XML data
-		parseVYMHandler handler;
-		QXmlInputSource source( file);
-		QXmlSimpleReader reader;
-		reader.setContentHandler( &handler );
-		reader.setErrorHandler( &handler );
-		handler.setModel (this);
-		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
-		handler.setLoadMode (ImportAdd);
-		blockReposition=true;
-		bool ok = reader.parse( source );
-		blockReposition=false;
-		if ( ok ) return true;
-		{	
-			// 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));
-	return false;
-}
-
-bool VymModel::addMapInsertInt (const QString &path, int pos)
-{
-	BranchItem *selbi=getSelectedBranch();
-	if (selbi)
-	{
-		if (addMapInsertInt (path))
-		{
-			if (selbi->depth()>0)
-				relinkBranch (selbi->getLastBranch(), selbi,pos);
-			return true;	
-		} else
-		{
-			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
-			return false;
-		}	
-	}		
-	qWarning ("ME::addMapInsertInt nothing selected");
-	return false;
-}
-
 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
 {
 	ImageItem *ii=createImage(dst);
@@ -975,7 +928,7 @@
 			{
 				case QMessageBox::Yes:
 					// Reload map
-					load (filePath,NewMap,fileType);
+					loadMap (filePath);
 		        case QMessageBox::Cancel:
 					fileChangedTime=tmod; // allow autosave to overwrite newer file!
 			}
@@ -1109,7 +1062,7 @@
 		return false;
 }
 
-void VymModel::undo()
+void VymModel::undo()	//FIXME-1 segfault when trying to undo in a brandnew map
 {
 	// Can we undo at all?
 	if (undosAvail<1) return;
@@ -1253,6 +1206,7 @@
 		makeSubDirs (histDir);
 
 	// Save depending on how much needs to be saved	
+	QList <Link*> tmpLinks;
 	if (saveSel)
 		backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
 		
@@ -1529,7 +1483,7 @@
 	return sortFilter;
 }
 
-void VymModel::setHeading(const QString &s)
+void VymModel::setHeading(const QString &s) 
 {
 	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
@@ -1541,7 +1495,7 @@
 			"setHeading (\""+s+"\")", 
 			QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
 		selbi->setHeading(s );
-		emitDataHasChanged ( selbi);	//FIXME-3 maybe emit signal from TreeItem? 
+		emitDataHasChanged ( selbi);	//FIXME-4 maybe emit signal from TreeItem? 
 		reposition();
 		emitSelectionChanged();
 	}
@@ -1655,7 +1609,7 @@
 {
 	rmodel->clear();
 	rmodel->setSearchString (s);
-	rmodel->setSearchFlags (0);	//FIXME-2 translate cs to QTextDocument::FindFlag
+	rmodel->setSearchFlags (0);	//FIXME-3 translate cs to QTextDocument::FindFlag
 	BranchItem *cur=NULL;
 	BranchItem *prev=NULL;
 	nextBranch(cur,prev);
@@ -1671,7 +1625,7 @@
 		int j=0;
 		while ( i>=0)
 		{
-			i=n.indexOf (s,i,cs); //FIXME-2 add subitems to rmodel
+			i=n.indexOf (s,i,cs); 
 			if (i>=0) 
 			{
 				// If not there yet, add "parent" item
@@ -2050,20 +2004,17 @@
 
 void VymModel::pasteNoSave(const int &n)
 {
-	bool old=blockSaveState;
-	blockSaveState=true;
 	bool zippedOrg=zipped;
 	if (redosAvail > 0 || n!=0)
 	{
 		// Use the "historical" buffer
 		QString bakMapName(QString("history-%1").arg(n));
 		QString bakMapDir(tmpMapDir +"/"+bakMapName);
-		load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
+		loadMap (bakMapDir+"/"+clipboardFile,ImportAdd, false);
 	} else
 		// Use the global buffer
-		load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
+		loadMap (clipboardDir+"/"+clipboardFile,ImportAdd, false);
 	zipped=zippedOrg;
-	blockSaveState=old;
 }
 
 void VymModel::paste()	
@@ -2231,39 +2182,61 @@
 	return NULL;
 }
 
-XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
-{
-	if (bi)
-	{
+bool VymModel::createLink(Link *link, bool createMO)
+{
+		BranchItem *begin=link->getBeginBranch();
+		BranchItem *end  =link->getEndBranch();
+
+		if (!begin || !end)
+		{
+			qWarning ()<<"VM::createXLinkNew part of XLink is NULL";
+			return false;
+		}
+
+
 		QModelIndex parix;
 		int n;
 
 		QList<QVariant> cData;
-		cData << "new xLink"<<"undef";
-
-		XLinkItem *newxli=new XLinkItem(cData) ;	
-		newxli->setBegin (bi);
+
+		cData << "new Link begin"<<"undef";
+		XLinkItem *newli=new XLinkItem(cData) ;	
+		newli->setLink (link);
+		link->setBeginLinkItem (newli);
 
 		emit (layoutAboutToBeChanged() );
 
-			parix=index(bi);
-			n=bi->getRowNumAppend(newxli);
+			parix=index(begin);
+			n=begin->getRowNumAppend(newli);
 			beginInsertRows (parix,n,n);
-			bi->appendChild (newxli);	
+			begin->appendChild (newli);	
 			endInsertRows ();
 
+		cData.clear();
+		cData << "new Link end"<<"undef";
+		newli=new XLinkItem(cData) ;	
+		newli->setLink (link);
+		link->setEndLinkItem (newli);
+
+			parix=index(end);
+			n=end->getRowNumAppend(newli);
+			beginInsertRows (parix,n,n);
+			end->appendChild (newli);	
+			endInsertRows ();
+
 		emit (layoutChanged() );
 
-		// save scroll state. If scrolled, automatically select
-		// new branch in order to tmp unscroll parent...
+		xlinks.append (link);
+		link->activate();
+
 		if (createMO) 
 		{
-			newxli->createMapObj(mapScene);
+			link->createMapObj(mapScene);
 			reposition();
 		}
-		return newxli;
-	} 
-	return NULL;
+//	} 
+	//return newli;
+	return true;
 }
 
 AttributeItem* VymModel::addAttribute()	
@@ -2279,7 +2252,7 @@
 	return NULL;
 }
 
-AttributeItem* VymModel::addAttribute(AttributeItem *ai)	// FIXME-2 savestate missing
+AttributeItem* VymModel::addAttribute(AttributeItem *ai)	// FIXME-3 savestate missing
 {
 	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
@@ -2294,7 +2267,7 @@
 
 		emit (layoutChanged() );
 
-		ai->createMapObj(mapScene);		//FIXME-2 check that...
+		ai->createMapObj(mapScene);		//FIXME-3 check that...
 		reposition();
 		return ai;
 	}
@@ -2564,7 +2537,30 @@
 	return false;
 }
 
-void VymModel::deleteSelection()	//FIXME-2 xLinks in a deleted subtree are not restored on undo	
+void VymModel::cleanupLinks()	
+{
+	// This probably could be done more elegant from destructor of a Link,
+	// but somehow this resulted in strange segfaults deep in Qt and glibc...
+	//qDebug ()<<"VM::cleanupLinks begin"<< "CUL="<<cleaningUpLinks;
+	cleaningUpLinks=true;
+	Link *l;
+	XLinkItem *xli;
+	while (!xlinks_obsolete.isEmpty())
+	{
+		l=xlinks_obsolete.takeFirst();
+		xli=l->getBeginLinkItem();
+		//qDebug()<<"VM::cleanupLinks  a)  l="<<l<<"  xli="<<xli;
+		if (xli) deleteItem (xli);
+		xli=l->getEndLinkItem();
+		//qDebug()<<"VM::cleanupLinks  b)  l="<<l<<"  xli="<<xli;
+		if (xli) deleteItem (xli);
+		delete (l);
+	}
+	cleaningUpLinks=false;
+	//qDebug ()<<"VM::cleanupLinks end";
+}
+
+void VymModel::deleteSelection()	
 {
 	BranchItem *selbi=getSelectedBranch();
 
@@ -2586,12 +2582,14 @@
 		}
 		return;
 	}
+
 	TreeItem *ti=getSelectedItem();
+
 	if (ti)
 	{	// Delete other item
 		TreeItem *pi=ti->parent();
 		if (!pi) return;
-		if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
+		if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute||ti->getType()==TreeItem::XLink)
 		{
 			saveStateChangingPart(
 				pi, 
@@ -2605,16 +2603,12 @@
 			select (pi);
 			reposition();
 			emitShowSelection();
-		} else if (ti->getType()==TreeItem::XLink)
-		{
-			//FIXME-2 savestate for deleting xlink missing
-			deleteItem (ti);
 		} else
 			qWarning ("VymmModel::deleteSelection()  unknown type?!");
 	}
 }
 
-void VymModel::deleteKeepChildren()	//FIXME-3 does not work yet for mapcenters
+void VymModel::deleteKeepChildren(bool saveStateFlag)	//FIXME-3 does not work yet for mapcenters
 
 {
 	BranchItem *selbi=getSelectedBranch();
@@ -2634,7 +2628,7 @@
 
 		QPointF p;
 		if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
-		saveStateChangingPart(
+		if (saveStateFlag) saveStateChangingPart(
 			pi,
 			selbi,
 			"deleteKeepChildren ()",
@@ -2693,6 +2687,7 @@
 	if (ti)
 	{
 		TreeItem *pi=ti->parent();
+		//qDebug()<<"VM::deleteItem  start ti="<<ti<<"  "<<ti->getHeading()<<"  pi="<<pi<<"="<<pi->getHeading();
 		QModelIndex parentIndex=index(pi);
 
 		emit (layoutAboutToBeChanged() );
@@ -2704,11 +2699,19 @@
 		reposition();
 
 		emit (layoutChanged() );
+		//qDebug()<<"VM::deleteItem  end   ti="<<ti;
+		if (!cleaningUpLinks) cleanupLinks();
 		if (pi->depth()>=0) return pi;
 	}	
 	return NULL;
 }
 
+void VymModel::deleteLink(Link* l)	
+{
+	int i=xlinks.indexOf(l);
+	if (i>-1) xlinks_obsolete.append (xlinks.takeAt (i));
+}
+
 void VymModel::clearItem (TreeItem *ti)
 {
 	if (ti)
@@ -3138,35 +3141,30 @@
 	}
 }
 
-void VymModel::editXLink(int i)	
-{
-	i=0;
+void VymModel::editXLink(int i)
+{
 	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
-		XLinkItem *xli=selbi->getXLinkNum(i);
-		if (xli) 
+		Link *l=selbi->getXLinkNum(i)->getLink();
+		if (l) 
 		{
 			EditXLinkDialog dia;
-			dia.setXLink (xli);
+			dia.setLink (l);
 			dia.setSelection(selbi);
 			if (dia.exec() == QDialog::Accepted)
 			{
 				if (dia.useSettingsGlobal() )
 				{
-					setMapDefXLinkColor (xli->getColor() );
-					setMapDefXLinkWidth (xli->getWidth() );
+					setMapDefXLinkColor (l->getColor() );
+					setMapDefXLinkWidth (l->getWidth() );
 				}
-				if (dia.deleteXLink()) deleteItem (xli);
+				if (dia.deleteXLink()) delete (l);
 			}
 		}	
 	}
 }
 
-
-
-
-
 //////////////////////////////////////////////
 // Scripting
 //////////////////////////////////////////////
@@ -3252,7 +3250,7 @@
 			//s=parser.parString (ok,0);	// selection
 			t=parser.parString (ok,0);	// path to map
 			if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
-			addMapReplaceInt(getSelectString(selbi),t);	
+			loadMap (t,ImportReplace,false,VymMap,n);
 		}
 	/////////////////////////////////////////////////////////////////////
 	} else if (com==QString("addMapInsert"))
@@ -3271,18 +3269,19 @@
 				t=parser.parString (ok,0);	// path to map
 				n=parser.parInt(ok,1);		// position
 				if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
-				addMapInsertInt(t,n);	
+				loadMap (t,ImportAdd,false,VymMap,n);
 			}
 		} else if (parser.parCount()==1)
 		{
 			t=parser.parString (ok,0);	// path to map
 			if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
-			addMapInsertInt(t);	
+			loadMap (t,ImportAdd,false);
 		} else
 			parser.setError (Aborted,"Wrong number of parameters");
 	/////////////////////////////////////////////////////////////////////
-	} else if (com==QString("addXLink"))
-	{
+	} else if (com==QString("addXLink"))  //FIXME-2 not ported yet to Link
+	{
+	/*
 		if (parser.parCount()>1)
 		{
 			s=parser.parString (ok,0);	// begin
@@ -3308,6 +3307,7 @@
 				parser.setError (Aborted,"Couldn't select begin or end of xLink");
 		} else
 			parser.setError (Aborted,"Need at least 2 parameters for begin and end");
+	*/		
 	/////////////////////////////////////////////////////////////////////
 	} else if (com=="clearFlags")	
 	{
@@ -4424,8 +4424,15 @@
 	//cout << "VM::reposition blocked="<<blockReposition<<endl;
 	if (blockReposition) return;
 
+	BranchObj *bo;
 	for (int i=0;i<rootItem->branchCount(); i++)
-		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
+	{
+		bo=rootItem->getBranchObjNum(i);
+		if (bo)
+			bo->reposition();	//	for positioning heading
+		else
+			qDebug()<<"VM::reposition bo=0";
+	}	
 	//emitSelectionChanged();	
 }
 
@@ -4763,6 +4770,20 @@
 		animObjList.removeAt (i);
 }
 
+void VymModel::stopAllAnimation ()
+{
+	BranchObj *bo;
+	int i=0;
+	while (i<animObjList.size() )
+	{
+		bo=(BranchObj*)animObjList.at(i);
+		bo->stopAnimation();
+		bo->requestReposition();
+		i++;
+	} 
+	reposition();
+}
+
 void VymModel::sendSelection()
 {
 	if (netstate!=Server) return;
@@ -5269,3 +5290,8 @@
 	return s;
 }
 
+QString VymModel::getSelectString (BranchItem *bi) 
+{
+	return getSelectString ((TreeItem*)bi);
+}
+
diff -r f0fe7c36ec5c -r 43268373032d vymmodel.h
--- a/vymmodel.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/vymmodel.h	Wed Jun 09 13:14:08 2010 +0000
@@ -21,6 +21,7 @@
 class BranchItem;
 class FindResultModel;
 class MapEditor;
+class Link;
 class XLinkItem;
 
 class VymModel :  public TreeModel {		
@@ -46,7 +47,7 @@
     void init();
 	void makeTmpDirectories();		//!< create temporary directories e.g. for history
 
-	MapEditor* getMapEditor();			// FIXME-2 still necessary?
+	MapEditor* getMapEditor();			
 	uint getID();						//! Return unique ID of model
 
 	bool isRepositionBlocked();		//!< While load or undo there is no need to update graphicsview
@@ -83,7 +84,7 @@
     QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
 
 	/*! Save all data in tree*/
-	QString saveTreeToDir (const QString&,const QString&,const QPointF&);// Save data recursivly to tempdir
+	QString saveTreeToDir (const QString&,const QString&,const QPointF&,QList <Link*> &tmpLinks);// Save data recursivly to tempdir
 
 
 	/*! \brief Sets filepath, filename and mapname
@@ -110,17 +111,19 @@
 		The data is read from file. Depending on LoadMode the current
 		selection gets replaced by data or the data is appended.
 	*/	
-    ErrorCode load (QString, const LoadMode &, const FileType& );	// newmap, import/replace selection
+    ErrorCode loadMap  (
+		QString,						//!< Path
+		const LoadMode &lmode=NewMap,	//!< New map, replace or add to selection
+		bool saveStateFlag=true,		//!< If called internally for history, don't save
+		const FileType &ftype=VymMap,	//!< VymMap or FreeMind
+		int pos=-1						//!< Optionally tell position where to add data
+	);	
 
 public:
 	/*! \brief Save the map to file */
     ErrorCode save(const SaveMode &);	
 
 private:
-    void addMapReplaceInt(const QString & undoSel, const QString & path);
-    bool addMapInsertInt (const QString & path);
-    bool addMapInsertInt (const QString & path, int pos);
-
 	ImageItem* loadFloatImageInt (BranchItem *dst,QString);
 	void saveFloatImageInt (ImageItem*, const QString &, const QString &);
 public:	
@@ -321,7 +324,9 @@
 	BranchItem* createMapCenter();				//!< Create MapCenter 
 	BranchItem* createBranch(BranchItem *dst);	//!< Create Branch
 	ImageItem* createImage(BranchItem *dst);	//!< Create image
-	XLinkItem* createXLink(BranchItem *dst,bool createMO=false);	//!< Create XLink starting at dst
+
+public:	
+	bool createLink(Link *l, bool createMO=false);			//!< Create XLink 
 
 	AttributeItem* addAttribute();
 	AttributeItem* addAttribute(AttributeItem* );
@@ -366,15 +371,20 @@
 	bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);	
 	bool relinkImage  (ImageItem* image, BranchItem* dst);	
 
+private:
+	bool cleaningUpLinks;				//!< True while cleaning up to avoid recursion
+public:	
+	void cleanupLinks();				//!< Delete orphaned XLinkItems
     void deleteSelection();				//!< Delete selection
-	void deleteKeepChildren();			//!< remove branch, but keep children
+	void deleteKeepChildren(bool saveStateFlag=true);	//!< remove branch, but keep children
+public:	
 	void deleteChildren();				//!< keep branch, but remove children
 
 	TreeItem* deleteItem(TreeItem*);	//!< Delete item and return parent (if parent!= rootItem)
+	void deleteLink (Link*);			//!< Remove Link and related LinkItems in TreeModel
 	void clearItem (TreeItem* ti);		//!< Remove all children of TreeItem ti
 	bool scrollBranch(BranchItem *);
 	bool unscrollBranch(BranchItem *);
-public:	
     void toggleScroll();
     void unscrollChildren();
 	void emitExpandAll();
@@ -406,7 +416,7 @@
 	QString getVymLink();					// return path to map
 	QStringList getVymLinks();				// return paths in subtree
 	void followXLink (int);
-	void editXLink (int);
+	void editXLink (int i=0);
 
 
 
@@ -536,6 +546,7 @@
 	void startAnimation(BranchObj *bo, const QPointF &v);
 	void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
 	void stopAnimation(MapObj *mo);
+	void stopAllAnimation();
 
 ////////////////////////////////////////////
 // Network related 
@@ -631,6 +642,7 @@
 	QString getSelectString ();
 	QString getSelectString (LinkableMapObj *lmo);
 	QString getSelectString (TreeItem *item);
+	QString getSelectString (BranchItem *item);
 	
 	
 signals:
diff -r f0fe7c36ec5c -r 43268373032d xlink.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xlink.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -0,0 +1,192 @@
+#include <QDebug>
+
+#include "xlink.h"
+
+#include "vymmodel.h"
+#include "xlinkitem.h"
+#include "xlinkobj.h"
+
+/////////////////////////////////////////////////////////////////
+// Link
+/////////////////////////////////////////////////////////////////
+
+Link::Link (VymModel *m)
+{
+	//qDebug() << "Const Link () this="<<this;
+	init();
+	model=m;
+}
+
+Link::~Link ()
+{
+	//qDebug()<<"* Destr Link begin this="<<this<<"  bLI="<<beginLinkItem<<"  eLI="<<endLinkItem;
+	//deactivate();
+	//qDebug()<<"* Destr Link end   this="<<this;
+}
+
+void Link::init () 
+{
+	xlo=NULL;
+	beginBranch=NULL;
+	endBranch=NULL;
+	xLinkState=Link::undefinedXLink;
+
+	color=QColor (180,180,180);
+	width=1;
+}
+
+void Link::setBeginBranch (BranchItem *bi)
+{
+	if (bi) 
+	{
+		xLinkState=initXLink;
+		beginBranch=bi;
+	}	
+}
+
+BranchItem* Link::getBeginBranch ()
+{
+	return beginBranch;
+}
+
+void Link::setEndBranch (BranchItem *bi)
+{
+	if (bi) 
+	{
+		xLinkState=initXLink;
+		endBranch=bi;
+	}		
+}
+
+BranchItem* Link::getEndBranch()
+{
+	return endBranch;
+}
+
+void Link::setEndPoint (QPointF p)
+{
+	if (xlo) xlo->setEnd (p);
+}
+
+void Link::setBeginLinkItem (XLinkItem *li)
+{
+	if (li) 
+	{
+		xLinkState=initXLink;
+		beginLinkItem=li;
+	}	
+}
+
+XLinkItem* Link::getBeginLinkItem ()
+{
+	return beginLinkItem;
+}
+
+void Link::setEndLinkItem (XLinkItem *li)
+{
+	if (li) 
+	{
+		xLinkState=initXLink;
+		endLinkItem=li;
+	}		
+}
+
+XLinkItem* Link::getEndLinkItem()
+{
+	return endLinkItem;
+}
+
+void Link::setWidth (int w)
+{
+	width=w;
+	if (xlo) xlo->updateXLink();
+}
+
+int Link::getWidth()
+{
+	return width;
+}
+
+void Link::setColor(QColor c)
+{
+	color=c;
+	if (xlo) xlo->updateXLink();
+}
+
+QColor Link::getColor()
+{
+	return color;
+}
+
+bool Link::activate ()	
+{
+	if (beginBranch && endBranch)
+	{
+		
+		if (beginBranch==endBranch) return false;
+		xLinkState=activeXLink;
+
+		model->updateActions();
+		return true;
+	} else
+		return false;
+}
+
+void Link::deactivate ()	
+{
+	// Remove pointers from XLinkItem to Link and
+	// delete XLinkObj
+
+	xLinkState=deleteXLink;
+	if (beginLinkItem) beginLinkItem->setLink (NULL);
+	if (endLinkItem) endLinkItem->setLink (NULL);
+	if (xlo)
+	{
+		delete (xlo);  
+		xlo=NULL;
+	}
+}
+
+void Link::removeXLinkItem (XLinkItem *xli)
+{
+	if (xli==beginLinkItem) beginLinkItem=NULL;
+	if (xli==endLinkItem) endLinkItem=NULL;
+}
+
+void Link::updateLink()
+{
+	if(xlo ) xlo->updateXLink();
+}
+
+QString Link::saveToDir ()
+{
+	QString s="";
+	if (beginBranch && endBranch && xLinkState==activeXLink)
+	{
+		if (beginBranch==endBranch )
+			qWarning ("Link::saveToDir  beginBranch==endBranch");
+		else
+		{
+			QString colAttr=attribut ("color",color.name());
+			QString widAttr=attribut ("width",QString().setNum(width,10));
+			QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
+			QString endSelAttr=attribut ("endID",  model->getSelectString(endBranch));
+			s=singleElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
+
+		}
+	}
+	return s;
+}
+
+XLinkObj* Link::getXLinkObj()
+{
+	return xlo;
+}
+
+XLinkObj* Link::createMapObj(QGraphicsScene *scene)  
+{
+	if (!xlo) xlo=new XLinkObj (scene,this);  
+	return xlo;
+}
+
+
diff -r f0fe7c36ec5c -r 43268373032d xlink.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xlink.h	Wed Jun 09 13:14:08 2010 +0000
@@ -0,0 +1,64 @@
+#ifndef LINK_H
+#define LINK_H
+
+#include <QColor>
+
+#include "xmlobj.h"
+
+class QPointF;
+class QGraphicsScene;
+class QString;
+
+class BranchItem;
+class LinkableMapObj;
+class VymModel;
+class XLinkItem;
+class XLinkObj;
+
+
+class Link:public XMLObj
+{
+public:
+	enum XLinkState {undefinedXLink,initXLink,activeXLink,deleteXLink};	
+
+	Link (VymModel *m);
+    virtual ~Link();
+    virtual void init ();
+	void setBeginBranch (BranchItem*);
+	BranchItem* getBeginBranch();
+	void setEndBranch   (BranchItem*);
+	void setEndPoint(QPointF);
+	BranchItem* getEndBranch();
+	void setBeginLinkItem (XLinkItem*);
+	XLinkItem* getBeginLinkItem();
+	void setEndLinkItem (XLinkItem*);
+	XLinkItem* getEndLinkItem ();
+	void setColor(QColor);
+	QColor getColor();
+	void setWidth (int);
+	int getWidth ();
+	bool activate ();			
+	void deactivate ();			
+	void removeXLinkItem (XLinkItem *xli);
+	void updateLink();
+	QString saveToDir ();
+	XLinkObj* getXLinkObj();
+	XLinkObj* createMapObj(QGraphicsScene *scene);
+
+private:
+	XLinkState xLinkState;	// init during drawing or active
+	QColor color;
+	int width;
+
+	XLinkObj *xlo;
+	VymModel *model;
+
+	BranchItem *beginBranch;
+	BranchItem *endBranch;
+	XLinkItem *beginLinkItem;
+	XLinkItem *endLinkItem;
+};
+
+
+#endif
+
diff -r f0fe7c36ec5c -r 43268373032d xlinkitem.cpp
--- a/xlinkitem.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/xlinkitem.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -19,205 +19,51 @@
 
 XLinkItem::~XLinkItem ()
 {
-	qDebug() << "Destr XLinkItem "<<this<<"  lmo="<<lmo;
-	if (lmo)
+	//qDebug() << "Destr XLinkItem begin "<<this<<"  pI="<<parentItem<<"  link="<<link;
+	if (link)
 	{
-		qDebug() <<" calling delete (lmo)"; 
-		delete (lmo);
-	}
-	if (partnerXLink)
-	{
-		// Also delete partner 
-		qDebug() << "  deleting partner="<<partnerXLink;
-		partnerXLink->partnerXLink=NULL;	// avoid endless recusion
-		model->deleteItem (partnerXLink);
-	}
+		// tell the model to remove the link later
+		// (and then remove partner link in VymModel::cleanupLinks)
+		model->deleteLink (link);
+		link->removeXLinkItem (this);
+		link->deactivate();
+	}	
+	//qDebug() << "Destr XLinkItem end"<<this;
 }
 
 
 void XLinkItem::init () 
 {
 	setType (XLink);
-	beginBranch=NULL;
-	endBranch=NULL;
-	partnerXLink=NULL;
-	isBeginXLink=true;
-	xLinkState=XLinkItem::undefinedXLink;
-
-	color=QColor (180,180,180);
-	width=1;
+	link=NULL;
 }
 
-void XLinkItem::setBegin (BranchItem *bi)
+void XLinkItem::setLink (Link *l)
 {
-	if (bi) 
-	{
-		xLinkState=initXLink;
-		beginBranch=bi;
-	}	
+	link=l;
 }
 
-BranchItem* XLinkItem::getBegin ()
+Link* XLinkItem::getLink ()
 {
-	return beginBranch;
-}
-
-void XLinkItem::setEnd (BranchItem *bi)
-{
-	if (bi) 
-	{
-		xLinkState=initXLink;
-		endBranch=bi;
-	}		
-}
-
-BranchItem* XLinkItem::getEnd()
-{
-	return endBranch;
-}
-
-void XLinkItem::setWidth (int w)
-{
-	if (isBeginXLink)
-	{
-		width=w;
-		if (lmo) ((XLinkObj*)lmo)->updateXLink();
-		return;
-	}
-	if (partnerXLink)
-		partnerXLink->setWidth (w);
-}
-
-int XLinkItem::getWidth()
-{
-	if (isBeginXLink) return width;
-	if (partnerXLink)
-		return partnerXLink->getWidth();
-	else
-		return -1;
-}
-
-void XLinkItem::setColor(QColor c)
-{
-	if (isBeginXLink)
-	{
-		color=c;
-		if (lmo) ((XLinkObj*)lmo)->updateXLink();
-		return;
-	}	
-	if (partnerXLink)
-		partnerXLink->setColor (c);
-}
-
-QColor XLinkItem::getColor()
-{
-	if (isBeginXLink) return color;
-	if (partnerXLink)
-		return partnerXLink->getColor();
-	else
-		return QColor();
-}
-
-void XLinkItem::setEnd (QPointF p)
-{
-	if (lmo) ((XLinkObj*)lmo)->setEnd (p);
-}
-
-bool XLinkItem::activate ()	
-{
-	if (beginBranch && endBranch)
-	{
-		if (beginBranch==endBranch) return false;
-
-		partnerXLink=model->createXLink (endBranch);
-		partnerXLink->setBegin (beginBranch);
-		partnerXLink->setEnd (endBranch);
-		partnerXLink->partnerXLink=this;
-		partnerXLink->isBeginXLink=false;
-
-		xLinkState=activeXLink;
-		partnerXLink->xLinkState=activeXLink;
-		partnerXLink->setHeading ("xLink to: "+beginBranch->getHeading());
-		setHeading ("xLink to: "+endBranch->getHeading());
-
-		model->updateActions();
-		return true;
-	} else
-		return false;
-}
-
-bool XLinkItem::isBegin()
-{
-	return isBeginXLink;
+	return link;
 }
 
 void XLinkItem::updateXLink()
 {
-	if(lmo && isBeginXLink) 
-		((XLinkObj*)lmo)->updateXLink();
-	else 
-		if (partnerXLink) partnerXLink->updateXLink();
-}
-
-void XLinkItem::updateVisibility()
-{
-	if (lmo) lmo->updateVisibility();
+	qDebug()<<"XLI::updateXLink";
+	if (link)
+		link->updateLink();
 }
 
 BranchItem* XLinkItem::getPartnerBranch()
 {
-	if (!beginBranch && !endBranch)
-		return NULL;
-	if (isBeginXLink)
-		return endBranch;
-	else	
-		return beginBranch;
+	if (link && link->getBeginBranch() && link->getEndBranch())
+	{
+		if (parentItem==link->getBeginBranch())
+			return link->getEndBranch();
+		else	
+			return link->getBeginBranch();
+	}
+	return NULL;
 }
 
-BranchItem* XLinkItem::getOtherBranch(TreeItem *ti)
-{
-	BranchItem *pb=getPartnerBranch();
-	if (!pb) return NULL;
-
-	if (ti==beginBranch)
-		return endBranch;
-	else
-		return beginBranch;
-}
-
-
-
-XLinkItem* XLinkItem::getPartnerXLink()
-{
-	return partnerXLink;
-}
-
-
-QString XLinkItem::saveToDir ()
-{
-	QString s="";
-	if (beginBranch && endBranch && xLinkState==activeXLink)
-	{
-		if (beginBranch==endBranch )
-			qWarning ("XLI::saveToDir  beginBranch==endBranch"); //FIXME-3	s=""
-		else
-		{
-			QString colAttr=attribut ("color",color.name());
-			QString widAttr=attribut ("width",QString().setNum(width,10));
-			QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
-			QString endSelAttr=attribut ("endID",  model->getSelectString(endBranch));
-			s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
-
-			s+=endElement ("xlink");
-		}
-	}
-	return s;
-}
-
-XLinkObj* XLinkItem::createMapObj(QGraphicsScene *scene)  
-{
-	XLinkObj* xlo=new XLinkObj (scene,this);
-	lmo=(LinkableMapObj*)xlo;
-	return xlo;
-}
-
diff -r f0fe7c36ec5c -r 43268373032d xlinkitem.h
--- a/xlinkitem.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/xlinkitem.h	Wed Jun 09 13:14:08 2010 +0000
@@ -2,14 +2,16 @@
 #define XLINKITEM_H
 
 class BranchItem;
+class QGraphicsScene;
 class XLinkObj;
-class QGraphicsScene;
 
 #include "mapitem.h"
+#include "xlink.h"
 
 /*! \brief xlinks are used to draw arbitrary connections between branches (BranchObj) in the map. */
 
 /////////////////////////////////////////////////////////////////////////////
+
 class XLinkItem:public MapItem {
 public:
 	enum XLinkState {undefinedXLink,initXLink,activeXLink,deleteXLink};	
@@ -17,33 +19,13 @@
 	XLinkItem (const QList<QVariant> &data, TreeItem *parent=NULL);
     virtual ~XLinkItem ();
     virtual void init ();
-	void setBegin (BranchItem*);
-	BranchItem* getBegin();
-	void setEnd   (BranchItem*);
-	void setEnd   (QPointF);
-	BranchItem* getEnd();
-	void setColor(QColor);
-	QColor getColor();
-	void setWidth (int);
-	int getWidth ();
-	bool activate ();			//! Creates a 2nd XLink (without a XLinkObj attached) 
-	bool isBegin();		//! true, if this is master xLink, which may have an XLinkObj attached
+	void setLink (Link*);
+	Link* getLink ();
 	void updateXLink();
-	virtual void updateVisibility();	// FIXME-3 not really needed atm...
 	BranchItem* getPartnerBranch ();
-	BranchItem* getOtherBranch (TreeItem *ti);
-	XLinkItem *getPartnerXLink();	//! Partner XLink
-	QString saveToDir ();
-	virtual XLinkObj* createMapObj(QGraphicsScene *scene);
 
 private:
-	XLinkState xLinkState;	// init during drawing or active
-	QColor color;
-	int width;
-	BranchItem *beginBranch;
-	BranchItem *endBranch;
-	XLinkItem *partnerXLink;
-	bool isBeginXLink;
+	Link *link;
 };
 
 #endif
diff -r f0fe7c36ec5c -r 43268373032d xlinkobj.cpp
--- a/xlinkobj.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/xlinkobj.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -1,11 +1,9 @@
+#include <QDebug>
+
 #include "xlinkobj.h"
 
 #include "branchobj.h"
 #include "branchitem.h"
-#include "xlinkitem.h"
-
-#include <iostream>
-using namespace std;
 
 /////////////////////////////////////////////////////////////////
 // XLinkObj
@@ -13,16 +11,18 @@
 
 int XLinkObj::arrowSize=10;					// make instances
 
-XLinkObj::XLinkObj (QGraphicsScene* scene, TreeItem* ti):MapObj(scene,ti)
+XLinkObj::XLinkObj (QGraphicsScene* scene,Link *l):MapObj(scene)
 {
-	//cout << "Const XLinkObj (s)\n";
+	//qDebug()<< "Const XLinkObj (s,Link)";
+	link=l;
 	init();
 }
 
 
+
 XLinkObj::~XLinkObj ()
 {
-	//cout << "Destr XLinkObj\n";
+	//qDebug() << "Destr XLinkObj";
 	delete (line);
 	delete (poly);
 }
@@ -30,16 +30,15 @@
 
 void XLinkObj::init () 
 {
-	XLinkItem *xli=(XLinkItem*)treeItem;
 	visBranch=NULL;
 
-	pen.setColor ( xli->getColor() );
-	pen.setWidth ( xli->getWidth() );
+	pen.setColor ( link->getColor() );
+	pen.setWidth ( link->getWidth() );
 	pen.setCapStyle (  Qt::RoundCap );
 	line=scene->addLine(QLineF(1,1,1,1),pen);
-    line->setZValue (Z_XLINK);
-	poly=scene->addPolygon(QPolygonF(),pen, xli->getColor());
-    poly->setZValue (Z_XLINK);
+	line->setZValue (Z_LINK);
+	poly=scene->addPolygon(QPolygonF(),pen, link->getColor());
+	poly->setZValue (Z_LINK);
 	setVisibility (true);
 }
 
@@ -53,7 +52,7 @@
 {
 	QPointF a,b;
 	QPolygonF pa;
-	if (visBranch)
+	if (visBranch)   
 	{
 		// Only one of the linked branches is visible
 		BranchObj *bo=(BranchObj*)(visBranch->getLMO());
@@ -81,7 +80,7 @@
 	} else
 	{
 		// Both linked branches are visible
-		BranchItem *bi=((XLinkItem*)treeItem)->getBegin();
+		BranchItem *bi=link->getBeginBranch();
 		if ( bi)
 		{
 			// If a link is just drawn in the editor,
@@ -96,8 +95,7 @@
 			// This shouldn't be reached normally...
 			a=beginPos;
 
-		// FIXME-3 try to get rid of xLinkstate if (xLinkState==activeXLink && endBranch)
-		bi=((XLinkItem*)treeItem)->getEnd();
+		bi=link->getEndBranch();
 		if (bi)
 		{
 			BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -112,10 +110,9 @@
 
 	beginPos=a;
 	endPos=b;
-	XLinkItem *xli=(XLinkItem*)treeItem;
-	pen.setColor ( xli->getColor() );
-	pen.setWidth ( xli->getWidth() );
-	poly->setBrush (xli->getColor() );
+	pen.setColor ( link->getColor() );
+	pen.setWidth ( link->getWidth() );
+	poly->setBrush (link->getColor() );
 	line->setPen (pen);
 	line->setLine(a.x(), a.y(), b.x(), b.y());
 }
@@ -148,12 +145,12 @@
 
 void XLinkObj::setVisibility ()
 {
-	BranchItem* beginBI=((XLinkItem*)treeItem)->getBegin();
+	BranchItem* beginBI=link->getBeginBranch();
 	BranchObj* beginBO=NULL;
 	if (beginBI) beginBO=(BranchObj*)(beginBI->getLMO());
 
 	BranchObj* endBO=NULL;
-	BranchItem* endBI=((XLinkItem*)treeItem)->getEnd();
+	BranchItem* endBI=link->getEndBranch();
 	if (endBI) endBO=(BranchObj*)(endBI->getLMO());
 	if (beginBO && endBO)
 	{
diff -r f0fe7c36ec5c -r 43268373032d xlinkobj.h
--- a/xlinkobj.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/xlinkobj.h	Wed Jun 09 13:14:08 2010 +0000
@@ -2,6 +2,7 @@
 #define XLINKOBJ_H
 
 #include "mapobj.h"
+#include "xlink.h"
 
 class BranchObj;
 class BranchItem;
@@ -11,7 +12,7 @@
 /////////////////////////////////////////////////////////////////////////////
 class XLinkObj:public MapObj {
 public:
-    XLinkObj (QGraphicsScene* scene, TreeItem* ti);
+    XLinkObj (QGraphicsScene* scene, Link* l );
     virtual ~XLinkObj ();
     virtual void init ();
 	virtual void setEnd (QPointF);
@@ -30,6 +31,7 @@
 	QPointF   endPos;
 
 	BranchItem *visBranch;	// the "visible" part of a partially scrolled li
+	Link *link;
 };
 
 #endif
diff -r f0fe7c36ec5c -r 43268373032d xml-base.cpp
--- a/xml-base.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/xml-base.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -99,8 +99,9 @@
 	inputFile=f;
 }
 
-void parseBaseHandler::setLoadMode (const LoadMode &lm)
+void parseBaseHandler::setLoadMode (const LoadMode &lm, int p)
 {
 	loadMode=lm;
+	insertPos=p;
 }
 
diff -r f0fe7c36ec5c -r 43268373032d xml-base.h
--- a/xml-base.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/xml-base.h	Wed Jun 09 13:14:08 2010 +0000
@@ -29,12 +29,14 @@
 	void setModel (VymModel *);
 	void setTmpDir (QString);
 	void setInputFile (QString);
-	void setLoadMode (const LoadMode &);
+	void setLoadMode (const LoadMode &,int p=-1);
 
 protected:
 	QString     errorProt;
 
 	LoadMode loadMode;
+	int insertPos;
+
 	bool isVymPart;
 //	State state;			 
 //	State laststate;
diff -r f0fe7c36ec5c -r 43268373032d xml-vym.cpp
--- a/xml-vym.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/xml-vym.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -146,9 +146,15 @@
 				lastBranch=bi;
 				if (loadMode==ImportAdd)
 				{
+					// Import Add
 					lastBranch=model->createBranch(lastBranch);
-				} //else
-					model->clearItem(lastBranch); 
+				} else  
+				{
+					// Import Replace 
+					// Parser should not be called with ImportReplace any longer,
+					// that's done in VymModel now.
+					qDebug()<<"xml-vym:  ImportReplace  ?!"; 
+				}
 			} else
 				// add mapCenter without parent
 				lastBranch=model->createMapCenter(); 
@@ -208,6 +214,8 @@
 				if (loadMode==ImportAdd)
 				{
 					lastBranch=model->createBranch(lastBranch);
+					if (insertPos>=0)
+						model->relinkBranch (lastBranch,(BranchItem*)ti,insertPos);
 				} else
 					model->clearItem (lastBranch);
 				readBranchAttr (atts);
@@ -239,6 +247,10 @@
 	{
 		state=StateBranchXLink;
 		if (!readXLinkAttr (atts)) return false;
+    } else if ( eName == "xlink" && state == StateMap) 
+	{
+		state=StateLink;
+		if (!readLinkNewAttr (atts)) return false;
     } else if ( eName == "branch" && state == StateBranch ) 
 	{
 		lastBranch=model->createBranch(lastBranch);
@@ -545,10 +557,17 @@
 	return true;
 }
 
-bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)	
+bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a) 
 {
+	// Format of links was changed several times:
+	//
 	// object ID is used starting in version 1.8.76
 	// (before there was beginBranch and endBranch)
+	//
+	// Starting in 1.13.2 xlinks are no longer subitems of branches,
+	// but listed at the end of the data in a map. This make handling 
+	// of links much safer and easier
+
 	if (!a.value( "beginID").isEmpty() ) 
 	{ 
 		if (!a.value( "endID").isEmpty() ) 
@@ -557,28 +576,66 @@
 			TreeItem   *endBI=model->findBySelectString (a.value( "endID"));
 			if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() )
 			{
-				XLinkItem *xli=model->createXLink (lastBranch,true);
-				xli->setBegin ( (BranchItem*)beginBI );
-				xli->setEnd ( (BranchItem*)endBI);
-				xli->activate();
+				Link *li=new Link (model);
+				li->setBeginBranch ( (BranchItem*)beginBI );
+				li->setEndBranch ( (BranchItem*)endBI);
 
 				if (!a.value( "color").isEmpty() ) 
 				{
 					QColor col;
 					col.setNamedColor(a.value("color"));
-					xli->setColor (col);
+					li->setColor (col);
 				}
 
 				if (!a.value( "width").isEmpty() ) 
 				{
 					bool okx;
-					xli->setWidth(a.value ("width").toInt (&okx, 10));
+					li->setWidth(a.value ("width").toInt (&okx, 10));
 				}
-				xli->updateXLink();
+				model->createLink (li,true);	// create MO by default
 			}
 		}           
 	}	
-	return true;	// xLinks can only be established at the "end branch", return true
+	return true;	
+}
+
+bool parseVYMHandler::readLinkNewAttr (const QXmlAttributes& a)	
+{
+	// object ID is used starting in version 1.8.76
+	// (before there was beginBranch and endBranch)
+
+	// Beginning in 1.13.2 xLinks are no longer parts of branches, but
+	// a separate list after all the mapCenters within <vymmap> ... </vymmap>
+
+	if (!a.value( "beginID").isEmpty() ) 
+	{ 
+		if (!a.value( "endID").isEmpty() ) 
+		{
+			TreeItem *beginBI=model->findBySelectString (a.value( "beginID"));
+			TreeItem   *endBI=model->findBySelectString (a.value( "endID"));
+			if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() )
+			{
+				Link *li=new Link (model);
+				li->setBeginBranch ( (BranchItem*)beginBI );
+				li->setEndBranch ( (BranchItem*)endBI);
+
+				if (!a.value( "color").isEmpty() ) 
+				{
+					QColor col;
+					col.setNamedColor(a.value("color"));
+					li->setColor (col);
+				}
+
+				if (!a.value( "width").isEmpty() ) 
+				{
+					bool okx;
+					li->setWidth(a.value ("width").toInt (&okx, 10));
+				}
+				model->createLink (li,true);	// create MO by default
+			}
+		}           
+	}	
+	return true;	
 }
 
 bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)
diff -r f0fe7c36ec5c -r 43268373032d xml-vym.h
--- a/xml-vym.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/xml-vym.h	Wed Jun 09 13:14:08 2010 +0000
@@ -22,6 +22,7 @@
 	bool readNoteAttr (const QXmlAttributes&);
 	bool readImageAttr (const QXmlAttributes&);
 	bool readXLinkAttr (const QXmlAttributes&);
+	bool readLinkNewAttr (const QXmlAttributes&);
 	bool readHtmlAttr (const QXmlAttributes&);
 	bool readSettingAttr (const QXmlAttributes&);
 
@@ -41,7 +42,8 @@
 		StateStandardFlag,
 		StateNote,
 		StateImage,
-		StateHeading
+		StateHeading,
+		StateLink,
 	 };
 
 	 int branchesCounter;
diff -r f0fe7c36ec5c -r 43268373032d xmlobj.cpp
--- a/xmlobj.cpp	Fri Apr 09 14:24:04 2010 +0000
+++ b/xmlobj.cpp	Wed Jun 09 13:14:08 2010 +0000
@@ -19,6 +19,29 @@
     return r;
 }
 
+QString quoteUmlaut(const QString &s)
+{
+	QString r=s;
+    QRegExp rx( "ü");
+    r.replace ( rx,"&uuml;");
+    rx.setPattern( "Ü");
+    r.replace ( rx,"&Uuml;");
+    rx.setPattern( "ö");
+    r.replace ( rx,"&ouml;");
+    rx.setPattern( "Ö");
+    r.replace ( rx,"&Ouml;");
+    rx.setPattern( "ä");
+    r.replace ( rx,"&auml;");
+    rx.setPattern( "Ö");
+    r.replace ( rx,"&Auml;");
+    rx.setPattern( "ß");
+    r.replace ( rx,"&szlig;");
+    rx.setPattern( "€");
+    r.replace ( rx,"&euro;");
+    return r;
+}
+
+
 
 
 int XMLObj::actindent=0;		// make instance of actindent
diff -r f0fe7c36ec5c -r 43268373032d xmlobj.h
--- a/xmlobj.h	Fri Apr 09 14:24:04 2010 +0000
+++ b/xmlobj.h	Wed Jun 09 13:14:08 2010 +0000
@@ -4,6 +4,7 @@
 class QString;
 
 QString quotemeta(const QString&);	
+QString quoteUmlaut(const QString&);	
 
 /////////////////////////////////////////////////////////////////////////////
 class XMLObj