# HG changeset patch
# User insilmaril
# Date 1249768706 0
# Node ID c6bb4fdcc55fd582c887c67a98f1ad08821dcf25
# Parent  6269016c99058eb6ef5223ca8f02fac149c1b713
Fixed selections with cursor in MapEditor

diff -r 6269016c9905 -r c6bb4fdcc55f branchitem.cpp
--- a/branchitem.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/branchitem.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -17,6 +17,9 @@
 
 	includeImagesVer=false;
 	includeImagesHor=false;
+	 
+	lastSelectedBranchNum=-1;
+	lastSelectedBranchNumAlt=-1;
 }
 
 BranchItem::~BranchItem()
@@ -299,6 +302,41 @@
 	return a;	
 }
 
+void BranchItem::setLastSelectedBranch()
+{
+	int d=depth();
+	if (d>=0)
+	{
+		if (d==1)
+			// Hack to save an additional lastSelected for mapcenters in MapEditor
+			// depending on orientation
+			// this allows to go both left and right from there
+			if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
+			{
+				((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
+				return;
+			}
+		((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
+	}
+}
+
+void BranchItem::setLastSelectedBranch(int i)
+{
+		lastSelectedBranchNum=i;
+}
+
+BranchItem* BranchItem::getLastSelectedBranch()
+{
+	return getBranchNum (lastSelectedBranchNum);
+}
+
+BranchItem* BranchItem::getLastSelectedBranchAlt()
+{
+	return getBranchNum (lastSelectedBranchNumAlt);
+}
+
+
+
 
 
 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
diff -r 6269016c9905 -r c6bb4fdcc55f branchitem.h
--- a/branchitem.h	Thu Aug 06 10:42:17 2009 +0000
+++ b/branchitem.h	Sat Aug 08 21:58:26 2009 +0000
@@ -45,9 +45,16 @@
 	bool getIncludeImagesHor();
 	QString getIncludeImageAttr();
 
+protected:
+	int lastSelectedBranchNum;
+	int lastSelectedBranchNumAlt;
 public:
+	virtual void setLastSelectedBranch();			//! Set myself as last selected in parent
+	virtual void setLastSelectedBranch(int i);		//! Set last selected branch directly
+	virtual BranchItem* getLastSelectedBranch();	//! Returns last selected branch usually
+	virtual BranchItem* getLastSelectedBranchAlt(); //! Used to return last selected branch left of a mapcenter
 
-
+public:
 	TreeItem* findMapItem (QPointF p,TreeItem* excludeTI);	//! search map for branches or images. Ignore excludeTI, where search is started 
 	virtual TreeItem* findID (QString sid);	//! search map for object with ID string
 
diff -r 6269016c9905 -r c6bb4fdcc55f branchpropwindow.cpp
--- a/branchpropwindow.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/branchpropwindow.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -46,10 +46,6 @@
 		show();
 	else	
 		hide();
-
-	// FIXME-2 for now remove attribute tab
-	ui.tabWidget->removeTab (3);
-
 }
 
 BranchPropertyWindow::~BranchPropertyWindow ()
@@ -59,17 +55,22 @@
 	settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
 }
 
-void BranchPropertyWindow::setBranch (BranchItem *bi)	
+void BranchPropertyWindow::setItem (TreeItem *ti)	
 {
 	disconnectSignals();
-	branchItem=bi;
-	if (branchItem)
+	if (!ti)
+		ui.tabWidget->setEnabled (false);
+	else if (ti->isBranchLikeType() )
 	{
+		branchItem=(BranchItem*)ti;
 
 		branch=(BranchObj*)(branchItem->getLMO());
-		if (branch)		// FIXME-3 move to branchItem later, when Frame is ported...
+		if (branch)		// FIXME-3 replace by branchItem later, when Frame is ported...
 		{
 			ui.tabWidget->setEnabled (true);
+			for (int i=0; i<3;++i)
+				ui.tabWidget->setTabEnabled (i,true);
+			ui.tabWidget->setTabEnabled (3,false);
 
 			// Frame
 			FrameObj::FrameType t=branch->getFrameType();
@@ -153,7 +154,13 @@
 
 			// Finally activate signals
 			connectSignals();
-		} // BranchObj	
+		} // BranchItem
+	} else if (ti->getType()==TreeItem::Attribute)
+	{
+		ui.tabWidget->setEnabled (true);
+		for (int i=0; i<3;++i)
+			ui.tabWidget->setTabEnabled (i,false);
+		ui.tabWidget->setTabEnabled (3,true);
 	} else
 	{
 		ui.tabWidget->setEnabled (false);
@@ -164,7 +171,7 @@
 {
 	model=m;
 	if (model) 
-		setBranch (model->getSelectedBranchItem() );
+		setItem (model->getSelectedItem() );
 	else
 		ui.tabWidget->setEnabled (false);
 		
@@ -185,7 +192,7 @@
 				model->setFramePadding (5); 
 				break;
 		}
-		setBranch (branchItem);
+		setItem (branchItem);
 	}	
 }
 
diff -r 6269016c9905 -r c6bb4fdcc55f branchpropwindow.h
--- a/branchpropwindow.h	Thu Aug 06 10:42:17 2009 +0000
+++ b/branchpropwindow.h	Sat Aug 08 21:58:26 2009 +0000
@@ -20,7 +20,7 @@
 public:
 	BranchPropertyWindow (QWidget *parent=0);
 	~BranchPropertyWindow ();
-	void setBranch (BranchItem *);
+	void setItem (TreeItem *);
 	void setModel (VymModel *);
 
 private slots:
diff -r 6269016c9905 -r c6bb4fdcc55f floatobj.cpp
--- a/floatobj.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/floatobj.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -37,7 +37,6 @@
 	zPlane=Z_ICON;
 	setLinkStyle (LinkableMapObj::Parabel);
 	//FIXME-2 setHideLinkUnselected(true);
-	cout << "FO::init  tI="<<treeItem<<endl;
 }
 
 void FloatObj::copy (FloatObj* other)
diff -r 6269016c9905 -r c6bb4fdcc55f mainwindow.cpp
--- a/mainwindow.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/mainwindow.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -3373,7 +3373,7 @@
 	if (m)
 	{
 		TreeItem *selti=m->getSelectedItem();
-		BranchItem *selbi=m->getSelectedBranchItem();
+		BranchItem *selbi=m->getSelectedBranch();
 		if (selti)
 		{
 			if (selbi)
diff -r 6269016c9905 -r c6bb4fdcc55f mapeditor.cpp
--- a/mapeditor.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/mapeditor.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -555,25 +555,185 @@
 */		
 }
 
+BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
+{
+	if (bi)
+	{
+		int i=bi->num();
+		if (i>0) return bi->parent()->getBranchNum(i-1);
+	}
+	return NULL;
+}
+
+BranchItem* MapEditor::getBranchAbove (BranchItem *selbi)
+{
+	if (selbi)
+	{
+		int dz=selbi->depth();	// original depth
+		bool invert=false;
+		if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
+			invert=true;
+
+		BranchItem *bi;
+
+		// Look for branch with same parent but directly above
+		if (dz==1 && invert)
+			bi=getBranchDirectBelow(selbi);
+		else
+			bi=getBranchDirectAbove (selbi);
+
+		if (bi) 
+			// direct predecessor
+			return bi;
+
+		// Go towards center and look for predecessor
+		while (selbi->depth()>0)
+		{
+			selbi=(BranchItem*)(selbi->parent());
+			if (selbi->depth()==1 && invert)
+				bi=getBranchDirectBelow (selbi);
+			else
+				bi=getBranchDirectAbove (selbi);
+			if (bi)
+			{
+				// turn 
+				selbi=bi;
+				while (selbi->depth()<dz)
+				{
+					// try to get back to original depth dz
+					bi=selbi->getLastBranch();
+					if (!bi) 
+					{
+						return selbi;
+					}
+					selbi=bi;
+				}
+				return selbi;
+			}
+		}
+	}
+	return NULL;
+}
+
+BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi)
+{
+	if (bi)
+	{
+		int i=bi->num();
+		if (i+1<bi->parent()->branchCount()) return bi->parent()->getBranchNum(i+1);
+	}
+	return NULL;
+}
+
+BranchItem* MapEditor::getBranchBelow (BranchItem *selbi)
+{
+	if (selbi)
+	{
+		BranchItem *bi;
+		int dz=selbi->depth();	// original depth
+		bool invert=false;
+		if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
+			invert=true;
+
+
+		// Look for branch with same parent but directly below
+		if (dz==1 && invert)
+			bi=getBranchDirectAbove (selbi);
+		else
+			bi=getBranchDirectBelow (selbi);
+		if (bi) 
+			// direct successor
+			return bi;
+
+
+		// Go towards center and look for neighbour
+		while (selbi->depth()>0)
+		{
+			selbi=(BranchItem*)(selbi->parent());
+			if (selbi->depth()==1 && invert)
+				bi=getBranchDirectAbove (selbi);
+			else
+				bi=getBranchDirectBelow (selbi);
+			if (bi)
+			{
+				// turn 
+				selbi=bi;
+				while (selbi->depth()<dz)
+				{
+					// try to get back to original depth dz
+					bi=selbi->getFirstBranch();
+					if (!bi) 
+					{
+						return selbi;
+					}
+					selbi=bi;
+				}
+				return selbi;
+			}
+		}
+	}
+	return NULL;
+}
+
+BranchItem* MapEditor::getLeftBranch (BranchItem *bi)
+{
+	if (bi)
+	{
+		if (bi->depth()==0)
+			// Special case: use alternative selection index
+			return bi->getLastSelectedBranchAlt();	
+		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	
+			// right of center
+			return (BranchItem*)(bi->parent());
+		else
+			// left of center
+			if (bi->getType()== TreeItem::Branch )
+				return bi->getLastSelectedBranch();
+	}
+	return NULL;
+}
+
+BranchItem* MapEditor::getRightBranch(BranchItem *bi)
+{
+	if (bi)
+	{
+		if (bi->depth()==0) return bi->getLastSelectedBranch();	
+		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter)	
+			// left of center
+			return (BranchItem*)(bi->parent());
+		else
+			// right of center
+			if (bi->getType()== TreeItem::Branch )
+				return (BranchItem*)bi->getLastSelectedBranch();
+	}
+	return NULL;
+}
+
+
+
 void MapEditor::cursorUp()
 {
-	model->selectUpperBranch();
+	BranchItem *bi=model->getSelectedBranch();
+	if (bi) model->select (getBranchAbove(bi));
 }
 
 void MapEditor::cursorDown()	
 
 {
-	model->selectLowerBranch();
+	BranchItem *bi=model->getSelectedBranch();
+	if (bi) model->select (getBranchBelow(bi));
 }
 
 void MapEditor::cursorLeft()
 {
-	model->selectLeftBranch();
+	BranchItem *bi=getLeftBranch (model->getSelectedBranch());
+	if (bi) model->select (bi);
 }
 
 void MapEditor::cursorRight()	
 {
-	model->selectRightBranch();
+	BranchItem *bi=getRightBranch (model->getSelectedBranch());
+	if (bi) model->select (bi);
 }
 
 void MapEditor::cursorFirst()	
