remember last directory when loading deck

This commit is contained in:
RickyRister 2025-01-05 02:17:46 -08:00
parent 38e99f2e87
commit eea65a61d4
4 changed files with 31 additions and 2 deletions

View file

@ -928,11 +928,19 @@ void TabDeckEditor::actLoadDeck()
} }
QFileDialog dialog(this, tr("Load deck")); QFileDialog dialog(this, tr("Load deck"));
dialog.setDirectory(SettingsCache::instance().getDeckPath());
QString startingDir = SettingsCache::instance().recents().getLatestDeckDirPath();
if (startingDir.isEmpty()) {
startingDir = SettingsCache::instance().getDeckPath();
}
dialog.setDirectory(startingDir);
dialog.setNameFilters(DeckLoader::fileNameFilters); dialog.setNameFilters(DeckLoader::fileNameFilters);
if (!dialog.exec()) if (!dialog.exec())
return; return;
SettingsCache::instance().recents().setLatestDeckDirPath(dialog.directory().absolutePath());
QString fileName = dialog.selectedFiles().at(0); QString fileName = dialog.selectedFiles().at(0);
openDeckFromFile(fileName, deckOpenLocation); openDeckFromFile(fileName, deckOpenLocation);
} }

View file

@ -289,11 +289,19 @@ void TabGame::refreshShortcuts()
void DeckViewContainer::loadLocalDeck() void DeckViewContainer::loadLocalDeck()
{ {
QFileDialog dialog(this, tr("Load deck")); QFileDialog dialog(this, tr("Load deck"));
dialog.setDirectory(SettingsCache::instance().getDeckPath());
QString startingDir = SettingsCache::instance().recents().getLatestDeckDirPath();
if (startingDir.isEmpty()) {
startingDir = SettingsCache::instance().getDeckPath();
}
dialog.setDirectory(startingDir);
dialog.setNameFilters(DeckLoader::fileNameFilters); dialog.setNameFilters(DeckLoader::fileNameFilters);
if (!dialog.exec()) if (!dialog.exec())
return; return;
SettingsCache::instance().recents().setLatestDeckDirPath(dialog.directory().absolutePath());
loadDeckFromFile(dialog.selectedFiles().at(0)); loadDeckFromFile(dialog.selectedFiles().at(0));
} }

View file

@ -29,4 +29,14 @@ void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
setValue(deckPaths, "deckpaths", "deckbuilder"); setValue(deckPaths, "deckpaths", "deckbuilder");
emit recentlyOpenedDeckPathsChanged(); emit recentlyOpenedDeckPathsChanged();
}
QString RecentsSettings::getLatestDeckDirPath()
{
return getValue("latestDeckDir", "dirs").toString();
}
void RecentsSettings::setLatestDeckDirPath(const QString &dirPath)
{
setValue(dirPath, "latestDeckDir", "dirs");
} }

View file

@ -16,6 +16,9 @@ public:
void clearRecentlyOpenedDeckPaths(); void clearRecentlyOpenedDeckPaths();
void updateRecentlyOpenedDeckPaths(const QString &deckPath); void updateRecentlyOpenedDeckPaths(const QString &deckPath);
QString getLatestDeckDirPath();
void setLatestDeckDirPath(const QString &dirPath);
signals: signals:
void recentlyOpenedDeckPathsChanged(); void recentlyOpenedDeckPathsChanged();
}; };