From b0e1d97af6be76c0820b065c2a74adfcbc7bfd85 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 27 Jul 2024 11:03:19 +0530 Subject: [PATCH] Also open multiple paths when dropped onto running editor instance --- src/calibre/gui2/tweak_book/boss.py | 18 +++++++++++++++++- src/calibre/gui2/tweak_book/main.py | 16 ++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index b617241272..54f19ebbea 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -118,6 +118,19 @@ def get_boss(): return get_boss.boss +def open_path_in_new_editor_instance(path: str): + import subprocess + + from calibre.gui2 import sanitize_env_vars + with sanitize_env_vars(): + if ismacos: + from calibre.utils.ipc.launch import macos_edit_book_bundle_path + bundle = os.path.dirname(os.path.dirname(macos_edit_book_bundle_path().rstrip('/'))) + subprocess.Popen(['open', '-n', '-a', bundle, path]) + else: + subprocess.Popen([sys.executable, path]) + + class Boss(QObject): handle_completion_result_signal = pyqtSignal(object) @@ -316,7 +329,10 @@ class Boss(QObject): if isinstance(path, (list, tuple)) and path: # Can happen from an file_event_hook on OS X when drag and dropping # onto the icon in the dock or using open -a - path = path[-1] + extra_paths = path[1:] + path = path[0] + for x in extra_paths: + open_path_in_new_editor_instance(x) if not self._check_before_open(): return if not hasattr(path, 'rpartition'): diff --git a/src/calibre/gui2/tweak_book/main.py b/src/calibre/gui2/tweak_book/main.py index 47f3a6e255..5b1d368eca 100644 --- a/src/calibre/gui2/tweak_book/main.py +++ b/src/calibre/gui2/tweak_book/main.py @@ -8,7 +8,7 @@ import time from qt.core import QIcon -from calibre.constants import EDITOR_APP_UID, islinux, ismacos +from calibre.constants import EDITOR_APP_UID, islinux from calibre.ebooks.oeb.polish.check.css import shutdown as shutdown_css_check_pool from calibre.gui2 import Application, decouple, set_gui_prefs, setup_gui_option_parser from calibre.ptempfile import reset_base_dir @@ -38,19 +38,6 @@ def gui_main(path=None, notify=None): _run(['ebook-edit', path], notify=notify) -def open_path_in_new_editor_instance(path: str): - import subprocess - - from calibre.gui2 import sanitize_env_vars - with sanitize_env_vars(): - if ismacos: - from calibre.utils.ipc.launch import macos_edit_book_bundle_path - bundle = os.path.dirname(os.path.dirname(macos_edit_book_bundle_path().rstrip('/'))) - subprocess.Popen(['open', '-n', '-a', bundle, path]) - else: - subprocess.Popen([sys.executable, path]) - - def _run(args, notify=None): from calibre.utils.webengine import setup_fake_protocol # Ensure we can continue to function if GUI is closed @@ -84,6 +71,7 @@ def _run(args, notify=None): paths = app.get_pending_file_open_events() if paths: if len(paths) > 1: + from .boss import open_path_in_new_editor_instance for path in paths[1:]: try: open_path_in_new_editor_instance(path)