@@ -595,7 +755,7 @@
 		return;
 	}
 	BranchObj *bo=model->getSelectedBranchObj();
-	BranchItem *bi=model->getSelectedBranchItem();
+	BranchItem *bi=model->getSelectedBranch();
 	if (bo)	
 	{
 		model->setSelectionBlocked(true);
@@ -649,7 +809,7 @@
 			branchContextMenu->popup(e->globalPos() );
 		} else
 		{
-			if (model->getSelectedImageItem() )
+			if (model->getSelectedImage() )
 			{
 				// Context Menu on floatimage
 				// model->updateActions(); FIXME-3 needed?
@@ -808,12 +968,12 @@
 			if (mainWindow->getModMode()==Main::ModModeCopy &&
 				e->state() & Qt::ControlModifier)
 			{
-				BranchItem *bi=model->getSelectedBranchItem();
+				BranchItem *bi=model->getSelectedBranch();
 				if (bi)
 				{
 					copyingObj=true;
 					//FIXME-2   TreeItem::addBranch (BranchItem still missing) 
-					//bi->addBranch (model->getSelectedBranchItem());
+					//bi->addBranch (model->getSelectedBranch());
 					model->unselect();
 					model->select(bi->getLastBranch());
 					model->reposition();
@@ -1065,7 +1225,7 @@
 			}	
 		}
 
-		BranchItem *bi=model->getSelectedBranchItem();
+		BranchItem *bi=model->getSelectedBranch();
 		if (bi && bi->depth()==0)
 		{	
             if (movingObj_orgPos != bi->getBranchObj()->getAbsPos())	// FIXME-3 check getBO here...
@@ -1242,7 +1402,7 @@
 
 void MapEditor::dropEvent(QDropEvent *event)
 {
-	BranchItem *selbi=model->getSelectedBranchItem();
+	BranchItem *selbi=model->getSelectedBranch();
 	if (selbi)
 	{
 		if (debug)
@@ -1317,13 +1477,13 @@
 	foreach (ix,newsel.indexes() )
 	{
 		TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
-		if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image )
+		if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
 			if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti);
 	}
 	foreach (ix,oldsel.indexes() )
 	{
 		TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
-		if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image )
+		if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
 			if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti);
 	}
 
diff -r 6269016c9905 -r c6bb4fdcc55f mapeditor.h
--- a/mapeditor.h	Thu Aug 06 10:42:17 2009 +0000
+++ b/mapeditor.h	Sat Aug 08 21:58:26 2009 +0000
@@ -61,6 +61,14 @@
     void testFunction1();				// just testing new stuff
     void testFunction2();				// just testing new stuff
 
+protected:	
+	BranchItem* getBranchDirectAbove(BranchItem *bi);	//!  get branch direct above bi (in TreeView) 
+	BranchItem* getBranchAbove(BranchItem *bi);			//! get branch above bi (in TreeView) 
+	BranchItem* getBranchDirectBelow(BranchItem *bi);	//!  bet branch direct below bi (in TreeView)
+	BranchItem* getBranchBelow(BranchItem *bi);			//! bet branch below bi (in TreeView)
+	BranchItem* getLeftBranch(BranchItem *bi);			//! bet branch left of bi (in TreeView)
+	BranchItem* getRightBranch(BranchItem *bi);			//! bet branch right of bi (in TreeView)
+
 public slots:
 	void cursorUp();
 	void cursorDown();
diff -r 6269016c9905 -r c6bb4fdcc55f tex/vym.changelog
--- a/tex/vym.changelog	Thu Aug 06 10:42:17 2009 +0000
+++ b/tex/vym.changelog	Sat Aug 08 21:58:26 2009 +0000
@@ -1,3 +1,15 @@
+-------------------------------------------------------------------
+Sat Aug  8 23:54:38 CEST 2009 - uwedr@suse.de
+
+- Feature: Selecting with cursor now remembers left & right of
+  mapcenters. Also improved selections in deeper trees
+- Bugfix: Selecting with cursor in MapEditor
+
+-------------------------------------------------------------------
+Thu Aug  6 19:33:01 CEST 2009 - uwedr@suse.de
+
+- Bugfix: Removed the "new" in new branches to allow easier copy & paste
+
 -------------------------------------------------------------------
 Wed Jul 22 21:51:04 CEST 2009 - uwedr@suse.de
 
diff -r 6269016c9905 -r c6bb4fdcc55f treeitem.cpp
--- a/treeitem.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/treeitem.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -67,7 +67,6 @@
 
 	branchOffset=0;
 	branchCounter=0;
-	lastSelectedBranchNum=-1;
 
 	imageOffset=0;
 	imageCounter=0;
@@ -244,6 +243,8 @@
 
 int TreeItem::depth() 
 {
+	// Rootitem d=-1
+	// MapCenter d=0
 	int d=-2;
 	TreeItem *ti=this;
 	while (ti!=NULL)
@@ -271,6 +272,7 @@
 		case MapCenter: return parentItem->childItems.indexOf (this) - parentItem->branchOffset;
 		case Branch: return parentItem->childItems.indexOf (this) - parentItem->branchOffset;
 		case Image: return parentItem->childItems.indexOf (this) - parentItem->imageOffset;
+		case Attribute: return parentItem->childItems.indexOf (this) - parentItem->attributeOffset;
 		default: return -1;
 	}
 }
@@ -284,6 +286,7 @@
 		case MapCenter: return childItems.indexOf (item) - branchOffset;
 		case Branch: return childItems.indexOf (item) - branchOffset;
 		case Image: return parentItem->childItems.indexOf (item) - imageOffset;
+		case Attribute: return parentItem->childItems.indexOf (item) - attributeOffset;
 		default: return -1;
 	}
 }
@@ -295,6 +298,7 @@
 
 TreeItem::Type TreeItem::getType()
 {
+	if (type==Branch && depth()==0) return MapCenter;
 	return type;
 }
 
@@ -592,22 +596,6 @@
 		return NULL;
 }
 
-void TreeItem::setLastSelectedBranch()
-{
-	if (parentItem)
-		parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this);
-}
-
-void TreeItem::setLastSelectedBranch(int i)
-{
-		lastSelectedBranchNum=i;
-}
-
-TreeItem* TreeItem::getLastSelectedBranch()
-{
-	return getBranchNum (lastSelectedBranchNum);
-}
-
 ImageItem* TreeItem::getImageNum (const int &n)
 {
 	if (n>=0 && n<imageCounter)
diff -r 6269016c9905 -r c6bb4fdcc55f treeitem.h
--- a/treeitem.h	Thu Aug 06 10:42:17 2009 +0000
+++ b/treeitem.h	Sat Aug 08 21:58:26 2009 +0000
@@ -151,9 +151,6 @@
 
 	virtual BranchItem* getBranchNum(const int &n);
 	virtual BranchObj* getBranchObjNum(const int &n);
-	virtual void setLastSelectedBranch();		//! Set myself as last selected in parent
-	virtual void setLastSelectedBranch(int i);	//! Set last selected branch directly
-	virtual TreeItem* getLastSelectedBranch();
 
 	virtual ImageItem* getImageNum(const int &n);
 	virtual FloatImageObj* getImageObjNum(const int &n);
@@ -182,8 +179,6 @@
  
 	int branchOffset;
 	int branchCounter;
-	int lastSelectedBranchNum;
-
 	int imageOffset;
 	int imageCounter;
 
diff -r 6269016c9905 -r c6bb4fdcc55f version.h
--- a/version.h	Thu Aug 06 10:42:17 2009 +0000
+++ b/version.h	Sat Aug 08 21:58:26 2009 +0000
@@ -7,7 +7,7 @@
 #define __VYM_VERSION "1.13.0"
 //#define __VYM_CODENAME "Codename: RC-1"
 #define __VYM_CODENAME "Codename: development version, not for production!"
-#define __VYM_BUILD_DATE "2009-08-03"
+#define __VYM_BUILD_DATE "2009-08-08"
 
 
 bool checkVersion(const QString &);
diff -r 6269016c9905 -r c6bb4fdcc55f vymmodel.cpp
--- a/vymmodel.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/vymmodel.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -360,7 +360,7 @@
 		// (map state is set later at end of load...)
 	} else
 	{
-		BranchItem *bi=getSelectedBranchItem();
+		BranchItem *bi=getSelectedBranch();
 		if (!bi) return aborted;
 		if (lmode==ImportAdd)
 			saveStateChangingPart(
@@ -607,7 +607,7 @@
 		if (selectionType()==TreeItem::Image)
 			saveFloatImage();
 		else	
-			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());	
+			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());	
 		// TODO take care of multiselections
 	}	
 
@@ -725,7 +725,7 @@
 
 void VymModel::loadFloatImage ()
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 
@@ -776,7 +776,7 @@
 
 void VymModel::saveFloatImage ()
 {
-	ImageItem *ii=getSelectedImageItem();
+	ImageItem *ii=getSelectedImage();
 	if (ii)
 	{
 		QFileDialog *fd=new QFileDialog( NULL);
@@ -1487,7 +1487,7 @@
 
 void VymModel::setHeading(const QString &s)
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		saveState(
@@ -1564,7 +1564,7 @@
 	//cout <<"still searching...  "<<qPrintable( itFind->getHeading())<<endl;
 	}	
 	if (!searching)
-		return getSelectedBranchItem();
+		return getSelectedBranch();
 	else
 		return NULL;
 }
@@ -1615,7 +1615,7 @@
 QStringList VymModel::getURLs()	
 {
 	QStringList urls;
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	BranchItem *cur=selbi;
 	BranchItem *prev=NULL;
 	while (cur) 
@@ -1629,7 +1629,7 @@
 
 void VymModel::setFrameType(const FrameObj::FrameType &t)	//FIXME-4 not saved if there is no LMO
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -1647,7 +1647,7 @@
 
 void VymModel::setFrameType(const QString &s)	//FIXME-4 not saved if there is no LMO
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -1665,7 +1665,7 @@
 void VymModel::setFramePenColor(const QColor &c)	//FIXME-4 not saved if there is no LMO
 
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -1680,7 +1680,7 @@
 
 void VymModel::setFrameBrushColor(const QColor &c)	//FIXME-4 not saved if there is no LMO
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -1695,7 +1695,7 @@
 
 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -1712,7 +1712,7 @@
 
 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		BranchObj *bo=(BranchObj*)(bi->getLMO());
@@ -1729,7 +1729,7 @@
 
 void VymModel::setIncludeImagesVer(bool b)
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		QString u= b ? "false" : "true";
@@ -1750,7 +1750,7 @@
 
 void VymModel::setIncludeImagesHor(bool b)	
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{
 		QString u= b ? "false" : "true";
@@ -1869,7 +1869,7 @@
 
 void VymModel::paste()	
 {   
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		saveStateChangingPart(
@@ -1896,7 +1896,7 @@
 
 void VymModel::moveUp()	
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		if (!selbi->canMoveUp()) return;
@@ -1909,7 +1909,7 @@
 
 void VymModel::moveDown()	
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		if (!selbi->canMoveDown()) return;
@@ -1985,8 +1985,6 @@
 
 AttributeItem* VymModel::addAttribute()
 {
-	cout << "VM::addAttribute\n";
-
 	TreeItem *selti=getSelectedItem();
 	if (selti)
 	{
@@ -2108,7 +2106,7 @@
 	//  0	add as child
 	// +1	add below
 	BranchItem *newbi=NULL;
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 
 	if (selbi)
 	{
@@ -2145,7 +2143,7 @@
 BranchItem* VymModel::addNewBranchBefore()	
 {
 	BranchItem *newbi=NULL;
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi && selbi->getType()==TreeItem::Branch)
 		 // We accept no MapCenter here, so we _have_ a parent
 	{
@@ -2255,7 +2253,7 @@
 
 void VymModel::deleteSelection()	// FIXME-2 include fix for deleted mapcenters from 1.12.4
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 
 	if (selbi && selbi->isBranchLikeType() )
 	{
@@ -2270,18 +2268,19 @@
 		}
 		return;
 	}
-	ImageItem *ii=getSelectedImageItem();
-	if (ii)
+	TreeItem *ti=getSelectedImage();
+	if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
 	{
-		BranchItem *pi=(BranchItem*)(ii->parent());
+		TreeItem *pi=ti->parent();
 		saveStateChangingPart(
 			pi, 
-			ii,
+			ti,
 			"delete ()",
-			QString("Delete %1").arg(getObjectName(ii))
+			QString("Delete %1").arg(getObjectName(ti))
 		);
 		unselect();
-		deleteItem (ii);
+		deleteItem (ti);
+		emitDataHasChanged (pi);
 		select (pi);
 		reposition();
 		emitShowSelection();
@@ -2289,10 +2288,10 @@
 	}
 }
 
-void VymModel::deleteKeepChildren()	//FIXME-2 does not work yet for mapcenters
-
-{
-	BranchItem *selbi=getSelectedBranchItem();
+void VymModel::deleteKeepChildren()	//FIXME-3 does not work yet for mapcenters
+
+{
+	BranchItem *selbi=getSelectedBranch();
 	BranchItem *pi;
 	if (selbi)
 	{
@@ -2341,7 +2340,7 @@
 void VymModel::deleteChildren()		
 
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{		
 		saveStateChangingPart(
@@ -2442,7 +2441,7 @@
 
 void VymModel::toggleScroll()	
 {
-	BranchItem *bi=(BranchItem*)getSelectedBranchItem();
+	BranchItem *bi=(BranchItem*)getSelectedBranch();
 	if (bi && bi->isBranchLikeType() )
 	{
 		if (bi->isScrolled())
@@ -2477,7 +2476,7 @@
 
 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi) 
 	{
 		QString u,r;
@@ -2524,7 +2523,7 @@
 
 void VymModel::colorBranch (QColor c)	
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		saveState(
@@ -2540,7 +2539,7 @@
 
 void VymModel::colorSubtree (QColor c) 
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		saveStateChangingPart(
@@ -2562,7 +2561,7 @@
 
 QColor VymModel::getCurrentHeadingColor()	
 {
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	if (selbi)	return selbi->getHeadingColor();
 		
 	QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
@@ -2651,7 +2650,7 @@
 
 void VymModel::editVymLink()
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{		
 		QStringList filters;
@@ -2695,7 +2694,7 @@
 
 void VymModel::deleteVymLink()
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 	{		
 		saveState(
@@ -2713,7 +2712,7 @@
 
 QString VymModel::getVymLink()
 {
-	BranchItem *bi=getSelectedBranchItem();
+	BranchItem *bi=getSelectedBranch();
 	if (bi)
 		return bi->getVymLink();
 	else	
@@ -2724,7 +2723,7 @@
 QStringList VymModel::getVymLinks()	
 {
 	QStringList links;
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	BranchItem *cur=selbi;
 	BranchItem *prev=NULL;
 	while (cur) 
@@ -2792,7 +2791,7 @@
 void VymModel::parseAtom(const QString &atom)
 {
 	TreeItem* selti=getSelectedItem();
-	BranchItem *selbi=getSelectedBranchItem();
+	BranchItem *selbi=getSelectedBranch();
 	QString s,t;
 	double x,y;
 	int n;
@@ -3307,7 +3306,7 @@
 	/////////////////////////////////////////////////////////////////////
 	} else if (com=="saveImage")
 	{
-		ImageItem *ii=getSelectedImageItem();
+		ImageItem *ii=getSelectedImage();
 		if (!ii )
 		{
 			parser.setError (Aborted,"No image selected");
@@ -4612,12 +4611,7 @@
 bool VymModel::select (const QString &s)
 {
 	TreeItem *ti=findBySelectString(s);
-	if (ti)
-	{
-		unselect();
-		select (ti);
-		return true;
-	} 
+	if (ti) return select (index(ti));
 	return false;
 }
 
@@ -4626,7 +4620,7 @@
 	QItemSelection oldsel=selModel->selection();
 
 	if (lmo)
-		return select (lmo->getTreeItem() );
+		return select (index (lmo->getTreeItem()) );
 	else	
 		return false;
 }
@@ -4642,7 +4636,8 @@
 	if (index.isValid() )
 	{
 		selModel->select (index,QItemSelectionModel::ClearAndSelect  );
-		getSelectedItem()->setLastSelectedBranch();
+		BranchItem *bi=getSelectedBranch();
+		if (bi) bi->setLastSelectedBranch();
 		return true;
 	}
 	return false;
@@ -4654,9 +4649,9 @@
 	selModel->clearSelection();
 }	
 
-void VymModel::reselect()
-{
-	select (lastSelectString);
+bool VymModel::reselect()
+{
+	return select (lastSelectString);
 }	
 
 void VymModel::emitShowSelection()	
@@ -4678,7 +4673,7 @@
 }
 
 
-//void VymModel::selectInt (LinkableMapObj *lmo)	// FIXME-3 still needed?
+//bool VymModel::selectInt (LinkableMapObj *lmo)	// FIXME-3 still needed?
 /*
 {
 	if (selection.select(lmo))
@@ -4687,7 +4682,7 @@
 	}
 }
 
-void VymModel::selectInt (TreeItem *ti)	
+bool VymModel::selectInt (TreeItem *ti)	
 {
 	if (selection.select(lmo))
 	{
@@ -4696,264 +4691,58 @@
 }
 */
 
-void VymModel::selectNextBranchInt()
-{
-	BranchItem *bi=getSelectedBranchItem();
-	if (bi)
-	{
-		TreeItem *pi=bi->parent();
-		if (bi!=rootItem)
-		{
-			int i=bi->num();
-			if (i<pi->branchCount() )
-			{
-				// select previous branch with same parent
-				i++;
-				select (pi->getBranchNum(i));
-				return;
-			}
-		}
-		
-	}
-}
-
-void VymModel::selectPrevBranchInt()
-{
-
-	BranchItem *bi=getSelectedBranchItem();
-	if (bi)
-	{
-		BranchItem *pi=(BranchItem*)bi->parent();
-		if (bi!=rootItem)
-		{
-			int i=bi->num();
-			if (i>0)
-			{
-				// select previous branch with same parent
-				bi=pi->getBranchNum(i-1);
-				select (bi);
-				return;
-			}
-			bi=pi;
-			while (bi->branchCount() >0)
-				bi=bi->getLastBranch();
-			select (bi);	
-
-			// Try to select last branch in parent pi2 previous to own parent pi
-			/*
-			TreeItem *pi2=pi->parent();
-			if (pi2)
-			{
-				int j=pi->num();
-				if (pi2->)
-			}
-			*/
-		}
-	}
-}
-
-void VymModel::selectAboveBranchInt()
-{
-	BranchItem *bi=getSelectedBranchItem();
-	if (bi)
-	{
-		BranchItem *newbi=NULL;
-		BranchItem *pi=(BranchItem*)bi->parent();
-		int i=bi->num();
-		if (i>0)
-		{
-			// goto previous branch with same parent
-			newbi=pi->getBranchNum(i-1);
-			while (newbi->branchCount() >0 )
-				newbi=newbi->getLastBranch();
-		}
-		else
-			newbi=pi;
-		if (newbi==rootItem) 
- 			// already at top branch (resp. mapcenter)
-			return;
-		select (newbi);
-	}
-}
-
-void VymModel::selectBelowBranchInt()
-{
-	BranchItem *bi=getSelectedBranchItem();
-	if (bi)
-	{
-		BranchItem *newbi=NULL;
-
-		if (bi->branchCount() >0)
-			newbi=bi->getFirstBranch();
-		else
-		{
-			BranchItem *pi;
-			int i;
-			while (!newbi)
-			{
-				pi=(BranchItem*)bi->parent();
-				i=bi->num();
-				if (pi->branchCount()-1 > i)
-				{
-					newbi=(BranchItem*)pi->getBranchNum(i+1);
-					//done...
-					break;
-				}	
-				else
-					// look for siblings of myself 
-					// or parent, or parent of parent...
-					bi=pi;
-				if (bi==rootItem)
-					// already at end
-					return;
-			}	
-		}
-		select (newbi);
-	}
-}
-
-void VymModel::selectUpperBranch()
-{
-	BranchItem *bi=getSelectedBranchItem();
-	if (bi && bi->isBranchLikeType())
-		selectAboveBranchInt();
-}
-
-void VymModel::selectLowerBranch()
-{
-	BranchItem *bi=getSelectedBranchItem();
-	if (bi && bi->isBranchLikeType())
-		selectBelowBranchInt();
-}
-
-
-void VymModel::selectLeftBranch()
-{
-	QItemSelection oldsel=selModel->selection();
-
-	BranchItem* par;
-	BranchItem *selbi=getSelectedBranchItem();
-	TreeItem::Type type=selbi->getType();
-	if (selbi)
-	{
-		if (type == TreeItem::MapCenter)
-		{
-			QModelIndex ix=index(selbi);
-			selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect  );
-		} else
-		{
-			par=(BranchItem*)selbi->parent();
-			if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	//FIXME-3 check getBO...
-			{
-				// right of center
-				if (type == TreeItem::Branch ||
-					type == TreeItem::Image)
-				{
-					QModelIndex ix=index (selbi->parent());
-					selModel->select (ix,QItemSelectionModel::ClearAndSelect  );
-				}
-			} else
-			{
-				// left of center
-				if (type == TreeItem::Branch )
-				{
-					selectLastSelectedBranch();
-					return;
-				}
-			}
-		}	
-	}
-}
-
-void VymModel::selectRightBranch()
-{
-	QItemSelection oldsel=selModel->selection();
-
-	BranchItem* par;
-	BranchItem *selbi=getSelectedBranchItem();
-	TreeItem::Type type=selbi->getType();
-	if (selbi)
-	{
-		if (type==TreeItem::MapCenter)
-		{
-			QModelIndex ix=index(selbi);
-			selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect  );
-		} else
-		{
-			par=(BranchItem*)selbi->parent();
-			if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	//FIXME-3 check getBO
-			{
-				// right of center
-				if ( type== TreeItem::Branch )
-				{
-					selectLastSelectedBranch();
-					return;
-				}
-			} else
-			{
-				// left of center
-				if (type == TreeItem::Branch ||
-					type == TreeItem::Image)
-				{
-					QModelIndex ix=index(selbi->parent());
-					selModel->select (ix,QItemSelectionModel::ClearAndSelect  );
-				}
-			}
-		}	
-	}
-}
-
-void VymModel::selectFirstBranch()
-{
-	TreeItem *ti=getSelectedBranchItem();
+bool VymModel::selectFirstBranch()
+{
+	TreeItem *ti=getSelectedBranch();
 	if (ti)
 	{
 		TreeItem *par=ti->parent();
-		if (!par) return;
-		TreeItem *ti2=par->getFirstBranch();
-		if (ti2) {
-			select(ti2);
-			emitSelectionChanged();
+		if (par) 
+		{
+			TreeItem *ti2=par->getFirstBranch();
+			if (ti2) return  select(ti2);
 		}
 	}		
+	return false;
 }
 
-void VymModel::selectLastBranch()
-{
-	TreeItem *ti=getSelectedBranchItem();
+bool VymModel::selectLastBranch()
+{
+	TreeItem *ti=getSelectedBranch();
 	if (ti)
 	{
 		TreeItem *par=ti->parent();
-		if (!par) return;
-		TreeItem *ti2=par->getLastBranch();
-		if (ti2) {
-			select(ti2);
-			emitSelectionChanged();
+		if (par) 
+		{
+			TreeItem *ti2=par->getLastBranch();
+			if (ti2) return select(ti2);
 		}
 	}		
+	return false;
 }
 
-void VymModel::selectLastSelectedBranch()
-{
-	TreeItem *ti=getSelectedBranchItem();
-	if (ti)
+bool VymModel::selectLastSelectedBranch()
+{
+	BranchItem *bi=getSelectedBranch();
+	if (bi)
 	{
-		ti=ti->getLastSelectedBranch();
-		if (ti) select (ti);
+		bi=bi->getLastSelectedBranch();
+		if (bi) return select (bi);
 	}		
+	return false;
 }
 
-void VymModel::selectParent()
+bool VymModel::selectParent()
 {
 	TreeItem *ti=getSelectedItem();
 	TreeItem *par;
 	if (ti)
 	{
 		par=ti->parent();
-		if (!par) return;
-		select(par);
-		emitSelectionChanged();
+		if (par) 
+			return select(par);
 	}		
+	return false;
 }
 
 TreeItem::Type VymModel::selectionType()
@@ -4980,14 +4769,14 @@
 
 BranchObj* VymModel::getSelectedBranchObj()	// FIXME-3 this should not be needed in the end!!!
 {
-	TreeItem *ti = getSelectedBranchItem();
+	TreeItem *ti = getSelectedBranch();
 	if (ti)
 		return (BranchObj*)(  ((MapItem*)ti)->getLMO());
 	else	
 		return NULL;
 }
 
-BranchItem* VymModel::getSelectedBranchItem()
+BranchItem* VymModel::getSelectedBranch()
 {
 	QModelIndexList list=selModel->selectedIndexes();
 	if (!list.isEmpty() )
@@ -5000,25 +4789,7 @@
 	return NULL;
 }
 
-TreeItem* VymModel::getSelectedItem()	
-{
-	QModelIndexList list=selModel->selectedIndexes();
-	if (!list.isEmpty() )
-		return getItem (list.first() );
-	else	
-		return NULL;
-}
-
-QModelIndex VymModel::getSelectedIndex()
-{
-	QModelIndexList list=selModel->selectedIndexes();
-	if (list.isEmpty() )
-		return QModelIndex();
-	else
-		return list.first();
-}
-
-ImageItem* VymModel::getSelectedImageItem()
+ImageItem* VymModel::getSelectedImage()
 {
 	QModelIndexList list=selModel->selectedIndexes();
 	if (!list.isEmpty())
@@ -5030,6 +4801,37 @@
 	return NULL;
 }
 
+AttributeItem* VymModel::getSelectedAttribute()	
+{
+	QModelIndexList list=selModel->selectedIndexes();
+	if (!list.isEmpty() )
+	{
+		TreeItem *ti = getItem (list.first() );
+		TreeItem::Type type=ti->getType();
+		if (type ==TreeItem::Attribute)
+			return (AttributeItem*)ti;
+	} 
+	return NULL;
+}
+
+TreeItem* VymModel::getSelectedItem()	
+{
+	QModelIndexList list=selModel->selectedIndexes();
+	if (!list.isEmpty() )
+		return getItem (list.first() );
+	else	
+		return NULL;
+}
+
+QModelIndex VymModel::getSelectedIndex()
+{
+	QModelIndexList list=selModel->selectedIndexes();
+	if (list.isEmpty() )
+		return QModelIndex();
+	else
+		return list.first();
+}
+
 QString VymModel::getSelectString ()
 {
 	return getSelectString (getSelectedItem());
@@ -5050,6 +4852,7 @@
 		case TreeItem::MapCenter: s="mc:"; break;
 		case TreeItem::Branch: s="bo:";break;
 		case TreeItem::Image: s="fi:";break;
+		case TreeItem::Attribute: s="ai:";break;
 		default:break;
 	}
 	s=  s + QString("%1").arg(ti->num());
diff -r 6269016c9905 -r c6bb4fdcc55f vymmodel.h
--- a/vymmodel.h	Thu Aug 06 10:42:17 2009 +0000
+++ b/vymmodel.h	Sat Aug 08 21:58:26 2009 +0000
@@ -565,37 +565,29 @@
 	bool select (TreeItem *ti );			//! Select by pointer to TreeItem
 	bool select (const QModelIndex &index);	//! Select by ModelIndex
 	void unselect();
-	void reselect();
+	bool reselect();
 
 	void emitShowSelection();				//!< Show selection in all views
 signals:
 	void showSelection();
 
-//	void selectInt(LinkableMapObj*);	//FIXME-4
+//	bool selectInt(LinkableMapObj*);	//FIXME-4
 
-private:	
-	void selectNextBranchInt();		// Increment number of branch
-	void selectPrevBranchInt();		//! Select the branch which would be above in vymmap view
-	void selectAboveBranchInt();	//! Select the branch which would be above current selection in TreeView
-	void selectBelowBranchInt();		// Increment number of branch
 public:	
-    void selectUpperBranch();
-    void selectLowerBranch();
-    void selectLeftBranch();
-    void selectRightBranch();
-    void selectFirstBranch();
-    void selectLastBranch();
-	void selectLastSelectedBranch();
-	void selectParent();
+    bool selectFirstBranch();
+    bool selectLastBranch();
+	bool selectLastSelectedBranch();
+	bool selectParent();
 
 public:
 	TreeItem::Type selectionType();
 	LinkableMapObj* getSelectedLMO();
 	BranchObj* getSelectedBranchObj();	// FIXME-3 replace by item...
-	BranchItem* getSelectedBranchItem();
+	BranchItem* getSelectedBranch();
+	ImageItem* getSelectedImage();
+	AttributeItem* getSelectedAttribute();
 	TreeItem* getSelectedItem();
 	QModelIndex getSelectedIndex();
-	ImageItem* getSelectedImageItem();
 	QString getSelectString ();
 	QString getSelectString (LinkableMapObj *lmo);
 	QString getSelectString (TreeItem *item);
diff -r 6269016c9905 -r c6bb4fdcc55f xml-freemind.cpp
--- a/xml-freemind.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/xml-freemind.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -90,7 +90,7 @@
 			if (atts.value ("POSITION")=="left")
 			{
 				model->select ("bo:1");
-				lastBranchItem=model->getSelectedBranchItem();
+				lastBranchItem=model->getSelectedBranch();
 				if (lastBranchItem)
 				{	
 					lastBranchItem=model->createBranch(lastBranchItem);
@@ -99,7 +99,7 @@
 			} else if (atts.value ("POSITION")=="right")
 			{
 				model->select ("bo:0");
-				lastBranchItem=model->getSelectedBranchItem();
+				lastBranchItem=model->getSelectedBranch();
 				if (lastBranchItem)
 				{	
 					lastBranchItem=model->createBranch(lastBranchItem);
diff -r 6269016c9905 -r c6bb4fdcc55f xml-vym.cpp
--- a/xml-vym.cpp	Thu Aug 06 10:42:17 2009 +0000
+++ b/xml-vym.cpp	Sat Aug 08 21:58:26 2009 +0000
@@ -145,7 +145,7 @@
 		{
 			// Treat the found mapcenter as a branch 
 			// in an existing map
-			BranchItem *bi=model->getSelectedBranchItem();	//FIXME-3 selection is no longer used here...
+			BranchItem *bi=model->getSelectedBranch();	//FIXME-3 selection is no longer used here...
 			if (bi)
 			{
 				lastBranch=bi;
@@ -271,7 +271,7 @@
 		<<">  state=" <<state 
 	//	<<"  laststate=" <<laststate
 	//	<<"  stateStack="<<stateStack.last() 
-		<<"  selString="<<model->getSelectString().toStdString()
+	//	<<"  selString="<<model->getSelectString().toStdString()
 		<<endl;
 	*/
     switch ( state ) 
@@ -282,7 +282,7 @@
         case StateMapCenter: 
 			model->emitDataHasChanged (lastBranch);
 			lastBranch=(BranchItem*)(lastBranch->parent());
-			lastBranch->setLastSelectedBranch (0);	// Reset last selected to first child branch
+		//	lastBranch->setLastSelectedBranch (0);	// Reset last selected to first child branch
             break;
         case StateBranch: 
 			// Empty branches may not be scrolled