Set to browser.py findreplace.ui remember the last selected field

by creating saveComboActiveIndex and restoreComboActiveIndex.

https://anki.tenderapp.com/discussions/ankidesktop/39468-find-and-replace-does-not-remember-the-input-from-last-time
This commit is contained in:
evandrocoan 2020-05-31 16:52:58 -03:00
parent 40f98a244f
commit a74e43a515
2 changed files with 24 additions and 1 deletions

View file

@ -36,11 +36,13 @@ from aqt.utils import (
getTag,
openHelp,
qtMenuShortcutWorkaround,
restoreComboActiveIndex,
restoreGeom,
restoreHeader,
restoreIsChecked,
restoreSplitter,
restoreState,
saveComboActiveIndex,
saveComboBoxHistory,
saveGeom,
saveHeader,
@ -1942,13 +1944,17 @@ update cards set usn=?, mod=?, did=? where id in """
restoreIsChecked(frm.ignoreCase, combo + "ignoreCase")
frm.find.setFocus()
frm.field.addItems([_("All Fields")] + fields)
allfields = [_("All Fields")] + fields
frm.field.addItems(allfields)
restoreComboActiveIndex(frm.field, allfields, combo + "Field")
qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp)
restoreGeom(d, "findreplace")
r = d.exec_()
saveGeom(d, "findreplace")
if not r:
return
saveComboActiveIndex(frm.field, combo + "Field")
if frm.field.currentIndex() == 0:
field = None
else:

View file

@ -503,6 +503,23 @@ def restoreIsChecked(widget, key):
widget.setChecked(aqt.mw.pm.profile[key])
def saveComboActiveIndex(widget, key):
textKey = key + "ComboActiveText"
indexKey = key + "ComboActiveIndex"
aqt.mw.pm.profile[textKey] = widget.currentText()
aqt.mw.pm.profile[indexKey] = widget.currentIndex()
def restoreComboActiveIndex(widget, history, key):
textKey = key + "ComboActiveText"
indexKey = key + "ComboActiveIndex"
text = aqt.mw.pm.profile.get(textKey)
index = aqt.mw.pm.profile.get(indexKey)
if text is not None and index is not None:
if index < len(history) and history[index] == text:
widget.setCurrentIndex(index)
def saveSplitter(widget, key):
key += "Splitter"
aqt.mw.pm.profile[key] = widget.saveState()