mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
simplify nid/nids searches, and ditch helper function
- IdList could be re-used for a cids: search in the future if required. - Embedding the message means it's easy to access from Python as an attribute of SearchTerm.
This commit is contained in:
parent
1adc9952f4
commit
cb6b88da0f
6 changed files with 23 additions and 18 deletions
|
@ -784,11 +784,5 @@ table.review-log {{ {revlog_style} }}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def nid_search_term(nids: List[int]) -> SearchTerm:
|
|
||||||
"""Helper function for building a NoteIDs message."""
|
|
||||||
|
|
||||||
return SearchTerm(nids=NoteIDs(nids=nids))
|
|
||||||
|
|
||||||
|
|
||||||
# legacy name
|
# legacy name
|
||||||
_Collection = Collection
|
_Collection = Collection
|
||||||
|
|
|
@ -7,7 +7,7 @@ import aqt.deckchooser
|
||||||
import aqt.editor
|
import aqt.editor
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
import aqt.modelchooser
|
import aqt.modelchooser
|
||||||
from anki.collection import nid_search_term
|
from anki.backend_pb2 import SearchTerm
|
||||||
from anki.consts import MODEL_CLOZE
|
from anki.consts import MODEL_CLOZE
|
||||||
from anki.notes import Note
|
from anki.notes import Note
|
||||||
from anki.utils import htmlToTextLine, isMac
|
from anki.utils import htmlToTextLine, isMac
|
||||||
|
@ -145,7 +145,7 @@ class AddCards(QDialog):
|
||||||
def onHistory(self) -> None:
|
def onHistory(self) -> None:
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
for nid in self.history:
|
for nid in self.history:
|
||||||
if self.mw.col.findNotes(nid_search_term([nid])):
|
if self.mw.col.findNotes(SearchTerm(nid=nid)):
|
||||||
note = self.mw.col.getNote(nid)
|
note = self.mw.col.getNote(nid)
|
||||||
fields = note.fields
|
fields = note.fields
|
||||||
txt = htmlToTextLine(", ".join(fields))
|
txt = htmlToTextLine(", ".join(fields))
|
||||||
|
@ -162,7 +162,7 @@ class AddCards(QDialog):
|
||||||
m.exec_(self.historyButton.mapToGlobal(QPoint(0, 0)))
|
m.exec_(self.historyButton.mapToGlobal(QPoint(0, 0)))
|
||||||
|
|
||||||
def editHistory(self, nid):
|
def editHistory(self, nid):
|
||||||
self.mw.browser_search(nid_search_term([nid]))
|
self.mw.browser_search(SearchTerm(nid=nid))
|
||||||
|
|
||||||
def addNote(self, note) -> Optional[Note]:
|
def addNote(self, note) -> Optional[Note]:
|
||||||
note.model()["did"] = self.deckChooser.selectedId()
|
note.model()["did"] = self.deckChooser.selectedId()
|
||||||
|
|
|
@ -13,7 +13,7 @@ from typing import List, Optional, Sequence, Tuple, cast
|
||||||
import aqt
|
import aqt
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
from anki.collection import Collection, InvalidInput, SearchTerm, nid_search_term
|
from anki.collection import Collection, InvalidInput, SearchTerm
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
from anki.lang import without_unicode_isolation
|
from anki.lang import without_unicode_isolation
|
||||||
from anki.models import NoteType
|
from anki.models import NoteType
|
||||||
|
@ -681,7 +681,7 @@ class Browser(QMainWindow):
|
||||||
nid = card and card.nid
|
nid = card and card.nid
|
||||||
if nid:
|
if nid:
|
||||||
self.card = card
|
self.card = card
|
||||||
search = self.col.build_search_string(nid_search_term([nid]))
|
search = self.col.build_search_string(SearchTerm(nid=nid))
|
||||||
search = gui_hooks.default_search(search, card)
|
search = gui_hooks.default_search(search, card)
|
||||||
self.form.searchEdit.lineEdit().setText(search)
|
self.form.searchEdit.lineEdit().setText(search)
|
||||||
self.onSearchActivated()
|
self.onSearchActivated()
|
||||||
|
@ -1522,7 +1522,9 @@ where id in %s"""
|
||||||
tv = self.form.tableView
|
tv = self.form.tableView
|
||||||
tv.selectionModel().clear()
|
tv.selectionModel().clear()
|
||||||
|
|
||||||
search = self.col.build_search_string(nid_search_term(nids))
|
search = self.col.build_search_string(
|
||||||
|
SearchTerm(nids=SearchTerm.IdList(ids=nids))
|
||||||
|
)
|
||||||
self.search_for(search)
|
self.search_for(search)
|
||||||
|
|
||||||
tv.selectAll()
|
tv.selectAll()
|
||||||
|
@ -1731,7 +1733,11 @@ where id in %s"""
|
||||||
t += (
|
t += (
|
||||||
"""<li><a href=# onclick="pycmd('%s');return false;">%s</a>: %s</a>"""
|
"""<li><a href=# onclick="pycmd('%s');return false;">%s</a>: %s</a>"""
|
||||||
% (
|
% (
|
||||||
html.escape(self.col.build_search_string(nid_search_term(nids))),
|
html.escape(
|
||||||
|
self.col.build_search_string(
|
||||||
|
SearchTerm(nids=SearchTerm.IdList(ids=nids))
|
||||||
|
)
|
||||||
|
),
|
||||||
tr(TR.BROWSING_NOTE_COUNT, count=len(nids)),
|
tr(TR.BROWSING_NOTE_COUNT, count=len(nids)),
|
||||||
html.escape(val),
|
html.escape(val),
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from concurrent.futures import Future
|
||||||
from typing import Iterable, List, Optional, Sequence, TypeVar
|
from typing import Iterable, List, Optional, Sequence, TypeVar
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki.collection import nid_search_term
|
from anki.backend_pb2 import SearchTerm
|
||||||
from anki.rsbackend import TR, Interrupted, ProgressKind, pb
|
from anki.rsbackend import TR, Interrupted, ProgressKind, pb
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
|
@ -146,7 +146,7 @@ class MediaChecker:
|
||||||
|
|
||||||
if out is not None:
|
if out is not None:
|
||||||
nid, err = out
|
nid, err = out
|
||||||
self.mw.browser_search(nid_search_term([nid]))
|
self.mw.browser_search(SearchTerm(nid=nid))
|
||||||
showText(err, type="html")
|
showText(err, type="html")
|
||||||
else:
|
else:
|
||||||
tooltip(tr(TR.MEDIA_CHECK_ALL_LATEX_RENDERED))
|
tooltip(tr(TR.MEDIA_CHECK_ALL_LATEX_RENDERED))
|
||||||
|
|
|
@ -797,12 +797,15 @@ message SearchTerm {
|
||||||
SUSPENDED = 4;
|
SUSPENDED = 4;
|
||||||
BURIED = 5;
|
BURIED = 5;
|
||||||
}
|
}
|
||||||
|
message IdList {
|
||||||
|
repeated int64 ids = 1;
|
||||||
|
}
|
||||||
oneof filter {
|
oneof filter {
|
||||||
string tag = 1;
|
string tag = 1;
|
||||||
string deck = 2;
|
string deck = 2;
|
||||||
string note = 3;
|
string note = 3;
|
||||||
uint32 template = 4;
|
uint32 template = 4;
|
||||||
NoteIDs nids = 5;
|
int64 nid = 5;
|
||||||
Dupe dupe = 6;
|
Dupe dupe = 6;
|
||||||
string field_name = 7;
|
string field_name = 7;
|
||||||
Rated rated = 8;
|
Rated rated = 8;
|
||||||
|
@ -812,6 +815,7 @@ message SearchTerm {
|
||||||
bool current_deck = 12;
|
bool current_deck = 12;
|
||||||
Flag flag = 13;
|
Flag flag = 13;
|
||||||
CardState card_state = 14;
|
CardState card_state = 14;
|
||||||
|
IdList nids = 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,9 +262,9 @@ impl From<pb::NoteId> for NoteID {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pb::NoteIDs {
|
impl pb::search_term::IdList {
|
||||||
fn into_id_string(self) -> String {
|
fn into_id_string(self) -> String {
|
||||||
self.nids
|
self.ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| i.to_string())
|
.map(|i| i.to_string())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
@ -307,6 +307,7 @@ impl From<pb::SearchTerm> for Node<'_> {
|
||||||
Filter::Template(u) => {
|
Filter::Template(u) => {
|
||||||
Node::Search(SearchNode::CardTemplate(TemplateKind::Ordinal(u as u16)))
|
Node::Search(SearchNode::CardTemplate(TemplateKind::Ordinal(u as u16)))
|
||||||
}
|
}
|
||||||
|
Filter::Nid(nid) => Node::Search(SearchNode::NoteIDs(nid.to_string().into())),
|
||||||
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.notetype_id.into(),
|
note_type_id: dupe.notetype_id.into(),
|
||||||
|
|
Loading…
Reference in a new issue