Sort decks according to their paths

Currently it's sorted alphabetically. Because of this, "A::B" appears
between "A9" and "AA" in list of decks.
This commit is contained in:
Arthur Milchior 2020-04-06 22:23:31 +02:00
parent 77741977a1
commit 5d55c4cda2
2 changed files with 11 additions and 4 deletions

View File

@ -5,7 +5,6 @@ from __future__ import annotations
import copy
import json
import operator
import unicodedata
from typing import Any, Dict, List, Optional, Set, Tuple, Union
@ -298,6 +297,10 @@ class DeckManager:
def _basename(self, name: str) -> Any:
return self._path(name)[-1]
@classmethod
def key(cls, deck: Dict[str, Any]) -> List[str]:
return cls._path(deck["name"])
def _ensureParents(self, name: str) -> Any:
"Ensure parents exist, and return name with case matching parents."
s = ""
@ -455,7 +458,7 @@ class DeckManager:
def _checkDeckTree(self) -> None:
decks = self.col.decks.all()
decks.sort(key=operator.itemgetter("name"))
decks.sort(key=self.key)
names: Set[str] = set()
for deck in decks:
@ -571,7 +574,7 @@ class DeckManager:
childMap = {}
# go through all decks, sorted by name
for deck in sorted(self.all(), key=operator.itemgetter("name")):
for deck in sorted(self.all(), key=self.key):
node: Dict[int, Any] = {}
childMap[deck["id"]] = node

View File

@ -3,6 +3,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import aqt
from anki.decks import DeckManager
from anki.lang import _
from aqt import gui_hooks
from aqt.qt import *
@ -51,7 +52,10 @@ class StudyDeck(QDialog):
if title:
self.setWindowTitle(title)
if not names:
names = sorted(self.mw.col.decks.allNames(dyn=dyn, force_default=False))
names = sorted(
self.mw.col.decks.allNames(dyn=dyn, force_default=False),
key=DeckManager._path,
)
self.nameFunc = None
self.origNames = names
else: