mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
allow individual fields to be marked sticky instead of adding a separate button
This commit is contained in:
parent
4a931f811f
commit
9bae1503bb
3 changed files with 37 additions and 38 deletions
|
@ -61,12 +61,6 @@ class AddCards(QDialog):
|
|||
self.addButton.setShortcut(QKeySequence("Ctrl+Return"))
|
||||
self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)")))
|
||||
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
|
||||
self.closeButton = QPushButton(_("Close"))
|
||||
self.closeButton.setAutoDefault(False)
|
||||
|
@ -98,13 +92,17 @@ class AddCards(QDialog):
|
|||
def onReset(self, model=None, keep=False):
|
||||
oldFact = self.editor.fact
|
||||
fact = self.setupNewFact(set=False)
|
||||
flds = fact.model().fields
|
||||
# copy fields from old fact
|
||||
if oldFact:
|
||||
if not keep:
|
||||
self.removeTempFact(oldFact)
|
||||
for n in range(len(fact.fields)):
|
||||
try:
|
||||
fact.fields[n] = oldFact.fields[n]
|
||||
if not keep or flds[n]['sticky']:
|
||||
fact.fields[n] = oldFact.fields[n]
|
||||
else:
|
||||
fact.fields[n] = ""
|
||||
except IndexError:
|
||||
break
|
||||
self.editor.setFact(fact)
|
||||
|
@ -150,10 +148,7 @@ question or answer on all cards."""), help="AddItems")
|
|||
# FIXME: return to overview on add?
|
||||
return fact
|
||||
|
||||
def addKeep(self):
|
||||
self.addCards(keep=True)
|
||||
|
||||
def addCards(self, keep=False):
|
||||
def addCards(self):
|
||||
self.editor.saveNow()
|
||||
fact = self.editor.fact
|
||||
fact = self.addFact(fact)
|
||||
|
@ -162,10 +157,7 @@ question or answer on all cards."""), help="AddItems")
|
|||
tooltip("Added", period=500)
|
||||
# stop anything playing
|
||||
clearAudioQueue()
|
||||
if keep:
|
||||
self.onReset(keep=True)
|
||||
else:
|
||||
self.setupNewFact()
|
||||
self.onReset(keep=True)
|
||||
self.mw.deck.autosave()
|
||||
|
||||
def keyPressEvent(self, evt):
|
||||
|
|
|
@ -277,36 +277,33 @@ class CardLayout(QDialog):
|
|||
self.fieldOrdinalUpdatedIds = []
|
||||
self.updatingFields = False
|
||||
self.needFieldRebuild = False
|
||||
self.connect(self.form.fieldList, SIGNAL("currentRowChanged(int)"),
|
||||
c = self.connect; f = self.form
|
||||
sc = SIGNAL("stateChanged(int)")
|
||||
cl = SIGNAL("clicked()")
|
||||
c(f.fieldAdd, cl, self.addField)
|
||||
c(f.fieldDelete, cl, self.deleteField)
|
||||
c(f.fieldUp, cl, self.moveFieldUp)
|
||||
c(f.fieldDown, cl, self.moveFieldDown)
|
||||
c(f.preserveWhitespace, sc, self.saveField)
|
||||
c(f.fieldUnique, sc, self.saveField)
|
||||
c(f.fieldRequired, sc, self.saveField)
|
||||
c(f.sticky, sc, self.saveField)
|
||||
c(f.fieldList, SIGNAL("currentRowChanged(int)"),
|
||||
self.fieldChanged)
|
||||
self.connect(self.form.fieldAdd, SIGNAL("clicked()"),
|
||||
self.addField)
|
||||
self.connect(self.form.fieldDelete, SIGNAL("clicked()"),
|
||||
self.deleteField)
|
||||
self.connect(self.form.fieldUp, SIGNAL("clicked()"),
|
||||
self.moveFieldUp)
|
||||
self.connect(self.form.fieldDown, SIGNAL("clicked()"),
|
||||
self.moveFieldDown)
|
||||
self.connect(self.form.fieldName, SIGNAL("lostFocus()"),
|
||||
c(f.fieldName, SIGNAL("lostFocus()"),
|
||||
self.saveField)
|
||||
self.connect(self.form.fontFamily, SIGNAL("currentFontChanged(QFont)"),
|
||||
c(f.fontFamily, SIGNAL("currentFontChanged(QFont)"),
|
||||
self.saveField)
|
||||
self.connect(self.form.fontSize, SIGNAL("valueChanged(int)"),
|
||||
c(f.fontSize, SIGNAL("valueChanged(int)"),
|
||||
self.saveField)
|
||||
self.connect(self.form.fontSizeEdit, SIGNAL("valueChanged(int)"),
|
||||
self.saveField)
|
||||
self.connect(self.form.preserveWhitespace, SIGNAL("stateChanged(int)"),
|
||||
self.saveField)
|
||||
self.connect(self.form.fieldUnique, SIGNAL("stateChanged(int)"),
|
||||
self.saveField)
|
||||
self.connect(self.form.fieldRequired, SIGNAL("stateChanged(int)"),
|
||||
c(f.fontSizeEdit, SIGNAL("valueChanged(int)"),
|
||||
self.saveField)
|
||||
w = self.form.fontColour
|
||||
if self.plastiqueStyle:
|
||||
w.setStyle(self.plastiqueStyle)
|
||||
self.connect(w, SIGNAL("clicked()"),
|
||||
c(w, SIGNAL("clicked()"),
|
||||
lambda w=w: self.chooseColour(w))
|
||||
self.connect(self.form.rtl,
|
||||
c(self.form.rtl,
|
||||
SIGNAL("stateChanged(int)"),
|
||||
self.saveField)
|
||||
|
||||
|
@ -331,6 +328,7 @@ class CardLayout(QDialog):
|
|||
f.fontColour.setPalette(QPalette(QColor(fld['qcol'])))
|
||||
f.rtl.setChecked(fld['rtl'])
|
||||
f.preserveWhitespace.setChecked(fld['pre'])
|
||||
f.sticky.setChecked(fld['sticky'])
|
||||
self.updatingFields = False
|
||||
|
||||
def saveField(self, *args):
|
||||
|
@ -353,6 +351,7 @@ class CardLayout(QDialog):
|
|||
self.form.fontColour.palette().window().color().name())
|
||||
fld['rtl'] = self.form.rtl.isChecked()
|
||||
fld['pre'] = self.form.preserveWhitespace.isChecked()
|
||||
fld['sticky'] = self.form.sticky.isChecked()
|
||||
self.updatingFields = False
|
||||
if fld['name'] != name:
|
||||
self.model.renameField(fld, name)
|
||||
|
|
|
@ -436,7 +436,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="rtl">
|
||||
<property name="text">
|
||||
<string>Reverse text direction (RTL)</string>
|
||||
|
@ -457,13 +457,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="preserveWhitespace">
|
||||
<property name="text">
|
||||
<string>Preserve whitespace</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="sticky">
|
||||
<property name="text">
|
||||
<string>Keep previous input when adding cards</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -565,6 +572,7 @@
|
|||
<tabstop>fontColour</tabstop>
|
||||
<tabstop>fieldUnique</tabstop>
|
||||
<tabstop>fieldRequired</tabstop>
|
||||
<tabstop>sticky</tabstop>
|
||||
<tabstop>preserveWhitespace</tabstop>
|
||||
<tabstop>rtl</tabstop>
|
||||
</tabstops>
|
||||
|
|
Loading…
Reference in a new issue