Skip to content

Commit

Permalink
Comments editor: Add a button to easily insert separators (i.e. <hr> …
Browse files Browse the repository at this point in the history
…tags) when editing comments
  • Loading branch information
kovidgoyal committed Jul 2, 2017
1 parent 9f4bf26 commit ebdec9f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
95 changes: 95 additions & 0 deletions imgsrc/format-text-hr.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/format-text-hr.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions src/calibre/gui2/comments_editor.py
Expand Up @@ -163,9 +163,13 @@ def __init__(self, parent=None):

self.action_insert_link = QAction(QIcon(I('insert-link.png')),
_('Insert link or image'), self)
self.action_insert_hr = QAction(QIcon(I('format-text-hr.png')),
_('Insert separator'), self)
self.action_insert_link.triggered.connect(self.insert_link)
self.action_insert_hr.triggered.connect(self.insert_hr)
self.pageAction(QWebPage.ToggleBold).changed.connect(self.update_link_action)
self.action_insert_link.setEnabled(False)
self.action_insert_hr.setEnabled(False)
self.action_clear = QAction(QIcon(I('trash.png')), _('Clear'), self)
self.action_clear.triggered.connect(self.clear_text)

Expand All @@ -177,8 +181,9 @@ def __init__(self, parent=None):
self.set_readonly(False)

def update_link_action(self):
wac = self.pageAction(QWebPage.ToggleBold)
self.action_insert_link.setEnabled(wac.isEnabled())
wac = self.pageAction(QWebPage.ToggleBold).isEnabled()
self.action_insert_link.setEnabled(wac)
self.action_insert_hr.setEnabled(wac)

def set_readonly(self, what):
self.readonly = what
Expand Down Expand Up @@ -209,6 +214,9 @@ def background_color(self):
if col.isValid():
self.exec_command('hiliteColor', unicode(col.name()))

def insert_hr(self, *args):
self.exec_command('insertHTML', '<hr>')

def insert_link(self, *args):
link, name, is_image = self.ask_link()
if not link:
Expand Down Expand Up @@ -705,6 +713,7 @@ def __init__(self, parent=None, one_line_toolbar=False, toolbar_prefs_name=None)
if hasattr(w, 'setPopupMode'):
w.setPopupMode(w.InstantPopup)
self.toolbar2.addAction(self.editor.action_insert_link)
self.toolbar2.addAction(self.editor.action_insert_hr)
# }}}

# toolbar3 {{{
Expand Down

0 comments on commit ebdec9f

Please sign in to comment.