From ba99c5ecb52d57e28d142bc5ca47eee377e63b82 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 00:04:21 -0300 Subject: [PATCH 01/15] Set to remember the last find input for findreplace.ui https://anki.tenderapp.com/discussions/ankidesktop/39468-find-and-replace-does-not-remember-the-input-from-last-time --- qt/aqt/browser.py | 17 ++++++++++++++++- qt/designer/findreplace.ui | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index c3a27a76f..777984ba0 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1929,6 +1929,13 @@ update cards set usn=?, mod=?, did=? where id in """ frm = aqt.forms.findreplace.Ui_Dialog() 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() + frm.find.setFocus() + frm.field.addItems([_("All Fields")] + fields) qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp) restoreGeom(d, "findreplace") @@ -1941,7 +1948,15 @@ update cards set usn=?, mod=?, did=? where id in """ else: field = fields[frm.field.currentIndex() - 1] - search = frm.find.text() + 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.text() regex = frm.re.isChecked() nocase = frm.ignoreCase.isChecked() diff --git a/qt/designer/findreplace.ui b/qt/designer/findreplace.ui index 4b94cf51f..c75599d1c 100644 --- a/qt/designer/findreplace.ui +++ b/qt/designer/findreplace.ui @@ -24,7 +24,20 @@ - + + + + 9 + 0 + + + + true + + + QComboBox::NoInsert + + From 3971ea551887dd1f6cefba57ed326861da7243d4 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 00:18:51 -0300 Subject: [PATCH 02/15] Set to remember the last replace input for findreplace.ui https://anki.tenderapp.com/discussions/ankidesktop/39468-find-and-replace-does-not-remember-the-input-from-last-time --- qt/aqt/browser.py | 15 ++++++++++++++- qt/designer/findreplace.ui | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 777984ba0..47225681a 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1936,6 +1936,11 @@ update cards set usn=?, mod=?, did=? where id in """ frm.find.lineEdit().selectAll() 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") @@ -1957,7 +1962,15 @@ update cards set usn=?, mod=?, did=? where id in """ frm.find.addItems(findhistory) self.mw.pm.profile["FindAndReplaceFindHistory"] = findhistory - replace = frm.replace.text() + 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() nocase = frm.ignoreCase.isChecked() diff --git a/qt/designer/findreplace.ui b/qt/designer/findreplace.ui index c75599d1c..e39103381 100644 --- a/qt/designer/findreplace.ui +++ b/qt/designer/findreplace.ui @@ -47,7 +47,20 @@ - + + + + 9 + 0 + + + + true + + + QComboBox::NoInsert + + From 54d7f136cb7e0979d993d20a2a5d8528250da17d Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 00:39:00 -0300 Subject: [PATCH 03/15] 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 --- qt/aqt/browser.py | 35 ++++++++--------------------------- qt/aqt/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 47225681a..8f77afcd7 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -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() diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 1acc57d54..d772ebf76 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -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 ###################################################################### From 40f98a244f1b6b8ff6c0149e451f2d4f67bf0fb8 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 00:57:11 -0300 Subject: [PATCH 04/15] Set to browser.py findreplace.ui remember the last regex/case by creating the saveIsChecked and restoreIsChecked. 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 | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 8f77afcd7..9dd19beef 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -38,11 +38,13 @@ from aqt.utils import ( qtMenuShortcutWorkaround, restoreGeom, restoreHeader, + restoreIsChecked, restoreSplitter, restoreState, saveComboBoxHistory, saveGeom, saveHeader, + saveIsChecked, saveSplitter, saveState, setupComboBoxHistory, @@ -1936,6 +1938,9 @@ update cards set usn=?, mod=?, did=? where id in """ findhistory = setupComboBoxHistory(frm.find, combo + "Find") replacehistory = setupComboBoxHistory(frm.replace, combo + "Replace") + restoreIsChecked(frm.re, combo + "Regex") + restoreIsChecked(frm.ignoreCase, combo + "ignoreCase") + frm.find.setFocus() frm.field.addItems([_("All Fields")] + fields) qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp) @@ -1955,6 +1960,9 @@ update cards set usn=?, mod=?, did=? where id in """ regex = frm.re.isChecked() nocase = frm.ignoreCase.isChecked() + saveIsChecked(frm.re, combo + "Regex") + saveIsChecked(frm.ignoreCase, combo + "ignoreCase") + self.mw.checkpoint(_("Find and Replace")) # starts progress dialog as well self.model.beginReset() diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index d772ebf76..63d1682dd 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -492,6 +492,17 @@ def restoreState(widget, key): widget.restoreState(aqt.mw.pm.profile[key]) +def saveIsChecked(widget, key): + key += "IsChecked" + aqt.mw.pm.profile[key] = widget.isChecked() + + +def restoreIsChecked(widget, key): + key += "IsChecked" + if aqt.mw.pm.profile.get(key) is not None: + widget.setChecked(aqt.mw.pm.profile[key]) + + def saveSplitter(widget, key): key += "Splitter" aqt.mw.pm.profile[key] = widget.saveState() From a74e43a5158508dd7fae0e9d6068c6b1470d8bf0 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 16:52:58 -0300 Subject: [PATCH 05/15] 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() From a78b3d522ee1d34e9918226fed07f6f11d998220 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 17:10:09 -0300 Subject: [PATCH 06/15] Set to browser.py finddupes.ui remember the last search text https://anki.tenderapp.com/discussions/ankidesktop/39468-find-and-replace-does-not-remember-the-input-from-last-time --- qt/aqt/browser.py | 7 ++++--- qt/designer/finddupes.ui | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 2bbb6b95f..b36c84109 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -2013,6 +2013,8 @@ update cards set usn=?, mod=?, did=? where id in """ frm = aqt.forms.finddupes.Ui_Dialog() frm.setupUi(d) restoreGeom(d, "findDupes") + searchHistory = setupComboBoxHistory(frm.search, "findDupesFind") + fields = sorted( anki.find.fieldNames(self.col, downcase=False), key=lambda x: x.lower() ) @@ -2030,10 +2032,9 @@ update cards set usn=?, mod=?, did=? where id in """ qconnect(d.finished, onFin) def onClick(): + search_text = saveComboBoxHistory(frm.search, searchHistory, "findDupesFind") field = fields[frm.fields.currentIndex()] - self.duplicatesReport( - frm.webView, field, frm.search.text(), frm, web_context - ) + self.duplicatesReport(frm.webView, field, search_text, frm, web_context) search = frm.buttonBox.addButton(_("Search"), QDialogButtonBox.ActionRole) qconnect(search.clicked, onClick) diff --git a/qt/designer/finddupes.ui b/qt/designer/finddupes.ui index fccba5f63..2884364c5 100644 --- a/qt/designer/finddupes.ui +++ b/qt/designer/finddupes.ui @@ -34,7 +34,20 @@ - + + + + 9 + 0 + + + + true + + + QComboBox::NoInsert + + From 6047c6ecc0109190ac54a2789afb206e01dbfa1b Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 17:29:07 -0300 Subject: [PATCH 07/15] Renamed setupComboBoxHistory to restoreComboHisotory, saveComboActiveIndex to saveComboIndex, saveComboBoxHistory to saveComboHistory and restoreComboActiveIndex to restoreComboIndex. --- qt/aqt/browser.py | 24 ++++++++++++------------ qt/aqt/utils.py | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index b36c84109..173f75c2f 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -36,20 +36,20 @@ from aqt.utils import ( getTag, openHelp, qtMenuShortcutWorkaround, - restoreComboActiveIndex, + restoreComboHistory, + restoreComboIndex, restoreGeom, restoreHeader, restoreIsChecked, restoreSplitter, restoreState, - saveComboActiveIndex, - saveComboBoxHistory, + saveComboHistory, + saveComboIndex, saveGeom, saveHeader, saveIsChecked, saveSplitter, saveState, - setupComboBoxHistory, shortcut, showInfo, showWarning, @@ -1937,8 +1937,8 @@ update cards set usn=?, mod=?, did=? where id in """ d.setWindowModality(Qt.WindowModal) combo = "BrowserFindAndReplace" - findhistory = setupComboBoxHistory(frm.find, combo + "Find") - replacehistory = setupComboBoxHistory(frm.replace, combo + "Replace") + findhistory = restoreComboHistory(frm.find, combo + "Find") + replacehistory = restoreComboHistory(frm.replace, combo + "Replace") restoreIsChecked(frm.re, combo + "Regex") restoreIsChecked(frm.ignoreCase, combo + "ignoreCase") @@ -1946,7 +1946,7 @@ update cards set usn=?, mod=?, did=? where id in """ frm.find.setFocus() allfields = [_("All Fields")] + fields frm.field.addItems(allfields) - restoreComboActiveIndex(frm.field, allfields, combo + "Field") + restoreComboIndex(frm.field, allfields, combo + "Field") qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp) restoreGeom(d, "findreplace") r = d.exec_() @@ -1954,14 +1954,14 @@ update cards set usn=?, mod=?, did=? where id in """ if not r: return - saveComboActiveIndex(frm.field, combo + "Field") + saveComboIndex(frm.field, combo + "Field") if frm.field.currentIndex() == 0: field = None else: field = fields[frm.field.currentIndex() - 1] - search = saveComboBoxHistory(frm.find, findhistory, combo + "Find") - replace = saveComboBoxHistory(frm.replace, replacehistory, combo + "Replace") + search = saveComboHistory(frm.find, findhistory, combo + "Find") + replace = saveComboHistory(frm.replace, replacehistory, combo + "Replace") regex = frm.re.isChecked() nocase = frm.ignoreCase.isChecked() @@ -2013,7 +2013,7 @@ update cards set usn=?, mod=?, did=? where id in """ frm = aqt.forms.finddupes.Ui_Dialog() frm.setupUi(d) restoreGeom(d, "findDupes") - searchHistory = setupComboBoxHistory(frm.search, "findDupesFind") + searchHistory = restoreComboHistory(frm.search, "findDupesFind") fields = sorted( anki.find.fieldNames(self.col, downcase=False), key=lambda x: x.lower() @@ -2032,7 +2032,7 @@ update cards set usn=?, mod=?, did=? where id in """ qconnect(d.finished, onFin) def onClick(): - search_text = saveComboBoxHistory(frm.search, searchHistory, "findDupesFind") + search_text = saveComboHistory(frm.search, searchHistory, "findDupesFind") field = fields[frm.fields.currentIndex()] self.duplicatesReport(frm.webView, field, search_text, frm, web_context) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index f559722f2..8b72c4a64 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -338,7 +338,7 @@ def getTag(parent, deck, question, tags="user", **kwargs): return ret -def setupComboBoxHistory(comboBox, name): +def restoreComboHistory(comboBox, name): name += "BoxHistory" history = aqt.mw.pm.profile.get(name, []) comboBox.addItems(history) @@ -347,7 +347,7 @@ def setupComboBoxHistory(comboBox, name): return history -def saveComboBoxHistory(comboBox, history, name): +def saveComboHistory(comboBox, history, name): name += "BoxHistory" text_input = comboBox.lineEdit().text() if text_input in history: @@ -503,14 +503,14 @@ def restoreIsChecked(widget, key): widget.setChecked(aqt.mw.pm.profile[key]) -def saveComboActiveIndex(widget, key): +def saveComboIndex(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): +def restoreComboIndex(widget, history, key): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" text = aqt.mw.pm.profile.get(textKey) From f27ad0c524b6a6647d910621190591f2a814aa0a Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 17:30:14 -0300 Subject: [PATCH 08/15] Moved restoreComboHistory closer to restoreComboIndex on utils.py --- qt/aqt/utils.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 8b72c4a64..66365fcfd 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -338,28 +338,6 @@ def getTag(parent, deck, question, tags="user", **kwargs): return ret -def restoreComboHistory(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 saveComboHistory(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 ###################################################################### @@ -520,6 +498,28 @@ def restoreComboIndex(widget, history, key): widget.setCurrentIndex(index) +def restoreComboHistory(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 saveComboHistory(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 + + def saveSplitter(widget, key): key += "Splitter" aqt.mw.pm.profile[key] = widget.saveState() From bf55ebbd8ac5f77a5493fa34bb7b8ce82cfa55f0 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 18:30:10 -0300 Subject: [PATCH 09/15] Added some type checking to utils.py QComboBox restore functions # Conflicts: # qt/aqt/utils.py --- qt/aqt/utils.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 66365fcfd..899d038f8 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -8,7 +8,7 @@ import os import re import subprocess import sys -from typing import TYPE_CHECKING, Any, Optional, Union +from typing import TYPE_CHECKING, Any, List, Optional, Union import anki import aqt @@ -409,7 +409,7 @@ def getSaveFile(parent, title, dir_description, key, ext, fname=None): return file -def saveGeom(widget, key): +def saveGeom(widget, key: str): key += "Geom" if isMac and widget.windowState() & Qt.WindowFullScreen: geom = None @@ -418,7 +418,7 @@ def saveGeom(widget, key): aqt.mw.pm.profile[key] = geom -def restoreGeom(widget, key, offset=None, adjustSize=False): +def restoreGeom(widget, key: str, offset=None, adjustSize=False): key += "Geom" if aqt.mw.pm.profile.get(key): widget.restoreGeometry(aqt.mw.pm.profile[key]) @@ -459,36 +459,36 @@ def ensureWidgetInScreenBoundaries(widget): widget.move(x, y) -def saveState(widget, key): +def saveState(widget, key: str): key += "State" aqt.mw.pm.profile[key] = widget.saveState() -def restoreState(widget, key): +def restoreState(widget, key: str): key += "State" if aqt.mw.pm.profile.get(key): widget.restoreState(aqt.mw.pm.profile[key]) -def saveIsChecked(widget, key): +def saveIsChecked(widget, key: str): key += "IsChecked" aqt.mw.pm.profile[key] = widget.isChecked() -def restoreIsChecked(widget, key): +def restoreIsChecked(widget, key: str): key += "IsChecked" if aqt.mw.pm.profile.get(key) is not None: widget.setChecked(aqt.mw.pm.profile[key]) -def saveComboIndex(widget, key): +def saveComboIndex(widget: QComboBox, key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" aqt.mw.pm.profile[textKey] = widget.currentText() aqt.mw.pm.profile[indexKey] = widget.currentIndex() -def restoreComboIndex(widget, history, key): +def restoreComboIndex(widget: QComboBox, history: List[str], key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" text = aqt.mw.pm.profile.get(textKey) @@ -498,7 +498,7 @@ def restoreComboIndex(widget, history, key): widget.setCurrentIndex(index) -def restoreComboHistory(comboBox, name): +def restoreComboHistory(comboBox: QComboBox, name: str): name += "BoxHistory" history = aqt.mw.pm.profile.get(name, []) comboBox.addItems(history) @@ -507,7 +507,7 @@ def restoreComboHistory(comboBox, name): return history -def saveComboHistory(comboBox, history, name): +def saveComboHistory(comboBox: QComboBox, history: List[str], name: str): name += "BoxHistory" text_input = comboBox.lineEdit().text() if text_input in history: From 87d051fa716bb35fc59aa4ee1179cc4bc406834d Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 18:37:10 -0300 Subject: [PATCH 10/15] Set to browser.py finddupes.ui remember the last selected field https://anki.tenderapp.com/discussions/ankidesktop/39468-find-and-replace-does-not-remember-the-input-from-last-time --- qt/aqt/browser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 173f75c2f..49eb64f8a 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -2019,7 +2019,9 @@ update cards set usn=?, mod=?, did=? where id in """ anki.find.fieldNames(self.col, downcase=False), key=lambda x: x.lower() ) frm.fields.addItems(fields) + restoreComboIndex(frm.fields, fields, "findDupesFields") self._dupesButton = None + # links frm.webView.title = "find duplicates" web_context = FindDupesDialog(dialog=d, browser=self) @@ -2033,6 +2035,7 @@ update cards set usn=?, mod=?, did=? where id in """ def onClick(): search_text = saveComboHistory(frm.search, searchHistory, "findDupesFind") + saveComboIndex(frm.fields, "findDupesFields") field = fields[frm.fields.currentIndex()] self.duplicatesReport(frm.webView, field, search_text, frm, web_context) From 4bc895f7df88a1b9cee1b96878b4bafe80ee8956 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 1 Jun 2020 12:34:26 -0300 Subject: [PATCH 11/15] Moved restoreComboHistory below saveComboHistory as others --- qt/aqt/utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 899d038f8..03e4943f5 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -498,15 +498,6 @@ def restoreComboIndex(widget: QComboBox, history: List[str], key: str): widget.setCurrentIndex(index) -def restoreComboHistory(comboBox: QComboBox, name: str): - 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 saveComboHistory(comboBox: QComboBox, history: List[str], name: str): name += "BoxHistory" text_input = comboBox.lineEdit().text() @@ -520,6 +511,15 @@ def saveComboHistory(comboBox: QComboBox, history: List[str], name: str): return text_input +def restoreComboHistory(comboBox: QComboBox, name: str): + 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 saveSplitter(widget, key): key += "Splitter" aqt.mw.pm.profile[key] = widget.saveState() From b23b404f687746fa51005c38435e3e7b6f8d01b0 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 1 Jun 2020 12:47:46 -0300 Subject: [PATCH 12/15] Created the profiles.py session attribute for things to forgot each time Anki restarted and set to only fill the find and replace dialogs when they were filled on the actual session. --- qt/aqt/profiles.py | 2 ++ qt/aqt/utils.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 9fc13a0bd..8ca096c3f 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -76,6 +76,8 @@ class AnkiRestart(SystemExit): class ProfileManager: def __init__(self, base=None): + ## Settings which should be forgotten each Anki restart + self.session = {} self.name = None self.db = None self.profile: Optional[Dict] = None diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 03e4943f5..d1f0afe92 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -484,15 +484,15 @@ def restoreIsChecked(widget, key: str): def saveComboIndex(widget: QComboBox, key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" - aqt.mw.pm.profile[textKey] = widget.currentText() - aqt.mw.pm.profile[indexKey] = widget.currentIndex() + aqt.mw.pm.session[textKey] = widget.currentText() + aqt.mw.pm.session[indexKey] = widget.currentIndex() def restoreComboIndex(widget: QComboBox, history: List[str], key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" - text = aqt.mw.pm.profile.get(textKey) - index = aqt.mw.pm.profile.get(indexKey) + text = aqt.mw.pm.session.get(textKey) + index = aqt.mw.pm.session.get(indexKey) if text is not None and index is not None: if index < len(history) and history[index] == text: widget.setCurrentIndex(index) @@ -507,6 +507,7 @@ def saveComboHistory(comboBox: QComboBox, history: List[str], name: str): history = history[:50] comboBox.clear() comboBox.addItems(history) + aqt.mw.pm.session[name] = text_input aqt.mw.pm.profile[name] = history return text_input @@ -514,9 +515,12 @@ def saveComboHistory(comboBox: QComboBox, history: List[str], name: str): def restoreComboHistory(comboBox: QComboBox, name: str): name += "BoxHistory" history = aqt.mw.pm.profile.get(name, []) - comboBox.addItems(history) - comboBox.lineEdit().setText(history[0] if history else "") - comboBox.lineEdit().selectAll() + comboBox.addItems([""] + history) + if history: + session_input = aqt.mw.pm.session.get(name) + if session_input and session_input == history[0]: + comboBox.lineEdit().setText(session_input) + comboBox.lineEdit().selectAll() return history From 1d3287386980fb5f31228bbe75a952d3ef82b077 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Thu, 4 Jun 2020 22:39:53 -0300 Subject: [PATCH 13/15] Renamed new function on qt/aqt/utils.py to snake case --- qt/aqt/browser.py | 40 ++++++++++++++++++++-------------------- qt/aqt/utils.py | 12 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 49eb64f8a..6ee72f9c2 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -36,18 +36,18 @@ from aqt.utils import ( getTag, openHelp, qtMenuShortcutWorkaround, - restoreComboHistory, - restoreComboIndex, + restore_combo_history, + restore_combo_index, + restore_is_checked, restoreGeom, restoreHeader, - restoreIsChecked, restoreSplitter, restoreState, - saveComboHistory, - saveComboIndex, + save_combo_history, + save_combo_index, + save_is_checked, saveGeom, saveHeader, - saveIsChecked, saveSplitter, saveState, shortcut, @@ -1937,16 +1937,16 @@ update cards set usn=?, mod=?, did=? where id in """ d.setWindowModality(Qt.WindowModal) combo = "BrowserFindAndReplace" - findhistory = restoreComboHistory(frm.find, combo + "Find") - replacehistory = restoreComboHistory(frm.replace, combo + "Replace") + findhistory = restore_combo_history(frm.find, combo + "Find") + replacehistory = restore_combo_history(frm.replace, combo + "Replace") - restoreIsChecked(frm.re, combo + "Regex") - restoreIsChecked(frm.ignoreCase, combo + "ignoreCase") + restore_is_checked(frm.re, combo + "Regex") + restore_is_checked(frm.ignoreCase, combo + "ignoreCase") frm.find.setFocus() allfields = [_("All Fields")] + fields frm.field.addItems(allfields) - restoreComboIndex(frm.field, allfields, combo + "Field") + restore_combo_index(frm.field, allfields, combo + "Field") qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp) restoreGeom(d, "findreplace") r = d.exec_() @@ -1954,20 +1954,20 @@ update cards set usn=?, mod=?, did=? where id in """ if not r: return - saveComboIndex(frm.field, combo + "Field") + save_combo_index(frm.field, combo + "Field") if frm.field.currentIndex() == 0: field = None else: field = fields[frm.field.currentIndex() - 1] - search = saveComboHistory(frm.find, findhistory, combo + "Find") - replace = saveComboHistory(frm.replace, replacehistory, combo + "Replace") + search = save_combo_history(frm.find, findhistory, combo + "Find") + replace = save_combo_history(frm.replace, replacehistory, combo + "Replace") regex = frm.re.isChecked() nocase = frm.ignoreCase.isChecked() - saveIsChecked(frm.re, combo + "Regex") - saveIsChecked(frm.ignoreCase, combo + "ignoreCase") + save_is_checked(frm.re, combo + "Regex") + save_is_checked(frm.ignoreCase, combo + "ignoreCase") self.mw.checkpoint(_("Find and Replace")) # starts progress dialog as well @@ -2013,13 +2013,13 @@ update cards set usn=?, mod=?, did=? where id in """ frm = aqt.forms.finddupes.Ui_Dialog() frm.setupUi(d) restoreGeom(d, "findDupes") - searchHistory = restoreComboHistory(frm.search, "findDupesFind") + searchHistory = restore_combo_history(frm.search, "findDupesFind") fields = sorted( anki.find.fieldNames(self.col, downcase=False), key=lambda x: x.lower() ) frm.fields.addItems(fields) - restoreComboIndex(frm.fields, fields, "findDupesFields") + restore_combo_index(frm.fields, fields, "findDupesFields") self._dupesButton = None # links @@ -2034,8 +2034,8 @@ update cards set usn=?, mod=?, did=? where id in """ qconnect(d.finished, onFin) def onClick(): - search_text = saveComboHistory(frm.search, searchHistory, "findDupesFind") - saveComboIndex(frm.fields, "findDupesFields") + search_text = save_combo_history(frm.search, searchHistory, "findDupesFind") + save_combo_index(frm.fields, "findDupesFields") field = fields[frm.fields.currentIndex()] self.duplicatesReport(frm.webView, field, search_text, frm, web_context) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index d1f0afe92..339e9a1e6 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -470,25 +470,25 @@ def restoreState(widget, key: str): widget.restoreState(aqt.mw.pm.profile[key]) -def saveIsChecked(widget, key: str): +def save_is_checked(widget, key: str): key += "IsChecked" aqt.mw.pm.profile[key] = widget.isChecked() -def restoreIsChecked(widget, key: str): +def restore_is_checked(widget, key: str): key += "IsChecked" if aqt.mw.pm.profile.get(key) is not None: widget.setChecked(aqt.mw.pm.profile[key]) -def saveComboIndex(widget: QComboBox, key: str): +def save_combo_index(widget: QComboBox, key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" aqt.mw.pm.session[textKey] = widget.currentText() aqt.mw.pm.session[indexKey] = widget.currentIndex() -def restoreComboIndex(widget: QComboBox, history: List[str], key: str): +def restore_combo_index(widget: QComboBox, history: List[str], key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" text = aqt.mw.pm.session.get(textKey) @@ -498,7 +498,7 @@ def restoreComboIndex(widget: QComboBox, history: List[str], key: str): widget.setCurrentIndex(index) -def saveComboHistory(comboBox: QComboBox, history: List[str], name: str): +def save_combo_history(comboBox: QComboBox, history: List[str], name: str): name += "BoxHistory" text_input = comboBox.lineEdit().text() if text_input in history: @@ -512,7 +512,7 @@ def saveComboHistory(comboBox: QComboBox, history: List[str], name: str): return text_input -def restoreComboHistory(comboBox: QComboBox, name: str): +def restore_combo_history(comboBox: QComboBox, name: str): name += "BoxHistory" history = aqt.mw.pm.profile.get(name, []) comboBox.addItems([""] + history) From 38fba41fb2011e7f49f260479af26d6114ff247f Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 8 Jun 2020 15:54:20 -0300 Subject: [PATCH 14/15] Renamed save_combo_index to save_combo_index_for_session --- qt/aqt/browser.py | 12 ++++++------ qt/aqt/utils.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 6ee72f9c2..5a6351083 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -37,14 +37,14 @@ from aqt.utils import ( openHelp, qtMenuShortcutWorkaround, restore_combo_history, - restore_combo_index, + restore_combo_index_for_session, restore_is_checked, restoreGeom, restoreHeader, restoreSplitter, restoreState, save_combo_history, - save_combo_index, + save_combo_index_for_session, save_is_checked, saveGeom, saveHeader, @@ -1946,7 +1946,7 @@ update cards set usn=?, mod=?, did=? where id in """ frm.find.setFocus() allfields = [_("All Fields")] + fields frm.field.addItems(allfields) - restore_combo_index(frm.field, allfields, combo + "Field") + restore_combo_index_for_session(frm.field, allfields, combo + "Field") qconnect(frm.buttonBox.helpRequested, self.onFindReplaceHelp) restoreGeom(d, "findreplace") r = d.exec_() @@ -1954,7 +1954,7 @@ update cards set usn=?, mod=?, did=? where id in """ if not r: return - save_combo_index(frm.field, combo + "Field") + save_combo_index_for_session(frm.field, combo + "Field") if frm.field.currentIndex() == 0: field = None else: @@ -2019,7 +2019,7 @@ update cards set usn=?, mod=?, did=? where id in """ anki.find.fieldNames(self.col, downcase=False), key=lambda x: x.lower() ) frm.fields.addItems(fields) - restore_combo_index(frm.fields, fields, "findDupesFields") + restore_combo_index_for_session(frm.fields, fields, "findDupesFields") self._dupesButton = None # links @@ -2035,7 +2035,7 @@ update cards set usn=?, mod=?, did=? where id in """ def onClick(): search_text = save_combo_history(frm.search, searchHistory, "findDupesFind") - save_combo_index(frm.fields, "findDupesFields") + save_combo_index_for_session(frm.fields, "findDupesFields") field = fields[frm.fields.currentIndex()] self.duplicatesReport(frm.webView, field, search_text, frm, web_context) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 339e9a1e6..8833c0944 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -481,14 +481,14 @@ def restore_is_checked(widget, key: str): widget.setChecked(aqt.mw.pm.profile[key]) -def save_combo_index(widget: QComboBox, key: str): +def save_combo_index_for_session(widget: QComboBox, key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" aqt.mw.pm.session[textKey] = widget.currentText() aqt.mw.pm.session[indexKey] = widget.currentIndex() -def restore_combo_index(widget: QComboBox, history: List[str], key: str): +def restore_combo_index_for_session(widget: QComboBox, history: List[str], key: str): textKey = key + "ComboActiveText" indexKey = key + "ComboActiveIndex" text = aqt.mw.pm.session.get(textKey) From 947f58032f94a30d151b8f104a8a109c3dd459b2 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Mon, 8 Jun 2020 15:55:25 -0300 Subject: [PATCH 15/15] Moved the utils.py new save/restore functions together --- qt/aqt/utils.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 8833c0944..59e936bff 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -470,6 +470,28 @@ def restoreState(widget, key: str): widget.restoreState(aqt.mw.pm.profile[key]) +def saveSplitter(widget, key): + key += "Splitter" + aqt.mw.pm.profile[key] = widget.saveState() + + +def restoreSplitter(widget, key): + key += "Splitter" + if aqt.mw.pm.profile.get(key): + widget.restoreState(aqt.mw.pm.profile[key]) + + +def saveHeader(widget, key): + key += "Header" + aqt.mw.pm.profile[key] = widget.saveState() + + +def restoreHeader(widget, key): + key += "Header" + if aqt.mw.pm.profile.get(key): + widget.restoreState(aqt.mw.pm.profile[key]) + + def save_is_checked(widget, key: str): key += "IsChecked" aqt.mw.pm.profile[key] = widget.isChecked() @@ -524,28 +546,6 @@ def restore_combo_history(comboBox: QComboBox, name: str): return history -def saveSplitter(widget, key): - key += "Splitter" - aqt.mw.pm.profile[key] = widget.saveState() - - -def restoreSplitter(widget, key): - key += "Splitter" - if aqt.mw.pm.profile.get(key): - widget.restoreState(aqt.mw.pm.profile[key]) - - -def saveHeader(widget, key): - key += "Header" - aqt.mw.pm.profile[key] = widget.saveState() - - -def restoreHeader(widget, key): - key += "Header" - if aqt.mw.pm.profile.get(key): - widget.restoreState(aqt.mw.pm.profile[key]) - - def mungeQA(col, txt): print("mungeQA() deprecated; use mw.prepare_card_text_for_display()") txt = col.media.escapeImages(txt)