Edit Book: When right clicking on a link add a menu entry to open the link

This commit is contained in:
Kovid Goyal 2014-07-13 08:42:03 +05:30
parent 6c1a552ef4
commit c70e0bef26

View File

@ -11,14 +11,14 @@ from functools import partial
from PyQt4.Qt import (
QMainWindow, Qt, QApplication, pyqtSignal, QMenu, qDrawShadeRect, QPainter,
QImage, QColor, QIcon, QPixmap, QToolButton, QAction)
QImage, QColor, QIcon, QPixmap, QToolButton, QAction, QTextCursor)
from calibre import prints
from calibre.constants import DEBUG
from calibre.ebooks.chardet import replace_encoding_declarations
from calibre.gui2 import error_dialog
from calibre.gui2.tweak_book import actions, current_container, tprefs, dictionaries, editor_toolbar_actions, editor_name
from calibre.gui2.tweak_book.editor import SPELL_PROPERTY
from calibre.gui2.tweak_book.editor import SPELL_PROPERTY, LINK_PROPERTY
from calibre.gui2.tweak_book.editor.text import TextEdit
from calibre.utils.icu import utf16_length
@ -398,7 +398,8 @@ class Editor(QMainWindow):
m = QMenu(self)
a = m.addAction
c = self.editor.cursorForPosition(pos)
r = self.editor.syntax_range_for_cursor(c)
origc = QTextCursor(c)
r = origr = self.editor.syntax_range_for_cursor(c)
if (r is None or not r.format.property(SPELL_PROPERTY).toBool()) and c.positionInBlock() > 0:
c.setPosition(c.position() - 1)
r = self.editor.syntax_range_for_cursor(c)
@ -438,6 +439,10 @@ class Editor(QMainWindow):
dmenu.addAction(dic.name, partial(self._nuke_word, dic.name, word, locale))
m.addSeparator()
if origr is not None and origr.format.property(LINK_PROPERTY).toBool():
href = self.editor.text_for_range(origc.block(), origr)
m.addAction(_('Open %s') % href, partial(self.link_clicked.emit, href))
for x in ('undo', 'redo'):
a(actions['editor-%s' % x])
m.addSeparator()