Use backend to set dupe filter

This commit is contained in:
RumovZ 2021-01-13 11:58:59 +01:00 committed by Damien Elmes
parent 6d9cfb85ab
commit 7b9cc017c4
3 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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: