mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-27 09:03:54 -07:00
add "open recent" menu option to deck editor tab (#5319)
* add "open recent" menu option to deck editor tab * change texts * also get it to work with loading from deck storage tab * add error message when fail to open * only update recents on successful open * only update recents on successful open * reword to "Clear"
This commit is contained in:
parent
e7585271fb
commit
4ca1fc083d
9 changed files with 130 additions and 5 deletions
|
|
@ -178,6 +178,7 @@ SettingsCache::SettingsCache()
|
|||
gameFiltersSettings = new GameFiltersSettings(settingsPath, this);
|
||||
layoutsSettings = new LayoutsSettings(settingsPath, this);
|
||||
downloadSettings = new DownloadSettings(settingsPath, this);
|
||||
recentsSettings = new RecentsSettings(settingsPath, this);
|
||||
|
||||
if (!QFile(settingsPath + "global.ini").exists())
|
||||
translateLegacySettings();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "game_filters_settings.h"
|
||||
#include "layouts_settings.h"
|
||||
#include "message_settings.h"
|
||||
#include "recents_settings.h"
|
||||
#include "servers_settings.h"
|
||||
#include "shortcuts_settings.h"
|
||||
|
||||
|
|
@ -82,6 +83,7 @@ private:
|
|||
GameFiltersSettings *gameFiltersSettings;
|
||||
LayoutsSettings *layoutsSettings;
|
||||
DownloadSettings *downloadSettings;
|
||||
RecentsSettings *recentsSettings;
|
||||
|
||||
QByteArray mainWindowGeometry;
|
||||
QByteArray tokenDialogGeometry;
|
||||
|
|
@ -598,6 +600,10 @@ public:
|
|||
{
|
||||
return *downloadSettings;
|
||||
}
|
||||
RecentsSettings &recents() const
|
||||
{
|
||||
return *recentsSettings;
|
||||
}
|
||||
bool getIsPortableBuild() const
|
||||
{
|
||||
return isPortableBuild;
|
||||
|
|
|
|||
32
cockatrice/src/settings/recents_settings.cpp
Normal file
32
cockatrice/src/settings/recents_settings.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "recents_settings.h"
|
||||
|
||||
#define MAX_RECENT_DECK_COUNT 10
|
||||
|
||||
RecentsSettings::RecentsSettings(QString settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "recents.ini", parent)
|
||||
{
|
||||
}
|
||||
|
||||
QStringList RecentsSettings::getRecentlyOpenedDeckPaths()
|
||||
{
|
||||
return getValue("deckpaths", "deckbuilder").toStringList();
|
||||
}
|
||||
void RecentsSettings::clearRecentlyOpenedDeckPaths()
|
||||
{
|
||||
deleteValue("deckpaths", "deckbuilder");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
|
||||
{
|
||||
auto deckPaths = getValue("deckpaths", "deckbuilder").toStringList();
|
||||
deckPaths.removeAll(deckPath);
|
||||
|
||||
deckPaths.prepend(deckPath);
|
||||
|
||||
while (deckPaths.size() > MAX_RECENT_DECK_COUNT) {
|
||||
deckPaths.removeLast();
|
||||
}
|
||||
|
||||
setValue(deckPaths, "deckpaths", "deckbuilder");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
23
cockatrice/src/settings/recents_settings.h
Normal file
23
cockatrice/src/settings/recents_settings.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef RECENTS_SETTINGS_H
|
||||
#define RECENTS_SETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
class RecentsSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
explicit RecentsSettings(QString settingPath, QObject *parent = nullptr);
|
||||
RecentsSettings(const RecentsSettings & /*other*/);
|
||||
|
||||
public:
|
||||
QStringList getRecentlyOpenedDeckPaths();
|
||||
void clearRecentlyOpenedDeckPaths();
|
||||
void updateRecentlyOpenedDeckPaths(const QString &deckPath);
|
||||
|
||||
signals:
|
||||
void recentlyOpenedDeckPathsChanged();
|
||||
};
|
||||
|
||||
#endif // RECENTS_SETTINGS_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue