[DeckEditor] Offer .cod conversion when tagging non-.cod decks

When the user tags a deck loaded from a .txt file, prompt for
conversion to the Cockatrice format (sharing the deck preview prompt)
and convert the deck in place via DeckLoader::convertToCockatriceFormat,
updating lastLoadInfo so the deck saves as .cod.


Took 2 minutes
This commit is contained in:
Lukas Brübach 2026-08-13 14:30:52 +02:00
parent 9f00ab6a11
commit 48a737d565
2 changed files with 28 additions and 0 deletions

View file

@ -2,6 +2,8 @@
#include "../../../client/settings/cache_settings.h"
#include "../../../client/settings/shortcuts_settings.h"
#include "../../deck_loader/deck_loader.h"
#include "../dialogs/dlg_convert_deck_to_cod_format.h"
#include "../settings_page/user_interface_settings_page.h"
#include "../tabs/api/commander_spellbook/commander_bracket_widget.h"
#include "deck_list_style_proxy.h"
@ -176,6 +178,23 @@ void DeckEditorDeckDockWidget::createDeckDock()
connect(deckTagsDisplayWidget, &DeckPreviewDeckTagsDisplayWidget::tagsChanged, deckStateManager,
&DeckStateManager::setTags);
// Local deck files in non-Cockatrice formats (e.g. .txt) can't store tags.
// Offer to convert the file to .cod before the user opens the tag dialog.
deckTagsDisplayWidget->setConversionPromptHandler([this] {
const LoadedDeck::LoadInfo &loadInfo = deckStateManager->getLastLoadInfo();
if (loadInfo.fileName.isEmpty()) {
return true; // A new, unsaved deck can hold tags in memory.
}
return promptFileConversionIfRequired(this, loadInfo.fileName, [this] {
LoadedDeck deck = deckStateManager->toLoadedDeck();
if (!DeckLoader::convertToCockatriceFormat(deck)) {
return false;
}
deckStateManager->setLastLoadInfo(deck.lastLoadInfo);
return true;
});
});
activeGroupCriteriaLabel = new QLabel(this);
activeGroupCriteriaComboBox = new QComboBox(this);

View file

@ -116,6 +116,15 @@ public:
*/
void clearDeck();
/**
* @brief Gets the lastLoadInfo.
* @return The lastLoadInfo
*/
const LoadedDeck::LoadInfo &getLastLoadInfo() const
{
return lastLoadInfo;
}
/**
* @brief Sets the lastLoadInfo.
* @param loadInfo The lastLoadInfo