mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-25 16:13:54 -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_tip_of_the_day.cpp
|
||||||
src/dialogs/dlg_update.cpp
|
src/dialogs/dlg_update.cpp
|
||||||
src/dialogs/dlg_view_log.cpp
|
src/dialogs/dlg_view_log.cpp
|
||||||
|
src/dialogs/dlg_load_deck.cpp
|
||||||
src/game/filters/filter_string.cpp
|
src/game/filters/filter_string.cpp
|
||||||
src/game/filters/filter_builder.cpp
|
src/game/filters/filter_builder.cpp
|
||||||
src/game/filters/filter_tree.cpp
|
src/game/filters/filter_tree.cpp
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "../../client/ui/widgets/cards/card_info_frame_widget.h"
|
#include "../../client/ui/widgets/cards/card_info_frame_widget.h"
|
||||||
#include "../../deck/deck_list_model.h"
|
#include "../../deck/deck_list_model.h"
|
||||||
#include "../../deck/deck_stats_interface.h"
|
#include "../../deck/deck_stats_interface.h"
|
||||||
|
#include "../../dialogs/dlg_load_deck.h"
|
||||||
#include "../../dialogs/dlg_load_deck_from_clipboard.h"
|
#include "../../dialogs/dlg_load_deck_from_clipboard.h"
|
||||||
#include "../../game/cards/card_database_manager.h"
|
#include "../../game/cards/card_database_manager.h"
|
||||||
#include "../../game/cards/card_database_model.h"
|
#include "../../game/cards/card_database_model.h"
|
||||||
|
|
@ -927,9 +928,7 @@ void TabDeckEditor::actLoadDeck()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileDialog dialog(this, tr("Load deck"));
|
DlgLoadDeck dialog(this);
|
||||||
dialog.setDirectory(SettingsCache::instance().getDeckPath());
|
|
||||||
dialog.setNameFilters(DeckLoader::fileNameFilters);
|
|
||||||
if (!dialog.exec())
|
if (!dialog.exec())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../../deck/deck_loader.h"
|
#include "../../deck/deck_loader.h"
|
||||||
#include "../../deck/deck_view.h"
|
#include "../../deck/deck_view.h"
|
||||||
#include "../../dialogs/dlg_create_game.h"
|
#include "../../dialogs/dlg_create_game.h"
|
||||||
|
#include "../../dialogs/dlg_load_deck.h"
|
||||||
#include "../../dialogs/dlg_load_remote_deck.h"
|
#include "../../dialogs/dlg_load_remote_deck.h"
|
||||||
#include "../../dialogs/dlg_manage_sets.h"
|
#include "../../dialogs/dlg_manage_sets.h"
|
||||||
#include "../../game/board/arrow_item.h"
|
#include "../../game/board/arrow_item.h"
|
||||||
|
|
@ -288,9 +289,7 @@ void TabGame::refreshShortcuts()
|
||||||
|
|
||||||
void DeckViewContainer::loadLocalDeck()
|
void DeckViewContainer::loadLocalDeck()
|
||||||
{
|
{
|
||||||
QFileDialog dialog(this, tr("Load deck"));
|
DlgLoadDeck dialog(this);
|
||||||
dialog.setDirectory(SettingsCache::instance().getDeckPath());
|
|
||||||
dialog.setNameFilters(DeckLoader::fileNameFilters);
|
|
||||||
if (!dialog.exec())
|
if (!dialog.exec())
|
||||||
return;
|
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");
|
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");
|
||||||
}
|
}
|
||||||
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue