mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
When text is selected in the viewer select the same text when opening the book for editing
This commit is contained in:
parent
1df4adac5c
commit
943f08e50e
@ -641,7 +641,7 @@ class EbookViewer(MainWindow):
|
|||||||
self.highlights_widget.refresh(highlights)
|
self.highlights_widget.refresh(highlights)
|
||||||
self.save_annotations()
|
self.save_annotations()
|
||||||
|
|
||||||
def edit_book(self, file_name, progress_frac):
|
def edit_book(self, file_name, progress_frac, selected_text):
|
||||||
import subprocess
|
import subprocess
|
||||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||||
from calibre.utils.ipc.launch import exe_path, macos_edit_book_bundle_path
|
from calibre.utils.ipc.launch import exe_path, macos_edit_book_bundle_path
|
||||||
@ -661,8 +661,11 @@ class EbookViewer(MainWindow):
|
|||||||
exe = os.path.join(macos_edit_book_bundle_path(), exe)
|
exe = os.path.join(macos_edit_book_bundle_path(), exe)
|
||||||
else:
|
else:
|
||||||
exe = exe_path(exe)
|
exe = exe_path(exe)
|
||||||
|
cmd = [exe]
|
||||||
|
if selected_text:
|
||||||
|
cmd += ['--select-text', selected_text]
|
||||||
with sanitize_env_vars():
|
with sanitize_env_vars():
|
||||||
subprocess.Popen([exe, path, file_name])
|
subprocess.Popen(cmd + [path, file_name])
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
with vprefs:
|
with vprefs:
|
||||||
|
@ -273,7 +273,7 @@ class ViewerBridge(Bridge):
|
|||||||
open_url = from_js(object)
|
open_url = from_js(object)
|
||||||
speak_simple_text = from_js(object)
|
speak_simple_text = from_js(object)
|
||||||
tts = from_js(object, object)
|
tts = from_js(object, object)
|
||||||
edit_book = from_js(object, object)
|
edit_book = from_js(object, object, object)
|
||||||
|
|
||||||
create_view = to_js()
|
create_view = to_js()
|
||||||
start_book_load = to_js()
|
start_book_load = to_js()
|
||||||
@ -473,7 +473,7 @@ class WebView(RestartingWebEngineView):
|
|||||||
scrollbar_context_menu = pyqtSignal(object, object, object)
|
scrollbar_context_menu = pyqtSignal(object, object, object)
|
||||||
close_prep_finished = pyqtSignal(object)
|
close_prep_finished = pyqtSignal(object)
|
||||||
highlights_changed = pyqtSignal(object)
|
highlights_changed = pyqtSignal(object)
|
||||||
edit_book = pyqtSignal(object, object)
|
edit_book = pyqtSignal(object, object, object)
|
||||||
shortcuts_changed = pyqtSignal(object)
|
shortcuts_changed = pyqtSignal(object)
|
||||||
paged_mode_changed = pyqtSignal()
|
paged_mode_changed = pyqtSignal()
|
||||||
standalone_misc_settings_changed = pyqtSignal(object)
|
standalone_misc_settings_changed = pyqtSignal(object)
|
||||||
|
@ -567,7 +567,7 @@ class SelectionBar:
|
|||||||
sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map)
|
sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map)
|
||||||
if not sc_name:
|
if not sc_name:
|
||||||
return
|
return
|
||||||
forwarded = {'toggle_highlights': True, 'extend_selection_by_word': True, 'shrink_selection_by_word': True}
|
forwarded = {'toggle_highlights': True, 'extend_selection_by_word': True, 'shrink_selection_by_word': True, 'edit_book': True}
|
||||||
if sc_name is 'show_chrome':
|
if sc_name is 'show_chrome':
|
||||||
self.clear_selection()
|
self.clear_selection()
|
||||||
elif sc_name is 'copy_to_clipboard':
|
elif sc_name is 'copy_to_clipboard':
|
||||||
|
@ -556,7 +556,7 @@ class View:
|
|||||||
elif data.name is 'metadata':
|
elif data.name is 'metadata':
|
||||||
self.overlay.show_metadata()
|
self.overlay.show_metadata()
|
||||||
elif data.name is 'edit_book':
|
elif data.name is 'edit_book':
|
||||||
ui_operations.edit_book(current_spine_item(), self.current_file_progress_frac)
|
ui_operations.edit_book(current_spine_item(), self.current_file_progress_frac, self.currently_showing?.selection?.text)
|
||||||
elif data.name is 'goto_location':
|
elif data.name is 'goto_location':
|
||||||
self.overlay.show_ask_for_location()
|
self.overlay.show_ask_for_location()
|
||||||
elif data.name is 'shrink_selection_by_word':
|
elif data.name is 'shrink_selection_by_word':
|
||||||
|
@ -419,8 +419,8 @@ if window is window.top:
|
|||||||
to_python.speak_simple_text(text)
|
to_python.speak_simple_text(text)
|
||||||
ui_operations.tts = def(action, data):
|
ui_operations.tts = def(action, data):
|
||||||
to_python.tts(action, data or v'{}')
|
to_python.tts(action, data or v'{}')
|
||||||
ui_operations.edit_book = def (spine_name, frac):
|
ui_operations.edit_book = def (spine_name, frac, selected_text):
|
||||||
to_python.edit_book(spine_name, frac)
|
to_python.edit_book(spine_name, frac, selected_text or '')
|
||||||
|
|
||||||
document.body.appendChild(E.div(id='view'))
|
document.body.appendChild(E.div(id='view'))
|
||||||
window.onerror = onerror
|
window.onerror = onerror
|
||||||
|
Loading…
x
Reference in New Issue
Block a user