9f3f6bab7d
Also: - fix issues where the Undo action in the Browse screen was not consistent with the main window. The existing hook signature has been changed; from a snapshot of the add-on code from a few months ago, it was not a hook that was being used by anyone. - change the undo shortcut in the Browse window to match the main window. It was different because undoing a change in the editing area could accidentally trigger an undo of an operation, but the damage is limited now that (most) operations can be redone. If it still proves to be a problem, perhaps we should just always swallow ctrl+z when an editing field is focused.
37 lines
970 B
Python
37 lines
970 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
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from anki.collection import UndoStatus
|
|
|
|
|
|
@dataclass
|
|
class UndoActionsInfo:
|
|
can_undo: bool
|
|
can_redo: bool
|
|
|
|
undo_text: str
|
|
redo_text: str
|
|
|
|
# menu item is hidden when legacy undo is active, since it can't be undone
|
|
show_redo: bool
|
|
|
|
@staticmethod
|
|
def from_undo_status(status: UndoStatus) -> UndoActionsInfo:
|
|
from aqt import tr
|
|
|
|
return UndoActionsInfo(
|
|
can_undo=bool(status.undo),
|
|
can_redo=bool(status.redo),
|
|
undo_text=tr.undo_undo_action(val=status.undo)
|
|
if status.undo
|
|
else tr.undo_undo(),
|
|
redo_text=tr.undo_redo_action(action=status.undo)
|
|
if status.redo
|
|
else tr.undo_redo(),
|
|
show_redo=status.last_step > 0,
|
|
)
|