Merge pull request #1222 from RumovZ/browser-card
Change handling of browser's card parameter
This commit is contained in:
commit
df600c094a
@ -80,8 +80,9 @@ class Browser(QMainWindow):
|
|||||||
search: Optional[Tuple[Union[str, SearchNode]]] = None,
|
search: Optional[Tuple[Union[str, SearchNode]]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
card : try to search for its note and select it
|
card -- try to select the provided card after executing "search" or
|
||||||
search: set and perform search; caller must ensure validity
|
"deck:current" (if "search" was None)
|
||||||
|
search -- set and perform search; caller must ensure validity
|
||||||
"""
|
"""
|
||||||
|
|
||||||
QMainWindow.__init__(self, None, Qt.Window)
|
QMainWindow.__init__(self, None, Qt.Window)
|
||||||
@ -241,9 +242,12 @@ class Browser(QMainWindow):
|
|||||||
if search is not None:
|
if search is not None:
|
||||||
self.search_for_terms(*search)
|
self.search_for_terms(*search)
|
||||||
self.form.searchEdit.setFocus()
|
self.form.searchEdit.setFocus()
|
||||||
elif card:
|
if card is not None:
|
||||||
self.show_single_card(card)
|
if search is None:
|
||||||
self.form.searchEdit.setFocus()
|
# implicitly assume 'card' is in the current deck
|
||||||
|
self._default_search(card)
|
||||||
|
self.form.searchEdit.setFocus()
|
||||||
|
self.table.select_single_card(card.id)
|
||||||
|
|
||||||
# Searching
|
# Searching
|
||||||
######################################################################
|
######################################################################
|
||||||
@ -261,13 +265,11 @@ class Browser(QMainWindow):
|
|||||||
self.form.searchEdit.addItems(self.mw.pm.profile["searchHistory"])
|
self.form.searchEdit.addItems(self.mw.pm.profile["searchHistory"])
|
||||||
if search is not None:
|
if search is not None:
|
||||||
self.search_for_terms(*search)
|
self.search_for_terms(*search)
|
||||||
elif card:
|
|
||||||
self.show_single_card(card)
|
|
||||||
else:
|
else:
|
||||||
self.search_for(
|
self._default_search(card)
|
||||||
self.col.build_search_string(SearchNode(deck="current")), ""
|
|
||||||
)
|
|
||||||
self.form.searchEdit.setFocus()
|
self.form.searchEdit.setFocus()
|
||||||
|
if card:
|
||||||
|
self.table.select_single_card(card.id)
|
||||||
|
|
||||||
# search triggered by user
|
# search triggered by user
|
||||||
@ensure_editor_saved
|
@ensure_editor_saved
|
||||||
@ -330,17 +332,11 @@ class Browser(QMainWindow):
|
|||||||
self.form.searchEdit.setEditText(search)
|
self.form.searchEdit.setEditText(search)
|
||||||
self.onSearchActivated()
|
self.onSearchActivated()
|
||||||
|
|
||||||
def show_single_card(self, card: Card) -> None:
|
def _default_search(self, card: Optional[Card] = None) -> None:
|
||||||
if card.nid:
|
search = self.col.build_search_string(SearchNode(deck="current"))
|
||||||
|
if card is not None:
|
||||||
def on_show_single_card() -> None:
|
search = gui_hooks.default_search(search, card)
|
||||||
self.card = card
|
self.search_for(search, "")
|
||||||
search = self.col.build_search_string(SearchNode(nid=card.nid))
|
|
||||||
search = gui_hooks.default_search(search, card)
|
|
||||||
self.search_for(search, "")
|
|
||||||
self.table.select_single_card(card.id)
|
|
||||||
|
|
||||||
self.editor.call_after_note_saved(on_show_single_card)
|
|
||||||
|
|
||||||
def onReset(self) -> None:
|
def onReset(self) -> None:
|
||||||
self.sidebar.refresh()
|
self.sidebar.refresh()
|
||||||
|
@ -129,6 +129,8 @@ class Table:
|
|||||||
self.clear_selection()
|
self.clear_selection()
|
||||||
if (row := self._model.get_card_row(card_id)) is not None:
|
if (row := self._model.get_card_row(card_id)) is not None:
|
||||||
self._view.selectRow(row)
|
self._view.selectRow(row)
|
||||||
|
# editor may pop up and hide the row later on
|
||||||
|
QTimer.singleShot(100, lambda: self._scroll_to_row(row))
|
||||||
|
|
||||||
# Reset
|
# Reset
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user