mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Edit Book: Allow drag and drop of files onto dock icon on OS X
This commit is contained in:
parent
e69c4b357d
commit
88a9ce16df
@ -242,6 +242,10 @@ class Boss(QObject):
|
||||
|
||||
:param edit_file: The name of a file inside the newly opened book to start editing. Can also be a list of names.
|
||||
'''
|
||||
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]
|
||||
if not self._check_before_open():
|
||||
return
|
||||
if not hasattr(path, 'rpartition'):
|
||||
|
@ -25,6 +25,14 @@ files inside the book which will be opened for editing automatically.
|
||||
setup_gui_option_parser(parser)
|
||||
return parser
|
||||
|
||||
class EventAccumulator(object):
|
||||
|
||||
def __init__(self):
|
||||
self.events = []
|
||||
|
||||
def __call__(self, ev):
|
||||
self.events.append(ev)
|
||||
|
||||
def gui_main(path=None, notify=None):
|
||||
_run(['ebook-edit', path], notify=notify)
|
||||
|
||||
@ -55,6 +63,7 @@ def _run(args, notify=None):
|
||||
decouple('edit-book-')
|
||||
override = 'calibre-edit-book' if islinux else None
|
||||
app = Application(args, override_program_name=override, color_prefs=tprefs)
|
||||
app.file_event_hook = EventAccumulator()
|
||||
app.load_builtin_fonts()
|
||||
app.setWindowIcon(QIcon(I('tweak.png')))
|
||||
Application.setOrganizationName(ORG_NAME)
|
||||
@ -64,6 +73,11 @@ def _run(args, notify=None):
|
||||
main.show()
|
||||
if len(args) > 1:
|
||||
main.boss.open_book(args[1], edit_file=args[2:], clear_notify_data=False)
|
||||
else:
|
||||
for path in reversed(app.file_event_hook.events):
|
||||
main.boss.open_book(path)
|
||||
break
|
||||
app.file_event_hook = main.boss.open_book
|
||||
app.exec_()
|
||||
# Ensure that the parse worker has quit so that temp files can be deleted
|
||||
# on windows
|
||||
|
Loading…
x
Reference in New Issue
Block a user