mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-27 00:53:55 -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
|
|
@ -122,6 +122,7 @@ set(cockatrice_SOURCES
|
||||||
src/settings/game_filters_settings.cpp
|
src/settings/game_filters_settings.cpp
|
||||||
src/settings/layouts_settings.cpp
|
src/settings/layouts_settings.cpp
|
||||||
src/settings/message_settings.cpp
|
src/settings/message_settings.cpp
|
||||||
|
src/settings/recents_settings.cpp
|
||||||
src/settings/servers_settings.cpp
|
src/settings/servers_settings.cpp
|
||||||
src/settings/settings_manager.cpp
|
src/settings/settings_manager.cpp
|
||||||
src/settings/cache_settings.cpp
|
src/settings/cache_settings.cpp
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,15 @@ void TabDeckEditor::createMenus()
|
||||||
aLoadDeck = new QAction(QString(), this);
|
aLoadDeck = new QAction(QString(), this);
|
||||||
connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck()));
|
connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck()));
|
||||||
|
|
||||||
|
loadRecentDeckMenu = new QMenu(this);
|
||||||
|
connect(&SettingsCache::instance().recents(), &RecentsSettings::recentlyOpenedDeckPathsChanged, this,
|
||||||
|
&TabDeckEditor::updateRecentlyOpened);
|
||||||
|
|
||||||
|
aClearRecents = new QAction(QString(), this);
|
||||||
|
connect(aClearRecents, &QAction::triggered, this, &TabDeckEditor::actClearRecents);
|
||||||
|
|
||||||
|
updateRecentlyOpened();
|
||||||
|
|
||||||
aSaveDeck = new QAction(QString(), this);
|
aSaveDeck = new QAction(QString(), this);
|
||||||
connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck()));
|
connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck()));
|
||||||
|
|
||||||
|
|
@ -342,6 +351,7 @@ void TabDeckEditor::createMenus()
|
||||||
deckMenu = new QMenu(this);
|
deckMenu = new QMenu(this);
|
||||||
deckMenu->addAction(aNewDeck);
|
deckMenu->addAction(aNewDeck);
|
||||||
deckMenu->addAction(aLoadDeck);
|
deckMenu->addAction(aLoadDeck);
|
||||||
|
deckMenu->addMenu(loadRecentDeckMenu);
|
||||||
deckMenu->addAction(aSaveDeck);
|
deckMenu->addAction(aSaveDeck);
|
||||||
deckMenu->addAction(aSaveDeckAs);
|
deckMenu->addAction(aSaveDeckAs);
|
||||||
deckMenu->addSeparator();
|
deckMenu->addSeparator();
|
||||||
|
|
@ -705,6 +715,8 @@ void TabDeckEditor::retranslateUi()
|
||||||
|
|
||||||
aNewDeck->setText(tr("&New deck"));
|
aNewDeck->setText(tr("&New deck"));
|
||||||
aLoadDeck->setText(tr("&Load deck..."));
|
aLoadDeck->setText(tr("&Load deck..."));
|
||||||
|
loadRecentDeckMenu->setTitle(tr("Load recent deck..."));
|
||||||
|
aClearRecents->setText(tr("Clear"));
|
||||||
aSaveDeck->setText(tr("&Save deck"));
|
aSaveDeck->setText(tr("&Save deck"));
|
||||||
aSaveDeckAs->setText(tr("Save deck &as..."));
|
aSaveDeckAs->setText(tr("Save deck &as..."));
|
||||||
aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard..."));
|
aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard..."));
|
||||||
|
|
@ -852,6 +864,20 @@ void TabDeckEditor::updateHash()
|
||||||
hashLabel->setText(deckModel->getDeckList()->getDeckHash());
|
hashLabel->setText(deckModel->getDeckList()->getDeckHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabDeckEditor::updateRecentlyOpened()
|
||||||
|
{
|
||||||
|
loadRecentDeckMenu->clear();
|
||||||
|
for (const auto &deckPath : SettingsCache::instance().recents().getRecentlyOpenedDeckPaths()) {
|
||||||
|
QAction *aRecentlyOpenedDeck = new QAction(deckPath, this);
|
||||||
|
loadRecentDeckMenu->addAction(aRecentlyOpenedDeck);
|
||||||
|
connect(aRecentlyOpenedDeck, &QAction::triggered, this,
|
||||||
|
[=, this] { actOpenRecent(aRecentlyOpenedDeck->text()); });
|
||||||
|
}
|
||||||
|
loadRecentDeckMenu->addSeparator();
|
||||||
|
loadRecentDeckMenu->addAction(aClearRecents);
|
||||||
|
aClearRecents->setEnabled(SettingsCache::instance().recents().getRecentlyOpenedDeckPaths().length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool TabDeckEditor::confirmClose()
|
bool TabDeckEditor::confirmClose()
|
||||||
{
|
{
|
||||||
if (modified) {
|
if (modified) {
|
||||||
|
|
@ -907,21 +933,50 @@ void TabDeckEditor::actLoadDeck()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
|
openDeckFromFile(fileName, deckOpenLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabDeckEditor::actOpenRecent(const QString &fileName)
|
||||||
|
{
|
||||||
|
auto deckOpenLocation = confirmOpen();
|
||||||
|
|
||||||
|
if (deckOpenLocation == CANCELLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openDeckFromFile(fileName, deckOpenLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually opens the deck from file
|
||||||
|
* @param fileName The path of the deck to open
|
||||||
|
* @param deckOpenLocation Which tab to open the deck
|
||||||
|
*/
|
||||||
|
void TabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation)
|
||||||
|
{
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||||
|
|
||||||
auto *l = new DeckLoader;
|
auto *l = new DeckLoader;
|
||||||
if (l->loadFromFile(fileName, fmt)) {
|
if (l->loadFromFile(fileName, fmt)) {
|
||||||
|
SettingsCache::instance().recents().updateRecentlyOpenedDeckPaths(fileName);
|
||||||
if (deckOpenLocation == NEW_TAB) {
|
if (deckOpenLocation == NEW_TAB) {
|
||||||
emit openDeckEditor(l);
|
emit openDeckEditor(l);
|
||||||
} else {
|
} else {
|
||||||
setSaveStatus(false);
|
setSaveStatus(false);
|
||||||
setDeck(l);
|
setDeck(l);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
delete l;
|
delete l;
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(fileName));
|
||||||
|
}
|
||||||
setSaveStatus(true);
|
setSaveStatus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabDeckEditor::actClearRecents()
|
||||||
|
{
|
||||||
|
SettingsCache::instance().recents().clearRecentlyOpenedDeckPaths();
|
||||||
|
}
|
||||||
|
|
||||||
void TabDeckEditor::saveDeckRemoteFinished(const Response &response)
|
void TabDeckEditor::saveDeckRemoteFinished(const Response &response)
|
||||||
{
|
{
|
||||||
if (response.response_code() != Response::RespOk)
|
if (response.response_code() != Response::RespOk)
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,12 @@ private slots:
|
||||||
void updateSearch(const QString &search);
|
void updateSearch(const QString &search);
|
||||||
void databaseCustomMenu(QPoint point);
|
void databaseCustomMenu(QPoint point);
|
||||||
void decklistCustomMenu(QPoint point);
|
void decklistCustomMenu(QPoint point);
|
||||||
|
void updateRecentlyOpened();
|
||||||
|
|
||||||
void actNewDeck();
|
void actNewDeck();
|
||||||
void actLoadDeck();
|
void actLoadDeck();
|
||||||
|
void actOpenRecent(const QString &fileName);
|
||||||
|
void actClearRecents();
|
||||||
bool actSaveDeck();
|
bool actSaveDeck();
|
||||||
bool actSaveDeckAs();
|
bool actSaveDeckAs();
|
||||||
void actLoadDeckFromClipboard();
|
void actLoadDeckFromClipboard();
|
||||||
|
|
@ -106,6 +109,7 @@ private:
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
void decrementCardHelper(QString zoneName);
|
void decrementCardHelper(QString zoneName);
|
||||||
void recursiveExpand(const QModelIndex &index);
|
void recursiveExpand(const QModelIndex &index);
|
||||||
|
void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
||||||
|
|
||||||
CardDatabaseModel *databaseModel;
|
CardDatabaseModel *databaseModel;
|
||||||
CardDatabaseDisplayModel *databaseDisplayModel;
|
CardDatabaseDisplayModel *databaseDisplayModel;
|
||||||
|
|
@ -131,10 +135,10 @@ private:
|
||||||
QWidget *filterBox;
|
QWidget *filterBox;
|
||||||
|
|
||||||
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *printingSelectorDockMenu,
|
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *printingSelectorDockMenu,
|
||||||
*analyzeDeckMenu, *saveDeckToClipboardMenu;
|
*analyzeDeckMenu, *saveDeckToClipboardMenu, *loadRecentDeckMenu;
|
||||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard,
|
QAction *aNewDeck, *aLoadDeck, *aClearRecents, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard,
|
||||||
*aSaveDeckToClipboardRaw, *aPrintDeck, *aExportDeckDecklist, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout,
|
*aSaveDeckToClipboard, *aSaveDeckToClipboardRaw, *aPrintDeck, *aExportDeckDecklist, *aAnalyzeDeckDeckstats,
|
||||||
*aClose;
|
*aAnalyzeDeckTappedout, *aClose;
|
||||||
QAction *aClearFilterAll, *aClearFilterOne;
|
QAction *aClearFilterAll, *aClearFilterOne;
|
||||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
||||||
QAction *aResetLayout;
|
QAction *aResetLayout;
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,8 @@ void TabDeckStorage::actOpenLocalDeck()
|
||||||
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat))
|
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
SettingsCache::instance().recents().updateRecentlyOpenedDeckPaths(filePath);
|
||||||
|
|
||||||
emit openDeckEditor(&deckLoader);
|
emit openDeckEditor(&deckLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,7 @@ SettingsCache::SettingsCache()
|
||||||
gameFiltersSettings = new GameFiltersSettings(settingsPath, this);
|
gameFiltersSettings = new GameFiltersSettings(settingsPath, this);
|
||||||
layoutsSettings = new LayoutsSettings(settingsPath, this);
|
layoutsSettings = new LayoutsSettings(settingsPath, this);
|
||||||
downloadSettings = new DownloadSettings(settingsPath, this);
|
downloadSettings = new DownloadSettings(settingsPath, this);
|
||||||
|
recentsSettings = new RecentsSettings(settingsPath, this);
|
||||||
|
|
||||||
if (!QFile(settingsPath + "global.ini").exists())
|
if (!QFile(settingsPath + "global.ini").exists())
|
||||||
translateLegacySettings();
|
translateLegacySettings();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "game_filters_settings.h"
|
#include "game_filters_settings.h"
|
||||||
#include "layouts_settings.h"
|
#include "layouts_settings.h"
|
||||||
#include "message_settings.h"
|
#include "message_settings.h"
|
||||||
|
#include "recents_settings.h"
|
||||||
#include "servers_settings.h"
|
#include "servers_settings.h"
|
||||||
#include "shortcuts_settings.h"
|
#include "shortcuts_settings.h"
|
||||||
|
|
||||||
|
|
@ -82,6 +83,7 @@ private:
|
||||||
GameFiltersSettings *gameFiltersSettings;
|
GameFiltersSettings *gameFiltersSettings;
|
||||||
LayoutsSettings *layoutsSettings;
|
LayoutsSettings *layoutsSettings;
|
||||||
DownloadSettings *downloadSettings;
|
DownloadSettings *downloadSettings;
|
||||||
|
RecentsSettings *recentsSettings;
|
||||||
|
|
||||||
QByteArray mainWindowGeometry;
|
QByteArray mainWindowGeometry;
|
||||||
QByteArray tokenDialogGeometry;
|
QByteArray tokenDialogGeometry;
|
||||||
|
|
@ -598,6 +600,10 @@ public:
|
||||||
{
|
{
|
||||||
return *downloadSettings;
|
return *downloadSettings;
|
||||||
}
|
}
|
||||||
|
RecentsSettings &recents() const
|
||||||
|
{
|
||||||
|
return *recentsSettings;
|
||||||
|
}
|
||||||
bool getIsPortableBuild() const
|
bool getIsPortableBuild() const
|
||||||
{
|
{
|
||||||
return isPortableBuild;
|
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
|
||||||
|
|
@ -28,6 +28,7 @@ set(oracle_SOURCES
|
||||||
../cockatrice/src/settings/servers_settings.cpp
|
../cockatrice/src/settings/servers_settings.cpp
|
||||||
../cockatrice/src/settings/settings_manager.cpp
|
../cockatrice/src/settings/settings_manager.cpp
|
||||||
../cockatrice/src/settings/message_settings.cpp
|
../cockatrice/src/settings/message_settings.cpp
|
||||||
|
../cockatrice/src/settings/recents_settings.cpp
|
||||||
../cockatrice/src/settings/game_filters_settings.cpp
|
../cockatrice/src/settings/game_filters_settings.cpp
|
||||||
../cockatrice/src/settings/layouts_settings.cpp
|
../cockatrice/src/settings/layouts_settings.cpp
|
||||||
../cockatrice/src/settings/download_settings.cpp
|
../cockatrice/src/settings/download_settings.cpp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue