undoing of notetype templates

This commit is contained in:
Damien Elmes 2021-04-30 17:30:48 +10:00
parent 9a46ad6352
commit 248373ef30
4 changed files with 9 additions and 22 deletions

View file

@ -839,8 +839,6 @@ where id in %s"""
def setupHooks(self) -> None: def setupHooks(self) -> None:
gui_hooks.undo_state_did_change.append(self.onUndoState) gui_hooks.undo_state_did_change.append(self.onUndoState)
# fixme: remove this once all items are using `operation_did_execute`
gui_hooks.sidebar_should_refresh_notetypes.append(self.on_item_added)
gui_hooks.backend_will_block.append(self.table.on_backend_will_block) gui_hooks.backend_will_block.append(self.table.on_backend_will_block)
gui_hooks.backend_did_block.append(self.table.on_backend_did_block) gui_hooks.backend_did_block.append(self.table.on_backend_did_block)
gui_hooks.operation_did_execute.append(self.on_operation_did_execute) gui_hooks.operation_did_execute.append(self.on_operation_did_execute)
@ -848,15 +846,11 @@ where id in %s"""
def teardownHooks(self) -> None: def teardownHooks(self) -> None:
gui_hooks.undo_state_did_change.remove(self.onUndoState) gui_hooks.undo_state_did_change.remove(self.onUndoState)
gui_hooks.sidebar_should_refresh_notetypes.remove(self.on_item_added)
gui_hooks.backend_will_block.remove(self.table.on_backend_will_block) gui_hooks.backend_will_block.remove(self.table.on_backend_will_block)
gui_hooks.backend_did_block.remove(self.table.on_backend_will_block) gui_hooks.backend_did_block.remove(self.table.on_backend_will_block)
gui_hooks.operation_did_execute.remove(self.on_operation_did_execute) gui_hooks.operation_did_execute.remove(self.on_operation_did_execute)
gui_hooks.focus_did_change.remove(self.on_focus_change) gui_hooks.focus_did_change.remove(self.on_focus_change)
def on_item_added(self, item: Any = None) -> None:
self.sidebar.refresh()
# Undo # Undo
###################################################################### ######################################################################

View file

@ -6,12 +6,13 @@ from concurrent.futures import Future
from typing import Any, Dict, List, Match, Optional from typing import Any, Dict, List, Match, Optional
import aqt import aqt
from anki.collection import OpChanges
from anki.consts import * from anki.consts import *
from anki.errors import TemplateError
from anki.lang import without_unicode_isolation from anki.lang import without_unicode_isolation
from anki.notes import Note from anki.notes import Note
from aqt import AnkiQt, gui_hooks from aqt import AnkiQt, gui_hooks
from aqt.forms.browserdisp import Ui_Dialog from aqt.forms.browserdisp import Ui_Dialog
from aqt.operations.notetype import update_notetype_legacy
from aqt.qt import * from aqt.qt import *
from aqt.schema_change_tracker import ChangeTracker from aqt.schema_change_tracker import ChangeTracker
from aqt.sound import av_player, play_clicked_audio from aqt.sound import av_player, play_clicked_audio
@ -29,7 +30,6 @@ from aqt.utils import (
saveSplitter, saveSplitter,
shortcut, shortcut,
showInfo, showInfo,
showWarning,
tooltip, tooltip,
tr, tr,
) )
@ -784,22 +784,15 @@ class CardLayout(QDialog):
###################################################################### ######################################################################
def accept(self) -> None: def accept(self) -> None:
def save() -> None: def on_done(changes: OpChanges) -> None:
self.mm.save(self.model)
def on_done(fut: Future) -> None:
try:
fut.result()
except TemplateError as e:
showWarning(str(e))
return
self.mw.reset()
tooltip(tr.card_templates_changes_saved(), parent=self.parentWidget()) tooltip(tr.card_templates_changes_saved(), parent=self.parentWidget())
self.cleanup() self.cleanup()
gui_hooks.sidebar_should_refresh_notetypes() gui_hooks.sidebar_should_refresh_notetypes()
return QDialog.accept(self) QDialog.accept(self)
self.mw.taskman.with_progress(save, on_done) update_notetype_legacy(parent=self.mw, notetype=self.model).success(
on_done
).run_in_background()
def reject(self) -> None: def reject(self) -> None:
if self.change_tracker.changed(): if self.change_tracker.changed():

View file

@ -234,7 +234,7 @@ class FieldDialog(QDialog):
self.saveField() self.saveField()
def on_done(changes: OpChanges) -> None: def on_done(changes: OpChanges) -> None:
tooltip("Changes saved.", parent=self.mw) tooltip(tr.card_templates_changes_saved(), parent=self.parentWidget())
QDialog.accept(self) QDialog.accept(self)
update_notetype_legacy(parent=self.mw, notetype=self.model).success( update_notetype_legacy(parent=self.mw, notetype=self.model).success(

View file

@ -916,7 +916,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
legacy_no_args=True, legacy_no_args=True,
), ),
Hook(name="sidebar_should_refresh_decks", doc="Legacy, do not use."), Hook(name="sidebar_should_refresh_decks", doc="Legacy, do not use."),
Hook(name="sidebar_should_refresh_notetypes"), Hook(name="sidebar_should_refresh_notetypes", doc="Legacy, do not use."),
Hook( Hook(
name="deck_browser_will_show_options_menu", name="deck_browser_will_show_options_menu",
args=["menu: QMenu", "deck_id: int"], args=["menu: QMenu", "deck_id: int"],