1.1 --- a/mainwindow.cpp Wed Feb 27 16:09:06 2008 +0000
1.2 +++ b/mainwindow.cpp Wed Feb 27 16:09:06 2008 +0000
1.3 @@ -1469,18 +1469,15 @@
1.4 a = new QAction( "Test function 1" , this);
1.5 a->setStatusTip( "Call test function 1" );
1.6 testMenu->addAction (a);
1.7 - //a->setShortcut (Qt::Key_F4 );
1.8 connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
1.9
1.10 a = new QAction( "Test function 2" , this);
1.11 a->setStatusTip( "Call test function 2" );
1.12 - //a->setShortcut (Qt::Key_F4 );
1.13 testMenu->addAction (a);
1.14 connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
1.15
1.16 a = new QAction( "Command" , this);
1.17 a->setStatusTip( "Enter command to call in editor" );
1.18 - //a->setShortcut (Qt::Key_F5 );
1.19 connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
1.20 testMenu->addAction (a);
1.21 }
1.22 @@ -1835,70 +1832,14 @@
1.23 tabWidget->showPage(me);
1.24 me->viewport()->setFocus();
1.25
1.26 - // Create temporary directory for packing
1.27 - bool ok;
1.28 - QString tmpZipDir=makeTmpDir (ok,"vym-pack");
1.29 - if (!ok)
1.30 - {
1.31 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.32 - tr("Couldn't create temporary directory before load\n"));
1.33 - return aborted;
1.34 - }
1.35 -
1.36 - // Try to unzip file
1.37 - err=unzipDir (tmpZipDir,fn);
1.38 - if (err==nozip)
1.39 - {
1.40 - mapfile=fn;
1.41 - me->setZipped(false);
1.42 - } else
1.43 - {
1.44 - me->setZipped(true);
1.45 -
1.46 - // Look for mapname.xml
1.47 - mapfile= fn.left(fn.findRev(".",-1,true));
1.48 - mapfile=mapfile.section( '/', -1 );
1.49 - QFile file( tmpZipDir + "/" + mapfile + ".xml");
1.50 - if (!file.exists() )
1.51 - {
1.52 - // mapname.xml does not exist, well,
1.53 - // maybe someone renamed the mapname.vym file...
1.54 - // Try to find any .xml in the toplevel
1.55 - // directory of the .vym file
1.56 - QStringList flist=QDir (tmpZipDir).entryList("*.xml");
1.57 - if (flist.count()==1)
1.58 - {
1.59 - // Only one entry, take this one
1.60 - mapfile=tmpZipDir + "/"+flist.first();
1.61 - } else
1.62 - {
1.63 - for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1.64 - *it=tmpZipDir + "/" + *it;
1.65 - // TODO Multiple entries, load all (but only the first one into this ME)
1.66 - //mainWindow->fileLoadFromTmp (flist);
1.67 - //returnCode=1; // Silently forget this attempt to load
1.68 - qWarning ("MainWindow::load (fn) multimap found...");
1.69 - }
1.70 -
1.71 - if (flist.isEmpty() )
1.72 - {
1.73 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.74 - tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1.75 - err=aborted;
1.76 - }
1.77 - } //file doesn't exist
1.78 - else
1.79 - mapfile=file.name();
1.80 - }
1.81 -
1.82 if (err!=aborted)
1.83 {
1.84 // Save existing filename in case we import
1.85 QString fn_org=me->getFilePath();
1.86
1.87 // Finally load map into mapEditor
1.88 - me->setFilePath (mapfile,fn);
1.89 - err=me->load(mapfile,lmode,ftype);
1.90 + me->setFilePath (fn);
1.91 + err=me->load(fn,lmode,ftype);
1.92
1.93 // Restore old (maybe empty) filepath, if this is an import
1.94 if (lmode!=NewMap)
1.95 @@ -1926,9 +1867,6 @@
1.96 }
1.97 statusBar()->message( "Loaded " + fn, statusbarTime );
1.98 }
1.99 -
1.100 - // Delete tmpDir
1.101 - removeDir (QDir(tmpZipDir));
1.102 }
1.103 return err;
1.104 }
1.105 @@ -2000,125 +1938,133 @@
1.106
1.107 void Main::fileSave(MapEditor *me, const SaveMode &savemode)
1.108 {
1.109 + /* FIXME moved to ME
1.110 + // Error codes
1.111 + ErrorCode err=success;
1.112 +
1.113 + QString safeFilePath;
1.114 +
1.115 + if (!me) return;
1.116 + bool saveZipped=me->saveZipped();
1.117 +
1.118 // tmp dir for zipping
1.119 QString tmpZipDir;
1.120
1.121 - // Error codes
1.122 - ErrorCode err=success;
1.123 + */
1.124
1.125 - QString safeFilePath;
1.126 -
1.127 - bool saveZipped=me->saveZipped();
1.128 -
1.129 - if (me)
1.130 - {
1.131 - QString fn=me->getFilePath();
1.132 - // filename=unnamed, filepath="" in constructor of mapEditor
1.133 - if ( !fn.isEmpty() )
1.134 - {
1.135 - // We have a filepath, go on saving
1.136 -
1.137 - // Look, if we should zip the data:
1.138 - if (!saveZipped)
1.139 +
1.140 + if (!me) return;
1.141 +
1.142 + // filename=unnamed, filepath="" in constructor of mapEditor
1.143 +
1.144 + /* FIXME moved to ME
1.145 + if ( !fn.isEmpty() )
1.146 + {
1.147 + // We have a filepath, go on saving
1.148 +
1.149 + // Look, if we should zip the data:
1.150 + if (!saveZipped)
1.151 + {
1.152 + QMessageBox mb( vymName,
1.153 + tr("The map %1\ndid not use the compressed "
1.154 + "vym file format.\nWriting it uncompressed will also write images \n"
1.155 + "and flags and thus may overwrite files in the "
1.156 + "given directory\n\nDo you want to write the map").arg(fn),
1.157 + QMessageBox::Warning,
1.158 + QMessageBox::Yes | QMessageBox::Default,
1.159 + QMessageBox::No ,
1.160 + QMessageBox::Cancel | QMessageBox::Escape);
1.161 + mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1.162 + mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1.163 + mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1.164 + switch( mb.exec() )
1.165 {
1.166 - QMessageBox mb( vymName,
1.167 - tr("The map %1\ndid not use the compressed "
1.168 - "vym file format.\nWriting it uncompressed will also write images \n"
1.169 - "and flags and thus may overwrite files in the "
1.170 - "given directory\n\nDo you want to write the map").arg(fn),
1.171 - QMessageBox::Warning,
1.172 - QMessageBox::Yes | QMessageBox::Default,
1.173 - QMessageBox::No ,
1.174 - QMessageBox::Cancel | QMessageBox::Escape);
1.175 - mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
1.176 - mb.setButtonText( QMessageBox::No, tr("uncompressed") );
1.177 - mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
1.178 - switch( mb.exec() )
1.179 + case QMessageBox::Yes:
1.180 + // save compressed (default file format)
1.181 + saveZipped=true;
1.182 + break;
1.183 + case QMessageBox::No:
1.184 + // save uncompressed
1.185 + saveZipped=false;
1.186 + break;
1.187 + case QMessageBox::Cancel:
1.188 + // do nothing
1.189 + return;
1.190 + break;
1.191 + }
1.192 + me->setZipped (saveZipped);
1.193 + }
1.194 +
1.195 + // First backup existing file, we
1.196 + // don't want to add to old zip archives
1.197 + QFile f(fn);
1.198 + if (f.exists())
1.199 + {
1.200 + if (actionSettingsWriteBackupFile->isOn())
1.201 + {
1.202 + QString bfn(fn + "~");
1.203 + QFile bf(bfn);
1.204 + if (bf.exists() && !bf.remove())
1.205 {
1.206 - case QMessageBox::Yes:
1.207 - // save compressed (default file format)
1.208 - saveZipped=true;
1.209 - break;
1.210 - case QMessageBox::No:
1.211 - // save uncompressed
1.212 - saveZipped=false;
1.213 - break;
1.214 - case QMessageBox::Cancel:
1.215 - // do nothing
1.216 - return;
1.217 - break;
1.218 + QMessageBox::warning(0, tr("Save Error"),
1.219 + bfn + tr("\ncould not be removed before saving"));
1.220 }
1.221 - me->setZipped (saveZipped);
1.222 + else if (!f.rename(bfn))
1.223 + {
1.224 + QMessageBox::warning(0, tr("Save Error"),
1.225 + fn + tr("\ncould not be renamed before saving"));
1.226 + }
1.227 }
1.228 -
1.229 - // First backup existing file, we
1.230 - // don't want to add to old zip archives
1.231 - QFile f(fn);
1.232 - if (f.exists())
1.233 - {
1.234 - if (actionSettingsWriteBackupFile->isOn())
1.235 - {
1.236 - QString bfn(fn + "~");
1.237 - QFile bf(bfn);
1.238 - if (bf.exists() && !bf.remove())
1.239 - {
1.240 - QMessageBox::warning(0, tr("Save Error"),
1.241 - bfn + tr("\ncould not be removed before saving"));
1.242 - }
1.243 - else if (!f.rename(bfn))
1.244 - {
1.245 - QMessageBox::warning(0, tr("Save Error"),
1.246 - fn + tr("\ncould not be renamed before saving"));
1.247 - }
1.248 - }
1.249 - }
1.250 -
1.251 - if (saveZipped)
1.252 + }
1.253 +
1.254 + if (saveZipped)
1.255 + {
1.256 + // Create temporary directory for packing
1.257 + bool ok;
1.258 + tmpZipDir=makeTmpDir (ok,"vym-zip");
1.259 + if (!ok)
1.260 {
1.261 - // Create temporary directory for packing
1.262 - bool ok;
1.263 - tmpZipDir=makeTmpDir (ok,"vym-zip");
1.264 - if (!ok)
1.265 - {
1.266 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.267 - tr("Couldn't create temporary directory before save\n"));
1.268 - return;
1.269 - }
1.270 -
1.271 - safeFilePath=me->getFilePath();
1.272 - me->setFilePath (tmpZipDir+"/"+
1.273 - me->getMapName()+ ".xml",
1.274 - safeFilePath);
1.275 - me->save (savemode);
1.276 - me->setFilePath (safeFilePath);
1.277 -
1.278 - zipDir (tmpZipDir,fn);
1.279 - } // save zipped
1.280 - else
1.281 - {
1.282 - // Save unzipped.
1.283 - safeFilePath=me->getFilePath();
1.284 - me->setFilePath (fn, safeFilePath);
1.285 - me->save (savemode);
1.286 - me->setFilePath (safeFilePath);
1.287 - } // save zipped
1.288 - } // filepath available
1.289 + QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.290 + tr("Couldn't create temporary directory before save\n"));
1.291 + return;
1.292 + }
1.293 +
1.294 + safeFilePath=me->getFilePath();
1.295 + me->setFilePath (tmpZipDir+"/"+
1.296 + me->getMapName()+ ".xml",
1.297 + safeFilePath);
1.298 + me->save (savemode);
1.299 + me->setFilePath (safeFilePath);
1.300 +
1.301 + zipDir (tmpZipDir,fn);
1.302 + } // save zipped
1.303 else
1.304 {
1.305 - // We have no filepath yet,
1.306 - // call fileSaveAs() now, this will call fileSave()
1.307 - // again.
1.308 - // First switch to editor
1.309 - tabWidget->setCurrentWidget (me);
1.310 - fileSaveAs(savemode);
1.311 - }
1.312 - }
1.313 -
1.314 + // Save unzipped.
1.315 + safeFilePath=me->getFilePath();
1.316 + me->setFilePath (fn, safeFilePath);
1.317 + me->save (savemode);
1.318 + me->setFilePath (safeFilePath);
1.319 + } // save zipped
1.320 + } // filepath available
1.321 + else
1.322 + */
1.323 + if ( me->getFilePath().isEmpty() )
1.324 + {
1.325 + // We have no filepath yet,
1.326 + // call fileSaveAs() now, this will call fileSave()
1.327 + // again.
1.328 + // First switch to editor
1.329 + tabWidget->setCurrentWidget (me);
1.330 + fileSaveAs(savemode);
1.331 + }
1.332 +
1.333 +/* FIXME moved to ME
1.334 if (saveZipped && !tmpZipDir.isEmpty())
1.335 // Delete tmpDir
1.336 removeDir (QDir(tmpZipDir));
1.337 -
1.338 - if (err==success)
1.339 +*/
1.340 + if (me->save (savemode)==success)
1.341 {
1.342 statusBar()->message(
1.343 tr("Saved %1").arg(me->getFilePath()),
1.344 @@ -3438,9 +3384,7 @@
1.345 tr("QInputDialog::getInteger()"),
1.346 tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
1.347 if (ok)
1.348 - {
1.349 settings.setValue ("/mapeditor/autosave/ms",i * 1000);
1.350 - }
1.351 }
1.352
1.353 void Main::settingsWriteBackupFileToggle()
1.354 @@ -3801,8 +3745,8 @@
1.355 void Main::testFunction1()
1.356 {
1.357 if (!currentMapEditor()) return;
1.358 - currentMapEditor()->testFunction1();
1.359 - //editAttribute();
1.360 + //currentMapEditor()->testFunction1();
1.361 + editAttribute();
1.362 }
1.363
1.364 void Main::testFunction2()