diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 619455d5e3..295432f9a8 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' -import tempfile, shutil, sys, os +import tempfile, shutil, sys, os, errno from functools import partial, wraps from urlparse import urlparse @@ -1283,7 +1283,20 @@ class Boss(QObject): self.set_modified() @in_thread_job - def export_requested(self, name, path): + def export_requested(self, name_or_names, path): + if isinstance(name_or_names, basestring): + return self.export_file(name_or_names, path) + for name in name_or_names: + dest = os.path.abspath(os.path.join(path, name)) + if '/' in name or os.sep in name: + try: + os.makedirs(os.path.dirname(dest)) + except EnvironmentError as err: + if err.errno != errno.EEXIST: + raise + self.export_file(name, dest) + + def export_file(self, name, path): if name in editors and not editors[name].is_synced_to_container: self.commit_editor_to_container(name) with current_container().open(name, 'rb') as src, open(path, 'wb') as dest: diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index b2d1726a2c..d3352d4a90 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -25,7 +25,8 @@ from calibre.ebooks.oeb.polish.cover import ( ) from calibre.ebooks.oeb.polish.replace import get_recommended_folders from calibre.gui2 import ( - choose_files, choose_save_file, elided_text, error_dialog, question_dialog + choose_dir, choose_files, choose_save_file, elided_text, error_dialog, + question_dialog ) from calibre.gui2.tweak_book import ( CONTAINER_DND_MIMETYPE, current_container, editors, tprefs @@ -34,7 +35,6 @@ from calibre.gui2.tweak_book.editor import syntax_from_mime from calibre.gui2.tweak_book.templates import template_for from calibre.utils.icu import sort_key - TOP_ICON_SIZE = 24 NAME_ROLE = Qt.UserRole CATEGORY_ROLE = NAME_ROLE + 1 @@ -482,6 +482,9 @@ class FileList(QTreeWidget): m.addAction(QIcon(I('save.png')), _('Export %s') % n, partial(self.export, cn)) if cn not in container.names_that_must_not_be_changed and cn not in container.names_that_must_not_be_removed and mt not in OEB_FONTS: m.addAction(_('Replace %s with file...') % n, partial(self.replace, cn)) + if num > 1: + m.addAction(QIcon(I('save.png')), _('Export all %d selected files') % num, self.export_selected) + m.addSeparator() m.addAction(QIcon(I('modified.png')), _('&Rename %s') % n, self.edit_current_item) @@ -732,6 +735,14 @@ class FileList(QTreeWidget): if path: self.export_requested.emit(name, path) + def export_selected(self): + names = self.selected_names + if not names: + return + path = choose_dir(self, 'tweak_book_export_selected', _('Choose location')) + if path: + self.export_requested.emit(names, path) + def replace(self, name): c = current_container() mt = c.mime_map[name]