mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
Created the setupComboBoxHistory and saveComboBoxHistory to remove
duplicated/common code. https://anki.tenderapp.com/discussions/ankidesktop/39468-find-and-replace-does-not-remember-the-input-from-last-time
This commit is contained in:
parent
3971ea5518
commit
54d7f136cb
2 changed files with 30 additions and 27 deletions
|
@ -40,10 +40,12 @@ from aqt.utils import (
|
|||
restoreHeader,
|
||||
restoreSplitter,
|
||||
restoreState,
|
||||
saveComboBoxHistory,
|
||||
saveGeom,
|
||||
saveHeader,
|
||||
saveSplitter,
|
||||
saveState,
|
||||
setupComboBoxHistory,
|
||||
shortcut,
|
||||
showInfo,
|
||||
showWarning,
|
||||
|
@ -1930,17 +1932,11 @@ update cards set usn=?, mod=?, did=? where id in """
|
|||
frm.setupUi(d)
|
||||
d.setWindowModality(Qt.WindowModal)
|
||||
|
||||
findhistory = self.mw.pm.profile.get("FindAndReplaceFindHistory", [])
|
||||
frm.find.addItems(findhistory)
|
||||
frm.find.lineEdit().setText(findhistory[0] if findhistory else "")
|
||||
frm.find.lineEdit().selectAll()
|
||||
combo = "BrowserFindAndReplace"
|
||||
findhistory = setupComboBoxHistory(frm.find, combo + "Find")
|
||||
replacehistory = setupComboBoxHistory(frm.replace, combo + "Replace")
|
||||
|
||||
frm.find.setFocus()
|
||||
|
||||
replacehistory = self.mw.pm.profile.get("FindAndReplaceReplaceHistory", [])
|
||||
frm.replace.addItems(replacehistory)
|
||||
frm.replace.lineEdit().setText(replacehistory[0] if replacehistory else "")
|
||||
frm.replace.lineEdit().selectAll()
|
||||
|
||||
frm.field.addItems([_("All Fields")] + fields)
|
||||
qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp)
|
||||
restoreGeom(d, "findreplace")
|
||||
|
@ -1953,23 +1949,8 @@ update cards set usn=?, mod=?, did=? where id in """
|
|||
else:
|
||||
field = fields[frm.field.currentIndex() - 1]
|
||||
|
||||
search = frm.find.lineEdit().text()
|
||||
if search in findhistory:
|
||||
findhistory.remove(search)
|
||||
findhistory.insert(0, search)
|
||||
findhistory = findhistory[:30]
|
||||
frm.find.clear()
|
||||
frm.find.addItems(findhistory)
|
||||
self.mw.pm.profile["FindAndReplaceFindHistory"] = findhistory
|
||||
|
||||
replace = frm.replace.lineEdit().text()
|
||||
if replace in replacehistory:
|
||||
replacehistory.remove(replace)
|
||||
replacehistory.insert(0, replace)
|
||||
replacehistory = replacehistory[:30]
|
||||
frm.replace.clear()
|
||||
frm.replace.addItems(replacehistory)
|
||||
self.mw.pm.profile["FindAndReplaceReplaceHistory"] = replacehistory
|
||||
search = saveComboBoxHistory(frm.find, findhistory, combo + "Find")
|
||||
replace = saveComboBoxHistory(frm.replace, replacehistory, combo + "Replace")
|
||||
|
||||
regex = frm.re.isChecked()
|
||||
nocase = frm.ignoreCase.isChecked()
|
||||
|
|
|
@ -338,6 +338,28 @@ def getTag(parent, deck, question, tags="user", **kwargs):
|
|||
return ret
|
||||
|
||||
|
||||
def setupComboBoxHistory(comboBox, name):
|
||||
name += "BoxHistory"
|
||||
history = aqt.mw.pm.profile.get(name, [])
|
||||
comboBox.addItems(history)
|
||||
comboBox.lineEdit().setText(history[0] if history else "")
|
||||
comboBox.lineEdit().selectAll()
|
||||
return history
|
||||
|
||||
|
||||
def saveComboBoxHistory(comboBox, history, name):
|
||||
name += "BoxHistory"
|
||||
text_input = comboBox.lineEdit().text()
|
||||
if text_input in history:
|
||||
history.remove(text_input)
|
||||
history.insert(0, text_input)
|
||||
history = history[:50]
|
||||
comboBox.clear()
|
||||
comboBox.addItems(history)
|
||||
aqt.mw.pm.profile[name] = history
|
||||
return text_input
|
||||
|
||||
|
||||
# File handling
|
||||
######################################################################
|
||||
|
||||
|
|
Loading…
Reference in a new issue