mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add cards history
This commit is contained in:
parent
236a1ed930
commit
82ad8d88f8
2 changed files with 33 additions and 19 deletions
|
@ -12,6 +12,7 @@ from anki.utils import stripHTML, parseTags
|
||||||
from aqt.utils import saveGeom, restoreGeom, showWarning, askUser
|
from aqt.utils import saveGeom, restoreGeom, showWarning, askUser
|
||||||
from anki.sound import clearAudioQueue
|
from anki.sound import clearAudioQueue
|
||||||
from anki.hooks import addHook, removeHook
|
from anki.hooks import addHook, removeHook
|
||||||
|
from anki.utils import stripHTMLMedia
|
||||||
import aqt.editor, aqt.modelchooser
|
import aqt.editor, aqt.modelchooser
|
||||||
|
|
||||||
# todo:
|
# todo:
|
||||||
|
@ -33,7 +34,7 @@ class AddCards(QDialog):
|
||||||
self.setupEditor()
|
self.setupEditor()
|
||||||
self.setupButtons()
|
self.setupButtons()
|
||||||
self.onReset()
|
self.onReset()
|
||||||
self.addedItems = 0
|
self.history = []
|
||||||
self.forceClose = False
|
self.forceClose = False
|
||||||
restoreGeom(self, "add")
|
restoreGeom(self, "add")
|
||||||
addHook('reset', self.onReset)
|
addHook('reset', self.onReset)
|
||||||
|
@ -51,6 +52,7 @@ class AddCards(QDialog):
|
||||||
aqt.openHelp("AddItems")
|
aqt.openHelp("AddItems")
|
||||||
|
|
||||||
def setupButtons(self):
|
def setupButtons(self):
|
||||||
|
# add
|
||||||
self.addButton = QPushButton(_("Add"))
|
self.addButton = QPushButton(_("Add"))
|
||||||
self.form.buttonBox.addButton(self.addButton,
|
self.form.buttonBox.addButton(self.addButton,
|
||||||
QDialogButtonBox.ActionRole)
|
QDialogButtonBox.ActionRole)
|
||||||
|
@ -62,21 +64,23 @@ class AddCards(QDialog):
|
||||||
s = QShortcut(QKeySequence(_("Ctrl+Enter")), self)
|
s = QShortcut(QKeySequence(_("Ctrl+Enter")), self)
|
||||||
s.connect(s, SIGNAL("activated()"), self.addButton, SLOT("click()"))
|
s.connect(s, SIGNAL("activated()"), self.addButton, SLOT("click()"))
|
||||||
self.connect(self.addButton, SIGNAL("clicked()"), self.addCards)
|
self.connect(self.addButton, SIGNAL("clicked()"), self.addCards)
|
||||||
|
# close
|
||||||
self.closeButton = QPushButton(_("Close"))
|
self.closeButton = QPushButton(_("Close"))
|
||||||
self.closeButton.setAutoDefault(False)
|
self.closeButton.setAutoDefault(False)
|
||||||
self.form.buttonBox.addButton(self.closeButton,
|
self.form.buttonBox.addButton(self.closeButton,
|
||||||
QDialogButtonBox.RejectRole)
|
QDialogButtonBox.RejectRole)
|
||||||
|
# help
|
||||||
self.helpButton = QPushButton(_("Help"))
|
self.helpButton = QPushButton(_("Help"))
|
||||||
self.helpButton.setAutoDefault(False)
|
self.helpButton.setAutoDefault(False)
|
||||||
self.form.buttonBox.addButton(self.helpButton,
|
self.form.buttonBox.addButton(self.helpButton,
|
||||||
QDialogButtonBox.HelpRole)
|
QDialogButtonBox.HelpRole)
|
||||||
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
|
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
|
||||||
|
# history
|
||||||
def onLink(self, url):
|
b = self.form.buttonBox.addButton(
|
||||||
browser = ui.dialogs.open("CardList", self.mw)
|
_("History"), QDialogButtonBox.ActionRole)
|
||||||
browser.dialog.filterEdit.setText("fid:" + url.toString())
|
self.connect(b, SIGNAL("clicked()"), self.onHistory)
|
||||||
browser.updateSearch()
|
b.setEnabled(False)
|
||||||
browser.onFact()
|
self.historyButton = b
|
||||||
|
|
||||||
# FIXME: need to make sure to clean up fact on exit
|
# FIXME: need to make sure to clean up fact on exit
|
||||||
def setupNewFact(self, set=True):
|
def setupNewFact(self, set=True):
|
||||||
|
@ -107,16 +111,26 @@ class AddCards(QDialog):
|
||||||
# we don't have to worry about cards; just the fact
|
# we don't have to worry about cards; just the fact
|
||||||
self.mw.deck._delFacts([fact.id])
|
self.mw.deck._delFacts([fact.id])
|
||||||
|
|
||||||
def reportAddedFact(self, fact):
|
def addHistory(self, fact):
|
||||||
return
|
txt = stripHTMLMedia(",".join(fact._fields))[:30]
|
||||||
self.form.status.append(
|
self.history.append((fact.id, txt))
|
||||||
_("Added %(num)d card(s) for <a href=\"%(id)d\">"
|
self.history = self.history[-15:]
|
||||||
"%(str)s</a>.") % {
|
self.historyButton.setEnabled(True)
|
||||||
"num": len(fact.cards),
|
|
||||||
"id": fact.id,
|
def onHistory(self):
|
||||||
# we're guaranteed that all fields will exist now
|
m = QMenu(self)
|
||||||
"str": stripHTML(fact[fact.fields[0].name]),
|
for fid, txt in self.history:
|
||||||
})
|
a = m.addAction(_("Edit %s" % txt))
|
||||||
|
a.connect(a, SIGNAL("activated()"),
|
||||||
|
lambda fid=fid: self.editHistory(fid))
|
||||||
|
m.exec_(self.historyButton.mapToGlobal(QPoint(0,0)))
|
||||||
|
|
||||||
|
def editHistory(self, fid):
|
||||||
|
print "edit", fid
|
||||||
|
# browser = ui.dialogs.open("CardList", self.mw)
|
||||||
|
# browser.dialog.filterEdit.setText("fid:" + url.toString())
|
||||||
|
# browser.updateSearch()
|
||||||
|
# browser.onFact()
|
||||||
|
|
||||||
def addFact(self, fact):
|
def addFact(self, fact):
|
||||||
if any(fact.problems()):
|
if any(fact.problems()):
|
||||||
|
@ -130,7 +144,7 @@ class AddCards(QDialog):
|
||||||
The input you have provided would make an empty
|
The input you have provided would make an empty
|
||||||
question or answer on all cards."""), help="AddItems")
|
question or answer on all cards."""), help="AddItems")
|
||||||
return
|
return
|
||||||
self.reportAddedFact(fact)
|
self.addHistory(fact)
|
||||||
# FIXME: return to overview on add?
|
# FIXME: return to overview on add?
|
||||||
return fact
|
return fact
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import time, types, sys, re
|
||||||
from operator import attrgetter, itemgetter
|
from operator import attrgetter, itemgetter
|
||||||
import anki, anki.utils, aqt.forms
|
import anki, anki.utils, aqt.forms
|
||||||
from anki.utils import fmtTimeSpan, parseTags, hasTag, addTags, delTags, \
|
from anki.utils import fmtTimeSpan, parseTags, hasTag, addTags, delTags, \
|
||||||
stripHTMLAlt, ids2str
|
ids2str
|
||||||
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
|
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
|
||||||
saveHeader, restoreHeader, saveState, restoreState, applyStyles
|
saveHeader, restoreHeader, saveState, restoreState, applyStyles
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
|
|
Loading…
Reference in a new issue