Edit Book: When adding a new HTML file, add it after the file being currently edited instead of at the end. Fixes #1728601 [[enhancement] placement in file browser of the editor when adding or importing file](https://bugs.launchpad.net/calibre/+bug/1728601)

This commit is contained in:
Kovid Goyal 2017-10-31 12:17:07 +05:30
parent 50785c72c8
commit 6d95b25dbd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 3 deletions

View File

@ -744,6 +744,14 @@ class Container(ContainerBase): # {{{
for item, name in non_linear:
yield item, name, False
def index_in_spine(self, name):
manifest_id_map = self.manifest_id_map
for i, item in enumerate(self.opf_xpath('//opf:spine/opf:itemref[@idref]')):
idref = item.get('idref')
q = manifest_id_map.get(idref, None)
if q == name:
return i
@property
def spine_names(self):
''' An iterator yielding name and is_linear for every item in the

View File

@ -433,7 +433,7 @@ class Boss(QObject):
completion_worker().clear_caches('names')
def add_file(self):
if not self.ensure_book(_('You must first open a book to tweak, before trying to create new files in it.')):
if not self.ensure_book(_('You must first open a book to edit, before trying to create new files in it.')):
return
self.commit_dirty_opf()
d = NewFileDialog(self.gui)
@ -448,8 +448,11 @@ class Boss(QObject):
self.add_savepoint(_('Before: Add file %s') % self.gui.elided_text(file_name))
c = current_container()
adata = data.replace(b'%CURSOR%', b'') if using_template else data
spine_index = c.index_in_spine(self.currently_editing or '')
if spine_index is not None:
spine_index += 1
try:
added_name = c.add_file(file_name, adata)
added_name = c.add_file(file_name, adata, spine_index=spine_index)
except:
self.rewind_savepoint()
raise
@ -469,7 +472,7 @@ class Boss(QObject):
return added_name
def add_files(self):
if not self.ensure_book(_('You must first open a book to tweak, before trying to create new files in it.')):
if not self.ensure_book(_('You must first open a book to edit, before trying to create new files in it.')):
return
files = choose_files(self.gui, 'tweak-book-bulk-import-files', _('Choose files'))