notetype removal undoable
This commit is contained in:
parent
ea758f0092
commit
394fe86f8f
@ -228,10 +228,10 @@ class ModelManager:
|
|||||||
self._remove_from_cache(NotetypeId(nt.id))
|
self._remove_from_cache(NotetypeId(nt.id))
|
||||||
self.col._backend.remove_notetype(nt.id)
|
self.col._backend.remove_notetype(nt.id)
|
||||||
|
|
||||||
def remove(self, id: NotetypeId) -> None:
|
def remove(self, id: NotetypeId) -> OpChanges:
|
||||||
"Modifies schema."
|
"Modifies schema."
|
||||||
self._remove_from_cache(id)
|
self._remove_from_cache(id)
|
||||||
self.col._backend.remove_notetype(id)
|
return self.col._backend.remove_notetype(id)
|
||||||
|
|
||||||
def add(self, m: NotetypeDict) -> OpChangesWithId:
|
def add(self, m: NotetypeDict) -> OpChangesWithId:
|
||||||
"Replaced with add_dict()"
|
"Replaced with add_dict()"
|
||||||
|
@ -11,8 +11,9 @@ from anki.lang import without_unicode_isolation
|
|||||||
from anki.models import NotetypeDict, NotetypeId, NotetypeNameIdUseCount
|
from anki.models import NotetypeDict, NotetypeId, NotetypeNameIdUseCount
|
||||||
from anki.notes import Note
|
from anki.notes import Note
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.operations.notetype import add_notetype_legacy
|
from aqt.operations.notetype import add_notetype_legacy, remove_notetype
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
from aqt.schema_change_tracker import ChangeTracker
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
HelpPage,
|
HelpPage,
|
||||||
askUser,
|
askUser,
|
||||||
@ -171,18 +172,14 @@ class Models(QDialog):
|
|||||||
if not askUser(msg, parent=self):
|
if not askUser(msg, parent=self):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.col.modSchema(check=True)
|
tracker = ChangeTracker(self.mw)
|
||||||
|
if not tracker.mark_schema():
|
||||||
|
return
|
||||||
|
|
||||||
nt = self.current_notetype()
|
nt = self.current_notetype()
|
||||||
|
remove_notetype(parent=self, notetype_id=nt["id"]).success(
|
||||||
def save() -> Sequence[NotetypeNameIdUseCount]:
|
lambda _: self.refresh_list()
|
||||||
self.mm.rem(nt)
|
).run_in_background()
|
||||||
return self.col.models.all_use_counts()
|
|
||||||
|
|
||||||
def on_done(fut: Future) -> None:
|
|
||||||
self.updateModelsList(fut.result())
|
|
||||||
|
|
||||||
self.mw.taskman.with_progress(save, on_done, self)
|
|
||||||
|
|
||||||
def onAdvanced(self) -> None:
|
def onAdvanced(self) -> None:
|
||||||
nt = self.current_notetype()
|
nt = self.current_notetype()
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from anki.collection import OpChanges, OpChangesWithId
|
from anki.collection import OpChanges, OpChangesWithId
|
||||||
from anki.models import NotetypeDict
|
from anki.models import NotetypeDict, NotetypeId
|
||||||
from aqt import QWidget
|
from aqt import QWidget
|
||||||
from aqt.operations import CollectionOp
|
from aqt.operations import CollectionOp
|
||||||
|
|
||||||
@ -23,3 +23,11 @@ def update_notetype_legacy(
|
|||||||
notetype: NotetypeDict,
|
notetype: NotetypeDict,
|
||||||
) -> CollectionOp[OpChanges]:
|
) -> CollectionOp[OpChanges]:
|
||||||
return CollectionOp(parent, lambda col: col.models.update_dict(notetype))
|
return CollectionOp(parent, lambda col: col.models.update_dict(notetype))
|
||||||
|
|
||||||
|
|
||||||
|
def remove_notetype(
|
||||||
|
*,
|
||||||
|
parent: QWidget,
|
||||||
|
notetype_id: NotetypeId,
|
||||||
|
) -> CollectionOp[OpChanges]:
|
||||||
|
return CollectionOp(parent, lambda col: col.models.remove(notetype_id))
|
||||||
|
Loading…
Reference in New Issue
Block a user