mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Use col instead of backend in aqt for search strs
This commit is contained in:
parent
51e1e82a9a
commit
ea46e24662
3 changed files with 25 additions and 52 deletions
|
@ -13,19 +13,11 @@ 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
|
from anki.collection import Collection, InvalidInput, NamedFilter
|
||||||
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
|
||||||
from anki.notes import Note
|
from anki.notes import Note
|
||||||
from anki.rsbackend import (
|
|
||||||
BackendNoteTypeID,
|
|
||||||
ConcatSeparator,
|
|
||||||
DupeIn,
|
|
||||||
FilterToSearchIn,
|
|
||||||
InvalidInput,
|
|
||||||
NamedFilter,
|
|
||||||
)
|
|
||||||
from anki.stats import CardStats
|
from anki.stats import CardStats
|
||||||
from anki.utils import htmlToTextLine, ids2str, isMac, isWin
|
from anki.utils import htmlToTextLine, ids2str, isMac, isWin
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
|
@ -678,7 +670,7 @@ class Browser(QMainWindow):
|
||||||
self._onRowChanged(None, None)
|
self._onRowChanged(None, None)
|
||||||
|
|
||||||
def normalize_search(self, search: str) -> str:
|
def normalize_search(self, search: str) -> str:
|
||||||
normed = self.col.backend.normalize_search(search)
|
normed = self.col.search_string(searches=[search])
|
||||||
self._lastSearchTxt = normed
|
self._lastSearchTxt = normed
|
||||||
self.form.searchEdit.lineEdit().setText(normed)
|
self.form.searchEdit.lineEdit().setText(normed)
|
||||||
return normed
|
return normed
|
||||||
|
@ -961,29 +953,19 @@ QTableView {{ gridline-color: {grid} }}
|
||||||
def update_search(self, *terms: str):
|
def update_search(self, *terms: str):
|
||||||
"Modify the current search string based on modified keys, then refresh."
|
"Modify the current search string based on modified keys, then refresh."
|
||||||
try:
|
try:
|
||||||
search = self.col.backend.concatenate_searches(
|
search = self.col.search_string(searches=list(terms))
|
||||||
sep=ConcatSeparator.AND, searches=terms
|
|
||||||
)
|
|
||||||
mods = self.mw.app.keyboardModifiers()
|
mods = self.mw.app.keyboardModifiers()
|
||||||
if mods & Qt.AltModifier:
|
if mods & Qt.AltModifier:
|
||||||
search = self.col.backend.negate_search(search)
|
search = self.col.search_string(negate=True, searches=[search])
|
||||||
cur = str(self.form.searchEdit.lineEdit().text())
|
cur = str(self.form.searchEdit.lineEdit().text())
|
||||||
if cur != self._searchPrompt:
|
if cur != self._searchPrompt:
|
||||||
if mods & Qt.ControlModifier and mods & Qt.ShiftModifier:
|
if mods & Qt.ControlModifier and mods & Qt.ShiftModifier:
|
||||||
search = self.col.backend.replace_search_term(
|
search = self.col.replace_search_term(cur, search)
|
||||||
search=cur, replacement=search
|
|
||||||
)
|
|
||||||
elif mods & Qt.ControlModifier:
|
elif mods & Qt.ControlModifier:
|
||||||
search = self.col.backend.concatenate_searches(
|
search = self.col.search_string(searches=[cur, search])
|
||||||
# pylint: disable=no-member
|
|
||||||
sep=ConcatSeparator.AND,
|
|
||||||
searches=[cur, search],
|
|
||||||
)
|
|
||||||
elif mods & Qt.ShiftModifier:
|
elif mods & Qt.ShiftModifier:
|
||||||
search = self.col.backend.concatenate_searches(
|
search = self.col.search_string(
|
||||||
# pylint: disable=no-member
|
concat_by_or=True, searches=[cur, search]
|
||||||
sep=ConcatSeparator.OR,
|
|
||||||
searches=[cur, search],
|
|
||||||
)
|
)
|
||||||
except InvalidInput as e:
|
except InvalidInput as e:
|
||||||
show_invalid_search_error(e)
|
show_invalid_search_error(e)
|
||||||
|
@ -1062,8 +1044,8 @@ QTableView {{ gridline-color: {grid} }}
|
||||||
|
|
||||||
def _onSaveFilter(self) -> None:
|
def _onSaveFilter(self) -> None:
|
||||||
try:
|
try:
|
||||||
filt = self.col.backend.normalize_search(
|
filt = self.col.search_string(
|
||||||
self.form.searchEdit.lineEdit().text()
|
searches=[self.form.searchEdit.lineEdit().text()]
|
||||||
)
|
)
|
||||||
except InvalidInput as e:
|
except InvalidInput as e:
|
||||||
show_invalid_search_error(e)
|
show_invalid_search_error(e)
|
||||||
|
@ -1105,12 +1087,12 @@ QTableView {{ gridline-color: {grid} }}
|
||||||
def _currentFilterIsSaved(self) -> Optional[str]:
|
def _currentFilterIsSaved(self) -> Optional[str]:
|
||||||
filt = self.form.searchEdit.lineEdit().text()
|
filt = self.form.searchEdit.lineEdit().text()
|
||||||
try:
|
try:
|
||||||
filt = self.col.backend.normalize_search(filt)
|
filt = self.col.search_string(searches=[filt])
|
||||||
except InvalidInput:
|
except InvalidInput:
|
||||||
pass
|
pass
|
||||||
for k, v in self.col.get_config("savedFilters").items():
|
for k, v in self.col.get_config("savedFilters").items():
|
||||||
try:
|
try:
|
||||||
v = self.col.backend.normalize_search(v)
|
v = self.col.search_string(searches=[v])
|
||||||
except InvalidInput:
|
except InvalidInput:
|
||||||
pass
|
pass
|
||||||
if filt == v:
|
if filt == v:
|
||||||
|
@ -1657,11 +1639,7 @@ where id in %s"""
|
||||||
# filter called by the editor
|
# filter called by the editor
|
||||||
def search_dupe(self, mid: int, text: str):
|
def search_dupe(self, mid: int, text: str):
|
||||||
self.form.searchEdit.lineEdit().setText(
|
self.form.searchEdit.lineEdit().setText(
|
||||||
self.col.backend.filter_to_search(
|
self.col.search_string(dupe=(mid, text))
|
||||||
FilterToSearchIn(
|
|
||||||
dupe=DupeIn(mid=BackendNoteTypeID(ntid=mid), text=text)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self.onSearchActivated()
|
self.onSearchActivated()
|
||||||
|
|
||||||
|
|
|
@ -119,11 +119,11 @@ class DeckConf(QDialog):
|
||||||
else:
|
else:
|
||||||
d["delays"] = None
|
d["delays"] = None
|
||||||
|
|
||||||
search = self.mw.col.backend.normalize_search(f.search.text())
|
search = self.mw.col.search_string(searches=[f.search.text()])
|
||||||
terms = [[search, f.limit.value(), f.order.currentIndex()]]
|
terms = [[search, f.limit.value(), f.order.currentIndex()]]
|
||||||
|
|
||||||
if f.secondFilter.isChecked():
|
if f.secondFilter.isChecked():
|
||||||
search_2 = self.mw.col.backend.normalize_search(f.search_2.text())
|
search_2 = self.mw.col.search_string(searches=[f.search_2.text()])
|
||||||
terms.append([search_2, f.limit_2.value(), f.order_2.currentIndex()])
|
terms.append([search_2, f.limit_2.value(), f.order_2.currentIndex()])
|
||||||
|
|
||||||
d["terms"] = terms
|
d["terms"] = terms
|
||||||
|
|
|
@ -9,8 +9,12 @@ from enum import Enum
|
||||||
from typing import Iterable, List, Optional
|
from typing import Iterable, List, Optional
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
from anki.collection import ( # pylint: disable=unused-import
|
||||||
|
FilterToSearchIn,
|
||||||
|
NamedFilter,
|
||||||
|
)
|
||||||
from anki.errors import DeckRenameError
|
from anki.errors import DeckRenameError
|
||||||
from anki.rsbackend import DeckTreeNode, FilterToSearchIn, NamedFilter, TagTreeNode
|
from anki.rsbackend import DeckTreeNode, TagTreeNode
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
from aqt.main import ResetReason
|
from aqt.main import ResetReason
|
||||||
from aqt.models import Models
|
from aqt.models import Models
|
||||||
|
@ -390,29 +394,20 @@ class SidebarTreeView(QTreeView):
|
||||||
root.addChild(item)
|
root.addChild(item)
|
||||||
|
|
||||||
def _named_filter(self, name: "FilterToSearchIn.NamedFilterValue") -> Callable:
|
def _named_filter(self, name: "FilterToSearchIn.NamedFilterValue") -> Callable:
|
||||||
return lambda: self.browser.update_search(
|
return lambda: self.browser.update_search(self.col.search_string(name=name))
|
||||||
self.col.backend.filter_to_search(FilterToSearchIn(name=name))
|
|
||||||
)
|
|
||||||
|
|
||||||
def _tag_filter(self, tag: str) -> Callable:
|
def _tag_filter(self, tag: str) -> Callable:
|
||||||
return lambda: self.browser.update_search(
|
return lambda: self.browser.update_search(self.col.search_string(tag=tag))
|
||||||
self.col.backend.filter_to_search(FilterToSearchIn(tag=tag))
|
|
||||||
)
|
|
||||||
|
|
||||||
def _deck_filter(self, deck: str) -> Callable:
|
def _deck_filter(self, deck: str) -> Callable:
|
||||||
return lambda: self.browser.update_search(
|
return lambda: self.browser.update_search(self.col.search_string(deck=deck))
|
||||||
self.col.backend.filter_to_search(FilterToSearchIn(deck=deck))
|
|
||||||
)
|
|
||||||
|
|
||||||
def _note_filter(self, note: str) -> Callable:
|
def _note_filter(self, note: str) -> Callable:
|
||||||
return lambda: self.browser.update_search(
|
return lambda: self.browser.update_search(self.col.search_string(note=note))
|
||||||
self.col.backend.filter_to_search(FilterToSearchIn(note=note))
|
|
||||||
)
|
|
||||||
|
|
||||||
def _template_filter(self, note: str, template: int) -> Callable:
|
def _template_filter(self, note: str, template: int) -> Callable:
|
||||||
return lambda: self.browser.update_search(
|
return lambda: self.browser.update_search(
|
||||||
self.col.backend.filter_to_search(FilterToSearchIn(note=note)),
|
self.col.search_string(note=note), self.col.search_string(template=template)
|
||||||
self.col.backend.filter_to_search(FilterToSearchIn(template=template)),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _saved_filter(self, saved: str) -> Callable:
|
def _saved_filter(self, saved: str) -> Callable:
|
||||||
|
|
Loading…
Reference in a new issue