mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Format block command for comments editor on EM page
This commit is contained in:
parent
2645ef6209
commit
8d0f8ba765
5
imgsrc/srv/heading.svg
Normal file
5
imgsrc/srv/heading.svg
Normal file
@ -0,0 +1,5 @@
|
||||
<svg viewBox="0 0 128 128" height="128" width="128">
|
||||
<g transform="translate(0,-924.36216)">
|
||||
<path d="m 123.37397,1043.8196 q -3.32374,0 -10.00899,-0.2527 -6.68525,-0.2528 -10.08453,-0.2528 -3.323751,0 -9.971231,0.2528 -6.64748,0.2527 -9.97122,0.2527 -1.81295,0 -2.79496,-1.4803 -0.98202,-1.4803 -0.98202,-3.2856 0,-2.2385 1.28417,-3.3216 1.28418,-1.0832 2.94605,-1.2276 1.66187,-0.1445 3.85251,-0.5055 2.19065,-0.3611 3.39929,-1.0832 2.4928,-1.5164 2.4928,-10.1094 l -0.0755,-28.23417 q 0,-1.51638 -0.0755,-2.23849 -0.98201,-0.28888 -3.77698,-0.28888 h -50.9892 q -2.87051,0 -3.85252,0.28888 -0.0755,0.72211 -0.0755,2.23849 l -0.0755,26.78997 q 0,10.2539 2.79496,11.8425 1.20864,0.7221 3.6259,0.9387 2.41727,0.2166 4.30576,0.2528 1.88849,0.036 3.39928,1.0831 1.51079,1.0471 1.51079,3.2856 0,1.8775 -0.94425,3.466 -0.94424,1.5887 -2.75719,1.5887 -3.55036,0 -10.53777,-0.2527 -6.98741,-0.2528 -10.46223,-0.2528 -3.2482,0 -9.66907,0.2528 -6.4208594,0.2527 -9.5935194,0.2527 -1.73741,0 -2.68165,-1.5164 -0.94425,-1.5165 -0.94425,-3.2495 0,-2.1663 1.17086,-3.2494 1.17087,-1.0832 2.71943,-1.2637 1.54856,-0.1806 3.5881294,-0.5416 2.03957,-0.3611 3.17266,-1.0832 2.49281,-1.6608 2.49281,-10.326 l -0.0755,-4.116 v -58.70691 q 0,-0.21662 0.0378,-1.87744 0.0378,-1.66083 0,-2.63568 -0.0378,-0.97485 -0.11331,-2.78012 -0.0755,-1.80517 -0.26439,-3.03277 -0.18885,-1.2276 -0.49101,-2.63568 -0.30216,-1.40807 -0.83093,-2.27462 -0.52878,-0.86655 -1.20864,-1.29977 -1.13309,-0.72211 -3.3992793,-0.86655 -2.2661901,-0.14444 -4.0036001,-0.14444 -1.7374099,0 -3.0971199,-1.01089 -1.3597101,-1.01099 -1.3597101,-3.24948 0,-1.87744 0.9064701,-3.46609 0.90648,-1.58865 2.71943,-1.58865 3.47482,0 10.4622293,0.25274 6.98741,0.25275 10.46223,0.25275 3.17266,0 9.55576,-0.25275 6.38309,-0.25274 9.55575,-0.25274 1.88849,0 2.83273,1.58865 0.94425,1.58865 0.94425,3.46609 0,2.16632 -1.28417,3.14117 -1.28418,0.97476 -2.90828,1.04703 -1.6241,0.0717 -3.73921,0.28878 -2.1151,0.21671 -3.2482,0.93882 -2.64388,1.51638 -2.64388,11.5536 l 0.0755,23.1073 q 0,1.51639 0.0755,2.31067 0.98201,0.21661 2.94604,0.21661 h 52.80216 q 1.88849,0 2.8705,-0.21661 0.0755,-0.79428 0.0755,-2.31067 l 0.0755,-23.1073 q 0,-10.03722 -2.64388,-11.5536 -1.35972,-0.79438 -4.41907,-0.90268 -3.05935,-0.10831 -4.98561,-0.93872 -1.92626,-0.83041 -1.92626,-3.5744 0,-1.87744 0.94425,-3.46609 0.94424,-1.58865 2.83273,-1.58865 3.32374,0 9.97122,0.25274 6.64748,0.25275 9.971231,0.25275 3.2482,0 9.7446,-0.25275 6.4964,-0.25274 9.7446,-0.25274 1.88849,0 2.83274,1.58865 0.94424,1.58865 0.94424,3.46609 0,2.16632 -1.32194,3.17721 -1.32194,1.01099 -3.02158,1.04712 -1.69964,0.0363 -3.89029,0.21661 -2.19065,0.18048 -3.32374,0.90259 -2.64389,1.66082 -2.64389,11.62587 l 0.0755,68.09425 q 0,8.593 2.56835,10.1093 1.20863,0.7222 3.47482,0.9749 2.26619,0.2527 4.04137,0.325 1.77518,0.072 3.13489,1.1192 1.35971,1.047 1.35971,3.2134 0,1.8775 -0.90647,3.466 -0.90648,1.5887 -2.71943,1.5887 z" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.9 KiB |
@ -8,6 +8,8 @@ from gettext import gettext as _
|
||||
from book_list.theme import get_color
|
||||
from dom import add_extra_css, build_rule, clear, ensure_id, svgicon
|
||||
from iframe_comm import IframeClient, IframeWrapper
|
||||
from modals import create_custom_dialog
|
||||
from widgets import create_button
|
||||
|
||||
CLASS_NAME = 'comments-editor'
|
||||
TOOLBAR_CLASS = 'comments-editor-toolbar'
|
||||
@ -27,6 +29,31 @@ add_extra_css(def():
|
||||
)
|
||||
|
||||
|
||||
def choose_block_style(proceed):
|
||||
create_custom_dialog(_('Choose style'), def(parent, close_modal):
|
||||
|
||||
def action(which):
|
||||
close_modal()
|
||||
proceed(which)
|
||||
|
||||
def s(text, tag):
|
||||
ans = create_button(text, action=action.bind(None, tag))
|
||||
ans.style.marginBottom = '1ex'
|
||||
return ans
|
||||
|
||||
spc = '\xa0'
|
||||
|
||||
parent.appendChild(E.div(
|
||||
E.div(_('Choose the block style you would like to use')),
|
||||
E.div(class_='button-box', style='flex-wrap: wrap',
|
||||
s(_('Normal'), 'div'), spc, s('H1', 'h1'), spc, s('H2', 'h2'), spc, s('H3', 'h3'), spc, s('H4', 'h4'), spc, s('H5', 'h5'), spc, s('H6', 'h6'), spc, s(_('Quote'), 'blockquote')
|
||||
)
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
def all_editor_actions(): # {{{
|
||||
if not all_editor_actions.ans:
|
||||
all_editor_actions.ans = {
|
||||
@ -96,6 +123,17 @@ def all_editor_actions(): # {{{
|
||||
'execute': def (editor, activated):
|
||||
editor.exec_command('insertHorizontalRule')
|
||||
},
|
||||
'format-block': {
|
||||
'icon': 'heading',
|
||||
'title': _('Style the selected text block'),
|
||||
'execute': def (editor, activated):
|
||||
choose_block_style(def(cmd):
|
||||
if cmd:
|
||||
editor.exec_command('formatBlock', f'<{cmd}>')
|
||||
editor.focus()
|
||||
)
|
||||
},
|
||||
|
||||
}
|
||||
return all_editor_actions.ans
|
||||
# }}}
|
||||
@ -272,7 +310,7 @@ def create_comments_editor(container):
|
||||
toolbar1 = E.div(class_=TOOLBAR_CLASS)
|
||||
toolbars.appendChild(toolbar1)
|
||||
acmap = all_editor_actions()
|
||||
for ac_name in 'undo redo select-all remove-format | bold italic underline strikethrough | hr superscript subscript'.split(' '):
|
||||
for ac_name in 'undo redo select-all remove-format | bold italic underline strikethrough | hr superscript subscript format-block'.split(' '):
|
||||
if acmap[ac_name]:
|
||||
add_action(toolbar1, ac_name, acmap[ac_name], editor.id)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user