Content server viewer: Allow viewing images in a new window by right clicking them, matches the calibre builtin viewer behavior. Fixes #1903333 [[Enhancement - Content server viewer] Ability to view image](https://bugs.launchpad.net/calibre/+bug/1903333)

This commit is contained in:
Kovid Goyal 2020-11-25 17:11:57 +05:30
parent b6b1af097b
commit 4bafec703d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 38 additions and 1 deletions

View File

@ -370,7 +370,22 @@ class MainOverlay: # {{{
def(): self.overlay.hide(), ui_operations.quit();, 'remove'),
))
else:
pass
copy_actions = E.ul()
if self.elements.link:
copy_actions.appendChild(ac(_('Copy link'), _('Copy the current link'), def():
self.overlay.hide(), ui_operations.copy_selection(self.elements.link)
, 'link'))
if self.elements.img:
copy_actions.appendChild(ac(_('View image'), _('View the current image'), def():
self.overlay.hide(), ui_operations.view_image(self.elements.img)
, 'image'))
if window.navigator.clipboard:
copy_actions.appendChild(ac(_('Copy image'), _('Copy the current image'), def():
self.overlay.hide(), ui_operations.copy_image(self.elements.img)
, 'copy'))
if copy_actions.childNodes.length:
actions_div.appendChild(copy_actions)
container.appendChild(set_css(E.div(class_=MAIN_OVERLAY_TS_CLASS, # top section
onclick=def (evt):evt.stopPropagation();,

View File

@ -81,6 +81,8 @@ class ReadUI:
ui_operations.stop_waiting_for_messages_from = self.stop_waiting_for_messages_from.bind(self)
ui_operations.update_metadata = self.update_metadata.bind(self)
ui_operations.close_book = self.close_book.bind(self)
ui_operations.copy_image = self.copy_image.bind(self)
ui_operations.view_image = self.view_image.bind(self)
ui_operations.open_url = def(url):
window.open(url, '_blank')
ui_operations.copy_selection = def(text, html):
@ -187,6 +189,26 @@ class ReadUI:
def close_book(self):
self.base_url_data = {}
def copy_image(self, image_file_name):
if not self.view?.book:
return
ui_operations.get_file(
self.view.book, image_file_name, def(blob, name, mimetype):
try:
window.navigator.clipboard.write([new ClipboardItem({mimetype: blob})]) # noqa
except Exception as err:
error_dialog(_('Could not copy image'), str(err))
)
def view_image(self, image_file_name):
if not self.view?.book:
return
ui_operations.get_file(
self.view.book, image_file_name, def(blob, name, mimetype):
url = window.URL.createObjectURL(blob)
window.open(url)
)
def load_book(self, library_id, book_id, fmt, metadata, force_reload):
self.base_url_data = {'library_id': library_id, 'book_id':book_id, 'fmt':fmt}
if not self.db.initialized: