undo/redo for delete BranchObj. Added calling commands in testmenu
authorinsilmaril
Wed, 18 Oct 2006 10:45:00 +0000
changeset 393053b8645e3e9
parent 392 18f824bd3070
child 394 67cfa6e6b863
undo/redo for delete BranchObj. Added calling commands in testmenu
branchobj.cpp
demos/todo.vym
exports.cpp
file.h
historywindow.cpp
imports.cpp
linkablemapobj.cpp
mainwindow.cpp
mainwindow.h
mapeditor.cpp
mapeditor.h
texteditor.cpp
version.h
     1.1 --- a/branchobj.cpp	Mon Oct 16 12:42:54 2006 +0000
     1.2 +++ b/branchobj.cpp	Wed Oct 18 10:45:00 2006 +0000
     1.3 @@ -1242,6 +1242,7 @@
     1.4  	int th = bboxTotal.height();	
     1.5  // TODO testing
     1.6  /*
     1.7 +*/
     1.8  	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
     1.9  	cout << "  d="<<depth<<
    1.10  		"  ref="<<ref<<
    1.11 @@ -1253,7 +1254,6 @@
    1.12  //		"  hidden="<<hidden<<
    1.13  //		"  th="<<th<<
    1.14  		endl;
    1.15 -*/
    1.16  
    1.17  	setOrientation();
    1.18  	//updateLink();
     2.1 Binary file demos/todo.vym has changed
     3.1 --- a/exports.cpp	Mon Oct 16 12:42:54 2006 +0000
     3.2 +++ b/exports.cpp	Wed Oct 18 10:45:00 2006 +0000
     3.3 @@ -1,7 +1,7 @@
     3.4 -#include <q3filedialog.h>
     3.5 -#include <QMessageBox>
     3.6 -#include <QProcess>
     3.7 -#include <QTextStream>
     3.8 +//#include <q3filedialog.h>
     3.9 +//#include <QMessageBox>
    3.10 +//#include <QProcess>
    3.11 +//#include <QTextStream>
    3.12  
    3.13  #include "exports.h"
    3.14  #include "file.h"
    3.15 @@ -19,7 +19,7 @@
    3.16  {
    3.17  	indentPerDepth="  ";
    3.18  	bool ok;
    3.19 -    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-XXXXXX"));
    3.20 +    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-export-XXXXXX"));
    3.21  	if (!tmpDir.exists() || !ok)
    3.22  		QMessageBox::critical( 0, QObject::tr( "Error" ),
    3.23  					   QObject::tr("Couldn't access temporary directory\n"));
     4.1 --- a/file.h	Mon Oct 16 12:42:54 2006 +0000
     4.2 +++ b/file.h	Wed Oct 18 10:45:00 2006 +0000
     4.3 @@ -1,7 +1,7 @@
     4.4  #ifndef FILE_H
     4.5  #define FILE_H
     4.6  
     4.7 -#include <qdir.h>
     4.8 +#include <QDir>
     4.9  
    4.10  enum LoadMode {NewMap,ImportAdd,ImportReplace};
    4.11  enum SaveMode {PartOfMap,CompleteMap,UndoCommand};
    4.12 @@ -20,9 +20,9 @@
    4.13  bool saveStringToDisk (const QString &, const QString &s);
    4.14  
    4.15  /////////////////////////////////////////////////////////////////////////////
    4.16 -#include <qlabel.h>
    4.17 +#include <QLabel>
    4.18  #include <q3filedialog.h>
    4.19 -#include <qpixmap.h>
    4.20 +#include <QPixmap>
    4.21  
    4.22  class ImagePreview : public QLabel, public Q3FilePreview
    4.23  {
     5.1 --- a/historywindow.cpp	Mon Oct 16 12:42:54 2006 +0000
     5.2 +++ b/historywindow.cpp	Wed Oct 18 10:45:00 2006 +0000
     5.3 @@ -1,6 +1,8 @@
     5.4  #include "historywindow.h"
     5.5  #include "mapeditor.h"
     5.6  
     5.7 +extern QString iconPath;
     5.8 +
     5.9  HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
    5.10  {
    5.11  	ui.setupUi (this);
    5.12 @@ -21,6 +23,9 @@
    5.13  
    5.14  	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
    5.15  
    5.16 +	ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
    5.17 +	ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
    5.18 +
    5.19  	connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
    5.20  	connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
    5.21  	connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
     6.1 --- a/imports.cpp	Mon Oct 16 12:42:54 2006 +0000
     6.2 +++ b/imports.cpp	Wed Oct 18 10:45:00 2006 +0000
     6.3 @@ -1,7 +1,3 @@
     6.4 -#include <QMessageBox>
     6.5 -//Added by qt3to4:
     6.6 -#include <QTextStream>
     6.7 -
     6.8  #include "file.h"
     6.9  #include "imports.h"
    6.10  #include "linkablemapobj.h"
    6.11 @@ -15,7 +11,7 @@
    6.12  ImportBase::ImportBase()
    6.13  {
    6.14  	bool ok;
    6.15 -    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-XXXXXX"));
    6.16 +    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-import-XXXXXX"));
    6.17  	if (!tmpDir.exists() || !ok)
    6.18  		QMessageBox::critical( 0, QObject::tr( "Error" ),
    6.19  					   QObject::tr("Couldn't access temporary directory\n"));
    6.20 @@ -82,8 +78,7 @@
    6.21  			lines += stream.readLine(); // line of text excluding '\n'
    6.22  		file.close();
    6.23  	}
    6.24 -	// FIXME
    6.25 -	// Generate vym from broken bookmarks above...
    6.26 +	// TODO Generate vym from broken bookmarks above...
    6.27  
    6.28  	return true;
    6.29  }
     7.1 --- a/linkablemapobj.cpp	Mon Oct 16 12:42:54 2006 +0000
     7.2 +++ b/linkablemapobj.cpp	Wed Oct 18 10:45:00 2006 +0000
     7.3 @@ -538,21 +538,7 @@
     7.4  
     7.5  
     7.6  	setDockPos(); // Call overloaded method
     7.7 -/* FIXME not needed?
     7.8 -	LinkOrient orientOld=orientation;
     7.9 -	if ((orientation!=orientOld) && (orientOld!= OrientUndef))
    7.10 -	{
    7.11 -		// Orientation just changed. Reorient this subbranch, because move is called
    7.12 -		// before updateLink => Position is still the old one, which could lead to 
    7.13 -		// linking of subranch to itself => segfault
    7.14 -		//
    7.15 -		// Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
    7.16 -		// no need to reposition now
    7.17 -		cout <<"Trying to reorientate...   orient="<<orientation<<endl;
    7.18 -		reposition();
    7.19 -	}
    7.20 -	
    7.21 -*/
    7.22 +	setOrientation();
    7.23  
    7.24  	double p1x=parPos.x();	// Link is drawn from P1 to P2
    7.25  	double p1y=parPos.y();
     8.1 --- a/mainwindow.cpp	Mon Oct 16 12:42:54 2006 +0000
     8.2 +++ b/mainwindow.cpp	Wed Oct 18 10:45:00 2006 +0000
     8.3 @@ -161,7 +161,7 @@
     8.4  
     8.5  	// Connect TextEditor, so that we can update flags if text changes
     8.6  	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
     8.7 -	connect (textEditor, SIGNAL (textClosed() ), this, SLOT (updateActions()));
     8.8 +	connect (textEditor, SIGNAL (textEditorClosed() ), this, SLOT (updateActions()));
     8.9  
    8.10  	updateGeometry();
    8.11  }
    8.12 @@ -681,8 +681,6 @@
    8.13      connect( a, SIGNAL( triggered() ), this, SLOT( editMapInfo() ) );
    8.14  	actionEditMapInfo=a;
    8.15  
    8.16 -	editMenu->addSeparator();
    8.17 -
    8.18  	// Import at selection (adding to selection)
    8.19      a = new QAction( tr( "Add map (insert)" ),this);
    8.20  	a->setStatusTip (tr( "Add map at selection" ));
    8.21 @@ -1393,10 +1391,16 @@
    8.22      QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
    8.23  
    8.24      QAction *a;
    8.25 -    a = new QAction( tr( "test flag" ), this);
    8.26 +    a = new QAction( tr( "Test function" ), this);
    8.27      a->setStatusTip( tr( "Call test function" ));
    8.28 +	a->setShortcut (Qt::Key_F4 );
    8.29      connect( a, SIGNAL( triggered() ), this, SLOT( testFunction() ) );
    8.30  	testMenu->addAction (a);
    8.31 +    a = new QAction( tr( "Command" ), this);
    8.32 +    a->setStatusTip( tr( "Enter command to call in editor" ));
    8.33 +	a->setShortcut (Qt::Key_F5 );
    8.34 +    connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
    8.35 +	testMenu->addAction (a);
    8.36  }
    8.37  
    8.38  // Help Actions
    8.39 @@ -3090,7 +3094,7 @@
    8.40  	if (!me) return;
    8.41  
    8.42  	// updateActions is also called when NoteEditor is closed
    8.43 -	actionViewToggleNoteEditor->setOn (textEditor->isVisible());
    8.44 +	actionViewToggleNoteEditor->setOn (textEditor->showWithMain());
    8.45  
    8.46  	QAction *a;
    8.47  	if (me->getLinkColorHint()==HeadingColor) 
    8.48 @@ -3333,9 +3337,19 @@
    8.49  
    8.50  void Main::testFunction()
    8.51  {
    8.52 +	if (!currentMapEditor()) return;
    8.53  	currentMapEditor()->testFunction();
    8.54  }
    8.55  
    8.56 +void Main::testCommand()
    8.57 +{
    8.58 +	if (!currentMapEditor()) return;
    8.59 +	bool ok;
    8.60 +	QString com = QInputDialog::getText(
    8.61 +			__VYM, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
    8.62 +	if (ok) currentMapEditor()->parseAtom(com);
    8.63 +}
    8.64 +
    8.65  void Main::helpDoc()
    8.66  {
    8.67  	QString docpath;
     9.1 --- a/mainwindow.h	Mon Oct 16 12:42:54 2006 +0000
     9.2 +++ b/mainwindow.h	Wed Oct 18 10:45:00 2006 +0000
     9.3 @@ -173,6 +173,7 @@
     9.4  	void standardFlagChanged();
     9.5  
     9.6      void testFunction();
     9.7 +    void testCommand();
     9.8  
     9.9      void helpDoc();
    9.10      void helpAbout();
    10.1 --- a/mapeditor.cpp	Mon Oct 16 12:42:54 2006 +0000
    10.2 +++ b/mapeditor.cpp	Wed Oct 18 10:45:00 2006 +0000
    10.3 @@ -372,7 +372,7 @@
    10.4  		mapCenter);
    10.5  }
    10.6  
    10.7 -void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
    10.8 +void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, const QString &comment)
    10.9  {
   10.10  	// save the selected part of the map, Undo will replace part of map 
   10.11  	QString undoSelection="";
   10.12 @@ -385,6 +385,25 @@
   10.13  		undoSel);
   10.14  }
   10.15  
   10.16 +void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
   10.17 +{
   10.18 +	if (!redoSel  ||typeid(*redoSel) != typeid(BranchObj) ) 
   10.19 +	{
   10.20 +		qWarning ("MapEditor::saveStateRemovingPart  no undoSel given!");
   10.21 +		return;
   10.22 +	}
   10.23 +
   10.24 +	// save the selected part of the map, Undo will insert part of map 
   10.25 +	QString undoSelection=redoSel->getParObj()->getSelectString();
   10.26 +	QString redoSelection=redoSel->getSelectString();
   10.27 +
   10.28 +	saveState (PartOfMap,
   10.29 +		undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
   10.30 +		redoSelection, "delete ()", 
   10.31 +		comment, 
   10.32 +		redoSel);
   10.33 +}
   10.34 +
   10.35  void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
   10.36  {
   10.37  	// selection does not change during action,
   10.38 @@ -401,22 +420,6 @@
   10.39  		NULL);
   10.40  }
   10.41  
   10.42 -/* FIXME not used
   10.43 -void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) 
   10.44 -{
   10.45 -	QString redoSelection="";
   10.46 -	if (redoSel) redoSelection=redoSel->getSelectString();
   10.47 -	QString undoSelection="";
   10.48 -	if (undoSel) undoSelection=undoSel->getSelectString();
   10.49 -
   10.50 -	saveState (UndoCommand,
   10.51 -		undoSelection, uc,
   10.52 -		redoSelection, "FIXME-redoCom",	//FIXME
   10.53 -		comment, 
   10.54 -		saveSel);
   10.55 -}
   10.56 -*/
   10.57 -
   10.58  void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) 
   10.59  {
   10.60  	// "Normal" savestate: save commands, selections and comment
   10.61 @@ -491,7 +494,8 @@
   10.62  	}	
   10.63  	else if (savemode==PartOfMap )
   10.64  	{
   10.65 -		undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
   10.66 +		undoCommand=undoCom;
   10.67 +		undoCommand.replace ("PATH",bakMapPath);
   10.68  	} else
   10.69  	{
   10.70  		undoCommand="undoMap (\""+bakMapPath+"\")";
   10.71 @@ -501,7 +505,7 @@
   10.72  		saveStringToDisk (QString(bakMapPath),backupXML);
   10.73  
   10.74  	// We would have to save all actions in a tree, to keep track of 
   10.75 -	// possible redos after a action. Too complex, forget about redos.
   10.76 +	// possible redos after a action. Possible, but we are too lazy: forget about redos.
   10.77  	redosAvail=0;
   10.78  
   10.79  	// Write the current state to disk
   10.80 @@ -545,51 +549,38 @@
   10.81  	QString com=api.command();
   10.82  	
   10.83  	// External commands
   10.84 -	if (com=="moveBranchUp")
   10.85 -		moveBranchUp();
   10.86 -	else if (com=="moveBranchDown")
   10.87 -		moveBranchDown();
   10.88 -	else if (com=="move")
   10.89 -	{
   10.90 -		if (api.checkParamCount(2) && selection )
   10.91 -		{	
   10.92 -			x=api.parInt (ok,0);
   10.93 -			if (ok)
   10.94 -			{
   10.95 -				y=api.parInt (ok,1);
   10.96 -				if (ok) move (x,y);
   10.97 -			}
   10.98 -		}	
   10.99 -	}
  10.100 -	else if (com=="moveRel")
  10.101 -	{
  10.102 -		if (api.checkParamCount(2) && selection )
  10.103 -		{	
  10.104 -			x=api.parInt (ok,0);
  10.105 -			if (ok)
  10.106 -			{
  10.107 -				y=api.parInt (ok,1);
  10.108 -				if (ok) moveRel (x,y);
  10.109 -			}
  10.110 -		}	
  10.111 -	}
  10.112 -	else if (com=="delete")
  10.113 -	{
  10.114 -		if (api.checkParamCount(1) && selection )
  10.115 -		{	
  10.116 -			s=api.parString(ok,0);
  10.117 -			if (ok &&select (s)) deleteSelection();
  10.118 -		}	
  10.119 -	}	
  10.120 -	else if (com=="addBranch")
  10.121 +	if (com=="addBranch")
  10.122  	{
  10.123  		if (api.checkParamCount(1) && selection )
  10.124  		{	
  10.125  			y=api.parInt (ok,0);
  10.126  			if (ok ) addNewBranchInt (y);
  10.127  		}	
  10.128 -	}	
  10.129 -	else if (com=="linkBranchToPos")
  10.130 +	} else if (com==QString("addMapReplace"))
  10.131 +	{
  10.132 +		if (api.checkParamCount(2))
  10.133 +		{
  10.134 +			s=api.parString (ok,0);	// selection
  10.135 +			t=api.parString (ok,1);	// path to map
  10.136 +			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
  10.137 +			addMapReplace(s,t);	
  10.138 +		}
  10.139 +	} else if (com==QString("addMapInsert"))
  10.140 +	{
  10.141 +		if (api.checkParamCount(2))
  10.142 +		{
  10.143 +			t=api.parString (ok,0);	// path to map
  10.144 +			y=api.parInt(ok,1);		// position
  10.145 +			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
  10.146 +			addMapInsert(t,y);	
  10.147 +		}
  10.148 +	} else if (com=="delete")
  10.149 +	{
  10.150 +		if (api.checkParamCount(0) && selection )
  10.151 +		{	
  10.152 +			deleteSelection();
  10.153 +		}	
  10.154 +	} else if (com=="linkBranchToPos")
  10.155  	{
  10.156  		if (selection && typeid(*selection) == typeid(BranchObj) ) 
  10.157  		{
  10.158 @@ -622,6 +613,33 @@
  10.159  				}	
  10.160  			}
  10.161  		}
  10.162 +	} else if (com=="moveBranchUp")
  10.163 +		moveBranchUp();
  10.164 +	else if (com=="moveBranchDown")
  10.165 +		moveBranchDown();
  10.166 +	else if (com=="move")
  10.167 +	{
  10.168 +		if (api.checkParamCount(2) && selection )
  10.169 +		{	
  10.170 +			x=api.parInt (ok,0);
  10.171 +			if (ok)
  10.172 +			{
  10.173 +				y=api.parInt (ok,1);
  10.174 +				if (ok) move (x,y);
  10.175 +			}
  10.176 +		}	
  10.177 +	}
  10.178 +	else if (com=="moveRel")
  10.179 +	{
  10.180 +		if (api.checkParamCount(2) && selection )
  10.181 +		{	
  10.182 +			x=api.parInt (ok,0);
  10.183 +			if (ok)
  10.184 +			{
  10.185 +				y=api.parInt (ok,1);
  10.186 +				if (ok) moveRel (x,y);
  10.187 +			}
  10.188 +		}	
  10.189  	} else if (com=="setHeading")
  10.190  	{
  10.191  		if (api.checkParamCount(1))
  10.192 @@ -676,22 +694,11 @@
  10.193  				}	
  10.194  			}	
  10.195  		}
  10.196 -	}	
  10.197 -	// Internal commands, used for undo etc.	
  10.198 -	else if (com==QString("undoMap"))
  10.199 +	// Internal commands
  10.200 +	} else if (com==QString("undoMap"))
  10.201  	{
  10.202  		if (api.checkParamCount(1))
  10.203 -			undoXML("",api.parString (ok,0));
  10.204 -	} else if (com==QString("undoPart"))
  10.205 -	{
  10.206 -		if (api.checkParamCount(2))
  10.207 -		{
  10.208 -			s=api.parString (ok,0);	// undo selection
  10.209 -			t=api.parString (ok,1);	// backup dir
  10.210 -			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
  10.211 -			cout <<t.ascii()<<endl;
  10.212 -			undoXML(s,t);	
  10.213 -		}
  10.214 +			addMapReplace("",api.parString (ok,0));
  10.215  	} else if (com=="select")
  10.216  	{
  10.217  		if (api.checkParamCount(1))
  10.218 @@ -824,7 +831,7 @@
  10.219  		// (map state is set later at end of load...)
  10.220  	} else
  10.221  	{
  10.222 -		saveStatePart(selection,"Load map");
  10.223 +		saveStateChangingPart(selection,"Load map");
  10.224  	}	
  10.225  	
  10.226      
  10.227 @@ -1279,7 +1286,7 @@
  10.228  
  10.229  bool MapEditor::isRedoAvailable()
  10.230  {
  10.231 -	if (undoSet.readNumEntry("/history/undosAvail",0)>0)
  10.232 +	if (undoSet.readNumEntry("/history/redosAvail",0)>0)
  10.233  		return true;
  10.234  	else	
  10.235  		return false;
  10.236 @@ -1381,11 +1388,11 @@
  10.237  	// And ignore clicking the current row ;-)	
  10.238  }
  10.239  
  10.240 -void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
  10.241 +void MapEditor::addMapReplace(const QString &undoSel, const QString &path)
  10.242  {
  10.243 -	QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
  10.244 -	QDir d(bakMapDir);
  10.245 -	QFile file (bakMapPath);
  10.246 +	QString pathDir=path.left(path.findRev("/"));
  10.247 +	QDir d(pathDir);
  10.248 +	QFile file (path);
  10.249  
  10.250  	if (d.exists() )
  10.251  	{
  10.252 @@ -1396,7 +1403,7 @@
  10.253  		reader.setContentHandler( &handler );
  10.254  		reader.setErrorHandler( &handler );
  10.255  		handler.setMapEditor( this );
  10.256 -		handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
  10.257 +		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  10.258  		if (undoSel.isEmpty())
  10.259  		{
  10.260  			unselect();
  10.261 @@ -1413,18 +1420,59 @@
  10.262  		if (! ok ) 
  10.263  		{	
  10.264  			// This should never ever happen
  10.265 -			QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
  10.266 -								   tr( handler.errorProtocol() )+" in "+bakMapDir );
  10.267 +			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  10.268 +								    handler.errorProtocol());
  10.269  		}
  10.270  	} else	
  10.271 +		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  10.272 +}
  10.273 +
  10.274 +void MapEditor::addMapInsert(const QString &path, int pos)
  10.275 +{
  10.276 +	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  10.277 +				      typeid(*selection) == typeid(MapCenterObj))) 
  10.278  	{
  10.279 -		QMessageBox::critical( 0, tr( "Critical Error" ),
  10.280 -			tr("Temporary directory %1 used for undo is gone. \n"
  10.281 -			"I will create a new one, but at the moment no undo is available.\n"
  10.282 -			"Maybe you want to reload your original data.\n\n"
  10.283 -			"Sorry for any inconveniences.").arg(bakMapDir) );
  10.284 -		makeTmpDirs();	
  10.285 -	}							
  10.286 +		QString pathDir=path.left(path.findRev("/"));
  10.287 +		QDir d(pathDir);
  10.288 +		QFile file (path);
  10.289 +
  10.290 +		BranchObj *bo=addNewBranchInt (pos);
  10.291 +		if (!bo)
  10.292 +		{
  10.293 +			
  10.294 +			QMessageBox::critical( 0, tr( "Critical Error" ), 
  10.295 +				tr("Could insert branch at position %1\n in branch %2").arg(pos)
  10.296 +				.arg(((BranchObj*)selection)->getHeading()));
  10.297 +			return;	
  10.298 +		}
  10.299 +		unselect();
  10.300 +		selection=bo;
  10.301 +		selection->select();
  10.302 +
  10.303 +		
  10.304 +		if (d.exists() )
  10.305 +		{
  10.306 +			// We need to parse saved XML data
  10.307 +			mapBuilderHandler handler;
  10.308 +			QXmlInputSource source( file);
  10.309 +			QXmlSimpleReader reader;
  10.310 +			reader.setContentHandler( &handler );
  10.311 +			reader.setErrorHandler( &handler );
  10.312 +			handler.setMapEditor( this );
  10.313 +			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  10.314 +			handler.setLoadMode (ImportReplace);
  10.315 +			blockReposition=true;
  10.316 +			bool ok = reader.parse( source );
  10.317 +			blockReposition=false;
  10.318 +			if (! ok ) 
  10.319 +			{	
  10.320 +				// This should never ever happen
  10.321 +				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  10.322 +										handler.errorProtocol());
  10.323 +			}
  10.324 +		} else	
  10.325 +			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  10.326 +	}		
  10.327  }
  10.328  
  10.329  void MapEditor::pasteNoSave()
  10.330 @@ -1443,7 +1491,7 @@
  10.331  	if (selection && (typeid(*selection) == typeid(BranchObj) ||
  10.332  				      typeid(*selection) == typeid(MapCenterObj))) 
  10.333  	{
  10.334 -		saveStatePart(selection,QString("Paste to %1").arg( getName(selection)));
  10.335 +		saveStateChangingPart(selection,QString("Paste to %1").arg( getName(selection)));
  10.336  		pasteNoSave();
  10.337  		mapCenter->reposition();
  10.338  		adjustCanvasSize();
  10.339 @@ -1452,7 +1500,7 @@
  10.340  
  10.341  void MapEditor::cut()
  10.342  {
  10.343 -	saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
  10.344 +	saveStateChangingPart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
  10.345  	copy();
  10.346  	cutNoSave();
  10.347  	mapCenter->reposition();
  10.348 @@ -1658,7 +1706,8 @@
  10.349  		if (newbo)
  10.350  		{
  10.351  			saveStateConstSelection (
  10.352 -				QString ("delete (\"%1\")").arg(newbo->getSelectString()),
  10.353 +				//QString ("delete (\"%1\")").arg(newbo->getSelectString()),
  10.354 +				"delete ()",
  10.355  				QString ("addBranch (%1)").arg(pos-2),
  10.356  				QString ("Add new branch to %1").arg(getName(bo)));	//TODO undoCommand
  10.357  
  10.358 @@ -1695,7 +1744,7 @@
  10.359  		 (typeid(*selection) == typeid(BranchObj) ) )
  10.360  	{
  10.361  		BranchObj* bo1 = (BranchObj*) selection;
  10.362 -		saveStatePart(selection, QString("Add new branch here").arg(getName(bo1)));
  10.363 +		saveStateChangingPart(selection, QString("Add new branch here").arg(getName(bo1)));
  10.364  
  10.365  		bool wasScrolled=false;
  10.366  		BranchObj *newbo=NULL;
  10.367 @@ -1739,12 +1788,10 @@
  10.368  		bo->unselect();
  10.369  		if (selection->getDepth()>1)
  10.370  			// Normal branch, save parent with childs
  10.371 -			saveStatePart(par,QString("Delete %1").arg(getName(bo)));
  10.372 -		//	naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
  10.373 +			saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
  10.374  		else
  10.375  			// Mainbranch, save whole map
  10.376 -			// TODO Better would be to insert mainbranch again at pos
  10.377 -			// But undoCommand is missing right now
  10.378 +			// TODO Better would be to insert mainbranch again at pos But undoCommand is missing right now
  10.379  			saveStateComplete(QString("Delete %1").arg(getName(bo)));
  10.380  		selection=NULL;
  10.381  		par->removeBranch(bo);
  10.382 @@ -1758,7 +1805,7 @@
  10.383  	{
  10.384  		FloatImageObj* fio=(FloatImageObj*)selection;
  10.385  		BranchObj* par=(BranchObj*)(fio->getParObj());
  10.386 -		saveStatePart(par, QString("Delete %1").arg(getName(fio)));
  10.387 +		saveStateChangingPart(par, QString("Delete %1").arg(getName(fio)));
  10.388  		fio->unselect();
  10.389  		selection=NULL;
  10.390  		par->removeFloatImage(fio);
  10.391 @@ -2226,7 +2273,7 @@
  10.392  			typeid(*selection) == typeid(MapCenterObj))
  10.393  		{
  10.394  			BranchObj *bo=(BranchObj*)selection;
  10.395 -			saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
  10.396 +			saveStateChangingPart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
  10.397  			bo->setColor(actColor); // color branch
  10.398  		}    
  10.399  	}
  10.400 @@ -2240,7 +2287,7 @@
  10.401  			typeid(*selection) == typeid(MapCenterObj))
  10.402  		{
  10.403  			BranchObj *bo=(BranchObj*)selection;
  10.404 -			saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
  10.405 +			saveStateChangingPart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name()));	//TODO undoCommand
  10.406  			bo->setColorChilds(actColor); // color links, color childs
  10.407  		}    
  10.408  	}
  10.409 @@ -2541,7 +2588,7 @@
  10.410  		if (bo->getDepth()==1)
  10.411  			saveStateComplete(s);
  10.412  		else	
  10.413 -			saveStatePart(selection->getParObj(),s);	// TODO undoCommand
  10.414 +			saveStateChangingPart(selection->getParObj(),s);	// TODO undoCommand
  10.415  		QString sel=selection->getSelectString();
  10.416  		unselect();
  10.417  		par->removeBranchHere(bo);
  10.418 @@ -2554,7 +2601,7 @@
  10.419  {
  10.420  	if (selection && (typeid(*selection) == typeid(BranchObj) ))
  10.421  	{		
  10.422 -		saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
  10.423 +		saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
  10.424  		((BranchObj*)selection)->removeChilds();
  10.425  		mapCenter->reposition();
  10.426  	}	
  10.427 @@ -2729,7 +2776,7 @@
  10.428  			s="Unscroll";
  10.429  		else	
  10.430  			s="Scroll";
  10.431 -		saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
  10.432 +		saveStateChangingPart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
  10.433  		bo->toggleScroll();
  10.434  		adjustCanvasSize();
  10.435  		canvas()->update();
  10.436 @@ -2769,7 +2816,7 @@
  10.437  		QString fn;
  10.438  		if ( fd->exec() == QDialog::Accepted )
  10.439  		{
  10.440 -			saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection)));
  10.441 +			saveStateChangingPart(selection, QString("Add floatimage to %1").arg(getName(selection)));
  10.442  			// FIXME in QT4 use:	lastImageDir=fd->directory();
  10.443  			lastImageDir=QDir (fd->dirPath());
  10.444  			QStringList flist = fd->selectedFiles();
  10.445 @@ -3728,7 +3775,7 @@
  10.446        (typeid(*selection) == typeid(MapCenterObj))  )
  10.447    {
  10.448      BranchObj *bo=((BranchObj*)selection);
  10.449 -    saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo)));
  10.450 +    saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
  10.451      //QString fn=fd->selectedFile();
  10.452      //lastImageDir=fn.left(fn.findRev ("/"));
  10.453      bo->addFloatImage();
    11.1 --- a/mapeditor.h	Mon Oct 16 12:42:54 2006 +0000
    11.2 +++ b/mapeditor.h	Wed Oct 18 10:45:00 2006 +0000
    11.3 @@ -32,13 +32,15 @@
    11.4  	void makeTmpDirs();		// create temporary directories
    11.5      QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    11.6      void saveStateComplete       (const QString &);					
    11.7 -    void saveStatePart           (LinkableMapObj *, const QString &);
    11.8 +    void saveStateChangingPart (LinkableMapObj *, const QString &);
    11.9 +    void saveStateRemovingPart (LinkableMapObj *, const QString &);
   11.10      void saveStateConstSelection (const QString &, const QString &, const QString &);
   11.11      void saveState(LinkableMapObj *, const QString &, LinkableMapObj *, const QString &, const QString &);
   11.12      void saveState(const QString &, const QString &, const QString &, const QString &, const QString &);
   11.13      void saveState(const SaveMode&, const QString &, const QString &, const QString &, const QString &, const QString &, LinkableMapObj *);
   11.14 +public:	
   11.15      void parseAtom(const QString &);	
   11.16 -
   11.17 +private:
   11.18      void addFloatImage(const QPixmap &img);
   11.19  
   11.20    private slots:
   11.21 @@ -82,18 +84,19 @@
   11.22      void undo();		// undo last action
   11.23  	bool isUndoAvailable();
   11.24  	void gotoStep (int);// goto a step in history
   11.25 +    void addMapReplace(const QString & undoSel, const QString & path);
   11.26 +    void addMapInsert (const QString & path, int pos);
   11.27  private:	
   11.28 -    void undoXML(const QString &, const QString &);
   11.29      void pasteNoSave();		// paste clipboard to branch
   11.30      void cutNoSave();	// cut to clipboard
   11.31  public:	
   11.32      void paste();		// paste clipboard to branch and backup
   11.33      void cut();			// cut to clipboard and backup
   11.34 -    void move    (const int &,const int&);
   11.35 -    void moveRel (const int &,const int&);
   11.36 +    void move    (const int &x, const int &y);
   11.37 +    void moveRel (const int &x, const int &y);
   11.38      void moveBranchUp();
   11.39      void moveBranchDown();
   11.40 -	QString getHeading (bool &,QPoint &);	// Get heading, ok if selection is branch
   11.41 +	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
   11.42  	void setHeading(const QString &);
   11.43  private:
   11.44  	void setHeadingInt(const QString &);
   11.45 @@ -230,7 +233,7 @@
   11.46  	bool printFooter;			// Print footer below map
   11.47  
   11.48  	bool zipped;				// should map be zipped
   11.49 -static	int mapNum;				// unique number for Editor
   11.50 +	static	int mapNum;			// unique number for Editor
   11.51  	QString fileName;			// short name of file (for tab)
   11.52  	QString filePath;			// path to file which will be saved
   11.53  	QString fileDir;			// dir where file is saved
    12.1 --- a/texteditor.cpp	Mon Oct 16 12:42:54 2006 +0000
    12.2 +++ b/texteditor.cpp	Wed Oct 18 10:45:00 2006 +0000
    12.3 @@ -496,9 +496,8 @@
    12.4  void TextEditor::closeEvent( QCloseEvent* ce )
    12.5  {
    12.6      ce->accept();	// TextEditor can be reopened with show()
    12.7 +    showwithmain=false;
    12.8  	emit (textEditorClosed() );
    12.9 -	cout << "TE closed\n";
   12.10 -    showwithmain=false;
   12.11      return;
   12.12  }
   12.13  
    13.1 --- a/version.h	Mon Oct 16 12:42:54 2006 +0000
    13.2 +++ b/version.h	Wed Oct 18 10:45:00 2006 +0000
    13.3 @@ -3,6 +3,6 @@
    13.4  
    13.5  #define __VYM "VYM"
    13.6  #define __VYM_VERSION "1.8.57"
    13.7 -#define __BUILD_DATE "October 13, 2006"
    13.8 +#define __BUILD_DATE "October 16, 2006"
    13.9  
   13.10  #endif