mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add a new 'add&keep' button to add cards
This commit is contained in:
parent
f1a88e4fdd
commit
ab3a84b984
1 changed files with 29 additions and 19 deletions
|
@ -10,7 +10,8 @@ import anki
|
||||||
from anki.facts import Fact
|
from anki.facts import Fact
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
from anki.utils import stripHTML, parseTags
|
from anki.utils import stripHTML, parseTags
|
||||||
from aqt.utils import saveGeom, restoreGeom, showWarning, askUser
|
from aqt.utils import saveGeom, restoreGeom, showWarning, askUser, shortcut, \
|
||||||
|
tooltip
|
||||||
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, isMac
|
from anki.utils import stripHTMLMedia, isMac
|
||||||
|
@ -53,32 +54,33 @@ class AddCards(QDialog):
|
||||||
aqt.openHelp("AddItems")
|
aqt.openHelp("AddItems")
|
||||||
|
|
||||||
def setupButtons(self):
|
def setupButtons(self):
|
||||||
|
bb = self.form.buttonBox
|
||||||
|
ar = QDialogButtonBox.ActionRole
|
||||||
# add
|
# add
|
||||||
self.addButton = QPushButton(_("Add"))
|
self.addButton = bb.addButton(_("Add"), ar)
|
||||||
self.form.buttonBox.addButton(self.addButton,
|
self.addButton.setShortcut(QKeySequence("Ctrl+Return"))
|
||||||
QDialogButtonBox.ActionRole)
|
self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)")))
|
||||||
self.addButton.setShortcut(_("Ctrl+Return"))
|
|
||||||
if isMac:
|
|
||||||
self.addButton.setToolTip(_("Add (shortcut: command+return)"))
|
|
||||||
else:
|
|
||||||
self.addButton.setToolTip(_("Add (shortcut: ctrl+return)"))
|
|
||||||
s = QShortcut(QKeySequence(_("Ctrl+Enter")), self)
|
|
||||||
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)
|
||||||
|
# add+keep
|
||||||
|
self.addKeepButton = bb.addButton(_("Add&&Keep"), ar)
|
||||||
|
self.addKeepButton.setShortcut(_("Ctrl+Shift+Return"))
|
||||||
|
self.addKeepButton.setToolTip(shortcut(
|
||||||
|
_("Add and keep entered text (shortcut: ctrl+shift+enter)")))
|
||||||
|
self.connect(self.addKeepButton, SIGNAL("clicked()"), self.addKeep)
|
||||||
# close
|
# close
|
||||||
self.closeButton = QPushButton(_("Close"))
|
self.closeButton = QPushButton(_("Close"))
|
||||||
self.closeButton.setAutoDefault(False)
|
self.closeButton.setAutoDefault(False)
|
||||||
self.form.buttonBox.addButton(self.closeButton,
|
bb.addButton(self.closeButton,
|
||||||
QDialogButtonBox.RejectRole)
|
QDialogButtonBox.RejectRole)
|
||||||
# help
|
# help
|
||||||
self.helpButton = QPushButton(_("Help"))
|
self.helpButton = QPushButton(_("Help"))
|
||||||
self.helpButton.setAutoDefault(False)
|
self.helpButton.setAutoDefault(False)
|
||||||
self.form.buttonBox.addButton(self.helpButton,
|
bb.addButton(self.helpButton,
|
||||||
QDialogButtonBox.HelpRole)
|
QDialogButtonBox.HelpRole)
|
||||||
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
|
self.connect(self.helpButton, SIGNAL("clicked()"), self.helpRequested)
|
||||||
# history
|
# history
|
||||||
b = self.form.buttonBox.addButton(
|
b = bb.addButton(
|
||||||
_("History")+ u'▼', QDialogButtonBox.ActionRole)
|
_("History")+ u'▼', ar)
|
||||||
self.connect(b, SIGNAL("clicked()"), self.onHistory)
|
self.connect(b, SIGNAL("clicked()"), self.onHistory)
|
||||||
b.setEnabled(False)
|
b.setEnabled(False)
|
||||||
self.historyButton = b
|
self.historyButton = b
|
||||||
|
@ -93,12 +95,13 @@ class AddCards(QDialog):
|
||||||
self.editor.setFact(f)
|
self.editor.setFact(f)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def onReset(self, model=None):
|
def onReset(self, model=None, keep=False):
|
||||||
oldFact = self.editor.fact
|
oldFact = self.editor.fact
|
||||||
fact = self.setupNewFact(set=False)
|
fact = self.setupNewFact(set=False)
|
||||||
# copy fields from old fact
|
# copy fields from old fact
|
||||||
if oldFact:
|
if oldFact:
|
||||||
self.removeTempFact(oldFact)
|
if not keep:
|
||||||
|
self.removeTempFact(oldFact)
|
||||||
for n in range(len(fact.fields)):
|
for n in range(len(fact.fields)):
|
||||||
try:
|
try:
|
||||||
fact.fields[n] = oldFact.fields[n]
|
fact.fields[n] = oldFact.fields[n]
|
||||||
|
@ -147,15 +150,22 @@ question or answer on all cards."""), help="AddItems")
|
||||||
# FIXME: return to overview on add?
|
# FIXME: return to overview on add?
|
||||||
return fact
|
return fact
|
||||||
|
|
||||||
def addCards(self):
|
def addKeep(self):
|
||||||
|
self.addCards(keep=True)
|
||||||
|
|
||||||
|
def addCards(self, keep=False):
|
||||||
self.editor.saveNow()
|
self.editor.saveNow()
|
||||||
fact = self.editor.fact
|
fact = self.editor.fact
|
||||||
fact = self.addFact(fact)
|
fact = self.addFact(fact)
|
||||||
if not fact:
|
if not fact:
|
||||||
return
|
return
|
||||||
|
tooltip("Added", period=500)
|
||||||
# stop anything playing
|
# stop anything playing
|
||||||
clearAudioQueue()
|
clearAudioQueue()
|
||||||
self.setupNewFact()
|
if keep:
|
||||||
|
self.onReset(keep=True)
|
||||||
|
else:
|
||||||
|
self.setupNewFact()
|
||||||
self.mw.deck.autosave()
|
self.mw.deck.autosave()
|
||||||
|
|
||||||
def keyPressEvent(self, evt):
|
def keyPressEvent(self, evt):
|
||||||
|
|
Loading…
Reference in a new issue