11#include " FredView.h"
22#include " ui_FredView.h"
33
4+ #include < ui/util/default_dir.h>
5+
46#include < QDir>
57#include < QFileDialog>
68#include < QFileInfo>
@@ -254,13 +256,15 @@ void FredView::loadMissionFile(const QString& pathName, int flags) {
254256}
255257
256258void FredView::openLoadMissionDialog () {
257- qDebug () << " Loading from directory:" << QDir::currentPath ();
258- QString pathName = QFileDialog::getOpenFileName (this , tr (" Load mission" ), QString (), tr (" FS2 missions (*.fs2)" ));
259+ const QString lastDir = fso::fred::util::getLastDir (" missions/loadMission" , CF_TYPE_MISSIONS );
260+
261+ QString pathName = QFileDialog::getOpenFileName (this , tr (" Load mission" ), lastDir, tr (" FS2 missions (*.fs2)" ));
259262
260263 if (pathName.isEmpty ()) {
261264 return ;
262265 }
263266
267+ fso::fred::util::saveLastDir (" missions/loadMission" , pathName);
264268 loadMissionFile (pathName.replace (' /' ,DIR_SEPARATOR_CHAR ));
265269}
266270
@@ -302,10 +306,15 @@ bool FredView::saveMissionAs() {
302306 save.set_fred_alt_names (Fred_alt_names);
303307 save.set_fred_callsigns (Fred_callsigns);
304308
305- saveName = QFileDialog::getSaveFileName (this , tr (" Save mission" ), QString (), tr (" FS2 missions (*.fs2)" ));
309+ {
310+ const QString lastDir = fso::fred::util::getLastDir (" missions/saveMission" , CF_TYPE_MISSIONS );
311+ saveName = QFileDialog::getSaveFileName (this , tr (" Save mission" ), lastDir, tr (" FS2 missions (*.fs2)" ));
306312
307- if (saveName.isEmpty ()) {
308- return false ;
313+ if (saveName.isEmpty ()) {
314+ return false ;
315+ }
316+
317+ fso::fred::util::saveLastDir (" missions/saveMission" , saveName);
309318 }
310319
311320 save.save_mission_file (saveName.replace (' /' ,DIR_SEPARATOR_CHAR ).toUtf8 ().constData ());
@@ -319,18 +328,22 @@ void FredView::saveAsTemplate() {
319328 if (metaDialog.exec () != QDialog::Accepted)
320329 return ;
321330
322- // Default to data/missions/templates/ and create it if needed
323- QString templatesDir = QDir::currentPath () + " /data/missions/templates" ;
324- QDir ().mkpath (templatesDir);
331+ // Ensure templates subdir exists; use missions dir as fallback default
332+ const QString defaultTemplatesDir = fso::fred::util::fredDefaultDir (CF_TYPE_MISSIONS ) + " /templates" ;
333+ QDir ().mkpath (defaultTemplatesDir);
334+
335+ const QString lastTemplatesDir = fso::fred::util::getLastDir (" missions/saveTemplate" , defaultTemplatesDir);
325336
326337 QString templateName = QFileDialog::getSaveFileName (this ,
327338 tr (" Save As Template" ),
328- templatesDir ,
339+ lastTemplatesDir ,
329340 tr (" FS2 mission templates (*.fst)" ));
330341
331342 if (templateName.isEmpty ())
332343 return ;
333344
345+ fso::fred::util::saveLastDir (" missions/saveTemplate" , templateName);
346+
334347 if (!templateName.endsWith (" .fst" , Qt::CaseInsensitive))
335348 templateName += " .fst" ;
336349
@@ -344,7 +357,7 @@ void FredView::saveAsTemplate() {
344357}
345358
346359void FredView::loadTemplate () {
347- QString templatesDir = QDir::currentPath ( ) + " /data/missions /templates" ;
360+ QString templatesDir = fso::fred::util::fredDefaultDir ( CF_TYPE_MISSIONS ) + " /templates" ;
348361 QDir ().mkpath (templatesDir);
349362
350363 dialogs::TemplateBrowserDialog browser (this , templatesDir);
@@ -429,18 +442,23 @@ void FredView::on_actionFS1_Mission_triggered(bool) {
429442
430443 QStringList srcPaths = QFileDialog::getOpenFileNames (this ,
431444 tr (" Select FS1 mission(s) to import" ),
432- QString ( ),
445+ fso::fred::util::getLastDir ( " missions/importFS1Source " , QDir::homePath () ),
433446 tr (" FreeSpace Missions (*.fsm)" ));
434447
435448 if (srcPaths.isEmpty ())
436449 return ;
437450
451+ fso::fred::util::saveLastDir (" missions/importFS1Source" , srcPaths.first ());
452+
438453 QString destDir = QFileDialog::getExistingDirectory (this ,
439- tr (" Select destination folder for converted missions" ));
454+ tr (" Select destination folder for converted missions" ),
455+ fso::fred::util::getLastDir (" missions/importFS1Dest" , CF_TYPE_MISSIONS ));
440456
441457 if (destDir.isEmpty ())
442458 return ;
443459
460+ fso::fred::util::saveLastDir (" missions/importFS1Dest" , destDir);
461+
444462 QApplication::setOverrideCursor (QCursor (Qt::WaitCursor));
445463
446464 int successes = 0 ;
0 commit comments