mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add books dialog: When a non-book file type is added the next time the dialog is used, preselect the "All files" filter. Fixes #1952562 [Update default selection filter for manual format adds via GUI](https://bugs.launchpad.net/calibre/+bug/1952562)
This commit is contained in:
parent
e80f16ddbf
commit
171e5f19e5
@ -688,6 +688,26 @@ else:
|
||||
choose_files, choose_images, choose_dir, choose_save_file
|
||||
|
||||
|
||||
def choose_files_and_remember_all_files(
|
||||
window, name, title, filters=[], select_only_single_file=False, default_dir='~'
|
||||
):
|
||||
pref_name = f'{name}-last-used-filter-spec-all-files'
|
||||
lufs = dynamic.get(pref_name, False)
|
||||
af = _('All files'), ['*']
|
||||
filters = list(filters)
|
||||
filters.insert(0, af) if lufs else filters.append(af)
|
||||
paths = choose_files(window, name, title, list(filters), False, select_only_single_file, default_dir)
|
||||
if paths:
|
||||
ext = paths[0].rpartition(os.extsep)[-1].lower()
|
||||
used_all_files = True
|
||||
for i, (name, exts) in enumerate(filters):
|
||||
if ext in exts:
|
||||
used_all_files = False
|
||||
break
|
||||
dynamic.set(pref_name, used_all_files)
|
||||
return paths
|
||||
|
||||
|
||||
def is_dark_theme():
|
||||
pal = QApplication.instance().palette()
|
||||
col = pal.color(QPalette.ColorRole.Window)
|
||||
|
@ -16,8 +16,8 @@ from calibre.constants import iswindows
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.ebooks.metadata import MetaInformation, normalize_isbn
|
||||
from calibre.gui2 import (
|
||||
choose_dir, choose_files, error_dialog, gprefs, info_dialog, question_dialog,
|
||||
warning_dialog
|
||||
choose_dir, choose_files, choose_files_and_remember_all_files, error_dialog,
|
||||
gprefs, info_dialog, question_dialog, warning_dialog
|
||||
)
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
from calibre.gui2.dialogs.add_empty_book import AddEmptyBookDialog
|
||||
@ -139,7 +139,7 @@ class AddAction(InterfaceAction):
|
||||
ids = self._check_add_formats_ok()
|
||||
if not ids:
|
||||
return
|
||||
books = choose_files(self.gui, 'add formats dialog dir',
|
||||
books = choose_files_and_remember_all_files(self.gui, 'add formats dialog dir',
|
||||
_('Select book files'), filters=get_filters())
|
||||
if books:
|
||||
self._add_formats(books, ids)
|
||||
@ -529,7 +529,7 @@ class AddAction(InterfaceAction):
|
||||
fmts = self.gui.device_manager.device.settings().format_map
|
||||
filters = [(_('Supported books'), fmts)]
|
||||
|
||||
books = choose_files(self.gui, 'add books dialog dir',
|
||||
books = choose_files_and_remember_all_files(self.gui, 'add books dialog dir',
|
||||
_('Select books'), filters=filters)
|
||||
if not books:
|
||||
return
|
||||
|
@ -163,7 +163,10 @@ def kdialog_choose_dir(window, name, title, default_dir='~', no_save_dir=False):
|
||||
def kdialog_filters(filters, all_files=True):
|
||||
ans = []
|
||||
for name, exts in filters:
|
||||
ans.append('{} ({})'.format(name, ' '.join('*.' + x for x in exts)))
|
||||
if not exts or (len(exts) == 1 and exts[0] == '*'):
|
||||
ans.append(name + ' (*)')
|
||||
else:
|
||||
ans.append('{} ({})'.format(name, ' '.join('*.' + x for x in exts)))
|
||||
if all_files:
|
||||
ans.append(_('All files') + ' (*)')
|
||||
return '\n'.join(ans)
|
||||
@ -240,7 +243,10 @@ def zenity_choose_dir(window, name, title, default_dir='~', no_save_dir=False):
|
||||
def zenity_filters(filters, all_files=True):
|
||||
ans = []
|
||||
for name, exts in filters:
|
||||
ans.append('--file-filter={} | {}'.format(name, ' '.join('*.' + x for x in exts)))
|
||||
if not exts or (len(exts) == 1 and exts[0] == '*'):
|
||||
ans.append('--file-filter={} | {}'.format(name, '*'))
|
||||
else:
|
||||
ans.append('--file-filter={} | {}'.format(name, ' '.join('*.' + x for x in exts)))
|
||||
if all_files:
|
||||
ans.append('--file-filter={} | {}'.format(_('All files'), '*'))
|
||||
return ans
|
||||
|
@ -56,8 +56,11 @@ class FileDialog(QObject):
|
||||
if filters:
|
||||
for filter in filters:
|
||||
text, extensions = filter
|
||||
extensions = ['*'+(i if i.startswith('.') else '.'+i) for i in
|
||||
extensions]
|
||||
if not extensions or (len(extensions) == 1 and extensions[0] == '*'):
|
||||
extensions = ['*']
|
||||
else:
|
||||
extensions = ['*'+(i if i.startswith('.') else '.'+i) for i in
|
||||
extensions]
|
||||
etext = '%s (%s);;'%(text, ' '.join(extensions))
|
||||
if len(etext) > 72:
|
||||
has_long_filter = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user