From c437a384468b480f3512d1006580a0abd826bb52 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 11 Apr 2013 14:02:01 +0900 Subject: [PATCH] move card type deletion back to X on card tabs --- anki/models.py | 5 +++++ aqt/clayout.py | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/anki/models.py b/anki/models.py index 8cd645d06..0099422bf 100644 --- a/anki/models.py +++ b/anki/models.py @@ -196,6 +196,11 @@ select id from cards where nid in (select id from notes where mid = ?)""", return self.col.db.scalar( "select count() from notes where mid = ?", m['id']) + def tmplUseCount(self, m, ord): + return self.col.db.scalar(""" +select count() from cards, notes where cards.nid = notes.id +and notes.mid = ? and cards.ord = ?""", m['id'], ord) + # Copying ################################################## diff --git a/aqt/clayout.py b/aqt/clayout.py index 5630ee075..8ceb9385b 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -58,6 +58,7 @@ class CardLayout(QDialog): c = self.connect cloze = self.model['type'] == MODEL_CLOZE self.tabs = QTabWidget() + self.tabs.setTabsClosable(not cloze) self.tabs.setUsesScrollButtons(True) if not cloze: add = QPushButton("+") @@ -66,6 +67,7 @@ class CardLayout(QDialog): c(add, SIGNAL("clicked()"), self.onAddCard) self.tabs.setCornerWidget(add) c(self.tabs, SIGNAL("currentChanged(int)"), self.selectCard) + c(self.tabs, SIGNAL("tabCloseRequested(int)"), self.onRemoveTab) def updateTabs(self): self.forms = [] @@ -127,8 +129,12 @@ class CardLayout(QDialog): def onRemoveTab(self, idx): if len(self.model['tmpls']) < 2: - return showInfo(_("At least one card is required.")) - if not askUser(_("Remove all cards of this type?")): + return showInfo(_("At least one card type is required.")) + cards = self.mm.tmplUseCount(self.model, idx) + cards = ngettext("%d card", "%d cards", cards) % cards + msg = _("Delete the '%s' card type, and its %s?" % + (self.model['tmpls'][idx]['name'], cards)) + if not askUser(msg): return if not self.mm.remTemplate(self.model, self.cards[idx].template()): return showWarning(_("""\ @@ -320,10 +326,6 @@ adjust the template manually to switch the question and answer.""")) a = m.addAction(_("Browser Appearance")) a.connect(a, SIGNAL("triggered()"), self.onBrowserDisplay) - if self.model['type'] != MODEL_CLOZE: - a = m.addAction(_("Delete")) - a.connect(a, SIGNAL("triggered()"), - lambda: self.onRemoveTab(self.tabs.currentIndex())) m.exec_(button.mapToGlobal(QPoint(0,0))) def onBrowserDisplay(self):