mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 14:17:13 -05:00
Merge pull request #280 from Arthur-Milchior/CorrectBranchInCardPreview
Correct Deck in card preview
This commit is contained in:
commit
3f72978535
3 changed files with 17 additions and 9 deletions
|
|
@ -417,7 +417,7 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""",
|
||||||
# type 0 - when previewing in add dialog, only non-empty
|
# type 0 - when previewing in add dialog, only non-empty
|
||||||
# type 1 - when previewing edit, only existing
|
# type 1 - when previewing edit, only existing
|
||||||
# type 2 - when previewing in models dialog, all templates
|
# type 2 - when previewing in models dialog, all templates
|
||||||
def previewCards(self, note, type=0):
|
def previewCards(self, note, type=0, did = None):
|
||||||
if type == 0:
|
if type == 0:
|
||||||
cms = self.findTemplates(note)
|
cms = self.findTemplates(note)
|
||||||
elif type == 1:
|
elif type == 1:
|
||||||
|
|
@ -428,19 +428,23 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""",
|
||||||
return []
|
return []
|
||||||
cards = []
|
cards = []
|
||||||
for template in cms:
|
for template in cms:
|
||||||
cards.append(self._newCard(note, template, 1, flush=False))
|
cards.append(self._newCard(note, template, 1, flush=False, did = did))
|
||||||
return cards
|
return cards
|
||||||
|
|
||||||
def _newCard(self, note, template, due, flush=True):
|
def _newCard(self, note, template, due, did = None, flush=True):
|
||||||
"Create a new card."
|
"Create a new card."
|
||||||
card = anki.cards.Card(self)
|
card = anki.cards.Card(self)
|
||||||
card.nid = note.id
|
card.nid = note.id
|
||||||
card.ord = template['ord']
|
card.ord = template['ord']
|
||||||
# Use template did (deck override) if valid, otherwise model did
|
card.did = self.db.scalar("select did from cards where nid = ? and ord = ?", card.nid, card.ord)
|
||||||
if template['did'] and str(template['did']) in self.decks.decks:
|
# Use template did (deck override) if valid, otherwise did in argument, otherwise model did
|
||||||
card.did = template['did']
|
if not card.did:
|
||||||
else:
|
if template['did'] and str(template['did']) in self.decks.decks:
|
||||||
card.did = note.model()['did']
|
card.did = template['did']
|
||||||
|
elif did:
|
||||||
|
card.did = did
|
||||||
|
else:
|
||||||
|
card.did = note.model()['did']
|
||||||
# if invalid did, use default instead
|
# if invalid did, use default instead
|
||||||
deck = self.decks.get(card.did)
|
deck = self.decks.get(card.did)
|
||||||
if deck['dyn']:
|
if deck['dyn']:
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ system. It's free and open source.")
|
||||||
"黃文龍",
|
"黃文龍",
|
||||||
"David Bailey",
|
"David Bailey",
|
||||||
"Arman High",
|
"Arman High",
|
||||||
|
"Arthur Milchior",
|
||||||
))
|
))
|
||||||
|
|
||||||
abouttext += '<p>' + _("Written by Damien Elmes, with patches, translation,\
|
abouttext += '<p>' + _("Written by Damien Elmes, with patches, translation,\
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,10 @@ class CardLayout(QDialog):
|
||||||
self.setFocus()
|
self.setFocus()
|
||||||
|
|
||||||
def redraw(self):
|
def redraw(self):
|
||||||
self.cards = self.col.previewCards(self.note, 2)
|
did = None
|
||||||
|
if hasattr(self.parent,"deckChooser"):
|
||||||
|
did = self.parent.deckChooser.selectedId()
|
||||||
|
self.cards = self.col.previewCards(self.note, 2, did = did)
|
||||||
idx = self.ord
|
idx = self.ord
|
||||||
if idx >= len(self.cards):
|
if idx >= len(self.cards):
|
||||||
self.ord = len(self.cards) - 1
|
self.ord = len(self.cards) - 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue