diff -r b8f0eefe4351 -r 4b935d7e1671 mapeditor.cpp --- a/mapeditor.cpp Mon Jul 23 12:42:02 2007 +0000 +++ b/mapeditor.cpp Mon Jul 30 09:47:14 2007 +0000 @@ -19,8 +19,8 @@ #include "misc.h" #include "texteditor.h" #include "warningdialog.h" -#include "xml.h" -#include "xml-fm.h" +#include "xml-freemind.h" +#include "xml-vym.h" extern TextEditor *textEditor; @@ -1485,10 +1485,20 @@ return destPath; } -ErrorCode MapEditor::load (QString fname, LoadMode lmode) +ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype) { ErrorCode err=success; + parseBaseHandler *handler; + switch (ftype) + { + case VymMap: handler=new parseVYMHandler; break; + case FreemindMap : handler=new parseFreemindHandler; break; + default: + QMessageBox::critical( 0, tr( "Critical Parse Error" ), + "Unknown FileType in MapEditor::load()"); + return aborted; + } if (lmode==NewMap) { if (xelection.isEmpty() ) xelection.unselect(); @@ -1513,9 +1523,7 @@ QString("addMapReplace(%1)").arg(fname), QString("Add map %1 to %2").arg(fname).arg(getName(bo))); } - - parseVYMHandler handler; QFile file( fname ); // I am paranoid: file should exist anyway @@ -1532,16 +1540,16 @@ blockSaveState=true; QXmlInputSource source( file); QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setMapEditor( this ); + reader.setContentHandler( handler ); + reader.setErrorHandler( handler ); + handler->setMapEditor( this ); // We need to set the tmpDir in order to load files with rel. path QString tmpdir= fname.left(fname.findRev("/",-1)); - handler.setTmpDir (tmpdir); - handler.setInputFile (file.name()); - handler.setLoadMode (lmode); + handler->setTmpDir (tmpdir); + handler->setInputFile (file.name()); + handler->setLoadMode (lmode); bool ok = reader.parse( source ); blockReposition=false; blockSaveState=blockSaveStateOrg; @@ -1560,7 +1568,7 @@ } else { QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr( handler.errorProtocol() ) ); + tr( handler->errorProtocol() ) ); // returnCode=1; // Still return "success": the map maybe at least // partially read by the parser @@ -2208,10 +2216,10 @@ // Use the "historical" buffer QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n)); QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName); - load (bakMapDir+"/"+clipboardFile,ImportAdd); + load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap); } else // Use the global buffer - load (clipboardDir+"/"+clipboardFile,ImportAdd); + load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap); blockSaveState=old; } @@ -4111,82 +4119,11 @@ void MapEditor::testFunction1() { - ErrorCode err=success; - LoadMode lmode=NewMap; - - //QString fname="test/freemind/doc/freemind.xml"; - QString fname="test/freemind/doc/icons.mm"; - parseFMHandler handler; - QFile file( fname ); - - // I am paranoid: file should exist anyway - // according to check in mainwindow. - if (!file.exists() ) - { - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr("Couldn't open map " +fname)+"."); - err=aborted; - } else - { - bool blockSaveStateOrg=blockSaveState; - blockReposition=true; - blockSaveState=true; - QXmlInputSource source( file); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setMapEditor( this ); - - - // We need to set the tmpDir in order to load files with rel. path - QString tmpdir= fname.left(fname.findRev("/",-1)); - handler.setTmpDir (tmpdir); - handler.setInputFile (file.name()); - //handler.setLoadMode (lmode); - bool ok = reader.parse( source ); - blockReposition=false; - blockSaveState=blockSaveStateOrg; - file.close(); - if ( ok ) - { - mapCenter->reposition(); - xelection.update(); - if (lmode==NewMap) - { - mapDefault=false; - mapChanged=false; - mapUnsaved=false; - autosaveTimer->stop(); - } - } else - { - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr( handler.errorProtocol() ) ); - // returnCode=1; - // Still return "success": the map maybe at least - // partially read by the parser - } - } - updateActions(); - //return err; /* BranchObj *bo=xelection.getBranch(); if (bo) animObjList.append( bo ); */ -/* - WarningDialog dia; - dia.showCancelButton (true); - dia.setText("This is a longer \nWarning"); - dia.setCaption("Warning: Flux problem"); - dia.setShowAgainName("mapeditor/testDialog"); - if (dia.exec()==QDialog::Accepted) - cout << "accepted!\n"; - else - cout << "canceled!\n"; - return; -*/ - /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) {