diff --git a/CHANGELOG.md b/CHANGELOG.md index eed6c36a..43bff1c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Added - Add `setScale` to the scripting API. +### Changed +- The last-used directory is now preserved in import/export file dialogs. + ## [5.0.0] - 2022-10-30 ### Breaking Changes - Proper support for pokefirered's clone objects was added, which requires the changes made in [pokefirered/#484](https://github.com/pret/pokefirered/pull/484). diff --git a/include/project.h b/include/project.h index c5599489..cf46dcd5 100644 --- a/include/project.h +++ b/include/project.h @@ -83,6 +83,7 @@ public: QFileSystemWatcher fileWatcher; QMap modifiedFileTimestamps; bool usingAsmTilesets; + QString importExportPath; const QPixmap entitiesPixmap = QPixmap(":/images/Entities_16x16.png"); @@ -213,6 +214,8 @@ public: QString getDefaultPrimaryTilesetLabel(); QString getDefaultSecondaryTilesetLabel(); + void setImportExportPath(QString filename); + static int getNumTilesPrimary(); static int getNumTilesTotal(); static int getNumMetatilesPrimary(); diff --git a/src/project.cpp b/src/project.cpp index 702d29ec..6a4467d3 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -91,6 +91,7 @@ void Project::initSignals() { void Project::set_root(QString dir) { this->root = dir; + this->importExportPath = dir; this->parser.set_root(dir); } @@ -2608,3 +2609,8 @@ int Project::getMaxObjectEvents() { return Project::max_object_events; } + +void Project::setImportExportPath(QString filename) +{ + this->importExportPath = QFileInfo(filename).absolutePath(); +} diff --git a/src/ui/mapimageexporter.cpp b/src/ui/mapimageexporter.cpp index a54b72a3..e2bdbee4 100644 --- a/src/ui/mapimageexporter.cpp +++ b/src/ui/mapimageexporter.cpp @@ -64,12 +64,13 @@ void MapImageExporter::saveImage() { } QString defaultFilepath = QString("%1/%2.%3") - .arg(editor->project->root) + .arg(editor->project->importExportPath) .arg(defaultFilename) .arg(this->mode == ImageExporterMode::Timelapse ? "gif" : "png"); QString filter = this->mode == ImageExporterMode::Timelapse ? "Image Files (*.gif)" : "Image Files (*.png *.jpg *.bmp)"; QString filepath = QFileDialog::getSaveFileName(this, title, defaultFilepath, filter); if (!filepath.isEmpty()) { + editor->project->setImportExportPath(filepath); switch (this->mode) { case ImageExporterMode::Normal: this->preview.save(filepath); diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index 3907a591..a674b4e7 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -384,12 +384,12 @@ void PaletteEditor::on_actionImport_Palette_triggered() QString filepath = QFileDialog::getOpenFileName( this, QString("Import Tileset Palette"), - this->project->root, + this->project->importExportPath, "Palette Files (*.pal *.act *tpl *gpl)"); if (filepath.isEmpty()) { return; } - + this->project->setImportExportPath(filepath); bool error = false; QList palette = PaletteUtil::parse(filepath, &error); if (error) { diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index cf6203cb..52859bf0 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -620,12 +620,12 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) { QString filepath = QFileDialog::getOpenFileName( this, QString("Import %1 Tileset Tiles Image").arg(descriptorCaps), - this->project->root, + this->project->importExportPath, "Image Files (*.png *.bmp *.jpg *.dib)"); if (filepath.isEmpty()) { return; } - + this->project->setImportExportPath(filepath); logInfo(QString("Importing %1 tileset tiles '%2'").arg(descriptor).arg(filepath)); // Read image data from buffer so that the built-in QImage doesn't try to detect file format @@ -681,12 +681,12 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) { QString filepath = QFileDialog::getOpenFileName( this, QString("Select Palette for Tiles Image").arg(descriptorCaps), - this->project->root, + this->project->importExportPath, "Palette Files (*.pal *.act *tpl *gpl)"); if (filepath.isEmpty()) { return; } - + this->project->setImportExportPath(filepath); bool error = false; QList palette = PaletteUtil::parse(filepath, &error); if (error) { @@ -916,9 +916,10 @@ void TilesetEditor::pasteMetatile(const Metatile * toPaste) void TilesetEditor::on_actionExport_Primary_Tiles_Image_triggered() { QString defaultName = QString("%1_Tiles_Pal%2").arg(this->primaryTileset->name).arg(this->paletteId); - QString defaultFilepath = QString("%1/%2.png").arg(this->project->root).arg(defaultName); + QString defaultFilepath = QString("%1/%2.png").arg(this->project->importExportPath).arg(defaultName); QString filepath = QFileDialog::getSaveFileName(this, "Export Primary Tiles Image", defaultFilepath, "Image Files (*.png)"); if (!filepath.isEmpty()) { + this->project->setImportExportPath(filepath); QImage image = this->tileSelector->buildPrimaryTilesIndexedImage(); exportIndexed4BPPPng(image, filepath); } @@ -927,9 +928,10 @@ void TilesetEditor::on_actionExport_Primary_Tiles_Image_triggered() void TilesetEditor::on_actionExport_Secondary_Tiles_Image_triggered() { QString defaultName = QString("%1_Tiles_Pal%2").arg(this->secondaryTileset->name).arg(this->paletteId); - QString defaultFilepath = QString("%1/%2.png").arg(this->project->root).arg(defaultName); + QString defaultFilepath = QString("%1/%2.png").arg(this->project->importExportPath).arg(defaultName); QString filepath = QFileDialog::getSaveFileName(this, "Export Secondary Tiles Image", defaultFilepath, "Image Files (*.png)"); if (!filepath.isEmpty()) { + this->project->setImportExportPath(filepath); QImage image = this->tileSelector->buildSecondaryTilesIndexedImage(); exportIndexed4BPPPng(image, filepath); } @@ -938,9 +940,10 @@ void TilesetEditor::on_actionExport_Secondary_Tiles_Image_triggered() void TilesetEditor::on_actionExport_Primary_Metatiles_Image_triggered() { QString defaultName = QString("%1_Metatiles").arg(this->primaryTileset->name); - QString defaultFilepath = QString("%1/%2.png").arg(this->project->root).arg(defaultName); + QString defaultFilepath = QString("%1/%2.png").arg(this->project->importExportPath).arg(defaultName); QString filepath = QFileDialog::getSaveFileName(this, "Export Primary Metatiles Image", defaultFilepath, "Image Files (*.png)"); if (!filepath.isEmpty()) { + this->project->setImportExportPath(filepath); QImage image = this->metatileSelector->buildPrimaryMetatilesImage(); image.save(filepath, "PNG"); } @@ -949,9 +952,10 @@ void TilesetEditor::on_actionExport_Primary_Metatiles_Image_triggered() void TilesetEditor::on_actionExport_Secondary_Metatiles_Image_triggered() { QString defaultName = QString("%1_Metatiles").arg(this->secondaryTileset->name); - QString defaultFilepath = QString("%1/%2.png").arg(this->project->root).arg(defaultName); + QString defaultFilepath = QString("%1/%2.png").arg(this->project->importExportPath).arg(defaultName); QString filepath = QFileDialog::getSaveFileName(this, "Export Secondary Metatiles Image", defaultFilepath, "Image Files (*.png)"); if (!filepath.isEmpty()) { + this->project->setImportExportPath(filepath); QImage image = this->metatileSelector->buildSecondaryMetatilesImage(); image.save(filepath, "PNG"); } @@ -975,12 +979,12 @@ void TilesetEditor::importTilesetMetatiles(Tileset *tileset, bool primary) QString filepath = QFileDialog::getOpenFileName( this, QString("Import %1 Tileset Metatiles from Advance Map 1.92").arg(descriptorCaps), - this->project->root, + this->project->importExportPath, "Advance Map 1.92 Metatile Files (*.bvd)"); if (filepath.isEmpty()) { return; } - + this->project->setImportExportPath(filepath); bool error = false; QList metatiles = MetatileParser::parse(filepath, &error, primary); if (error) {