From 7b9cc017c431fae9090bdfb4c7eaee734a02b55d Mon Sep 17 00:00:00 2001 From: RumovZ Date: Wed, 13 Jan 2021 11:58:59 +0100 Subject: [PATCH] Use backend to set dupe filter --- pylib/anki/rsbackend.py | 2 ++ qt/aqt/browser.py | 13 +++++++++++++ qt/aqt/editor.py | 6 +----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index 770fefe11..88316b23f 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -48,6 +48,8 @@ DeckTreeNode = pb.DeckTreeNode StockNoteType = pb.StockNoteType FilterToSearchIn = pb.FilterToSearchIn NamedFilter = pb.FilterToSearchIn.NamedFilter +DupeIn = pb.FilterToSearchIn.DupeIn +BackendNoteTypeID = pb.NoteTypeID ConcatSeparator = pb.ConcatenateSearchesIn.Separator SyncAuth = pb.SyncAuth SyncOutput = pb.SyncCollectionOut diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 0cdadce6b..6ecacc6d0 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -21,8 +21,10 @@ from anki.lang import without_unicode_isolation from anki.models import NoteType from anki.notes import Note from anki.rsbackend import ( + BackendNoteTypeID, ConcatSeparator, DeckTreeNode, + DupeIn, FilterToSearchIn, InvalidInput, NamedFilter, @@ -2016,6 +2018,17 @@ where id in %s""" # Edit: finding dupes ###################################################################### + # filter called by the editor + def search_dupe(self, mid: int, text: str): + self.form.searchEdit.lineEdit().setText( + self.col.backend.filter_to_search( + FilterToSearchIn( + dupe=DupeIn(mid=BackendNoteTypeID(ntid=mid), text=text) + ) + ) + ) + self.onSearchActivated() + def onFindDupes(self): self.editor.saveNow(self._onFindDupes) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 3f69f068e..bbe3a4add 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -537,12 +537,8 @@ class Editor: self.web.eval("setBackgrounds(%s);" % json.dumps(cols)) def showDupes(self): - contents = self.note.fields[0].replace('"', r"\"") browser = aqt.dialogs.open("Browser", self.mw) - browser.form.searchEdit.lineEdit().setText( - '"dupe:%s,%s"' % (self.note.model()["id"], contents) - ) - browser.onSearchActivated() + browser.search_dupe(self.note.model()["id"], self.note.fields[0]) def fieldsAreBlank(self, previousNote=None): if not self.note: