mapeditor.cpp
changeset 576 f342fa346580
parent 564 b8f0eefe4351
child 595 0bd62e09d061
     1.1 --- a/mapeditor.cpp	Mon Jul 23 12:42:02 2007 +0000
     1.2 +++ b/mapeditor.cpp	Mon Jul 30 09:47:15 2007 +0000
     1.3 @@ -19,8 +19,8 @@
     1.4  #include "misc.h"
     1.5  #include "texteditor.h"
     1.6  #include "warningdialog.h"
     1.7 -#include "xml.h"
     1.8 -#include "xml-fm.h"
     1.9 +#include "xml-freemind.h"
    1.10 +#include "xml-vym.h"
    1.11  
    1.12  
    1.13  extern TextEditor *textEditor;
    1.14 @@ -1485,10 +1485,20 @@
    1.15  	return destPath;
    1.16  }
    1.17  
    1.18 -ErrorCode MapEditor::load (QString fname, LoadMode lmode)
    1.19 +ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
    1.20  {
    1.21  	ErrorCode err=success;
    1.22  
    1.23 +	parseBaseHandler *handler;
    1.24 +	switch (ftype)
    1.25 +	{
    1.26 +		case VymMap: handler=new parseVYMHandler; break;
    1.27 +		case FreemindMap : handler=new parseFreemindHandler; break;
    1.28 +		default: 
    1.29 +			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
    1.30 +				   "Unknown FileType in MapEditor::load()");
    1.31 +		return aborted;	
    1.32 +	}
    1.33  	if (lmode==NewMap)
    1.34  	{
    1.35  		if (xelection.isEmpty() ) xelection.unselect();
    1.36 @@ -1513,9 +1523,7 @@
    1.37  				QString("addMapReplace(%1)").arg(fname),
    1.38  				QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
    1.39  	}	
    1.40 -	
    1.41      
    1.42 -    parseVYMHandler handler;
    1.43  	QFile file( fname );
    1.44  
    1.45  	// I am paranoid: file should exist anyway
    1.46 @@ -1532,16 +1540,16 @@
    1.47  		blockSaveState=true;
    1.48  		QXmlInputSource source( file);
    1.49  		QXmlSimpleReader reader;
    1.50 -		reader.setContentHandler( &handler );
    1.51 -		reader.setErrorHandler( &handler );
    1.52 -		handler.setMapEditor( this );
    1.53 +		reader.setContentHandler( handler );
    1.54 +		reader.setErrorHandler( handler );
    1.55 +		handler->setMapEditor( this );
    1.56  
    1.57  
    1.58  		// We need to set the tmpDir in order  to load files with rel. path
    1.59  		QString tmpdir= fname.left(fname.findRev("/",-1));	
    1.60 -		handler.setTmpDir (tmpdir);
    1.61 -		handler.setInputFile (file.name());
    1.62 -		handler.setLoadMode (lmode);
    1.63 +		handler->setTmpDir (tmpdir);
    1.64 +		handler->setInputFile (file.name());
    1.65 +		handler->setLoadMode (lmode);
    1.66  		bool ok = reader.parse( source );
    1.67  		blockReposition=false;
    1.68  		blockSaveState=blockSaveStateOrg;
    1.69 @@ -1560,7 +1568,7 @@
    1.70  		} else 
    1.71  		{
    1.72  			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
    1.73 -					   tr( handler.errorProtocol() ) );
    1.74 +					   tr( handler->errorProtocol() ) );
    1.75  			// returnCode=1;	
    1.76  			// Still return "success": the map maybe at least
    1.77  			// partially read by the parser
    1.78 @@ -2208,10 +2216,10 @@
    1.79  		// Use the "historical" buffer
    1.80  		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
    1.81  		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
    1.82 -		load (bakMapDir+"/"+clipboardFile,ImportAdd);
    1.83 +		load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
    1.84  	} else
    1.85  		// Use the global buffer
    1.86 -		load (clipboardDir+"/"+clipboardFile,ImportAdd);
    1.87 +		load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
    1.88  	blockSaveState=old;
    1.89  }
    1.90  
    1.91 @@ -4111,82 +4119,11 @@
    1.92  
    1.93  void MapEditor::testFunction1()
    1.94  {
    1.95 -	ErrorCode err=success;
    1.96 -	LoadMode lmode=NewMap;
    1.97 -
    1.98 -	//QString fname="test/freemind/doc/freemind.xml";
    1.99 -	QString fname="test/freemind/doc/icons.mm";
   1.100 -    parseFMHandler handler;
   1.101 -	QFile file( fname );
   1.102 -
   1.103 -	// I am paranoid: file should exist anyway
   1.104 -	// according to check in mainwindow.
   1.105 -	if (!file.exists() )
   1.106 -	{
   1.107 -		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
   1.108 -				   tr("Couldn't open map " +fname)+".");
   1.109 -		err=aborted;	
   1.110 -	} else
   1.111 -	{
   1.112 -		bool blockSaveStateOrg=blockSaveState;
   1.113 -		blockReposition=true;
   1.114 -		blockSaveState=true;
   1.115 -		QXmlInputSource source( file);
   1.116 -		QXmlSimpleReader reader;
   1.117 -		reader.setContentHandler( &handler );
   1.118 -		reader.setErrorHandler( &handler );
   1.119 -		handler.setMapEditor( this );
   1.120 -
   1.121 -
   1.122 -		// We need to set the tmpDir in order  to load files with rel. path
   1.123 -		QString tmpdir= fname.left(fname.findRev("/",-1));	
   1.124 -		handler.setTmpDir (tmpdir);
   1.125 -		handler.setInputFile (file.name());
   1.126 -		//handler.setLoadMode (lmode);
   1.127 -		bool ok = reader.parse( source );
   1.128 -		blockReposition=false;
   1.129 -		blockSaveState=blockSaveStateOrg;
   1.130 -		file.close();
   1.131 -		if ( ok ) 
   1.132 -		{
   1.133 -			mapCenter->reposition();
   1.134 -			xelection.update();
   1.135 -			if (lmode==NewMap)
   1.136 -			{
   1.137 -				mapDefault=false;
   1.138 -				mapChanged=false;
   1.139 -				mapUnsaved=false;
   1.140 -				autosaveTimer->stop();
   1.141 -			}
   1.142 -		} else 
   1.143 -		{
   1.144 -			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
   1.145 -					   tr( handler.errorProtocol() ) );
   1.146 -			// returnCode=1;	
   1.147 -			// Still return "success": the map maybe at least
   1.148 -			// partially read by the parser
   1.149 -		}	
   1.150 -	}	
   1.151 -	updateActions();
   1.152 -	//return err;
   1.153  /*
   1.154  	BranchObj *bo=xelection.getBranch();
   1.155  	if (bo) animObjList.append( bo );
   1.156  */	
   1.157  	
   1.158 -/*
   1.159 -	WarningDialog dia;
   1.160 -	dia.showCancelButton (true);
   1.161 -	dia.setText("This is a longer \nWarning");
   1.162 -	dia.setCaption("Warning: Flux problem");
   1.163 -	dia.setShowAgainName("mapeditor/testDialog");
   1.164 -	if (dia.exec()==QDialog::Accepted)
   1.165 -		cout << "accepted!\n";
   1.166 -	else	
   1.167 -		cout << "canceled!\n";
   1.168 -	return;
   1.169 -*/
   1.170 -
   1.171  /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
   1.172  	if (hidemode==HideNone)
   1.173  	{