mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Remove ExportLimit in favour of separate classes
This commit is contained in:
parent
cf9d490576
commit
702f47c522
2 changed files with 16 additions and 27 deletions
|
@ -92,31 +92,17 @@ class LegacyCheckpoint:
|
|||
LegacyUndoResult = Union[None, LegacyCheckpoint, LegacyReviewUndo]
|
||||
|
||||
|
||||
class ExportLimit:
|
||||
"""Limit to what will be exported. Either specific notes, or a deck, or the
|
||||
whole collection (if neither is set). Only the last set value is preserved.
|
||||
"""
|
||||
@dataclass
|
||||
class DeckIdLimit:
|
||||
deck_id: DeckId
|
||||
|
||||
_note_ids: Sequence[NoteId] | None
|
||||
_deck_id: DeckId | None
|
||||
|
||||
@property
|
||||
def note_ids(self) -> Sequence[NoteId] | None:
|
||||
return self._note_ids
|
||||
@dataclass
|
||||
class NoteIdsLimit:
|
||||
note_ids: Sequence[NoteId]
|
||||
|
||||
@note_ids.setter
|
||||
def note_ids(self, note_ids: Sequence[NoteId] | None) -> None:
|
||||
self._note_ids = note_ids
|
||||
self._deck_id = None
|
||||
|
||||
@property
|
||||
def deck_id(self) -> DeckId | None:
|
||||
return self._deck_id
|
||||
|
||||
@deck_id.setter
|
||||
def deck_id(self, deck_id: DeckId | None) -> None:
|
||||
self._deck_id = deck_id
|
||||
self._note_ids = None
|
||||
ExportLimit = Union[DeckIdLimit, NoteIdsLimit, None]
|
||||
|
||||
|
||||
class Collection(DeprecatedNamesMixin):
|
||||
|
@ -408,9 +394,9 @@ class Collection(DeprecatedNamesMixin):
|
|||
with_media=with_media,
|
||||
legacy=True,
|
||||
)
|
||||
if limit.deck_id is not None:
|
||||
if isinstance(limit, DeckIdLimit):
|
||||
request.deck_id = limit.deck_id
|
||||
elif limit.note_ids is not None:
|
||||
elif isinstance(limit, NoteIdsLimit):
|
||||
request.note_ids.note_ids.extend(limit.note_ids)
|
||||
else:
|
||||
request.whole_collection.SetInParent()
|
||||
|
|
|
@ -13,7 +13,7 @@ from typing import Sequence, Type
|
|||
|
||||
import aqt.forms
|
||||
import aqt.main
|
||||
from anki.collection import ExportLimit
|
||||
from anki.collection import DeckIdLimit, ExportLimit, NoteIdsLimit
|
||||
from anki.decks import DeckId, DeckNameId
|
||||
from anki.notes import NoteId
|
||||
from aqt import gui_hooks
|
||||
|
@ -107,9 +107,12 @@ class ExportDialog(QDialog):
|
|||
return path
|
||||
|
||||
def options(self, out_path: str) -> Options:
|
||||
limit = ExportLimit()
|
||||
limit.deck_id = self.current_deck_id()
|
||||
limit.note_ids = self.nids
|
||||
limit: ExportLimit = None
|
||||
if self.nids:
|
||||
limit = NoteIdsLimit(self.nids)
|
||||
elif current_deck_id := self.current_deck_id():
|
||||
limit = DeckIdLimit(current_deck_id)
|
||||
|
||||
return Options(
|
||||
out_path=out_path,
|
||||
include_scheduling=self.frm.includeSched.isChecked(),
|
||||
|
|
Loading…
Reference in a new issue