anki/qt/aqt/schema_change_tracker.py
Damien Elmes dd13e78eca
Add ability to restore a notetype to its original configuration (#2472)
* Store the original stock notetype kind in the notetype

Will allow us to provide a command to restore a notetype to its default
settings/templates.

* Add a new action to restore a notetype to its original state
2023-04-18 14:07:51 +10:00

40 lines
990 B
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
import enum
from aqt import AnkiQt
class Change(enum.Enum):
NO_CHANGE = 0
BASIC_CHANGE = 1
SCHEMA_CHANGE = 2
class ChangeTracker:
_changed = Change.NO_CHANGE
def __init__(self, mw: AnkiQt) -> None:
self.mw = mw
def mark_basic(self) -> None:
if self._changed == Change.NO_CHANGE:
self._changed = Change.BASIC_CHANGE
def mark_schema(self) -> bool:
"If false, processing should be aborted."
if self._changed != Change.SCHEMA_CHANGE:
if not self.mw.confirm_schema_modification():
return False
self._changed = Change.SCHEMA_CHANGE
return True
def changed(self) -> bool:
return self._changed != Change.NO_CHANGE
def set_unchanged(self) -> None:
self._changed = Change.NO_CHANGE