From a74e43a5158508dd7fae0e9d6068c6b1470d8bf0 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 16:52:58 -0300 Subject: [PATCH] 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 --- qt/aqt/browser.py | 8 +++++++- qt/aqt/utils.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 9dd19beef..2bbb6b95f 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -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: diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 63d1682dd..f559722f2 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -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()