Add a few more ensure books

This commit is contained in:
Kovid Goyal 2021-05-12 07:45:27 +05:30
parent 1c9d837e08
commit e50e00b855
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -554,6 +554,8 @@ class Boss(QObject):
show_font_face_rule_for_font_files(c, added_fonts, self.gui)
def add_cover(self):
if not self.ensure_book():
return
d = AddCover(current_container(), self.gui)
d.import_requested.connect(self.do_add_file)
try:
@ -567,7 +569,8 @@ class Boss(QObject):
finally:
d.import_requested.disconnect()
def ensure_book(self, msg):
def ensure_book(self, msg=None):
msg = msg or _('No book is currently open. You must first open a book.')
if current_container() is None:
error_dialog(self.gui, _('No book open'), msg, show=True)
return False
@ -601,6 +604,8 @@ class Boss(QObject):
self.edit_file(name, 'html')
def polish(self, action, name, parent=None):
if not self.ensure_book():
return
from calibre.gui2.tweak_book.polish import get_customization, show_report
customization = get_customization(action, name, parent or self.gui)
if customization is None:
@ -682,6 +687,8 @@ class Boss(QObject):
# Renaming {{{
def rationalize_folders(self):
if not self.ensure_book():
return
c = current_container()
if not c.SUPPORTS_FILENAMES:
return error_dialog(self.gui, _('Not supported'),
@ -848,6 +855,8 @@ class Boss(QObject):
self.show_current_diff(allow_revert=allow_revert, to_container=to_container)
def compare_book(self):
if not self.ensure_book():
return
self.commit_all_editors_to_container()
c = current_container()
path = choose_files(self.gui, 'select-book-for-comparison', _('Choose book'), filters=[
@ -975,6 +984,8 @@ class Boss(QObject):
'No class {} found to change').format(class_name), show=True)
def set_semantics(self):
if not self.ensure_book():
return
self.commit_all_editors_to_container()
c = current_container()
if c.book_type == 'azw3':