mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Comments editor: Fix data file links not working
This commit is contained in:
parent
1160486703
commit
9c84994d32
@ -1333,8 +1333,14 @@ class BookDetails(DetailsLayout): # {{{
|
||||
)
|
||||
|
||||
def browse(url):
|
||||
if url.startswith(DATA_DIR_NAME + '/') and self.last_data.get('book_id'):
|
||||
base = get_gui().current_db.abspath(self.last_data['book_id'], index_is_id=True)
|
||||
path = os.path.join(base, url)
|
||||
qurl = QUrl.fromLocalFile(path)
|
||||
else:
|
||||
qurl = QUrl(url, QUrl.ParsingMode.TolerantMode)
|
||||
try:
|
||||
safe_open_url(QUrl(url, QUrl.ParsingMode.TolerantMode))
|
||||
safe_open_url(qurl)
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
@ -1389,7 +1395,7 @@ class BookDetails(DetailsLayout): # {{{
|
||||
|
||||
def show_data(self, data):
|
||||
try:
|
||||
self.last_data = {'title':data.title, 'authors':data.authors}
|
||||
self.last_data = {'title':data.title, 'authors':data.authors, 'book_id': getattr(data, 'id', None)}
|
||||
except Exception:
|
||||
self.last_data = {}
|
||||
self.book_info.show_data(data)
|
||||
|
@ -1003,6 +1003,12 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
||||
if a <= q <= b:
|
||||
return cf
|
||||
|
||||
def open_link(self, link: str) -> None:
|
||||
qurl = QUrl(link, QUrl.ParsingMode.TolerantMode)
|
||||
if qurl.isRelative() and self.base_url:
|
||||
qurl = QUrl.fromLocalFile(os.path.join(os.path.dirname(self.base_url.toLocalFile()), qurl.path()))
|
||||
safe_open_url(qurl)
|
||||
|
||||
def contextMenuEvent(self, ev):
|
||||
menu = QMenu(self)
|
||||
img_name = self.document().documentLayout().imageAt(QPointF(ev.pos()))
|
||||
@ -1033,7 +1039,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
||||
align_menu.addAction(QIcon.ic('trash.png'), _('Remove this image')).triggered.connect(partial(self.remove_image_at, c.position()))
|
||||
link_name = self.document().documentLayout().anchorAt(QPointF(ev.pos()))
|
||||
if link_name:
|
||||
menu.addAction(QIcon.ic('insert-link.png'), _('Open link'), partial(safe_open_url, QUrl(link_name)))
|
||||
menu.addAction(QIcon.ic('insert-link.png'), _('Open link'), partial(self.open_link, link_name))
|
||||
for ac in 'undo redo -- cut copy paste paste_and_match_style -- select_all'.split():
|
||||
if ac == '--':
|
||||
menu.addSeparator()
|
||||
|
Loading…
x
Reference in New Issue
Block a user