mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
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:
parent
50785c72c8
commit
6d95b25dbd
@ -744,6 +744,14 @@ class Container(ContainerBase): # {{{
|
|||||||
for item, name in non_linear:
|
for item, name in non_linear:
|
||||||
yield item, name, False
|
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
|
@property
|
||||||
def spine_names(self):
|
def spine_names(self):
|
||||||
''' An iterator yielding name and is_linear for every item in the
|
''' An iterator yielding name and is_linear for every item in the
|
||||||
|
@ -433,7 +433,7 @@ class Boss(QObject):
|
|||||||
completion_worker().clear_caches('names')
|
completion_worker().clear_caches('names')
|
||||||
|
|
||||||
def add_file(self):
|
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
|
return
|
||||||
self.commit_dirty_opf()
|
self.commit_dirty_opf()
|
||||||
d = NewFileDialog(self.gui)
|
d = NewFileDialog(self.gui)
|
||||||
@ -448,8 +448,11 @@ class Boss(QObject):
|
|||||||
self.add_savepoint(_('Before: Add file %s') % self.gui.elided_text(file_name))
|
self.add_savepoint(_('Before: Add file %s') % self.gui.elided_text(file_name))
|
||||||
c = current_container()
|
c = current_container()
|
||||||
adata = data.replace(b'%CURSOR%', b'') if using_template else data
|
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:
|
try:
|
||||||
added_name = c.add_file(file_name, adata)
|
added_name = c.add_file(file_name, adata, spine_index=spine_index)
|
||||||
except:
|
except:
|
||||||
self.rewind_savepoint()
|
self.rewind_savepoint()
|
||||||
raise
|
raise
|
||||||
@ -469,7 +472,7 @@ class Boss(QObject):
|
|||||||
return added_name
|
return added_name
|
||||||
|
|
||||||
def add_files(self):
|
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
|
return
|
||||||
|
|
||||||
files = choose_files(self.gui, 'tweak-book-bulk-import-files', _('Choose files'))
|
files = choose_files(self.gui, 'tweak-book-bulk-import-files', _('Choose files'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user