mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: When exporting files, fill the choose filename popup with the name of the file being exported as the default name
This commit is contained in:
parent
45e6468b01
commit
15962b8897
@ -605,7 +605,8 @@ class FileDialog(QObject):
|
|||||||
name='',
|
name='',
|
||||||
mode=QFileDialog.ExistingFiles,
|
mode=QFileDialog.ExistingFiles,
|
||||||
default_dir='~',
|
default_dir='~',
|
||||||
no_save_dir=False
|
no_save_dir=False,
|
||||||
|
combine_file_and_saved_dir=False
|
||||||
):
|
):
|
||||||
QObject.__init__(self)
|
QObject.__init__(self)
|
||||||
ftext = ''
|
ftext = ''
|
||||||
@ -624,14 +625,25 @@ class FileDialog(QObject):
|
|||||||
self.selected_files = None
|
self.selected_files = None
|
||||||
self.fd = None
|
self.fd = None
|
||||||
|
|
||||||
if no_save_dir:
|
if combine_file_and_saved_dir:
|
||||||
|
bn = os.path.basename(default_dir)
|
||||||
|
prev = dynamic.get(self.dialog_name,
|
||||||
|
os.path.expanduser('~'))
|
||||||
|
if os.path.exists(prev):
|
||||||
|
if os.path.isfile(prev):
|
||||||
|
prev = os.path.dirname(prev)
|
||||||
|
else:
|
||||||
|
prev = os.path.expanduser('~')
|
||||||
|
initial_dir = os.path.join(prev, bn)
|
||||||
|
elif no_save_dir:
|
||||||
initial_dir = os.path.expanduser(default_dir)
|
initial_dir = os.path.expanduser(default_dir)
|
||||||
else:
|
else:
|
||||||
initial_dir = dynamic.get(self.dialog_name,
|
initial_dir = dynamic.get(self.dialog_name,
|
||||||
os.path.expanduser(default_dir))
|
os.path.expanduser(default_dir))
|
||||||
if not isinstance(initial_dir, basestring):
|
if not isinstance(initial_dir, basestring):
|
||||||
initial_dir = os.path.expanduser(default_dir)
|
initial_dir = os.path.expanduser(default_dir)
|
||||||
if not initial_dir or not os.path.exists(initial_dir):
|
if not initial_dir or (not os.path.exists(initial_dir) and not (
|
||||||
|
mode == QFileDialog.AnyFile and (no_save_dir or combine_file_and_saved_dir))):
|
||||||
initial_dir = select_initial_dir(initial_dir)
|
initial_dir = select_initial_dir(initial_dir)
|
||||||
self.selected_files = []
|
self.selected_files = []
|
||||||
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
|
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
|
||||||
@ -722,7 +734,7 @@ def choose_files(window, name, title,
|
|||||||
return fd.get_files()
|
return fd.get_files()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def choose_save_file(window, name, title, filters=[], all_files=True, initial_dir=None):
|
def choose_save_file(window, name, title, filters=[], all_files=True, initial_path=None, initial_filename=None):
|
||||||
'''
|
'''
|
||||||
Ask user to choose a file to save to. Can be a non-existent file.
|
Ask user to choose a file to save to. Can be a non-existent file.
|
||||||
:param filters: list of allowable extensions. Each element of the list
|
:param filters: list of allowable extensions. Each element of the list
|
||||||
@ -730,12 +742,17 @@ def choose_save_file(window, name, title, filters=[], all_files=True, initial_di
|
|||||||
the type of files to be filtered and second element a list
|
the type of files to be filtered and second element a list
|
||||||
of extensions.
|
of extensions.
|
||||||
:param all_files: If True add All files to filters.
|
:param all_files: If True add All files to filters.
|
||||||
|
:param initial_path: The initially selected path (does not need to exist). Cannot be used with initial_filename.
|
||||||
|
:param initial_filename: If specified, the initially selected path is this filename in the previously used directory. Cannot be used with initial_path.
|
||||||
'''
|
'''
|
||||||
kwargs = dict(title=title, name=name, filters=filters,
|
kwargs = dict(title=title, name=name, filters=filters,
|
||||||
parent=window, add_all_files_filter=all_files, mode=QFileDialog.AnyFile)
|
parent=window, add_all_files_filter=all_files, mode=QFileDialog.AnyFile)
|
||||||
if initial_dir is not None:
|
if initial_path is not None:
|
||||||
kwargs['no_save_dir'] = True
|
kwargs['no_save_dir'] = True
|
||||||
kwargs['default_dir'] = initial_dir
|
kwargs['default_dir'] = initial_path
|
||||||
|
elif initial_filename is not None:
|
||||||
|
kwargs['combine_file_and_saved_dir'] = True
|
||||||
|
kwargs['default_dir'] = initial_filename
|
||||||
fd = FileDialog(**kwargs)
|
fd = FileDialog(**kwargs)
|
||||||
fd.setParent(None)
|
fd.setParent(None)
|
||||||
ans = None
|
ans = None
|
||||||
|
@ -859,8 +859,9 @@ class Boss(QObject):
|
|||||||
show_copy_button=False, show=True)
|
show_copy_button=False, show=True)
|
||||||
fmt = path_to_ebook.rpartition('.')[-1].lower()
|
fmt = path_to_ebook.rpartition('.')[-1].lower()
|
||||||
start_dir = find_first_existing_ancestor(path_to_ebook)
|
start_dir = find_first_existing_ancestor(path_to_ebook)
|
||||||
path = choose_save_file(self.gui, 'choose-new-save-location', _('Choose file location'), initial_dir=start_dir,
|
path = choose_save_file(
|
||||||
filters=[(fmt.upper(), (fmt,))], all_files=False)
|
self.gui, 'choose-new-save-location', _('Choose file location'), initial_path=os.path.join(start_dir, os.path.basename(path_to_ebook)),
|
||||||
|
filters=[(fmt.upper(), (fmt,))], all_files=False)
|
||||||
if path is not None:
|
if path is not None:
|
||||||
if not path.lower().endswith('.' + fmt):
|
if not path.lower().endswith('.' + fmt):
|
||||||
path = path + '.' + fmt
|
path = path + '.' + fmt
|
||||||
|
@ -616,7 +616,7 @@ class FileList(QTreeWidget):
|
|||||||
|
|
||||||
def export(self, name):
|
def export(self, name):
|
||||||
path = choose_save_file(self, 'tweak_book_export_file', _('Choose location'), filters=[
|
path = choose_save_file(self, 'tweak_book_export_file', _('Choose location'), filters=[
|
||||||
(_('Files'), [name.rpartition('.')[-1].lower()])], all_files=False)
|
(_('Files'), [name.rpartition('.')[-1].lower()])], all_files=False, initial_filename=name.split('/')[-1])
|
||||||
if path:
|
if path:
|
||||||
self.export_requested.emit(name, path)
|
self.export_requested.emit(name, path)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user