mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
simplify Dupe message and ditch helper function
Calling code doesn't need to know about the existence of such helpers; it can just rely on code completion to discover the required arguments.
This commit is contained in:
parent
5e6dd54c8e
commit
1adc9952f4
4 changed files with 12 additions and 15 deletions
|
@ -784,13 +784,6 @@ table.review-log {{ {revlog_style} }}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def dupe_search_term(mid: int, text: str) -> SearchTerm:
|
|
||||||
"""Helper function for building a DupeIn message."""
|
|
||||||
|
|
||||||
dupe_in = SearchTerm.DupeIn(mid=BackendNoteTypeID(ntid=mid), text=text)
|
|
||||||
return SearchTerm(dupe=dupe_in)
|
|
||||||
|
|
||||||
|
|
||||||
def nid_search_term(nids: List[int]) -> SearchTerm:
|
def nid_search_term(nids: List[int]) -> SearchTerm:
|
||||||
"""Helper function for building a NoteIDs message."""
|
"""Helper function for building a NoteIDs message."""
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ from bs4 import BeautifulSoup
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
import aqt.sound
|
import aqt.sound
|
||||||
|
from anki.backend_pb2 import SearchTerm
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
from anki.collection import dupe_search_term
|
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
from anki.httpclient import HttpClient
|
from anki.httpclient import HttpClient
|
||||||
from anki.notes import Note
|
from anki.notes import Note
|
||||||
|
@ -541,7 +541,11 @@ class Editor:
|
||||||
|
|
||||||
def showDupes(self):
|
def showDupes(self):
|
||||||
self.mw.browser_search(
|
self.mw.browser_search(
|
||||||
dupe_search_term(self.note.model()["id"], self.note.fields[0])
|
SearchTerm(
|
||||||
|
dupe=SearchTerm.Dupe(
|
||||||
|
notetype_id=self.note.model()["id"], first_field=self.note.fields[0]
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def fieldsAreBlank(self, previousNote=None):
|
def fieldsAreBlank(self, previousNote=None):
|
||||||
|
|
|
@ -765,9 +765,9 @@ message BuiltinSearchOrder {
|
||||||
}
|
}
|
||||||
|
|
||||||
message SearchTerm {
|
message SearchTerm {
|
||||||
message DupeIn {
|
message Dupe {
|
||||||
NoteTypeID mid = 1;
|
int64 notetype_id = 1;
|
||||||
string text = 2;
|
string first_field = 2;
|
||||||
}
|
}
|
||||||
enum Flag {
|
enum Flag {
|
||||||
WITHOUT = 0;
|
WITHOUT = 0;
|
||||||
|
@ -803,7 +803,7 @@ message SearchTerm {
|
||||||
string note = 3;
|
string note = 3;
|
||||||
uint32 template = 4;
|
uint32 template = 4;
|
||||||
NoteIDs nids = 5;
|
NoteIDs nids = 5;
|
||||||
DupeIn dupe = 6;
|
Dupe dupe = 6;
|
||||||
string field_name = 7;
|
string field_name = 7;
|
||||||
Rated rated = 8;
|
Rated rated = 8;
|
||||||
uint32 added_in_days = 9;
|
uint32 added_in_days = 9;
|
||||||
|
|
|
@ -309,8 +309,8 @@ impl From<pb::SearchTerm> for Node<'_> {
|
||||||
}
|
}
|
||||||
Filter::Nids(nids) => Node::Search(SearchNode::NoteIDs(nids.into_id_string().into())),
|
Filter::Nids(nids) => Node::Search(SearchNode::NoteIDs(nids.into_id_string().into())),
|
||||||
Filter::Dupe(dupe) => Node::Search(SearchNode::Duplicates {
|
Filter::Dupe(dupe) => Node::Search(SearchNode::Duplicates {
|
||||||
note_type_id: dupe.mid.unwrap_or(pb::NoteTypeId { ntid: 0 }).into(),
|
note_type_id: dupe.notetype_id.into(),
|
||||||
text: dupe.text.into(),
|
text: dupe.first_field.into(),
|
||||||
}),
|
}),
|
||||||
Filter::FieldName(s) => Node::Search(SearchNode::SingleField {
|
Filter::FieldName(s) => Node::Search(SearchNode::SingleField {
|
||||||
field: escape_anki_wildcards(&s).into_owned().into(),
|
field: escape_anki_wildcards(&s).into_owned().into(),
|
||||||
|
|
Loading…
Reference in a new issue