Skip to content

Commit

Permalink
Add Create Copy to reviewer and use current card's deck (#1569)
Browse files Browse the repository at this point in the history
* Use deck of current card when copying note

* Add Create Copy to reviewer menu

* Add ellipsis to Set Due Date
  • Loading branch information
RumovZ committed Dec 31, 2021
1 parent 2df3698 commit 30dc2cf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
10 changes: 6 additions & 4 deletions qt/aqt/addcards.py
@@ -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
Expand Down Expand Up @@ -54,12 +56,12 @@ def __init__(self, mw: AnkiQt) -> None:
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()
Expand Down
3 changes: 2 additions & 1 deletion qt/aqt/browser/browser.py
Expand Up @@ -591,7 +591,8 @@ def onHelp(self) -> None:

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
Expand Down
19 changes: 18 additions & 1 deletion qt/aqt/reviewer.py
Expand Up @@ -13,6 +13,7 @@
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
Expand Down Expand Up @@ -458,6 +459,7 @@ def _shortcutKeys(
("-", 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),
Expand Down Expand Up @@ -913,7 +915,11 @@ def _contextMenu(self) -> list[Any]:
],
],
[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],
Expand All @@ -922,6 +928,11 @@ def _contextMenu(self) -> list[Any]:
[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],
Expand Down Expand Up @@ -1042,6 +1053,12 @@ def bury_current_card(self) -> None:
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
Expand Down

0 comments on commit 30dc2cf

Please sign in to comment.