@@ -177,8 +177,17 @@ MainWindow::MainWindow(QWidget *parent) :
177177 settings = new QSettings (QSettings::IniFormat, QSettings::UserScope, " pcb2gcodeGUI" , " " , this );
178178
179179 ui->actionAutomatically_generate_previews ->setChecked (settings->value (" autoPreview" , true ).toBool ());
180- lastDir = settings->value (" lastDir" , QStandardPaths::writableLocation (QStandardPaths::HomeLocation)).toString ();
181- if (lastDir.isEmpty ())
180+ lastGcodeDir = settings->value (" lastGcodeDir" , QStandardPaths::writableLocation (QStandardPaths::HomeLocation)).toString ();
181+ if (lastGcodeDir.isEmpty ())
182+ QMessageBox::information (this , tr (" Error" ), tr (" Can't retrieve home location" ));
183+ lastPreambleDir = settings->value (" lastPreambleDir" , QStandardPaths::writableLocation (QStandardPaths::HomeLocation)).toString ();
184+ if (lastPreambleDir.isEmpty ())
185+ QMessageBox::information (this , tr (" Error" ), tr (" Can't retrieve home location" ));
186+ lastOutputDir = settings->value (" lastOutputDir" , QStandardPaths::writableLocation (QStandardPaths::HomeLocation)).toString ();
187+ if (lastOutputDir.isEmpty ())
188+ QMessageBox::information (this , tr (" Error" ), tr (" Can't retrieve home location" ));
189+ lastConfigDir = settings->value (" lastConfigDir" , QStandardPaths::writableLocation (QStandardPaths::HomeLocation)).toString ();
190+ if (lastConfigDir.isEmpty ())
182191 QMessageBox::information (this , tr (" Error" ), tr (" Can't retrieve home location" ));
183192
184193 this ->resize (settings->value (" Window/width" , this ->width ()).toInt (),
@@ -282,17 +291,17 @@ void MainWindow::getDrillFile()
282291
283292void MainWindow::getPreambleFile ()
284293{
285- getFilename (ui->preambleLineEdit , tr (" preamble file" ), gcode_file_filter);
294+ getPreFilename (ui->preambleLineEdit , tr (" preamble file" ), gcode_file_filter);
286295}
287296
288297void MainWindow::getPreambletextFile ()
289298{
290- getFilename (ui->preambletextLineEdit , tr (" preamble text file" ), text_file_filter);
299+ getPreFilename (ui->preambletextLineEdit , tr (" preamble text file" ), text_file_filter);
291300}
292301
293302void MainWindow::getPostambleFile ()
294303{
295- getFilename (ui->postambleLineEdit , tr (" postamble file" ), gcode_file_filter);
304+ getPreFilename (ui->postambleLineEdit , tr (" postamble file" ), gcode_file_filter);
296305}
297306
298307void MainWindow::generateImages ()
@@ -427,13 +436,29 @@ bool MainWindow::getFilename(QLineEdit *saveTo, const QString name, QString filt
427436{
428437 QString filename;
429438
430- filename = QFileDialog::getOpenFileName (this , tr (" Select the " ) + name, lastDir, filter );
439+ filename = QFileDialog::getOpenFileName (this , tr (" Select the " ) + name, lastGcodeDir, filter );
440+
441+ if ( filename.isEmpty () )
442+ return false ;
443+ else
444+ {
445+ lastGcodeDir = QFileInfo (filename).path ();
446+ saveTo->setText ( filename );
447+ return true ;
448+ }
449+ }
450+
451+ bool MainWindow::getPreFilename (QLineEdit *saveTo, const QString name, QString filter)
452+ {
453+ QString filename;
454+
455+ filename = QFileDialog::getOpenFileName (this , tr (" Select the " ) + name, lastPreambleDir, filter );
431456
432457 if ( filename.isEmpty () )
433458 return false ;
434459 else
435460 {
436- lastDir = QFileInfo (filename).path ();
461+ lastPreambleDir = QFileInfo (filename).path ();
437462 saveTo->setText ( filename );
438463 return true ;
439464 }
@@ -443,10 +468,10 @@ void MainWindow::getOutputDirectory()
443468{
444469 QString dirname;
445470
446- dirname = QFileDialog::getExistingDirectory (this , tr (" Select the output directory" ), lastDir );
471+ dirname = QFileDialog::getExistingDirectory (this , tr (" Select the output directory" ), lastOutputDir );
447472 if ( !dirname.isEmpty () )
448473 {
449- lastDir = dirname;
474+ lastOutputDir = dirname;
450475 ui->outputDirLineEdit ->setText ( dirname );
451476 }
452477}
@@ -734,10 +759,10 @@ void MainWindow::askAndLoadConfFile()
734759{
735760 QString filename;
736761
737- filename = QFileDialog::getOpenFileName (this , tr (" Select a configuration file" ), lastDir );
762+ filename = QFileDialog::getOpenFileName (this , tr (" Select a configuration file" ), lastConfigDir );
738763 if ( !filename.isEmpty () )
739764 {
740- lastDir = QFileInfo (filename).path ();
765+ lastConfigDir = QFileInfo (filename).path ();
741766 if ( !loadConfFile (filename) )
742767 QMessageBox::information (this , tr (" Error" ), tr (" The selected file can't be opened" ));
743768 }
@@ -819,10 +844,10 @@ void MainWindow::askAndSaveConfFile()
819844{
820845 QString filename;
821846
822- filename = QFileDialog::getSaveFileName (this , tr (" Save configuration file" ), lastDir );
847+ filename = QFileDialog::getSaveFileName (this , tr (" Save configuration file" ), lastConfigDir );
823848 if ( !filename.isEmpty () )
824849 {
825- lastDir = QFileInfo (filename).path ();
850+ lastConfigDir = QFileInfo (filename).path ();
826851 saveConfFile (filename);
827852 }
828853}
@@ -930,7 +955,10 @@ void MainWindow::closeEvent(QCloseEvent *)
930955 QDir ().rmdir (imagesFolder);
931956
932957 settings->setValue (" autoPreview" , ui->actionAutomatically_generate_previews ->isChecked ());
933- settings->setValue (" lastDir" , lastDir);
958+ settings->setValue (" lastGcodeDir" , lastGcodeDir);
959+ settings->setValue (" lastPreambleDir" , lastPreambleDir);
960+ settings->setValue (" lastOutputDir" , lastOutputDir);
961+ settings->setValue (" lastConfigDir" , lastConfigDir);
934962
935963 settings->setValue (" Window/width" , this ->width ());
936964 settings->setValue (" Window/height" , this ->height ());
0 commit comments