# HG changeset patch
# User insilmaril
# Date 1179433143 0
# Node ID c58b3973337cd16bf1aba75fe1033bf7bfd7cd31
# Parent  a6499713d8aebd9cf401fa9101c25f12554966fb
minor bugfixes

diff -r a6499713d8ae -r c58b3973337c main.cpp
--- a/main.cpp	Thu May 17 20:19:03 2007 +0000
+++ b/main.cpp	Thu May 17 20:19:03 2007 +0000
@@ -17,6 +17,7 @@
 Main *mainWindow;				// used in BranchObj::select()								
 QString tmpVymDir;				// All temp files go there, created in mainwindow
 QString clipboardDir;			// Clipboard used in all mapEditors
+QString clipboardFile;			// Clipboard used in all mapEditors
 QDir vymBaseDir;				// Containing all styles, scripts, images, ...
 QDir lastImageDir;
 QDir lastFileDir;
diff -r a6499713d8ae -r c58b3973337c mainwindow.cpp
--- a/mainwindow.cpp	Thu May 17 20:19:03 2007 +0000
+++ b/mainwindow.cpp	Thu May 17 20:19:03 2007 +0000
@@ -25,6 +25,7 @@
 extern Main *mainWindow;
 extern QString tmpVymDir;
 extern QString clipboardDir;
+extern QString clipboardFile;
 extern bool clipboardEmpty;
 extern int statusbarTime;
 extern FlagRowObj* standardFlagsDefault;
@@ -85,6 +86,7 @@
 
 	// Create direcctory for clipboard
 	clipboardDir=tmpVymDir+"/clipboard";
+	clipboardFile="part";
 	QDir d(clipboardDir);
 	d.mkdir (clipboardDir,true);
 	makeSubDirs (clipboardDir);
@@ -197,6 +199,7 @@
 	settings.setValue( "/version/version", vymVersion );
 	settings.setValue( "/version/builddate", vymBuildDate );
 
+	settings.setValue( "/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
 	settings.setValue( "/mapeditor/editmode/autoSelectHeading",actionSettingsAutoSelectHeading->isOn() );
 	settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isOn() );
 	settings.setValue( "/mapeditor/editmode/autoEdit",actionSettingsAutoEdit->isOn() );
@@ -252,13 +255,19 @@
 	tb->setObjectName ("mapTB");
 
     QAction *a;
-    a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&New...","File menu" ),this);
+    a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&New map","File menu" ),this);
 	a->setStatusTip ( tr( "New map","Status tip File menu" ) );
 	a->setShortcut ( Qt::CTRL + Qt::Key_N );		//New map
     a->addTo( tb );
 	fileMenu->addAction (a);
     connect( a, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
 	
+    a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&Copy to new map","File menu" ),this);
+	a->setStatusTip ( tr( "Copy selection to mapcenter of a new map","Status tip File menu" ) );
+	a->setShortcut ( Qt::CTRL +Qt::SHIFT + Qt::Key_N );		//New map
+	fileMenu->addAction (a);
+    connect( a, SIGNAL( triggered() ), this, SLOT( fileNewCopy() ) );
+	
     a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Open..." ,"File menu"),this);
 	a->setStatusTip (tr( "Open","Status tip File menu" ) );
 	a->setShortcut ( Qt::CTRL + Qt::Key_O );		//Open map
@@ -1629,7 +1638,7 @@
 
 void Main::showEvent (QShowEvent * )
 {
-	//FIXME if (textEditor->showWithMain()) textEditor->showNormal();
+	if (actionViewToggleNoteEditor->isOn()) textEditor->showNormal();
 }
 
 bool Main::reallyWriteDirectory(const QString &dir)
@@ -1715,6 +1724,29 @@
 	me->select("mc:");
 }
 
