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]
|
LegacyUndoResult = Union[None, LegacyCheckpoint, LegacyReviewUndo]
|
||||||
|
|
||||||
|
|
||||||
class ExportLimit:
|
@dataclass
|
||||||
"""Limit to what will be exported. Either specific notes, or a deck, or the
|
class DeckIdLimit:
|
||||||
whole collection (if neither is set). Only the last set value is preserved.
|
deck_id: DeckId
|
||||||
"""
|
|
||||||
|
|
||||||
_note_ids: Sequence[NoteId] | None
|
|
||||||
_deck_id: DeckId | None
|
|
||||||
|
|
||||||
@property
|
@dataclass
|
||||||
def note_ids(self) -> Sequence[NoteId] | None:
|
class NoteIdsLimit:
|
||||||
return self._note_ids
|
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
|
ExportLimit = Union[DeckIdLimit, NoteIdsLimit, None]
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class Collection(DeprecatedNamesMixin):
|
class Collection(DeprecatedNamesMixin):
|
||||||
|
@ -408,9 +394,9 @@ class Collection(DeprecatedNamesMixin):
|
||||||
with_media=with_media,
|
with_media=with_media,
|
||||||
legacy=True,
|
legacy=True,
|
||||||
)
|
)
|
||||||
if limit.deck_id is not None:
|
if isinstance(limit, DeckIdLimit):
|
||||||
request.deck_id = limit.deck_id
|
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)
|
request.note_ids.note_ids.extend(limit.note_ids)
|
||||||
else:
|
else:
|
||||||
request.whole_collection.SetInParent()
|
request.whole_collection.SetInParent()
|
||||||
|
|
|
@ -13,7 +13,7 @@ from typing import Sequence, Type
|
||||||
|
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
import aqt.main
|
import aqt.main
|
||||||
from anki.collection import ExportLimit
|
from anki.collection import DeckIdLimit, ExportLimit, NoteIdsLimit
|
||||||
from anki.decks import DeckId, DeckNameId
|
from anki.decks import DeckId, DeckNameId
|
||||||
from anki.notes import NoteId
|
from anki.notes import NoteId
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
|
@ -107,9 +107,12 @@ class ExportDialog(QDialog):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def options(self, out_path: str) -> Options:
|
def options(self, out_path: str) -> Options:
|
||||||
limit = ExportLimit()
|
limit: ExportLimit = None
|
||||||
limit.deck_id = self.current_deck_id()
|
if self.nids:
|
||||||
limit.note_ids = self.nids
|
limit = NoteIdsLimit(self.nids)
|
||||||
|
elif current_deck_id := self.current_deck_id():
|
||||||
|
limit = DeckIdLimit(current_deck_id)
|
||||||
|
|
||||||
return Options(
|
return Options(
|
||||||
out_path=out_path,
|
out_path=out_path,
|
||||||
include_scheduling=self.frm.includeSched.isChecked(),
|
include_scheduling=self.frm.includeSched.isChecked(),
|
||||||
|
|
Loading…
Reference in a new issue