diff -r e524edc45aff -r 3dabc6424d73 mainwindow.cpp --- a/mainwindow.cpp Wed Feb 27 16:09:06 2008 +0000 +++ b/mainwindow.cpp Wed Feb 27 16:09:06 2008 +0000 @@ -1469,18 +1469,15 @@ a = new QAction( "Test function 1" , this); a->setStatusTip( "Call test function 1" ); testMenu->addAction (a); - //a->setShortcut (Qt::Key_F4 ); connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) ); a = new QAction( "Test function 2" , this); a->setStatusTip( "Call test function 2" ); - //a->setShortcut (Qt::Key_F4 ); testMenu->addAction (a); connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) ); a = new QAction( "Command" , this); a->setStatusTip( "Enter command to call in editor" ); - //a->setShortcut (Qt::Key_F5 ); connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) ); testMenu->addAction (a); } @@ -1835,70 +1832,14 @@ tabWidget->showPage(me); me->viewport()->setFocus(); - // Create temporary directory for packing - bool ok; - QString tmpZipDir=makeTmpDir (ok,"vym-pack"); - if (!ok) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't create temporary directory before load\n")); - return aborted; - } - - // Try to unzip file - err=unzipDir (tmpZipDir,fn); - if (err==nozip) - { - mapfile=fn; - me->setZipped(false); - } else - { - me->setZipped(true); - - // Look for mapname.xml - mapfile= fn.left(fn.findRev(".",-1,true)); - mapfile=mapfile.section( '/', -1 ); - QFile file( tmpZipDir + "/" + mapfile + ".xml"); - if (!file.exists() ) - { - // mapname.xml does not exist, well, - // maybe someone renamed the mapname.vym file... - // Try to find any .xml in the toplevel - // directory of the .vym file - QStringList flist=QDir (tmpZipDir).entryList("*.xml"); - if (flist.count()==1) - { - // Only one entry, take this one - mapfile=tmpZipDir + "/"+flist.first(); - } else - { - for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) - *it=tmpZipDir + "/" + *it; - // TODO Multiple entries, load all (but only the first one into this ME) - //mainWindow->fileLoadFromTmp (flist); - //returnCode=1; // Silently forget this attempt to load - qWarning ("MainWindow::load (fn) multimap found..."); - } - - if (flist.isEmpty() ) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't find a map (*.xml) in .vym archive.\n")); - err=aborted; - } - } //file doesn't exist - else - mapfile=file.name(); - } - if (err!=aborted) { // Save existing filename in case we import QString fn_org=me->getFilePath(); // Finally load map into mapEditor - me->setFilePath (mapfile,fn); - err=me->load(mapfile,lmode,ftype); + me->setFilePath (fn); + err=me->load(fn,lmode,ftype); // Restore old (maybe empty) filepath, if this is an import if (lmode!=NewMap) @@ -1926,9 +1867,6 @@ } statusBar()->message( "Loaded " + fn, statusbarTime ); } - - // Delete tmpDir - removeDir (QDir(tmpZipDir)); } return err; } @@ -2000,125 +1938,133 @@ void Main::fileSave(MapEditor *me, const SaveMode &savemode) { + /* FIXME moved to ME + // Error codes + ErrorCode err=success; + + QString safeFilePath; + + if (!me) return; + bool saveZipped=me->saveZipped(); + // tmp dir for zipping QString tmpZipDir; - // Error codes - ErrorCode err=success; + */ - QString safeFilePath; - - bool saveZipped=me->saveZipped(); - - if (me) - { - QString fn=me->getFilePath(); - // filename=unnamed, filepath="" in constructor of mapEditor - if ( !fn.isEmpty() ) - { - // We have a filepath, go on saving - - // Look, if we should zip the data: - if (!saveZipped) + + if (!me) return; + + // filename=unnamed, filepath="" in constructor of mapEditor + + /* FIXME moved to ME + if ( !fn.isEmpty() ) + { + // We have a filepath, go on saving + + // Look, if we should zip the data: + if (!saveZipped) + { + QMessageBox mb( vymName, + tr("The map %1\ndid not use the compressed " + "vym file format.\nWriting it uncompressed will also write images \n" + "and flags and thus may overwrite files in the " + "given directory\n\nDo you want to write the map").arg(fn), + QMessageBox::Warning, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No , + QMessageBox::Cancel | QMessageBox::Escape); + mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); + mb.setButtonText( QMessageBox::No, tr("uncompressed") ); + mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); + switch( mb.exec() ) { - QMessageBox mb( vymName, - tr("The map %1\ndid not use the compressed " - "vym file format.\nWriting it uncompressed will also write images \n" - "and flags and thus may overwrite files in the " - "given directory\n\nDo you want to write the map").arg(fn), - QMessageBox::Warning, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No , - QMessageBox::Cancel | QMessageBox::Escape); - mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); - mb.setButtonText( QMessageBox::No, tr("uncompressed") ); - mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); - switch( mb.exec() ) + case QMessageBox::Yes: + // save compressed (default file format) + saveZipped=true; + break; + case QMessageBox::No: + // save uncompressed + saveZipped=false; + break; + case QMessageBox::Cancel: + // do nothing + return; + break; + } + me->setZipped (saveZipped); + } + + // First backup existing file, we + // don't want to add to old zip archives + QFile f(fn); + if (f.exists()) + { + if (actionSettingsWriteBackupFile->isOn()) + { + QString bfn(fn + "~"); + QFile bf(bfn); + if (bf.exists() && !bf.remove()) { - case QMessageBox::Yes: - // save compressed (default file format) - saveZipped=true; - break; - case QMessageBox::No: - // save uncompressed - saveZipped=false; - break; - case QMessageBox::Cancel: - // do nothing - return; - break; + QMessageBox::warning(0, tr("Save Error"), + bfn + tr("\ncould not be removed before saving")); } - me->setZipped (saveZipped); + else if (!f.rename(bfn)) + { + QMessageBox::warning(0, tr("Save Error"), + fn + tr("\ncould not be renamed before saving")); + } } - - // First backup existing file, we - // don't want to add to old zip archives - QFile f(fn); - if (f.exists()) - { - if (actionSettingsWriteBackupFile->isOn()) - { - QString bfn(fn + "~"); - QFile bf(bfn); - if (bf.exists() && !bf.remove()) - { - QMessageBox::warning(0, tr("Save Error"), - bfn + tr("\ncould not be removed before saving")); - } - else if (!f.rename(bfn)) - { - QMessageBox::warning(0, tr("Save Error"), - fn + tr("\ncould not be renamed before saving")); - } - } - } - - if (saveZipped) + } + + if (saveZipped) + { + // Create temporary directory for packing + bool ok; + tmpZipDir=makeTmpDir (ok,"vym-zip"); + if (!ok) { - // Create temporary directory for packing - bool ok; - tmpZipDir=makeTmpDir (ok,"vym-zip"); - if (!ok) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't create temporary directory before save\n")); - return; - } - - safeFilePath=me->getFilePath(); - me->setFilePath (tmpZipDir+"/"+ - me->getMapName()+ ".xml", - safeFilePath); - me->save (savemode); - me->setFilePath (safeFilePath); - - zipDir (tmpZipDir,fn); - } // save zipped - else - { - // Save unzipped. - safeFilePath=me->getFilePath(); - me->setFilePath (fn, safeFilePath); - me->save (savemode); - me->setFilePath (safeFilePath); - } // save zipped - } // filepath available + QMessageBox::critical( 0, tr( "Critical Load Error" ), + tr("Couldn't create temporary directory before save\n")); + return; + } + + safeFilePath=me->getFilePath(); + me->setFilePath (tmpZipDir+"/"+ + me->getMapName()+ ".xml", + safeFilePath); + me->save (savemode); + me->setFilePath (safeFilePath); + + zipDir (tmpZipDir,fn); + } // save zipped else { - // We have no filepath yet, - // call fileSaveAs() now, this will call fileSave() - // again. - // First switch to editor - tabWidget->setCurrentWidget (me); - fileSaveAs(savemode); - } - } - + // Save unzipped. + safeFilePath=me->getFilePath(); + me->setFilePath (fn, safeFilePath); + me->save (savemode); + me->setFilePath (safeFilePath); + } // save zipped + } // filepath available + else + */ + if ( me->getFilePath().isEmpty() ) + { + // We have no filepath yet, + // call fileSaveAs() now, this will call fileSave() + // again. + // First switch to editor + tabWidget->setCurrentWidget (me); + fileSaveAs(savemode); + } + +/* FIXME moved to ME if (saveZipped && !tmpZipDir.isEmpty()) // Delete tmpDir removeDir (QDir(tmpZipDir)); - - if (err==success) +*/ + if (me->save (savemode)==success) { statusBar()->message( tr("Saved %1").arg(me->getFilePath()), @@ -3438,9 +3384,7 @@ tr("QInputDialog::getInteger()"), tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok); if (ok) - { settings.setValue ("/mapeditor/autosave/ms",i * 1000); - } } void Main::settingsWriteBackupFileToggle() @@ -3801,8 +3745,8 @@ void Main::testFunction1() { if (!currentMapEditor()) return; - currentMapEditor()->testFunction1(); - //editAttribute(); + //currentMapEditor()->testFunction1(); + editAttribute(); } void Main::testFunction2()