Also open multiple paths when dropped onto running editor instance

This commit is contained in:
Kovid Goyal 2024-07-27 11:03:19 +05:30
parent 4c0df1ba17
commit b0e1d97af6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 19 additions and 15 deletions

View File

@ -118,6 +118,19 @@ def get_boss():
return get_boss.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): class Boss(QObject):
handle_completion_result_signal = pyqtSignal(object) handle_completion_result_signal = pyqtSignal(object)
@ -316,7 +329,10 @@ class Boss(QObject):
if isinstance(path, (list, tuple)) and path: if isinstance(path, (list, tuple)) and path:
# Can happen from an file_event_hook on OS X when drag and dropping # Can happen from an file_event_hook on OS X when drag and dropping
# onto the icon in the dock or using open -a # 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(): if not self._check_before_open():
return return
if not hasattr(path, 'rpartition'): if not hasattr(path, 'rpartition'):

View File

@ -8,7 +8,7 @@ import time
from qt.core import QIcon 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.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.gui2 import Application, decouple, set_gui_prefs, setup_gui_option_parser
from calibre.ptempfile import reset_base_dir from calibre.ptempfile import reset_base_dir
@ -38,19 +38,6 @@ def gui_main(path=None, notify=None):
_run(['ebook-edit', path], notify=notify) _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): def _run(args, notify=None):
from calibre.utils.webengine import setup_fake_protocol from calibre.utils.webengine import setup_fake_protocol
# Ensure we can continue to function if GUI is closed # 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() paths = app.get_pending_file_open_events()
if paths: if paths:
if len(paths) > 1: if len(paths) > 1:
from .boss import open_path_in_new_editor_instance
for path in paths[1:]: for path in paths[1:]:
try: try:
open_path_in_new_editor_instance(path) open_path_in_new_editor_instance(path)