diff -r 67a91e28b30f -r 276468359068 mapeditor.cpp --- a/mapeditor.cpp Mon Jun 06 20:27:42 2005 +0000 +++ b/mapeditor.cpp Fri Jul 08 07:24:42 2005 +0000 @@ -341,7 +341,6 @@ mapChanged=false; mapDefault=true; mapUnsaved=false; - undoSelection=NULL; zipped=true; filePath=""; @@ -468,8 +467,7 @@ char tmpdir[]="/tmp/vym-XXXXXX"; bakMapDir=mkdtemp(tmpdir); makeSubDirs(bakMapDir); - // FIXME set permissions - // and maybe use QT method for portability + // FIXME set permissions and maybe use QT method for portability } void MapEditor::delTmpDirs() @@ -487,7 +485,7 @@ } -QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode) +QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection) { // tmpdir temporary directory to which data will be writte // prefix mapname, which will be appended to images etc. @@ -521,7 +519,7 @@ colhint=attribut("linkColorHint","HeadingColor"); QString mapAttr=attribut("version",__VYM_VERSION__); - if (savemode==CompleteMap) + if (!saveSelection) mapAttr+= attribut("author",mapCenter->getAuthor()) + attribut("comment",mapCenter->getComment()) + attribut("date",mapCenter->getDate()) + @@ -538,15 +536,15 @@ standardFlagsDefault->resetUsedCounter(); // Build xml recursivly - if (savemode==CompleteMap) + if (!saveSelection) s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset); else { - if ( undoSelection && - typeid(*undoSelection) == typeid(BranchObj) ) - s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset); + if ( typeid(*saveSelection) == typeid(BranchObj) ) + s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset); else if (selection && typeid(*selection)==typeid(BranchObj)) + // This is used if selected branch is saved from mainwindow s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset); } @@ -554,7 +552,7 @@ s+=settings.getXMLData (destPath); // Save selection - if (selection) + if (selection && !saveSelection) s+=valueElement("select",selection->getSelectString()); decIndent(); @@ -567,44 +565,76 @@ void MapEditor::saveState() { - saveState (CompleteMap,NULL); + saveState (CompleteMap,NULL,""); } -void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part) +void MapEditor::saveState(LinkableMapObj *undoSel) { - saveState (mode,part,""); + saveState (PartOfMap,undoSel,""); } -void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part, const QString &undoCom) +void MapEditor::saveState(const QString & c) { - // all binary data is saved in bakMapDir (created in Constructor) - // the xml data itself is kept in memory in backupXML - // - // For faster write/read of data, a part of the map can be - // written. Then the undoSelection will mark the part of the - // map which should be replaced if an undo is wanted later. - - if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) ) + saveState (UndoCommand,NULL,c); +} + +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom) +{ + if (savemode==UndoCommand) { - // So far we only test undoCommands for BranchObjs undoCommand=undoCom; - if (undoCommand!="") - { - undoSelection=part; - } else - { - // Writing a vympart only is useful for BranchObj - undoSelection=part; - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap); - } - } else + backupXML=""; + } + else if (savemode==PartOfMap && undoSel) { - undoCommand=""; - undoSelection=NULL; - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap); + undoCommand="undoPart (\""+undoSel->getSelectString()+"\")"; + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel); + } else + { + undoCommand="undoMap ()"; + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL); + } + /* FIXME testing + cout << "ME::saveState()\n"; + cout << " undoCom="<=0) fileName=fileName.remove (0,i+1); - - // Forget the .vym (or .xml) for name of map - mapName=fileName.left(fileName.findRev(".",-1,true) ); + if (fname.isEmpty()) + { + filePath=""; + fileName=""; + destPath=""; + } else + { + filePath=fname; // becomes absolute path + fileName=fname; // gets stripped of path + destPath=destname; // needed for vymlinks + + // If fname is not an absolute path, complete it + filePath=QDir(fname).absPath(); + fileDir=filePath.left (1+filePath.findRev ("/")); + + // Set short name, too. Search from behind: + int i=fileName.findRev("/"); + if (i>=0) fileName=fileName.remove (0,i+1); + + // Forget the .vym (or .xml) for name of map + mapName=fileName.left(fileName.findRev(".",-1,true) ); + } } QString MapEditor::getFilePath() @@ -728,7 +766,7 @@ } else { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); } @@ -785,6 +823,9 @@ int returnCode=0; + // The SaveMode UndoCommand is not supported here + if (savemode==UndoCommand) return 1; + // Create mapName and fileDir makeSubDirs (fileDir); QString fname; @@ -807,7 +848,10 @@ file.close(); QString saveFile; - saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode); + if (savemode==CompleteMap || selection==NULL) + saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL); + else + saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection); file.setName ( fileDir + fname); if ( !file.open( IO_WriteOnly ) ) @@ -1073,7 +1117,7 @@ makeSubDirs (dir); // write to directory - QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap); + QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL); QFile file; file.setName ( dir + "/"+mapName+".xml"); @@ -1105,82 +1149,6 @@ mapCenter->clear(); } -void MapEditor::undo() -{ - QDir d; - d.setPath(bakMapDir); - if (d.exists() ) - { - // Finish open lineEdits - if (lineedit) finishedLineEditNoSave(); - - if (selection) - { - selection->unselect(); - selection=NULL; - } - - if (undoCommand!="" && undoSelection) - { - // We don't need to parse XML backup, but - // do the undoCommand - selection=undoSelection; - selection->select(); - parseTest (undoCommand); - - } else - { - // We need to parse saved XML data - mapBuilderHandler handler; - QXmlInputSource source; - source.setData(backupXML); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setMapEditor( this ); - handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path - if (undoSelection) - { - selection=undoSelection; - selection->select(); - handler.setLoadMode (ImportReplace); - - } else - { - mapCenter->clear(); - handler.setLoadMode (NewMap); - } - blockreposition=true; - bool ok = reader.parse( source ); - blockreposition=false; - if ( ok ) - mapCenter->reposition(); - - else - { - // This should never ever happen - QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), - tr( handler.errorProtocol() )+" in "+backupXML ); - } - } // restoring saved version - - // Undo not longer available now - actionEditUndo->setEnabled (false); - undoSelection=false; - mapChanged=false; - return; - } else - { - QMessageBox::critical( 0, tr( "Critical Error" ), - "Temporary directory " +bakMapDir + - tr (" used for undo is gone. \n" - "I will create a new one, but at the moment no undo is available.\n" - "Maybe you want to reload your original data.\n\n" - "Sorry for any inconveniences.") ); - makeTmpDirs(); - } -} - void MapEditor::copy() { // Finish open lineEdits @@ -1244,6 +1212,72 @@ } } +void MapEditor::undo() +{ + // Finish open lineEdits + if (lineedit) finishedLineEditNoSave(); + + // Unselect + if (selection) + { + selection->unselect(); + selection=NULL; + } + + parseAtom (undoCommand); + mapCenter->reposition(); + + // Undo not longer available now + actionEditUndo->setEnabled (false); + mapChanged=false; + +} + +void MapEditor::undoXML(const QString &undoSel) +{ + QDir d; + d.setPath(bakMapDir); + if (d.exists() ) + { + // We need to parse saved XML data + mapBuilderHandler handler; + QXmlInputSource source; + source.setData(backupXML); + QXmlSimpleReader reader; + reader.setContentHandler( &handler ); + reader.setErrorHandler( &handler ); + handler.setMapEditor( this ); + handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path + if (undoSel.isEmpty()) + { + mapCenter->clear(); + handler.setLoadMode (NewMap); + } else + { + select (undoSel); + handler.setLoadMode (ImportReplace); + } + blockreposition=true; + bool ok = reader.parse( source ); + blockreposition=false; + if (! ok ) + { + // This should never ever happen + QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), + tr( handler.errorProtocol() )+" in "+backupXML ); + } + } else + { + QMessageBox::critical( 0, tr( "Critical Error" ), + "Temporary directory " +bakMapDir + + tr (" used for undo is gone. \n" + "I will create a new one, but at the moment no undo is available.\n" + "Maybe you want to reload your original data.\n\n" + "Sorry for any inconveniences.") ); + makeTmpDirs(); + } +} + LinkableMapObj* MapEditor::pasteNoSave() { // Finish open lineEdits @@ -1309,7 +1343,7 @@ void MapEditor::paste() { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); pasteNoSave(); mapCenter->reposition(); adjustCanvasSize(); @@ -1318,7 +1352,7 @@ void MapEditor::cut() { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(selection->getParObj()); copy(); cutNoSave(); mapCenter->reposition(); @@ -1335,7 +1369,7 @@ if (typeid(*selection) == typeid(BranchObj) ) { setChanged(); - saveState(PartOfMap,selection,"moveBranchDown ()"); + saveState("moveBranchDown ()"); bo=(BranchObj*)(selection); par=(BranchObj*)(bo->getParObj()); selection->unselect(); @@ -1356,7 +1390,7 @@ if (typeid(*selection) == typeid(BranchObj) ) { setChanged(); - saveState(PartOfMap,selection,"moveBranchUp ()"); + saveState("moveBranchUp ()"); bo=(BranchObj*)(selection); par=(BranchObj*)(bo->getParObj()); selection->unselect(); @@ -1377,7 +1411,7 @@ typeid(*selection) == typeid(MapCenterObj) ) ) { setChanged(); - saveState(PartOfMap,selection); + saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")"); ensureSelectionVisible(); editingBO=(BranchObj*)(selection); @@ -1395,6 +1429,20 @@ } } +void MapEditor::setHeading(const QString &s) +{ + // Internal function, no saveState needed + if (selection && + (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj) ) ) + { + ((BranchObj*)(selection))->setHeading(s); + mapCenter->reposition(); + adjustCanvasSize(); + ensureSelectionVisible(); + } +} + void MapEditor::addNewBranch(int pos) { // Finish open lineEdits @@ -1405,7 +1453,7 @@ typeid(*selection) == typeid(MapCenterObj) ) ) { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); BranchObj* bo1 = (BranchObj*) (selection); bool wasScrolled=false; @@ -1471,7 +1519,7 @@ (typeid(*selection) == typeid(BranchObj) ) ) { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); BranchObj* bo1 = (BranchObj*) (selection); bool wasScrolled=false; @@ -1520,7 +1568,7 @@ if (selection && typeid(*selection) ==typeid(BranchObj) ) { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(selection->getParObj()); BranchObj* bo=dynamic_cast (selection); BranchObj* par=(BranchObj*)(bo->getParObj()); bo->unselect(); @@ -1535,7 +1583,7 @@ if (selection && typeid(*selection) ==typeid(FloatImageObj) ) { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(selection->getParObj()); FloatImageObj* fio=dynamic_cast (selection); BranchObj* par=(BranchObj*)(fio->getParObj()); fio->unselect(); @@ -1556,7 +1604,7 @@ bool MapEditor::select (const QString &s) { - LinkableMapObj *lmo=mapCenter->findObj(s); + LinkableMapObj *lmo=mapCenter->findObjBySelect(s); // Finally select the found object if (lmo) @@ -2006,7 +2054,7 @@ typeid(*selection) == typeid(MapCenterObj)) { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); BranchObj *bo=(BranchObj*)(selection); bo->setColor(actColor, false); // color links, color childs } @@ -2021,7 +2069,7 @@ typeid(*selection) == typeid(MapCenterObj)) { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); BranchObj *bo=(BranchObj*)(selection); bo->setColor(actColor, true); // color links, color childs } @@ -2034,7 +2082,7 @@ if (selection) { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups); } } @@ -2234,7 +2282,7 @@ if (selection && (typeid(*selection) == typeid(BranchObj) )) { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(selection->getParObj()); QString sel=selection->getSelectString(); BranchObj* bo=(BranchObj*)(selection); BranchObj* par=(BranchObj*)(bo->getParObj()); @@ -2250,7 +2298,7 @@ if (selection && (typeid(*selection) == typeid(BranchObj) )) { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(selection->getParObj()); ((BranchObj*)(selection))->removeChilds(); mapCenter->reposition(); } @@ -2555,7 +2603,7 @@ if (bo->countBranches()==0) return; if (bo->getDepth()==0) return; setChanged(); - saveState(PartOfMap,selection); + saveState(selection); bo->toggleScroll(); adjustCanvasSize(); canvas()->update(); @@ -2595,7 +2643,7 @@ if ( fd->exec() == QDialog::Accepted ) { setChanged(); - saveState(PartOfMap,selection); + saveState(selection); QString fn=fd->selectedFile(); lastImageDir=fn.left(fn.findRev ("/")); bo->addFloatImage(); @@ -2816,25 +2864,10 @@ (typeid(*selection) == typeid(BranchObj)) ) { QString s=((BranchObj*)(selection))->getHeading(); - parseTest (s); + parseAtom(s); } } -void MapEditor::parseTest(const QString &s) -{ - API api; - QString c,p,p0; - api.parseCommand (s,c,p); - if (c==QString("moveBranchUp")) - moveBranchUp(); - else if (c=="moveBranchDown") - moveBranchDown(); - else if (c=="select") - select (p); - else - cout << "Don't know about command \""<move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); } else { @@ -3326,7 +3359,7 @@ selection=lmo; selection->select(); setChanged(); - saveState(PartOfMap,selection); + saveState(selection); editHeading(); } }