Skip to content

Commit ee6b6b9

Browse files
committed
App now remembers last folder of Gerber Pre/Post-ambles output and config files separately
Signed-off-by: Michael Brown <producer@holotronic.dk>
1 parent d6c79e9 commit ee6b6b9

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

mainwindow.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

283292
void 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

288297
void 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

293302
void 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

298307
void 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());

mainwindow.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ private slots:
102102
QButtonGroup mirrorType;
103103

104104
const QString pcb2gcodeVersion;
105-
QString lastDir;
105+
QString lastGcodeDir;
106+
QString lastPreambleDir;
107+
QString lastOutputDir;
108+
QString lastConfigDir;
106109
QProcess pcb2gcodeProcess;
107110
bool pcb2gcodeKilled;
108111
bool changeMetricImperialValues;
@@ -128,6 +131,7 @@ private slots:
128131
void checkPcb2gcodeVersion();
129132
QStringList getCmdLineArguments();
130133
bool getFilename(QLineEdit *saveTo, const QString name, QString filter);
134+
bool getPreFilename(QLineEdit *saveTo, const QString name, QString filter);
131135
void adjustMetricImperial(QSpinBox *spinBox, const double cfactor, const QString suffix);
132136
void adjustMetricImperial(QDoubleSpinBox *doubleSpinBox, const double cfactor, const QString suffix);
133137
void saveConfFile(const QString filename);

0 commit comments

Comments
 (0)