Add Create Copy to reviewer and use current card's deck (#1569)

* Use deck of current card when copying note

* Add Create Copy to reviewer menu

* Add ellipsis to Set Due Date
This commit is contained in:
RumovZ 2021-12-31 07:45:30 +01:00 committed by GitHub
parent 2df3698e8c
commit 30dc2cf7ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 6 deletions

View file

@ -1,6 +1,8 @@
# 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 typing import Callable, Optional
import aqt.editor
@ -54,12 +56,12 @@ class AddCards(QMainWindow):
gui_hooks.add_cards_did_init(self)
self.show()
def set_note(self, note: Note) -> None:
"""Set tags, field contents and notetype (and its deck)
according to `note`.
def set_note(self, note: Note, deck_id: DeckId | None = None) -> None:
"""Set tags, field contents and notetype according to `note`. Deck is set
to `deck_id` or the deck last used with the notetype.
"""
self.notetype_chooser.selected_notetype_id = note.mid
if deck_id := self.col.default_deck_for_notetype(note.mid):
if deck_id or (deck_id := self.col.default_deck_for_notetype(note.mid)):
self.deck_chooser.selected_deck_id = deck_id
new_note = self._new_note()

View file

@ -591,7 +591,8 @@ class Browser(QMainWindow):
def on_create_copy(self) -> None:
if note := self.table.get_current_note():
aqt.dialogs.open("AddCards", self.mw).set_note(note)
deck_id = self.table.get_current_card().did
aqt.dialogs.open("AddCards", self.mw).set_note(note, deck_id)
@no_arg_trigger
@skip_if_selection_is_empty

View file

@ -13,6 +13,7 @@ from dataclasses import dataclass
from enum import Enum, auto
from typing import Any, Callable, Literal, Match, Sequence, cast
import aqt
from anki import hooks
from anki.cards import Card, CardId
from anki.collection import Config, OpChanges, OpChangesWithCount
@ -458,6 +459,7 @@ class Reviewer:
("-", self.bury_current_card),
("!", self.suspend_current_note),
("@", self.suspend_current_card),
("Ctrl+Alt+E", self.on_create_copy),
("Ctrl+Delete", self.delete_current_note),
("Ctrl+Shift+D", self.on_set_due),
("v", self.onReplayRecorded),
@ -913,7 +915,11 @@ time = %(time)d;
],
],
[tr.studying_bury_card(), "-", self.bury_current_card],
[tr.actions_set_due_date(), "Ctrl+Shift+D", self.on_set_due],
[
tr.actions_with_ellipsis(action=tr.actions_set_due_date()),
"Ctrl+Shift+D",
self.on_set_due,
],
[tr.actions_suspend_card(), "@", self.suspend_current_card],
[tr.actions_options(), "O", self.onOptions],
[tr.actions_card_info(), "I", self.on_card_info],
@ -922,6 +928,11 @@ time = %(time)d;
[tr.studying_mark_note(), "*", self.toggle_mark_on_current_note],
[tr.studying_bury_note(), "=", self.bury_current_note],
[tr.studying_suspend_note(), "!", self.suspend_current_note],
[
tr.actions_with_ellipsis(action=tr.actions_create_copy()),
"Ctrl+Alt+E",
self.on_create_copy,
],
[tr.studying_delete_note(), "Ctrl+Delete", self.delete_current_note],
None,
[tr.actions_replay_audio(), "R", self.replayAudio],
@ -1042,6 +1053,12 @@ time = %(time)d;
lambda res: tooltip(tr.studying_cards_buried(count=res.count))
).run_in_background()
def on_create_copy(self) -> None:
if self.card:
aqt.dialogs.open("AddCards", self.mw).set_note(
self.card.note(), self.card.did
)
def delete_current_note(self) -> None:
# need to check state because the shortcut is global to the main
# window