-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathquick_tagging.py
93 lines (73 loc) · 2.76 KB
/
quick_tagging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Quick Tagging is an anki2 addon for quickly adding tags while reviewing
# Copyright 2012 Cayenne Boyer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# CONFIGURATION OPTIONS
# Change this to change what keybinding opens the add tags dialog
tag_shortcut = 't'
quick_tags = {
# Add lines here to create shortcuts that add specified tags
# Examples (remove the leading #):
# Keybinding to add a named tag:
#'j': {'tags': 'hard'},
# Add multiple tags by seperating them with spaces:
#'k': {'tags': 'hard marked'},
# Bury by adding a True bury element:
#'l': {'tags': 'needs_elaboration', bury: True},
} # end quick_tags
# END CONFIGURATION OPTIONS
from aqt import mw
from aqt.utils import getTag, tooltip
from aqt.reviewer import Reviewer
# add space separated tags to a note
def addTags(note, tagString):
# add tags to card
tagList = mw.col.tags.split(tagString)
for tag in tagList:
note.addTag(tag)
note.flush()
# prompt for tags and add the results to a note
def promptAndAddTags(note):
# prompt for new tags
prompt = _("Enter tags to add:")
(tagString, r) = getTag(mw, mw.col, prompt)
# don't do anything if we didn't get anything
if not r:
return
# otherwise, add the given tags:
addTags(note, tagString)
tooltip('Added tag(s) "%s"' % tagString)
# replace _keyHandler in reviewer.py to add a keybinding
def newKeyHandler(self, evt):
key = unicode(evt.text())
note = mw.reviewer.card.note()
if key == tag_shortcut:
mw.checkpoint(_("Add Tags"))
promptAndAddTags(note)
elif key in quick_tags:
if 'bury' in quick_tags[key] and quick_tags[key]['bury']:
mw.checkpoint("Add Tags and Bury")
addTags(note, quick_tags[key]['tags'])
mw.col.sched.buryNote(note.id)
mw.reset()
tooltip('Added tag(s) "%s" and buried note'
% quick_tags[key]['tags'])
else:
mw.checkpoint(_("Add Tags"))
addTags(note, quick_tags[key]['tags'])
tooltip('Added tag(s) "%s"' % quick_tags[key]['tags'])
else:
origKeyHandler(self, evt)
origKeyHandler = Reviewer._keyHandler
Reviewer._keyHandler = newKeyHandler