Merge pull request #495 from GriffinRichards/keep-import-path

Preserve import/export path in file dialogs
This commit is contained in:
t 2023-01-16 14:19:31 -05:00 committed by GitHub
commit d29506d755
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 16 deletions

View file

@ -14,6 +14,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
### Changed
- Hovering on border metatiles with the mouse will now display their information in the bottom bar.
- The last-used directory is now preserved in import/export file dialogs.
### Fixed
- Fix the Region Map Editor being opened by the Shortcuts Editor.

View file

@ -83,6 +83,7 @@ public:
QFileSystemWatcher fileWatcher;
QMap<QString, qint64> 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();

View file

@ -2409,12 +2409,12 @@ void MainWindow::importMapFromAdvanceMap1_92()
QString filepath = QFileDialog::getOpenFileName(
this,
QString("Import Map from Advance Map 1.92"),
this->editor->project->root,
this->editor->project->importExportPath,
"Advance Map 1.92 Map Files (*.map)");
if (filepath.isEmpty()) {
return;
}
this->editor->project->setImportExportPath(filepath);
MapParser parser;
bool error = false;
MapLayout *mapLayout = parser.parse(filepath, &error, editor->project);

View file

@ -91,6 +91,7 @@ void Project::initSignals() {
void Project::set_root(QString dir) {
this->root = dir;
this->importExportPath = dir;
this->parser.set_root(dir);
}
@ -2552,3 +2553,8 @@ int Project::getMaxObjectEvents()
{
return Project::max_object_events;
}
void Project::setImportExportPath(QString filename)
{
this->importExportPath = QFileInfo(filename).absolutePath();
}

View file

@ -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);

View file

@ -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<QRgb> palette = PaletteUtil::parse(filepath, &error);
if (error) {

View file

@ -34,7 +34,9 @@ QString RegionMapPropertiesDialog::browse(QString filter, QFileDialog::FileMode
if (!this->project) return QString();
QFileDialog browser;
browser.setFileMode(mode);
QString filepath = browser.getOpenFileName(this, "Select a File", this->project->root, filter);
QString filepath = browser.getOpenFileName(this, "Select a File", this->project->importExportPath, filter);
if (!filepath.isEmpty())
this->project->setImportExportPath(filepath);
// remove the project root from the filepath
return filepath.replace(this->project->root + "/", "");

View file

@ -626,12 +626,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
@ -687,12 +687,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<QRgb> palette = PaletteUtil::parse(filepath, &error);
if (error) {
@ -922,9 +922,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);
}
@ -933,9 +934,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);
}
@ -944,9 +946,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");
}
@ -955,9 +958,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");
}
@ -981,12 +985,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<Metatile*> metatiles = MetatileParser::parse(filepath, &error, primary);
if (error) {