+void Main::fileNewCopy()
+{
+	QString fn="unnamed";
+	MapEditor* oldME =currentMapEditor();
+	if (oldME)
+	{
+		oldME->copy();
+		MapEditor* newME = new MapEditor ( NULL);
+		if (newME)
+		{
+			tabWidget->addTab (newME,fn);
+			tabWidget->showPage(newME);
+			newME->viewport()->setFocus();
+			newME->setAntiAlias (actionViewToggleAntiAlias->isOn());
+			newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
+			// For the very first map we do not have flagrows yet...
+			newME->select("mc:");
+			newME->load (clipboardDir+"/"+clipboardFile,ImportReplace);
+		}
+
+	}
+}
+
 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode)
 {
 	ErrorCode err=success;
@@ -2698,6 +2730,7 @@
 	MapEditor *me=currentMapEditor();
 	if (me)
 	{
+		me->setStateEditHeading (false);
 		QPoint p;	//Not used here, only to find out pos of branch
 		bool ok;
 		QString s=me->getHeading(ok,p);
@@ -2733,6 +2766,7 @@
 
 			if (ok)
 			{
+				me->setStateEditHeading (true);
 #if defined(Q_OS_MACX)
 				p=currentMapEditor()->mapTo (this,p);
 				QDialog *d =new QDialog(NULL);
@@ -3346,7 +3380,7 @@
 	MapEditor *me=currentMapEditor();
 	if (!me) return;
 
-	historyWindow->setCaption (vymName + " - " +tr("History for %1").arg(currentMapEditor()->getFileName(),"Window Caption"));
+	historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(currentMapEditor()->getFileName()));
 
 	// updateActions is also called when NoteEditor is closed
 	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
diff -r a6499713d8ae -r c58b3973337c mainwindow.h
--- a/mainwindow.h	Thu May 17 20:19:03 2007 +0000
+++ b/mainwindow.h	Thu May 17 20:19:03 2007 +0000
@@ -32,6 +32,7 @@
 
 public slots:
     void fileNew();
+    void fileNewCopy();
 
 protected:
 	void closeEvent( QCloseEvent* );
diff -r a6499713d8ae -r c58b3973337c mapeditor.cpp
--- a/mapeditor.cpp	Thu May 17 20:19:03 2007 +0000
+++ b/mapeditor.cpp	Thu May 17 20:19:03 2007 +0000
@@ -26,6 +26,7 @@
 extern Main *mainWindow;
 extern QString tmpVymDir;
 extern QString clipboardDir;
+extern QString clipboardFile;
 extern bool clipboardEmpty;
 extern bool debug;
 extern FlagRowObj *standardFlagsDefault;
@@ -115,6 +116,7 @@
 
 	stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
 	undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
+	mainWindow->updateHistory (undoSet);
 	
 	// Initialize find routine
 	itFind=NULL;				
@@ -160,6 +162,21 @@
     return mapScene;
 }
 
+MapEditor::State MapEditor::getState()
+{
+    return state;
+}
+
+void MapEditor::setStateEditHeading(bool s)
+{
+	if (s)
+	{
+		if (state==Idle) state=EditHeading;
+	}
+	else	
+		state=Idle;
+}
+
 bool MapEditor::isRepositionBlocked()
 {
 	return blockReposition;
@@ -170,6 +187,14 @@
 	blockSaveState=b;
 }
 
+bool MapEditor::isSelectBlocked()
+{
+	if (state==EditHeading)
+		return true;
+	else
+		return false; 
+}
+
 QString MapEditor::getName (const LinkableMapObj *lmo)
 {
 	QString s;
@@ -287,8 +312,6 @@
 
 	if (blockSaveState) return;
 
-	/* TODO remove after testing
-	*/
 	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
 	
 	int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
@@ -569,9 +592,9 @@
 		if (xelection.isEmpty())
 		{
 			parser.setError (Aborted,"Nothing selected");
-		} else if ( xelection.type()!=Branch  && 
-					xelection.type()!=MapCenter  &&
-					xelection.type()!=FloatImage )
+		} else if ( xelection.type()!=Selection::Branch  && 
+					xelection.type()!=Selection::MapCenter  &&
+					xelection.type()!=Selection::FloatImage )
 		{				  
 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
 		} else if (parser.checkParamCount(0))
@@ -583,7 +606,7 @@
 		if (xelection.isEmpty())
 		{
 			parser.setError (Aborted,"Nothing selected");
-		} else if (xelection.type() != Branch && xelection.type() != FloatImage )
+		} else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
 		{
 			parser.setError (Aborted,"Type of selection is wrong.");
 		} else if (parser.checkParamCount(0))
@@ -614,6 +637,19 @@
 		{	
 			deleteChilds();
 		}	
+	} else if (com=="importDir")
+	{
+		if (xelection.isEmpty())
+		{
+			parser.setError (Aborted,"Nothing selected");
+		} else if (! selb )
+		{				  
+			parser.setError (Aborted,"Type of selection is not a branch");
+		} else if (parser.checkParamCount(1))
+		{
+			s=parser.parString(ok,0);
+			if (ok) importDirInt(s);
+		}	
 	} else if (com=="linkTo")
 	{
 		if (xelection.isEmpty())
@@ -649,7 +685,7 @@
 					}	
 				}	
 			}	
-		} else if ( xelection.type() == FloatImage) 
+		} else if ( xelection.type() == Selection::FloatImage) 
 		{
 			if (parser.checkParamCount(1))
 			{
@@ -708,9 +744,9 @@
 		if (xelection.isEmpty() )
 		{
 			parser.setError (Aborted,"Nothing selected");
-		} else if ( xelection.type()!=Branch  && 
-					xelection.type()!=MapCenter  &&
-					xelection.type()!=FloatImage )
+		} else if ( xelection.type()!=Selection::Branch  && 
+					xelection.type()!=Selection::MapCenter  &&
+					xelection.type()!=Selection::FloatImage )
 		{				  
 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
 		} else if (parser.checkParamCount(2))
@@ -727,9 +763,9 @@
 		if (xelection.isEmpty() )
 		{
 			parser.setError (Aborted,"Nothing selected");
-		} else if ( xelection.type()!=Branch  && 
-					xelection.type()!=MapCenter  &&
-					xelection.type()!=FloatImage )
+		} else if ( xelection.type()!=Selection::Selection::Branch  && 
+					xelection.type()!=Selection::Selection::MapCenter  &&
+					xelection.type()!=Selection::Selection::FloatImage )
 		{				  
 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
 		} else if (parser.checkParamCount(2))
@@ -822,7 +858,7 @@
 		}	
 	} else if (com=="setFrameType")
 	{
-		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
+		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
 		{
 			parser.setError (Aborted,"Type of selection does not allow setting frame type");
 		}
@@ -833,7 +869,7 @@
 		}	
 	} else if (com=="setFramePenColor")
 	{
-		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
+		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
 		{
 			parser.setError (Aborted,"Type of selection does not allow setting of pen color");
 		}
@@ -844,7 +880,7 @@
 		}	
 	} else if (com=="setFrameBrushColor")
 	{
-		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
+		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
 		{
 			parser.setError (Aborted,"Type of selection does not allow setting brush color");
 		}
@@ -855,7 +891,7 @@
 		}	
 	} else if (com=="setFramePadding")
 	{
-		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
+		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
 		{
 			parser.setError (Aborted,"Type of selection does not allow setting frame padding");
 		}
@@ -866,7 +902,7 @@
 		}	
 	} else if (com=="setFrameBorderWidth")
 	{
-		if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage)
+		if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
 		{
 			parser.setError (Aborted,"Type of selection does not allow setting frame border width");
 		}
@@ -941,7 +977,7 @@
 		if (xelection.isEmpty() )
 		{
 			parser.setError (Aborted,"Nothing selected");
-		} else if (xelection.type()!=Branch && xelection.type() != MapCenter &&xelection.type()!=FloatImage)
+		} else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
 		{				  
 			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
 		} else if (parser.checkParamCount(1))
@@ -975,6 +1011,19 @@
 			b=parser.parBool(ok,0);
 			if (ok) setIncludeImagesVer(b);
 		}
+	} else if (com=="setHideLinkUnselected")
+	{
+		if (xelection.isEmpty() )
+		{
+			parser.setError (Aborted,"Nothing selected");
+		} else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
+		{				  
+			parser.setError (Aborted,"Type of selection does not allow hiding the link");
+		} else if (parser.checkParamCount(1))
+		{
+			b=parser.parBool(ok,0);
+			if (ok) setHideLinkUnselected(b);
+		}
 	} else if (com=="setSelectionColor")
 	{
 		if (parser.checkParamCount(1))
@@ -993,7 +1042,7 @@
 		} else if (parser.checkParamCount(1))
 		{
 			s=parser.parString (ok,0);
-			if (ok) setURLInt(s);
+			if (ok) setURL(s);
 		}	
 	} else if (com=="setVymLink")
 	{
@@ -1307,8 +1356,13 @@
 	if (savemode==CompleteMap || xelection.isEmpty())
 		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
 	else	
-		//save () FIXME check FIO
-		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
+	{
+		// TODO take care of multiselections
+		if (xelection.type()==Selection::FloatImage)
+			saveFloatImage();
+		else	
+			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
+	}	
 
 	if (!saveStringToDisk(fileDir+fname,saveFile))
 		return 1;
@@ -1556,11 +1610,10 @@
 	if (sel)
 	{
 		// write to directory
-		QString clipfile="part";
-		QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO
+		QString saveFile=saveToDir (fileDir,clipboardFile+"-",true,QPointF(),sel ); // FIXME check FIO
 		QFile file;
 
-		file.setName ( clipboardDir + "/"+clipfile+".xml");
+		file.setName ( clipboardDir + "/"+clipboardFile);
 		if ( !file.open( QIODevice::WriteOnly ) )
 		{
 			// This should neverever happen
@@ -1761,7 +1814,11 @@
 	}	
 	// Clicking below current step makes us redo things
 	if (i>undosAvail) 
-		for (int j=undosAvail; j<i; j++) redo();
+		for (int j=undosAvail; j<i; j++) 
+		{
+		cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
+		redo();
+		}
 
 	// And ignore clicking the current row ;-)	
 }
@@ -1843,13 +1900,10 @@
 
 void MapEditor::pasteNoSave()
 {
-	load (clipboardDir+"/part.xml",ImportAdd);
-}
-
-void MapEditor::cutNoSave()
-{
-	copy();
-	deleteSelection();
+	bool old=blockSaveState;
+	blockSaveState=true;
+	load (clipboardDir+"/"+clipboardFile,ImportAdd);
+	blockSaveState=old;
 }
 
 void MapEditor::paste()		// FIXME no pasting of FIO ???
@@ -1857,13 +1911,13 @@
 	BranchObj *sel=xelection.getBranch();
 	if (sel)
 	{
-		pasteNoSave();
 		saveStateChangingPart(
 			sel,
 			sel,
 			"paste ()",
 			QString("Paste to %1").arg( getName(sel))
 		);
+		pasteNoSave();
 		mapCenter->reposition();
 	}
 }
@@ -1871,18 +1925,20 @@
 void MapEditor::cut()
 {
 	LinkableMapObj *sel=xelection.single();
-	if ( sel && (xelection.type() == Branch ||
-		xelection.type()==MapCenter ||
-		xelection.type()==FloatImage))
+	if ( sel && (xelection.type() == Selection::Branch ||
+		xelection.type()==Selection::MapCenter ||
+		xelection.type()==Selection::FloatImage))
 	{
+	/* No savestate! savestate is called in cutNoSave
 		saveStateChangingPart(
 			sel->getParObj(),
 			sel,
 			"cut ()",
 			QString("Cut %1").arg(getName(sel ))
 		);
+	*/	
 		copy();
-		cutNoSave();
+		deleteSelection();
 		mapCenter->reposition();
 	}
 }
@@ -1957,7 +2013,7 @@
 	}	
 }
 
-void MapEditor::linkTo(const QString &dstString)	// FIXME needed? only for FIO ??
+void MapEditor::linkTo(const QString &dstString)	
 {
 	FloatImageObj *fio=xelection.getFloatImage();
 	if (fio)
@@ -2018,19 +2074,6 @@
 	}
 }
 
-void MapEditor::setURLInt (const QString &s)
-{
-	// Internal function, no saveState needed
-	BranchObj *bo=xelection.getBranch();
-	if (bo)
-	{
-		bo->setURL(s);
-		mapCenter->reposition();
-		xelection.update();
-		ensureSelectionVisible();
-	}
-}
-
 void MapEditor::setHeadingInt(const QString &s)
 {
 	BranchObj *bo=xelection.getBranch();
@@ -2051,6 +2094,7 @@
 	{
 		bo->setVymLink(s);
 		mapCenter->reposition();
+		updateActions();
 		xelection.update();
 		ensureSelectionVisible();
 	}
@@ -2124,7 +2168,7 @@
 {
 	BranchObj *newbo=NULL;
 	BranchObj *bo = xelection.getBranch();
-	if (bo && xelection.type()==Branch)
+	if (bo && xelection.type()==Selection::Branch)
 		 // We accept no MapCenterObj here, so we _have_ a parent
 	{
 		QPointF p=bo->getRelPos();
@@ -2154,7 +2198,7 @@
 void MapEditor::deleteSelection()
 {
 	BranchObj *bo = xelection.getBranch();
-	if (bo && xelection.type()==Branch)
+	if (bo && xelection.type()==Selection::Branch)
 	{
 		BranchObj* par=(BranchObj*)(bo->getParObj());
 		xelection.unselect();
@@ -2235,7 +2279,7 @@
 
 void MapEditor::selectInt (LinkableMapObj *lmo)
 {
-	if (lmo && xelection.single()!= lmo)
+	if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
 	{
 		xelection.select(lmo);
 		xelection.update();
@@ -2406,8 +2450,10 @@
 
 void MapEditor::selectUpperBranch()
 {
+	if (isSelectBlocked() ) return;
+
 	BranchObj *bo=xelection.getBranch();
-	if (bo && xelection.type()==Branch)
+	if (bo && xelection.type()==Selection::Branch)
 	{
 		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
 			selectPrevBranchInt();
@@ -2421,8 +2467,10 @@
 
 void MapEditor::selectLowerBranch()
 {
+	if (isSelectBlocked() ) return;
+
 	BranchObj *bo=xelection.getBranch();
-	if (bo && xelection.type()==Branch)
+	if (bo && xelection.type()==Selection::Branch)
 		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
 			selectNextBranchInt();
 		else
@@ -2435,12 +2483,14 @@
 
 void MapEditor::selectLeftBranch()
 {
+	if (isSelectBlocked() ) return;
+
 	BranchObj* bo;
 	BranchObj* par;
 	LinkableMapObj *sel=xelection.single();
 	if (sel)
 	{
-		if (xelection.type()== MapCenter)
+		if (xelection.type()== Selection::MapCenter)
 		{
 			par=xelection.getBranch();
 			bo=par->getLastSelectedBranch();
@@ -2462,8 +2512,8 @@
 			par=(BranchObj*)(sel->getParObj());
 			if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
 			{
-				if (xelection.type() == Branch ||
-					xelection.type() == FloatImage)
+				if (xelection.type() == Selection::Branch ||
+					xelection.type() == Selection::FloatImage)
 				{
 					xelection.select(par);
 					xelection.update();
@@ -2471,7 +2521,7 @@
 				}
 			} else
 			{
-				if (xelection.type() == Branch )
+				if (xelection.type() == Selection::Branch )
 				{
 					bo=xelection.getBranch()->getLastSelectedBranch();
 					if (bo) 
@@ -2488,12 +2538,14 @@
 
 void MapEditor::selectRightBranch()
 {
+	if (isSelectBlocked() ) return;
+
 	BranchObj* bo;
 	BranchObj* par;
 	LinkableMapObj *sel=xelection.single();
 	if (sel)
 	{
-		if (xelection.type()==MapCenter) 
+		if (xelection.type()==Selection::MapCenter) 
 		{
 			par=xelection.getBranch();
 			bo=par->getLastSelectedBranch();
@@ -2514,8 +2566,8 @@
 			par=(BranchObj*)(xelection.single()->getParObj());
 			if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
 			{
-				if (xelection.type() == Branch ||
-					xelection.type() == FloatImage)
+				if (xelection.type() == Selection::Branch ||
+					xelection.type() == Selection::FloatImage)
 				{
 					xelection.select(par);
 					xelection.update();
@@ -2523,7 +2575,7 @@
 				}
 			} else
 			{
-				if (xelection.type()  == Branch) 
+				if (xelection.type()  == Selection::Branch) 
 				{
 					bo=xelection.getBranch()->getLastSelectedBranch();
 					if (bo) 
@@ -2776,6 +2828,9 @@
 			QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
 		);
 		updateActions();
+		mapCenter->reposition();
+		xelection.update();
+		ensureSelectionVisible();
 	}
 }	
 
@@ -2881,10 +2936,7 @@
 				"setVymLink (\""+fd->selectedFile()+"\")",
 				QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
 			);	
-			bo->setVymLink (fd->selectedFile() );
-			updateActions();
-			mapCenter->reposition();
-			scene()->update();
+			setVymLinkInt (fd->selectedFile() );
 		}
 	}
 }
@@ -2926,6 +2978,7 @@
 		);	
 		updateActions();
 		mapCenter->reposition();
+		xelection.update();
 		scene()->update();
 	}
 }
@@ -2995,7 +3048,7 @@
 	if (bo)
 	{		
 		saveStateChangingPart(
-			bo->getParObj(), 
+			bo, 
 			bo,
 			"deleteChilds ()",
 			QString( "Remove childs of branch %1").arg(getName(bo))
@@ -3264,6 +3317,7 @@
 			QString ("%1 %2").arg(r).arg(getName(bo))
 		);
 		bo->toggleScroll();
+		xelection.update();
 		scene()->update();
 		return true;
 	}	
@@ -3288,6 +3342,7 @@
 			QString ("%1 %2").arg(r).arg(getName(bo))
 		);
 		bo->toggleScroll();
+		xelection.update();
 		scene()->update();
 		return true;
 	}	
@@ -3297,7 +3352,7 @@
 void MapEditor::toggleScroll()
 {
 	BranchObj *bo=xelection.getBranch();
-	if (xelection.type()==Branch )
+	if (xelection.type()==Selection::Branch )
 	{
 		if (bo->isScrolled())
 			unscrollBranch (bo);
@@ -3355,7 +3410,7 @@
 
 		if ( fd->exec() == QDialog::Accepted )
 		{
-			// FIXME loadFIO in QT4 use:	lastImageDir=fd->directory();
+			// TODO loadFIO in QT4 use:	lastImageDir=fd->directory();
 			lastImageDir=QDir (fd->dirPath());
 			QString s;
 			FloatImageObj *fio;
@@ -3372,7 +3427,7 @@
 						QString("Add image %1 to %2").arg(s).arg(getName(bo))
 					);
 				else
-					// FIXME loadFIO error handling
+					// TODO loadFIO error handling
 					qWarning ("Failed to load "+s);
 			}
 		}
@@ -3548,17 +3603,29 @@
 	}	
 }
 
-void MapEditor::setHideLinkUnselected (bool b)	// FIXME missing saveState
+void MapEditor::setHideLinkUnselected (bool b)
 {
 	LinkableMapObj *sel=xelection.single();
 	if (sel &&
-		(xelection.type() == Branch || 
-		xelection.type() == MapCenter  ||
-		xelection.type() == FloatImage ))
+		(xelection.type() == Selection::Branch || 
+		xelection.type() == Selection::MapCenter  ||
+		xelection.type() == Selection::FloatImage ))
+	{
+		QString u= b ? "false" : "true";
+		QString r=!b ? "false" : "true";
+		
+		saveState(
+			sel,
+			QString("setHideLinkUnselected (%1)").arg(u),
+			sel, 
+			QString("setHideLinkUnselected (%1)").arg(r),
+			QString("Hide link of %1 if unselected").arg(getName(sel))
+		);	
 		sel->setHideLinkUnselected(b);
+	}
 }
 
-void MapEditor::importDirInt(BranchObj *dst, QDir d)	// FIXME missing saveState
+void MapEditor::importDirInt(BranchObj *dst, QDir d)
 {
 	BranchObj *bo=xelection.getBranch();
 	if (bo)
@@ -3605,6 +3672,18 @@
 	}		
 }
 
+void MapEditor::importDirInt (const QString &s)
+{
+	BranchObj *bo=xelection.getBranch();
+	if (bo)
+	{
+		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
+
+		QDir d(s);
+		importDirInt (bo,d);
+	}
+}	
+
 void MapEditor::importDir()
 {
 	BranchObj *bo=xelection.getBranch();
@@ -3621,7 +3700,7 @@
 		QString fn;
 		if ( fd->exec() == QDialog::Accepted )
 		{
-			importDirInt (bo,QDir(fd->selectedFile()) );
+			importDirInt (fd->selectedFile() );
 			mapCenter->reposition();
 			scene()->update();
 		}
@@ -3790,6 +3869,13 @@
 		return;
 	}
 
+	//Ignore clicks while editing heading
+	if (isSelectBlocked() ) 
+	{
+		e->ignore();
+		return;
+	}
+
     QPointF p = mapToScene(e->pos());
     LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
 	
@@ -3880,7 +3966,7 @@
 			if (mainWindow->getModMode()==Main::ModModeCopy &&
 				e->state() & Qt::ControlModifier)
 			{
-				if (xelection.type()==Branch)
+				if (xelection.type()==Selection::Branch)
 				{
 					copyingObj=true;
 					mapCenter->addBranch ((BranchObj*)xelection.single());
@@ -4081,7 +4167,7 @@
 	}
 
 	// Have we been drawing a link?
-	if (drawingLink)	//FIXME savestate missing
+	if (drawingLink)	
 	{
 		drawingLink=false;
 		// Check if we are over another branch
@@ -4090,7 +4176,7 @@
 		{	
 			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
 			tmpXLink->updateXLink();
-			tmpXLink->activate();
+			tmpXLink->activate(); //FIXME savestate missing
 			//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );	
 		} else
 		{
@@ -4127,11 +4213,11 @@
 		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
 			dst=NULL;
 		
-		if (xelection.type() == MapCenter )
+		if (xelection.type() == Selection::MapCenter )
 		{	// FIXME The MapCenter was moved, no savestate yet
 		}
 		
-		if (xelection.type() == Branch )
+		if (xelection.type() == Selection::Branch )
 		{	// A branch was moved
 			
 			// save the position in case we link to mapcenter
@@ -4216,6 +4302,12 @@
 
 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
 {
+	if (isSelectBlocked() ) 
+	{
+		e->ignore();
+		return;
+	}
+
 	if (e->button() == Qt::LeftButton )
 	{
 		QPointF p = mapToScene(e->pos());
@@ -4310,7 +4402,7 @@
 	event->acceptProposedAction();
 }
 
-void MapEditor::timerEvent(QTimerEvent *event)  //FIXME testing
+void MapEditor::timerEvent(QTimerEvent *event)  //TODO animation
 {
     Q_UNUSED(event);
 
@@ -4326,12 +4418,12 @@
 
 void MapEditor::autosave()
 {
-	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/used",true).toBool() )
+	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
 		mainWindow->fileSave (this);
 }
 
 
-/*FIXME not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
+/*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
 {
 
 		} else if (event->provides("application/x-moz-file-promise-url") && 
@@ -4401,7 +4493,7 @@
   {
 	FloatImageObj *fio=bo->addFloatImage();
     fio->load(img);
-    fio->setOriginalFilename("Image added by Drag and Drop");	// FIXME savestate
+    fio->setOriginalFilename("Image added by Drag and Drop");	// FIXME savestate missing
     mapCenter->reposition();
     scene()->update();
   }
diff -r a6499713d8ae -r c58b3973337c mapeditor.h
--- a/mapeditor.h	Thu May 17 20:19:03 2007 +0000
+++ b/mapeditor.h	Thu May 17 20:19:03 2007 +0000
@@ -1,7 +1,6 @@
 #ifndef MAPEDITOR_H
 #define MAPEDITOR_H
 
-//#include <QBuffer>
 #include <QGraphicsView>
 
 #include "mapcenterobj.h"
@@ -19,15 +18,33 @@
     Q_OBJECT
 
 public:
+    /*! \brief State of the mapeditor 
+		
+		While a heading is edited, the state has to change, so
+		that e.g. no other object might get selected. This is done
+		in Main by calling setStateEditHeading
+	*/
+	enum State {
+		Idle,			//!< Idle, waiting for user event
+		EditHeading		//!< Editing heading (dont't select another branch now)
+	};
     MapEditor(QWidget* parent=0);
 	~MapEditor();
-    MapCenterObj* getMapCenter();
+    MapCenterObj* getMapCenter();		//!< Return center of map
 	QGraphicsScene * getScene();
-	bool isRepositionBlocked(); // block while load or undo
-	bool isSaveStateBlocked();	// block while undo/redo or while running scripts
-	void setSaveStateBlocked(bool);
+	State getState();					//!< Return State of MapEditor
+	void setStateEditHeading (bool);	//!< If set to true, State will change to EditHeading
+	bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
+	bool isSaveStateBlocked();			//!< block while undo/redo or while running scripts
+	void setSaveStateBlocked(bool);		//!< block saving the undo/redo state
+	bool isSelectBlocked();		//!< true, if no change of selection is possible, e.g. while editing the heading of abranch
 	
 protected:
+	/*! \brief Get name of object
+	  
+	  Returns heading of a branch or name of an object for use in comment
+	  of undo/redo history
+	*/ 
 	QString getName(const LinkableMapObj*);	// Get e.g. heading or filename
 	void makeTmpDirs();		// create temporary directories
 
@@ -81,64 +98,99 @@
 		 to map.xml. The destname is needed for vymLinks, pointing to another map. 
 		 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
 	*/	 
+
+	/*! \brief Set File path
+
+	     The destname is needed to construct the references between maps
+	*/	 
 	void setFilePath (QString filepath,QString destname);	
 	void setFilePath (QString);	//!< Overloaded for convenience
 	QString getFilePath ();	//!< Full path e.g. "/home/tux/map.xml"
 	QString getFileName ();	//!< e.g. "map.xml"
 	QString getMapName ();	//!< e.g. "map"
 	QString getDestPath (); //!< e.g. "/home/tux/map.vym"
+
+	/*! \brief Load map
+
+		The data is read from file. Depending on LoadMode the current
+		selection gets replaced by data or the data is appended.
+	*/	
     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
 public:
-    int save(const SaveMode &);	// Save map 
-	void setZipped(bool);		// save map zipped
-	bool saveZipped();			// 1 if file will be saved zipped
-    void print();				// print canvas
-	void setAntiAlias (bool);
-	void setSmoothPixmap(bool);
+	/*! \brief Save the map to file */
+    int save(const SaveMode &);	
+	void setZipped(bool);		//!< Set or unset compression of map with zip save map zipped
+	bool saveZipped();			//!< True, if file will be saved zipped
+    void print();				//!< Print the map
+	void setAntiAlias (bool);	//!< Set or unset antialiasing
+	void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
 private:
     QPixmap getPixmap();
 	void setHideTmpMode (BranchObj::HideTmpMode);	// temporary hide stuff
 	BranchObj::HideTmpMode getHideTmpMode();		// temporary hide stuff
 public:
-	void setExportMode (bool);			// temporary hide stuff during export
-    void exportImage (QString fn);			// export as PNG	
-    void exportImage (QString fn, QString);	// export in given format
-    void exportOOPresentation(const QString &,const QString &);
-    void exportXML(const QString&);		// export to directory
-    void clear();		// clear map
-    void copy();		// copy branch to clipboard
-    void redo();		// redo last action
-	bool isRedoAvailable();
-    void undo();		// undo last action
-	bool isUndoAvailable();
-	void gotoHistoryStep (int);// goto a step in history
+	void setExportMode (bool);			//!< Set or unset temporary hiding of objects during export
+    void exportImage (QString fn);			//!< Export as PNG	
+    void exportImage (QString fn, QString);	//!< Export in given format
+    void exportOOPresentation(const QString &,const QString &);	//!< Export as OpenOfficeOrg presentation
+    void exportXML(const QString&);		//!< Export as XML to directory
+    void clear();						//!< Clear map
+    void copy();						//!< Copy to clipboard
+    void redo();						//!< Redo last action
+	bool isRedoAvailable();				//!< True, if redo is available
+    void undo();						//!< Undo last action
+	bool isUndoAvailable();				//!< True, if undo is available
+	void gotoHistoryStep (int);			//!< Goto a specifig step in history
 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:	
-    void paste();		// paste clipboard to branch and backup
-    void cut();			// cut to clipboard and backup
+    void paste();		//!< Paste clipboard to branch and backup
+    void cut();			//!< Cut to clipboard (and copy)
+	/*! \brief Move absolutly
+
+		Move absolutly to (x,y).
+	*/	
     void move    (const int &x, const int &y);
+	/*! \brief Move relativly
+
+		Move relativly to (x,y).
+	*/	
     void moveRel (const int &x, const int &y);
-    void moveBranchUp();
-    void moveBranchDown();
+    void moveBranchUp();	//!< Move branch up
+    void moveBranchDown();	//!< Move branch down
 private:	
 	void linkTo(const QString &);
 public:	
-	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
-	void setHeading(const QString &);
+	QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
+	void setHeading(const QString &);		//!< Set heading of branch	
 private:
 	void setHeadingInt(const QString &);
-	void setURLInt(const QString &);		// Just set the URL for selection
 	void setVymLinkInt(const QString &);	// Set vymLink for selection
+	/*! \brief Add new branch
+
+		Depending on num the new branch is created
+
+		-3 above selection as child of selections parent
+		-2 as child of selection
+		-1 below selection as child of selections parent
+		0..n	insert at a specific position in selections parent
+		(needed for free relinking)
+	*/	
     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
 public:	
-    BranchObj* addNewBranch(int);			// pos allows to add above/below selection
-    BranchObj* addNewBranchBefore();		// insert and make selection its
-    void deleteSelection();
-	LinkableMapObj* getSelection();			// returns selection
+	/*! \Add new branch
+		
+		Depending on num the new branch is created
+		-1 above selection
+		 0 as child of selection
+		 1 below selection
+	*/
+    BranchObj* addNewBranch(int pos);		
+    BranchObj* addNewBranchBefore();		//!< Insert branch between selection and its parent
+    void deleteSelection();					//!< Delete selection
+	LinkableMapObj* getSelection();			//!< Returns selection
 	BranchObj* getSelectedBranch();			// returns selected branch or NULL
 	FloatImageObj* getSelectedFloatImage();	// returns selected branch or NULL
 	void unselect();						// before changing current noteedit
@@ -232,6 +284,7 @@
 	bool getHideLinkUnselected ();
 private:	
     void importDirInt(BranchObj *,QDir);
+    void importDirInt(const QString&);
 public:	
     void importDir();
 	void followXLink (int);
@@ -260,6 +313,7 @@
 	void autosave ();
 
 private:
+	State state;				// State of MapEditor
 	QGraphicsScene *mapScene;
     MapCenterObj* mapCenter;
 	QTimer *autosaveTimer;