" % node.deck_id
)
# children
if not node.collapsed:
for child in node.children:
buf += self._render_deck_node(child, ctx)
return buf
def _topLevelDragRow(self):
return "
"
# Options
##########################################################################
def _showOptions(self, did: str) -> None:
m = QMenu(self.mw)
a = m.addAction(_("Rename"))
qconnect(a.triggered, lambda b, did=did: self._rename(int(did)))
a = m.addAction(_("Options"))
qconnect(a.triggered, lambda b, did=did: self._options(did))
a = m.addAction(_("Export"))
qconnect(a.triggered, lambda b, did=did: self._export(did))
a = m.addAction(_("Delete"))
qconnect(a.triggered, lambda b, did=did: self._delete(int(did)))
gui_hooks.deck_browser_will_show_options_menu(m, int(did))
m.exec_(QCursor.pos())
def _export(self, did):
self.mw.onExport(did=did)
def _rename(self, did: int) -> None:
self.mw.checkpoint(_("Rename Deck"))
deck = self.mw.col.decks.get(did)
oldName = deck["name"]
newName = getOnlyText(_("New deck name:"), default=oldName)
newName = newName.replace('"', "")
if not newName or newName == oldName:
return
try:
self.mw.col.decks.rename(deck, newName)
gui_hooks.sidebar_should_refresh_decks()
except DeckRenameError as e:
return showWarning(e.description)
self.show()
def _options(self, did):
# select the deck first, because the dyn deck conf assumes the deck
# we're editing is the current one
self.mw.col.decks.select(did)
self.mw.onDeckConf()
def _collapse(self, did: int) -> None:
self.mw.col.decks.collapse(did)
node = self.mw.col.decks.find_deck_in_tree(self._dueTree, did)
if node:
node.collapsed = not node.collapsed
self._renderPage(reuse=True)
def _dragDeckOnto(self, draggedDeckDid, ontoDeckDid):
try:
self.mw.col.decks.renameForDragAndDrop(draggedDeckDid, ontoDeckDid)
gui_hooks.sidebar_should_refresh_decks()
except DeckRenameError as e:
return showWarning(e.description)
self.show()
def _delete(self, did):
self.mw.checkpoint(_("Delete Deck"))
deck = self.mw.col.decks.get(did)
if not deck["dyn"]:
dids = [did] + [r[1] for r in self.mw.col.decks.children(did)]
cnt = self.mw.col.db.scalar(
"select count() from cards where did in {0} or "
"odid in {0}".format(ids2str(dids))
)
if cnt:
extra = ngettext(" It has %d card.", " It has %d cards.", cnt) % cnt
else:
extra = None
if (
deck["dyn"]
or not extra
or askUser(
(_("Are you sure you wish to delete %s?") % deck["name"]) + extra
)
):
self.mw.progress.start(immediate=True)
self.mw.col.decks.rem(did, True)
self.mw.progress.finish()
self.show()
# Top buttons
######################################################################
drawLinks = [
["", "shared", _("Get Shared")],
["", "create", _("Create Deck")],
["Ctrl+I", "import", _("Import File")], # Ctrl+I works from menu
]
def _drawButtons(self):
buf = ""
drawLinks = deepcopy(self.drawLinks)
for b in drawLinks:
if b[0]:
b[0] = _("Shortcut key: %s") % shortcut(b[0])
buf += """
""" % tuple(
b
)
self.bottom.draw(
buf=buf,
link_handler=self._linkHandler,
web_context=DeckBrowserBottomBar(self),
)
def _onShared(self):
openLink(aqt.appShared + "decks/")