mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: When right clicking on a link add a menu entry to open the link
This commit is contained in:
parent
6c1a552ef4
commit
c70e0bef26
@ -11,14 +11,14 @@ from functools import partial
|
|||||||
|
|
||||||
from PyQt4.Qt import (
|
from PyQt4.Qt import (
|
||||||
QMainWindow, Qt, QApplication, pyqtSignal, QMenu, qDrawShadeRect, QPainter,
|
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 import prints
|
||||||
from calibre.constants import DEBUG
|
from calibre.constants import DEBUG
|
||||||
from calibre.ebooks.chardet import replace_encoding_declarations
|
from calibre.ebooks.chardet import replace_encoding_declarations
|
||||||
from calibre.gui2 import error_dialog
|
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 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.gui2.tweak_book.editor.text import TextEdit
|
||||||
from calibre.utils.icu import utf16_length
|
from calibre.utils.icu import utf16_length
|
||||||
|
|
||||||
@ -398,7 +398,8 @@ class Editor(QMainWindow):
|
|||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
a = m.addAction
|
a = m.addAction
|
||||||
c = self.editor.cursorForPosition(pos)
|
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:
|
if (r is None or not r.format.property(SPELL_PROPERTY).toBool()) and c.positionInBlock() > 0:
|
||||||
c.setPosition(c.position() - 1)
|
c.setPosition(c.position() - 1)
|
||||||
r = self.editor.syntax_range_for_cursor(c)
|
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))
|
dmenu.addAction(dic.name, partial(self._nuke_word, dic.name, word, locale))
|
||||||
m.addSeparator()
|
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'):
|
for x in ('undo', 'redo'):
|
||||||
a(actions['editor-%s' % x])
|
a(actions['editor-%s' % x])
|
||||||
m.addSeparator()
|
m.addSeparator()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user