Merge pull request #1090 from glutanimate/filtered-deck-dialog-hooks

Add hooks to the filtered deck dialog
This commit is contained in:
Damien Elmes 2021-03-26 10:28:23 +10:00 committed by GitHub
commit e34412a4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View File

@ -4,12 +4,12 @@
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
import aqt import aqt
from anki.collection import OpChangesWithCount, SearchNode from anki.collection import OpChangesWithID, SearchNode
from anki.decks import DeckDict, DeckID, FilteredDeckConfig from anki.decks import DeckDict, DeckID, FilteredDeckConfig
from anki.errors import SearchError from anki.errors import SearchError
from anki.lang import without_unicode_isolation from anki.lang import without_unicode_isolation
from anki.scheduler import FilteredDeckForUpdate from anki.scheduler import FilteredDeckForUpdate
from aqt import AnkiQt, colors from aqt import AnkiQt, colors, gui_hooks
from aqt.qt import * from aqt.qt import *
from aqt.scheduling_ops import add_or_update_filtered_deck from aqt.scheduling_ops import add_or_update_filtered_deck
from aqt.theme import theme_manager from aqt.theme import theme_manager
@ -156,6 +156,8 @@ class FilteredDeckConfigDialog(QDialog):
without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck.name)) without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck.name))
) )
gui_hooks.filtered_deck_dialog_did_load_deck(self, deck)
def reopen( def reopen(
self, self,
_mw: AnkiQt, _mw: AnkiQt,
@ -299,11 +301,16 @@ class FilteredDeckConfigDialog(QDialog):
if not self._update_deck(): if not self._update_deck():
return return
def success(out: OpChangesWithCount) -> None: def success(out: OpChangesWithID) -> None:
gui_hooks.filtered_deck_dialog_did_add_or_update_deck(
self, self.deck, out.id
)
saveGeom(self, self.GEOMETRY_KEY) saveGeom(self, self.GEOMETRY_KEY)
aqt.dialogs.markClosed(self.DIALOG_KEY) aqt.dialogs.markClosed(self.DIALOG_KEY)
QDialog.accept(self) QDialog.accept(self)
gui_hooks.filtered_deck_dialog_will_add_or_update_deck(self, self.deck)
add_or_update_filtered_deck(mw=self.mw, deck=self.deck, success=success) add_or_update_filtered_deck(mw=self.mw, deck=self.deck, success=success)
# Step load/save # Step load/save

View File

@ -284,6 +284,33 @@ hooks = [
], ],
doc="Called before config group is renamed", doc="Called before config group is renamed",
), ),
# Filtered deck options
###################
Hook(
name="filtered_deck_dialog_did_load_deck",
args=[
"filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog",
"filtered_deck: anki.scheduler.FilteredDeckForUpdate",
],
doc="Allows updating widget state once the filtered deck config is loaded",
),
Hook(
name="filtered_deck_dialog_will_add_or_update_deck",
args=[
"filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog",
"filtered_deck: anki.scheduler.FilteredDeckForUpdate",
],
doc="Allows modifying the filtered deck config object before it is written",
),
Hook(
name="filtered_deck_dialog_did_add_or_update_deck",
args=[
"filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog",
"filtered_deck: anki.scheduler.FilteredDeckForUpdate",
"deck_id: int",
],
doc="Allows performing changes after a filtered deck has been added or updated",
),
# Browser # Browser
################### ###################
Hook( Hook(