diff --git a/CHANGELOG.md b/CHANGELOG.md index 49bf85d..739b043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ and this project adheres to Color to a polynomial fitted to data provided by Warren and Brandt in their paper Optical Constants of Ice from The Ultraviolet to The Microwave, which is what HaloPoint 2.0 used to use +- HaloRay now remembers which folder you opened last when loading or saving + files like simulation parameter files or images, and opens the file dialog + picker in that same folder the next time ## 4.0.1 - 2021-08-26 diff --git a/src/haloray-core/gui/mainWindow.cpp b/src/haloray-core/gui/mainWindow.cpp index 44e1790..68610bb 100644 --- a/src/haloray-core/gui/mainWindow.cpp +++ b/src/haloray-core/gui/mainWindow.cpp @@ -98,39 +98,43 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_previousTimedIt auto defaultFilename = QString("haloray_%1.png") .arg(currentTime) .replace(":", "-"); + auto defaultFilePath = getLatestAccessedFolder().absoluteFilePath(defaultFilename); QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), - defaultFilename, + defaultFilePath, tr("Images (*.png)")); - if (!filename.isNull()) - { - image.save(filename, "PNG", 50); - } + if (filename.isNull()) return; + + image.save(filename, "PNG", 50); + updateLatestAccessedFolder(filename); }); connect(m_saveSimulationAction, &QAction::triggered, [this]() { auto currentTime = QDateTime::currentDateTimeUtc().toString(Qt::DateFormat::ISODate); auto defaultFilename = QString("haloray_sim_%1.ini") .arg(currentTime) .replace(":", "-"); + auto defaultFilePath = getLatestAccessedFolder().absoluteFilePath(defaultFilename); QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), - defaultFilename, + defaultFilePath, tr("Simulation files (*.ini)")); if (filename.isNull()) return; StateSaver::SaveState(filename, m_engine, m_crystalRepository.get()); + updateLatestAccessedFolder(filename); }); connect(m_loadSimulationAction, &QAction::triggered, [this]() { QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), - QString(), + getLatestAccessedFolder().absolutePath(), tr("Simulation files (*.ini)")); if (filename.isNull()) return; StateSaver::LoadState(filename, m_simulationStateModel, m_crystalModel); + updateLatestAccessedFolder(filename); }); connect(m_openCrystalPreviewWindow, &QAction::triggered, [this]() { auto previewWindow = new CrystalPreviewWindow(m_crystalModel, m_crystalSettingsWidget->getCurrentPopulationIndex(), this); @@ -273,4 +277,24 @@ void HaloRay::MainWindow::restartSimulation() m_openGLWidget->update(); } +QDir MainWindow::getLatestAccessedFolder() const +{ + QSettings settings; + QString pathString = settings.value("filedialog/latestFolder", QString()).toString(); + QDir dir(pathString); + if (dir.exists()) { + return dir; + } + + return QDir(); +} + +void MainWindow::updateLatestAccessedFolder(QString fileOrDirPath) +{ + QFileInfo fileInfo(fileOrDirPath); + QString path = fileInfo.absoluteDir().path(); + QSettings settings; + settings.setValue("filedialog/latestFolder", path); +} + } diff --git a/src/haloray-core/gui/mainWindow.h b/src/haloray-core/gui/mainWindow.h index 66aebc2..63c8292 100644 --- a/src/haloray-core/gui/mainWindow.h +++ b/src/haloray-core/gui/mainWindow.h @@ -4,11 +4,11 @@ #include #include "gui/models/simulationStateModel.h" - class QDoubleSpinBox; class QProgressBar; class QScrollArea; class QAction; +class QDir; namespace HaloRay { @@ -39,6 +39,9 @@ class MainWindow : public QMainWindow void setupRenderTimer(); void restartSimulation(); + QDir getLatestAccessedFolder() const; + void updateLatestAccessedFolder(QString fileOrDirPath); + GeneralSettingsWidget *m_generalSettingsWidget; CrystalSettingsWidget *m_crystalSettingsWidget; ViewSettingsWidget *m_viewSettingsWidget;