From abe9f50c148b3843aa9c6e4cb6a89943df85bfbd Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 21 Feb 2020 12:27:39 +1000 Subject: [PATCH] Revert "Merge pull request #452 from Arthur-Milchior/noDefaultDeckInBrowser" This reverts commit b93d30795c55343e1db14528da688462167bb540, reversing changes made to e16d6055c148dbca2e0983e1b77e1fffb92d5be7. More discussion required on https://github.com/ankitects/anki/pull/452 --- pylib/anki/decks.py | 49 +++++++-------------------------------------- qt/aqt/browser.py | 27 ++++++------------------- qt/aqt/studydeck.py | 7 +------ 3 files changed, 14 insertions(+), 69 deletions(-) diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index c683eb8d5..47696ad8a 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -92,16 +92,6 @@ defaultConf = { "usn": 0, } -# How to select list of decks - -# difference between WITHOUT_EMPTY_DEFAULT and -# WITHOUT_EMPTY_LEAF_DEFAULT is that the first contains default when -# it has a child. This is required for deck tree. - -WITHOUT_EMPTY_DEFAULT = 0 -ALL_DECKS = 1 -WITHOUT_EMPTY_LEAF_DEFAULT = 2 - class DeckManager: decks: Dict[str, Any] @@ -229,7 +219,7 @@ class DeckManager: self.select(int(list(self.decks.keys())[0])) self.save() - def allNames(self, dyn: bool = True, forceDefault: int = ALL_DECKS) -> List: + def allNames(self, dyn: bool = True, forceDefault: bool = True) -> List: "An unsorted list of all deck names." if dyn: return [x["name"] for x in self.all(forceDefault=forceDefault)] @@ -238,10 +228,14 @@ class DeckManager: x["name"] for x in self.all(forceDefault=forceDefault) if not x["dyn"] ] - def all(self, forceDefault: int = ALL_DECKS) -> List: + def all(self, forceDefault: bool = True) -> List: "A list of all decks." decks = list(self.decks.values()) - if not forceDefault and not self.shouldDefaultBeDisplayed(forceDefault): + if ( + not forceDefault + and not self.col.db.scalar("select 1 from cards where did = 1 limit 1") + and len(decks) > 1 + ): decks = [deck for deck in decks if deck["id"] != 1] return decks @@ -519,35 +513,6 @@ class DeckManager: self._recoverOrphans() self._checkDeckTree() - def shouldDeckBeDisplayed(self, deck, forceDefault: int = ALL_DECKS) -> bool: - """Whether the deck should appear in main window, browser side list, filter, deck selection... - - True, except for empty default deck without children""" - if deck["id"] != "1": - return True - return self.shouldDefaultBeDisplayed(forceDefault) - - def shouldDefaultBeDisplayed( - self, forceDefault: int = ALL_DECKS, defaultDeck=None - ) -> bool: - """Whether the default deck should appear in main window, browser side list, filter, deck selection... - - True, except for empty default deck (without children)""" - if forceDefault == ALL_DECKS: - return True - if self.col.db.scalar("select 1 from cards where did = 1 limit 1"): - return True - if len(self.decks) == 1: - return True - if forceDefault == WITHOUT_EMPTY_LEAF_DEFAULT: - if defaultDeck is None: - defaultDeck = self.get(1) - defaultName = defaultDeck["name"] - for name in self.allNames(): - if name.startswith(f"{defaultName}::"): - return True - return False - # Deck selection ############################################################# diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 239758e26..301683d95 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -21,7 +21,6 @@ from anki import hooks from anki.cards import Card from anki.collection import _Collection from anki.consts import * -from anki.decks import WITHOUT_EMPTY_DEFAULT from anki.lang import _, ngettext from anki.models import NoteType from anki.notes import Note @@ -1157,25 +1156,16 @@ by clicking on one on the left.""" def fillGroups(root, grps, head=""): for g in grps: - baseName = g[0] - did = g[1] - children = g[5] - if str(did) == "1" and not children: - if not self.mw.col.decks.shouldDefaultBeDisplayed( - WITHOUT_EMPTY_DEFAULT - ): - # No need to test for children, we know there are not - continue item = SidebarItem( - baseName, + g[0], ":/icons/deck.svg", - lambda baseName=baseName: self.setFilter("deck", head + baseName), - lambda expanded, did=did: self.mw.col.decks.collapseBrowser(did), + lambda g=g: self.setFilter("deck", head + g[0]), + lambda expanded, g=g: self.mw.col.decks.collapseBrowser(g[1]), not self.mw.col.decks.get(g[1]).get("browserCollapsed", False), ) root.addChild(item) - newhead = head + baseName + "::" - fillGroups(item, children, newhead) + newhead = head + g[0] + "::" + fillGroups(item, g[5], newhead) fillGroups(root, grps) @@ -1322,12 +1312,7 @@ by clicking on one on the left.""" subm.addSeparator() addDecks(subm, children) else: - if did != 1 or self.col.decks.shouldDefaultBeDisplayed( - WITHOUT_EMPTY_DEFAULT - # no need to check for children, we know - # there are none in this else branch - ): - parent.addItem(shortname, self._filterFunc("deck", name)) + parent.addItem(shortname, self._filterFunc("deck", name)) # fixme: could rewrite to avoid calculating due # in the future alldecks = self.col.sched.deckDueTree() diff --git a/qt/aqt/studydeck.py b/qt/aqt/studydeck.py index b0d56bcd9..8a331f5e6 100644 --- a/qt/aqt/studydeck.py +++ b/qt/aqt/studydeck.py @@ -3,7 +3,6 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import aqt -from anki.decks import WITHOUT_EMPTY_LEAF_DEFAULT from anki.lang import _ from aqt import gui_hooks from aqt.qt import * @@ -52,11 +51,7 @@ class StudyDeck(QDialog): if title: self.setWindowTitle(title) if not names: - names = sorted( - self.mw.col.decks.allNames( - dyn=dyn, forceDefault=WITHOUT_EMPTY_LEAF_DEFAULT - ) - ) + names = sorted(self.mw.col.decks.allNames(dyn=dyn, forceDefault=False)) self.nameFunc = None self.origNames = names else: