mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Remember last opened directory when loading decks (#5418)
* remember last directory when loading deck * move shared code into new dlg class
This commit is contained in:
parent
9c38c9ed1b
commit
93fab3d78f
7 changed files with 61 additions and 6 deletions
|
|
@ -56,6 +56,7 @@ set(cockatrice_SOURCES
|
|||
src/dialogs/dlg_tip_of_the_day.cpp
|
||||
src/dialogs/dlg_update.cpp
|
||||
src/dialogs/dlg_view_log.cpp
|
||||
src/dialogs/dlg_load_deck.cpp
|
||||
src/game/filters/filter_string.cpp
|
||||
src/game/filters/filter_builder.cpp
|
||||
src/game/filters/filter_tree.cpp
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "../../client/ui/widgets/cards/card_info_frame_widget.h"
|
||||
#include "../../deck/deck_list_model.h"
|
||||
#include "../../deck/deck_stats_interface.h"
|
||||
#include "../../dialogs/dlg_load_deck.h"
|
||||
#include "../../dialogs/dlg_load_deck_from_clipboard.h"
|
||||
#include "../../game/cards/card_database_manager.h"
|
||||
#include "../../game/cards/card_database_model.h"
|
||||
|
|
@ -927,9 +928,7 @@ void TabDeckEditor::actLoadDeck()
|
|||
return;
|
||||
}
|
||||
|
||||
QFileDialog dialog(this, tr("Load deck"));
|
||||
dialog.setDirectory(SettingsCache::instance().getDeckPath());
|
||||
dialog.setNameFilters(DeckLoader::fileNameFilters);
|
||||
DlgLoadDeck dialog(this);
|
||||
if (!dialog.exec())
|
||||
return;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "../../deck/deck_loader.h"
|
||||
#include "../../deck/deck_view.h"
|
||||
#include "../../dialogs/dlg_create_game.h"
|
||||
#include "../../dialogs/dlg_load_deck.h"
|
||||
#include "../../dialogs/dlg_load_remote_deck.h"
|
||||
#include "../../dialogs/dlg_manage_sets.h"
|
||||
#include "../../game/board/arrow_item.h"
|
||||
|
|
@ -288,9 +289,7 @@ void TabGame::refreshShortcuts()
|
|||
|
||||
void DeckViewContainer::loadLocalDeck()
|
||||
{
|
||||
QFileDialog dialog(this, tr("Load deck"));
|
||||
dialog.setDirectory(SettingsCache::instance().getDeckPath());
|
||||
dialog.setNameFilters(DeckLoader::fileNameFilters);
|
||||
DlgLoadDeck dialog(this);
|
||||
if (!dialog.exec())
|
||||
return;
|
||||
|
||||
|
|
|
|||
22
cockatrice/src/dialogs/dlg_load_deck.cpp
Normal file
22
cockatrice/src/dialogs/dlg_load_deck.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "dlg_load_deck.h"
|
||||
|
||||
#include "../deck/deck_loader.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
|
||||
DlgLoadDeck::DlgLoadDeck(QWidget *parent) : QFileDialog(parent, tr("Load Deck"))
|
||||
{
|
||||
QString startingDir = SettingsCache::instance().recents().getLatestDeckDirPath();
|
||||
if (startingDir.isEmpty()) {
|
||||
startingDir = SettingsCache::instance().getDeckPath();
|
||||
}
|
||||
|
||||
setDirectory(startingDir);
|
||||
setNameFilters(DeckLoader::fileNameFilters);
|
||||
|
||||
connect(this, &DlgLoadDeck::accepted, this, &DlgLoadDeck::actAccepted);
|
||||
}
|
||||
|
||||
void DlgLoadDeck::actAccepted()
|
||||
{
|
||||
SettingsCache::instance().recents().setLatestDeckDirPath(directory().absolutePath());
|
||||
}
|
||||
21
cockatrice/src/dialogs/dlg_load_deck.h
Normal file
21
cockatrice/src/dialogs/dlg_load_deck.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
#ifndef DLG_LOAD_DECK_H
|
||||
#define DLG_LOAD_DECK_H
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
/**
|
||||
* The file dialog for "Load Deck" operations.
|
||||
* Handles remembering the most recently used deck loading directory.
|
||||
*/
|
||||
class DlgLoadDeck : public QFileDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
void actAccepted();
|
||||
|
||||
public:
|
||||
explicit DlgLoadDeck(QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // DLG_LOAD_DECK_H
|
||||
|
|
@ -29,4 +29,14 @@ void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
|
|||
|
||||
setValue(deckPaths, "deckpaths", "deckbuilder");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
|
||||
QString RecentsSettings::getLatestDeckDirPath()
|
||||
{
|
||||
return getValue("latestDeckDir", "dirs").toString();
|
||||
}
|
||||
|
||||
void RecentsSettings::setLatestDeckDirPath(const QString &dirPath)
|
||||
{
|
||||
setValue(dirPath, "latestDeckDir", "dirs");
|
||||
}
|
||||
|
|
@ -16,6 +16,9 @@ public:
|
|||
void clearRecentlyOpenedDeckPaths();
|
||||
void updateRecentlyOpenedDeckPaths(const QString &deckPath);
|
||||
|
||||
QString getLatestDeckDirPath();
|
||||
void setLatestDeckDirPath(const QString &dirPath);
|
||||
|
||||
signals:
|
||||
void recentlyOpenedDeckPathsChanged();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue