Skip to content

Commit

Permalink
Add option to make button toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
simgunz committed Jan 8, 2017
1 parent 67246f8 commit a5c24aa
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions aqt/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
// 'col': document.queryCommandValue("forecolor")
};
function toggleEditorButton(buttonid) {
if ($(buttonid).hasClass("highlighted")) {
$(buttonid).removeClass("highlighted");
} else {
$(buttonid).addClass("highlighted");
}
};
function setFormat(cmd, arg, nosave) {
document.execCommand(cmd, false, arg);
if (!nosave) {
Expand Down Expand Up @@ -486,7 +494,7 @@ def resourceToData(self, path):
data64 = b''.join(base64.encodestring(data).splitlines())
return 'data:%s;base64,%s' % (mime, data64.decode('ascii'))

def _addButton(self, icon, cmd, tip="", id=None):
def _addButton(self, icon, cmd, tip="", id=None, toggleable=False):
if os.path.isabs(icon):
iconstr = self.resourceToData(icon)
else:
Expand All @@ -495,8 +503,12 @@ def _addButton(self, icon, cmd, tip="", id=None):
idstr = 'id={}'.format(id)
else:
idstr = ""
return '''<button tabindex=-1 {id} class=linkb type="button" title="{tip}" onclick="pycmd('{cmd}');return false;">
<img class=topbut src="{icon}"></button>'''.format(icon=iconstr, cmd=cmd, tip=_(tip), id=idstr)
if toggleable:
toggleScript = 'toggleEditorButton(this);'
else:
toggleScript = ''
return '''<button tabindex=-1 {id} class=linkb type="button" title="{tip}" onclick="pycmd('{cmd}');{togglesc}return false;">
<img class=topbut src="{icon}"></button>'''.format(icon=iconstr, cmd=cmd, tip=_(tip), id=idstr, togglesc=toggleScript)

def setupShortcuts(self):
cuts = [
Expand Down

0 comments on commit a5c24aa

Please sign in to comment.