From 949dc9defd2956bd12c8b0450aa32fb239af9b85 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 12 Apr 2011 23:50:13 +0900 Subject: [PATCH] hide the editor when more than one card is selected --- aqt/browser.py | 45 +++++++++++++++++++++------------------------ aqt/editor.py | 2 ++ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/aqt/browser.py b/aqt/browser.py index bf18b2a92..2e8185803 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -399,10 +399,6 @@ class Browser(QMainWindow): txt = unicode(self.form.searchEdit.text()).strip() self.model.search(txt) show = not not self.model.cards - self.form.cardLabel.setShown(show) - self.form.fieldsArea.setShown(show) - if not show: - self.editor.setFact(None) def updateTitle(self): selected = len(self.form.tableView.selectionModel().selectedRows()) @@ -414,6 +410,7 @@ class Browser(QMainWindow): "tot": self.deck.cardCount(), "sel": ngettext("%d selected", "%d selected", selected) % selected } + " - " + self.deck.name()) + return selected # Table view & editor ###################################################################### @@ -424,36 +421,30 @@ class Browser(QMainWindow): self.form.tableView.setShowGrid(False) self.form.tableView.setModel(self.model) self.form.tableView.selectionModel() - self.connect(self.form.tableView.selectionModel(), - SIGNAL("selectionChanged(QItemSelection,QItemSelection)"), - self.updateTitle) self.form.tableView.setItemDelegate(StatusDelegate(self, self.model)) self.connect(self.form.tableView.selectionModel(), - SIGNAL("currentRowChanged(QModelIndex, QModelIndex)"), - self.rowChanged) + SIGNAL("selectionChanged(QItemSelection,QItemSelection)"), + self.onRowChanged) def setupEditor(self): self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea) self.editor.stealFocus = False - def rowChanged(self, current, previous): - self.currentRow = current - self.card = self.model.getCard(current) - if not self.card: - self.editor.setFact(None, True) - return - fact = self.card.fact() - self.editor.setFact(fact) - self.editor.card = self.card - self.showCardInfo(self.card) + def onRowChanged(self, current, previous): + "Update current fact and hide/show editor." + show = self.model.cards and self.updateTitle() == 1 + self.form.splitter_2.widget(1).setShown(show) + if not show: + self.editor.setFact(None) + else: + self.card = self.model.getCard( + self.form.tableView.selectionModel().currentIndex()) + self.editor.setFact(self.card.fact()) + self.editor.card = self.card + self.showCardInfo(self.card) self.updateToggles() - def cardRow(self): - try: - return self.model.cards.index(self.card.id) - except: - return -1 # Headers & sorting ###################################################################### @@ -701,6 +692,12 @@ where id in %s""" % ids2str( # Menu options ###################################################################### + def cardRow(self): + try: + return self.model.cards.index(self.card.id) + except: + return -1 + def deleteCards(self): cards = self.selectedCards() n = _("Delete Cards") diff --git a/aqt/editor.py b/aqt/editor.py index 2f20ca691..4c737c55e 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -352,6 +352,8 @@ class Editor(object): def setFact(self, fact): "Make FACT the current fact." + if self.fact and fact and self.fact.id == fact.id: + return self.fact = fact # change timer if self.fact: