restore marking support

maybe multiple mark types would make sense in the future, but for now
let's stick to what will work in the older clients
This commit is contained in:
Damien Elmes 2017-08-16 20:30:29 +10:00
parent 43d2fc2307
commit 4467b7c991
5 changed files with 65 additions and 3 deletions

View File

@ -314,6 +314,7 @@ class DataModel(QAbstractTableModel):
######################################################################
COLOUR_SUSPENDED = "#FFFFB2"
COLOUR_MARKED = "#ccc"
flagColours = {
1: "#F5B7B1",
@ -345,7 +346,8 @@ class StatusDelegate(QItemDelegate):
col = COLOUR_SUSPENDED
elif c.userFlag() > 0:
col = flagColours[c.userFlag()]
elif c.note().hasTag("Marked"):
col = COLOUR_MARKED
if col:
brush = QBrush(QColor(col))
painter.save()
@ -408,6 +410,7 @@ class Browser(QMainWindow):
f.actionAdd_Tags.triggered.connect(lambda: self.addTags())
f.actionRemove_Tags.triggered.connect(lambda: self.deleteTags())
f.actionClear_Unused_Tags.triggered.connect(self.clearUnusedTags)
f.actionToggle_Mark.triggered.connect(lambda: self.onMark())
f.actionChangeModel.triggered.connect(self.onChangeModel)
f.actionFindDuplicates.triggered.connect(self.onFindDupes)
f.actionFindReplace.triggered.connect(self.onFindReplace)
@ -1464,13 +1467,24 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
self.model.reset()
self.mw.requireReset()
# Flags
# Flags & Marking
######################################################################
def onSetFlag(self, n):
self.col.setUserFlag(n, self.selectedCards())
self.model.reset()
def onMark(self, mark=None):
if mark is None:
mark = not self.isMarked()
if mark:
self.addTags(tags="marked", label=False)
else:
self.deleteTags(tags="marked", label=False)
def isMarked(self):
return not not (self.card and self.card.note().hasTag("Marked"))
# Repositioning
######################################################################

View File

@ -120,6 +120,7 @@ class Reviewer:
def revHtml(self):
extra = self.mw.col.conf.get("reviewExtra", "")
return f"""
<div id=_mark>&#x2605;</div>
<div id=_flag>&#x2691;</div>
<div id=qa></div>
{extra}
@ -171,6 +172,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
self.web.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass))
self._drawFlag()
self._drawMark()
self._showAnswerButton()
# if we have a type answer field, focus main web
if self.typeCorrect:
@ -190,6 +192,10 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
def _drawFlag(self):
self.web.eval("_drawFlag(%s);" % self.card.userFlag())
def _drawMark(self):
self.web.eval("_drawMark(%s);" % json.dumps(
self.card.note().hasTag("marked")))
# Showing the answer
##########################################################################
@ -243,6 +249,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
("Ctrl+3", lambda: self.setFlag(3)),
("Ctrl+4", lambda: self.setFlag(4)),
("Ctrl+0", lambda: self.setFlag(0)),
("*", self.onMark),
("=", self.onBuryNote),
("-", self.onBuryCard),
("!", self.onSuspend),
@ -574,6 +581,7 @@ time = %(time)d;
[_("Blue Flag"), "Ctrl+4", lambda: self.setFlag(4)],
[_("No Flag"), "Ctrl+5", lambda: self.setFlag(0)],
]],
[_("Mark Note"), "*", self.onMark],
[_("Bury Card"), "-", self.onBuryCard],
[_("Bury Note"), "=", self.onBuryNote],
[_("Suspend Card"), "@", self.onSuspendCard],
@ -616,6 +624,15 @@ time = %(time)d;
self.card.flush()
self._drawFlag()
def onMark(self):
f = self.card.note()
if f.hasTag("marked"):
f.delTag("marked")
else:
f.addTag("marked")
f.flush()
self._drawMark()
def onSuspend(self):
self.mw.checkpoint(_("Suspend"))
self.mw.col.sched.suspendCards(

View File

@ -294,6 +294,7 @@
<addaction name="actionAdd_Tags"/>
<addaction name="actionRemove_Tags"/>
<addaction name="actionClear_Unused_Tags"/>
<addaction name="actionToggle_Mark"/>
<addaction name="separator"/>
<addaction name="actionChangeModel"/>
<addaction name="separator"/>
@ -569,6 +570,14 @@
<string>Manage Note Types...</string>
</property>
</action>
<action name="actionToggle_Mark">
<property name="text">
<string>Toggle Mark</string>
</property>
<property name="shortcut">
<string>Ctrl+K</string>
</property>
</action>
</widget>
<resources>
<include location="icons.qrc"/>

View File

@ -14,10 +14,23 @@ img {
#_flag {
position: fixed;
right: 7px;
right: 10px;
top: 0;
font-size: 30px;
display: none;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: black;
}
#_mark {
position: fixed;
left: 10px;
top: 0;
font-size: 30px;
color: yellow;
display: none;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: black;
}
#typeans {

View File

@ -76,6 +76,15 @@ function _drawFlag(flag) {
elem.css("color", _flagColours[flag]);
}
function _drawMark(mark) {
var elem = $("#_mark");
if (!mark) {
elem.hide();
} else {
elem.show();
}
}
function _typeAnsPress() {
if (window.event.keyCode === 13) {
pycmd("ans");