Merge pull request #354 from Arthur-Milchior/ignoreStickyFieldOnlyIfTheyDidntChanged

Ignore sticky field only if they didnt changed
This commit is contained in:
Damien Elmes 2019-11-25 11:31:14 +13:00 committed by GitHub
commit 734f7acf73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -28,6 +28,7 @@ class AddCards(QDialog):
self.setupButtons()
self.onReset()
self.history = []
self.previousNote = None
restoreGeom(self, "add")
addHook('reset', self.onReset)
addHook('currentModelChanged', self.onModelChange)
@ -83,6 +84,7 @@ class AddCards(QDialog):
def onModelChange(self):
oldNote = self.editor.note
note = self.mw.col.newNote()
self.previousNote = None
if oldNote:
oldFields = list(oldNote.keys())
newFields = list(note.keys())
@ -176,6 +178,7 @@ question on all cards."""), help="AddItems")
return
self.addHistory(note)
self.mw.requireReset()
self.previousNote = note
return note
def addCards(self):
@ -183,9 +186,7 @@ question on all cards."""), help="AddItems")
def _addCards(self):
self.editor.saveAddModeVars()
note = self.editor.note
note = self.addNote(note)
if not note:
if not self.addNote(self.editor.note):
return
tooltip(_("Added"), period=500)
# stop anything playing
@ -219,7 +220,7 @@ question on all cards."""), help="AddItems")
def ifCanClose(self, onOk):
def afterSave():
ok = (self.editor.fieldsAreBlank() or
ok = (self.editor.fieldsAreBlank(self.previousNote) or
askUser(_("Close and lose current input?"), defaultno=True))
if ok:
onOk()

View File

@ -371,12 +371,15 @@ class Editor:
contents))
browser.onSearchActivated()
def fieldsAreBlank(self):
def fieldsAreBlank(self, previousNote=None):
if not self.note:
return True
m = self.note.model()
for c, f in enumerate(self.note.fields):
if f and not m['flds'][c]['sticky']:
notChangedvalues = {"", "<br>"}
if previousNote and m['flds'][c]['sticky']:
notChangedvalues.add(previousNote.fields[c])
if f not in notChangedvalues:
return False
return True