mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
preferences update needs to be a collection op
- fixes https://forums.ankiweb.net/t/v3-bug-card-modified-without-updating-queue/12418 - fixes undo menu not updating after closing preferences screen
This commit is contained in:
parent
b9d42af423
commit
d92913eb8c
3 changed files with 38 additions and 16 deletions
|
@ -1082,8 +1082,8 @@ table.review-log {{ {revlog_style} }}
|
||||||
def get_preferences(self) -> Preferences:
|
def get_preferences(self) -> Preferences:
|
||||||
return self._backend.get_preferences()
|
return self._backend.get_preferences()
|
||||||
|
|
||||||
def set_preferences(self, prefs: Preferences) -> None:
|
def set_preferences(self, prefs: Preferences) -> OpChanges:
|
||||||
self._backend.set_preferences(prefs)
|
return self._backend.set_preferences(prefs)
|
||||||
|
|
||||||
def render_markdown(self, text: str, sanitize: bool = True) -> str:
|
def render_markdown(self, text: str, sanitize: bool = True) -> str:
|
||||||
"Not intended for public consumption at this time."
|
"Not intended for public consumption at this time."
|
||||||
|
|
|
@ -3,7 +3,13 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from anki.collection import LegacyCheckpoint, LegacyReviewUndo, OpChangesAfterUndo
|
from anki.collection import (
|
||||||
|
LegacyCheckpoint,
|
||||||
|
LegacyReviewUndo,
|
||||||
|
OpChanges,
|
||||||
|
OpChangesAfterUndo,
|
||||||
|
Preferences,
|
||||||
|
)
|
||||||
from anki.errors import UndoEmpty
|
from anki.errors import UndoEmpty
|
||||||
from anki.types import assert_exhaustive
|
from anki.types import assert_exhaustive
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
|
@ -87,3 +93,9 @@ def _legacy_undo(*, parent: QWidget) -> None:
|
||||||
tooltip(tr.undo_action_undone(action=name), parent=parent)
|
tooltip(tr.undo_action_undone(action=name), parent=parent)
|
||||||
gui_hooks.state_did_revert(name)
|
gui_hooks.state_did_revert(name)
|
||||||
mw.update_undo_actions()
|
mw.update_undo_actions()
|
||||||
|
|
||||||
|
|
||||||
|
def set_preferences(
|
||||||
|
*, parent: QWidget, preferences: Preferences
|
||||||
|
) -> CollectionOp[OpChanges]:
|
||||||
|
return CollectionOp(parent, lambda col: col.set_preferences(preferences))
|
||||||
|
|
|
@ -5,8 +5,10 @@ from typing import Any, cast
|
||||||
|
|
||||||
import anki.lang
|
import anki.lang
|
||||||
import aqt
|
import aqt
|
||||||
|
from anki.collection import OpChanges
|
||||||
from anki.consts import newCardSchedulingLabels
|
from anki.consts import newCardSchedulingLabels
|
||||||
from aqt import AnkiQt
|
from aqt import AnkiQt
|
||||||
|
from aqt.operations.collection import set_preferences
|
||||||
from aqt.profiles import RecordingDriver, VideoDriver
|
from aqt.profiles import RecordingDriver, VideoDriver
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import HelpPage, disable_help_button, openHelp, showInfo, showWarning, tr
|
from aqt.utils import HelpPage, disable_help_button, openHelp, showInfo, showWarning, tr
|
||||||
|
@ -35,13 +37,16 @@ class Preferences(QDialog):
|
||||||
# avoid exception if main window is already closed
|
# avoid exception if main window is already closed
|
||||||
if not self.mw.col:
|
if not self.mw.col:
|
||||||
return
|
return
|
||||||
self.update_collection()
|
|
||||||
|
def after_collection_update() -> None:
|
||||||
self.update_profile()
|
self.update_profile()
|
||||||
self.update_global()
|
self.update_global()
|
||||||
self.mw.pm.save()
|
self.mw.pm.save()
|
||||||
self.done(0)
|
self.done(0)
|
||||||
aqt.dialogs.markClosed("Preferences")
|
aqt.dialogs.markClosed("Preferences")
|
||||||
|
|
||||||
|
self.update_collection(after_collection_update)
|
||||||
|
|
||||||
def reject(self) -> None:
|
def reject(self) -> None:
|
||||||
self.accept()
|
self.accept()
|
||||||
|
|
||||||
|
@ -84,7 +89,7 @@ class Preferences(QDialog):
|
||||||
form.pastePNG.setChecked(editing.paste_images_as_png)
|
form.pastePNG.setChecked(editing.paste_images_as_png)
|
||||||
form.default_search_text.setText(editing.default_search_text)
|
form.default_search_text.setText(editing.default_search_text)
|
||||||
|
|
||||||
def update_collection(self) -> None:
|
def update_collection(self, on_done: Callable[[], None]) -> None:
|
||||||
form = self.form
|
form = self.form
|
||||||
|
|
||||||
scheduling = self.prefs.scheduling
|
scheduling = self.prefs.scheduling
|
||||||
|
@ -107,14 +112,19 @@ class Preferences(QDialog):
|
||||||
editing.paste_strips_formatting = self.form.paste_strips_formatting.isChecked()
|
editing.paste_strips_formatting = self.form.paste_strips_formatting.isChecked()
|
||||||
editing.default_search_text = self.form.default_search_text.text()
|
editing.default_search_text = self.form.default_search_text.text()
|
||||||
|
|
||||||
self.mw.col.set_preferences(self.prefs)
|
def after_prefs_update(changes: OpChanges) -> None:
|
||||||
self.mw.apply_collection_options()
|
self.mw.apply_collection_options()
|
||||||
|
|
||||||
if scheduling.scheduler_version > 1:
|
if scheduling.scheduler_version > 1:
|
||||||
want_v3 = form.sched2021.isChecked()
|
want_v3 = form.sched2021.isChecked()
|
||||||
if self.mw.col.v3_scheduler() != want_v3:
|
if self.mw.col.v3_scheduler() != want_v3:
|
||||||
self.mw.col.set_v3_scheduler(want_v3)
|
self.mw.col.set_v3_scheduler(want_v3)
|
||||||
|
|
||||||
|
on_done()
|
||||||
|
|
||||||
|
set_preferences(parent=self, preferences=self.prefs).success(
|
||||||
|
after_prefs_update
|
||||||
|
).run_in_background()
|
||||||
|
|
||||||
# Preferences stored in the profile
|
# Preferences stored in the profile
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue