Search_model has context

I have an add-on which allow to open multiple windows. So would like to know which browser has done the search. This
would allow me to have browser with various setting. In particular, I've an add-on which allow to show a single line by
note, and I would like for some browser to have this feature on and for some other to have this feature off.
This commit is contained in:
Arthur Milchior 2020-08-11 22:30:03 +02:00
parent c3f8f7dd94
commit ae078d4fd0

View file

@ -70,6 +70,7 @@ class FindDupesDialog:
@dataclass @dataclass
class SearchContext: class SearchContext:
search: str search: str
browser: Browser
order: Union[bool, str] = True order: Union[bool, str] = True
# if set, provided card ids will be used instead of the regular search # if set, provided card ids will be used instead of the regular search
card_ids: Optional[Sequence[int]] = None card_ids: Optional[Sequence[int]] = None
@ -181,7 +182,7 @@ class DataModel(QAbstractTableModel):
self.cards = [] self.cards = []
error_message: Optional[str] = None error_message: Optional[str] = None
try: try:
ctx = SearchContext(search=txt) ctx = SearchContext(search=txt, browser=self.browser)
gui_hooks.browser_will_search(ctx) gui_hooks.browser_will_search(ctx)
if ctx.card_ids is None: if ctx.card_ids is None:
ctx.card_ids = self.col.find_cards(ctx.search, order=ctx.order) ctx.card_ids = self.col.find_cards(ctx.search, order=ctx.order)