mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -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,
|
restoreHeader,
|
||||||
restoreSplitter,
|
restoreSplitter,
|
||||||
restoreState,
|
restoreState,
|
||||||
|
saveComboBoxHistory,
|
||||||
saveGeom,
|
saveGeom,
|
||||||
saveHeader,
|
saveHeader,
|
||||||
saveSplitter,
|
saveSplitter,
|
||||||
saveState,
|
saveState,
|
||||||
|
setupComboBoxHistory,
|
||||||
shortcut,
|
shortcut,
|
||||||
showInfo,
|
showInfo,
|
||||||
showWarning,
|
showWarning,
|
||||||
|
@ -1930,17 +1932,11 @@ update cards set usn=?, mod=?, did=? where id in """
|
||||||
frm.setupUi(d)
|
frm.setupUi(d)
|
||||||
d.setWindowModality(Qt.WindowModal)
|
d.setWindowModality(Qt.WindowModal)
|
||||||
|
|
||||||
findhistory = self.mw.pm.profile.get("FindAndReplaceFindHistory", [])
|
combo = "BrowserFindAndReplace"
|
||||||
frm.find.addItems(findhistory)
|
findhistory = setupComboBoxHistory(frm.find, combo + "Find")
|
||||||
frm.find.lineEdit().setText(findhistory[0] if findhistory else "")
|
replacehistory = setupComboBoxHistory(frm.replace, combo + "Replace")
|
||||||
frm.find.lineEdit().selectAll()
|
|
||||||
frm.find.setFocus()
|
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)
|
frm.field.addItems([_("All Fields")] + fields)
|
||||||
qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp)
|
qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp)
|
||||||
restoreGeom(d, "findreplace")
|
restoreGeom(d, "findreplace")
|
||||||
|
@ -1953,23 +1949,8 @@ update cards set usn=?, mod=?, did=? where id in """
|
||||||
else:
|
else:
|
||||||
field = fields[frm.field.currentIndex() - 1]
|
field = fields[frm.field.currentIndex() - 1]
|
||||||
|
|
||||||
search = frm.find.lineEdit().text()
|
search = saveComboBoxHistory(frm.find, findhistory, combo + "Find")
|
||||||
if search in findhistory:
|
replace = saveComboBoxHistory(frm.replace, replacehistory, combo + "Replace")
|
||||||
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
|
|
||||||
|
|
||||||
regex = frm.re.isChecked()
|
regex = frm.re.isChecked()
|
||||||
nocase = frm.ignoreCase.isChecked()
|
nocase = frm.ignoreCase.isChecked()
|
||||||
|
|
|
@ -338,6 +338,28 @@ def getTag(parent, deck, question, tags="user", **kwargs):
|
||||||
return ret
|
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
|
# File handling
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue