From 86a4b130ff52ce2c6f75326e98c098b1bf04bf98 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:59:34 -0800 Subject: [PATCH] don't open deck in new tab if current tab is blank (#5169) --- cockatrice/src/client/tabs/tab_deck_editor.cpp | 13 +++++++++++-- cockatrice/src/client/tabs/tab_deck_editor.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index ffc93e607..79f82ebc2 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -783,7 +783,7 @@ void TabDeckEditor::actNewDeck() void TabDeckEditor::actLoadDeck() { - bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab(); + bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab() && !isBlankNewDeck(); if (!openInNewTab && !confirmClose()) return; @@ -876,7 +876,7 @@ bool TabDeckEditor::actSaveDeckAs() void TabDeckEditor::actLoadDeckFromClipboard() { - bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab(); + bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab() && !isBlankNewDeck(); if (!openInNewTab && !confirmClose()) return; @@ -985,6 +985,15 @@ void TabDeckEditor::recursiveExpand(const QModelIndex &index) deckView->expand(index); } +/** + * @brief Returns true if this tab is a blank newly opened tab, as if it was just created with the `New Deck` action. + */ +bool TabDeckEditor::isBlankNewDeck() const +{ + DeckLoader *const deck = deckModel->getDeckList(); + return !modified && deck->getLastFileName().isEmpty() && deck->getLastRemoteDeckId() == -1; +} + CardInfoPtr TabDeckEditor::currentCardInfo() const { const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex(); diff --git a/cockatrice/src/client/tabs/tab_deck_editor.h b/cockatrice/src/client/tabs/tab_deck_editor.h index 48e400ce7..b8c45c110 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.h +++ b/cockatrice/src/client/tabs/tab_deck_editor.h @@ -100,6 +100,7 @@ private slots: void showSearchSyntaxHelp(); private: + bool isBlankNewDeck() const; CardInfoPtr currentCardInfo() const; void addCardHelper(QString zoneName); void offsetCountAtIndex(const QModelIndex &idx, int offset);