File open dialogs; If the previously used initial directory, no longer exists, use a directory one level up. Fixes #1255216 [Adding book or new format opening Windows\System32 folder as default](https://bugs.launchpad.net/calibre/+bug/1255216)

This commit is contained in:
Kovid Goyal 2013-11-27 08:44:27 +05:30
parent 6c0b9ec38b
commit 89271681cf

View File

@ -585,6 +585,16 @@ def file_icon_provider():
initialize_file_icon_provider()
return _file_icon_provider
def select_initial_dir(q):
while q:
c = os.path.dirname(q)
if c == q:
break
if os.path.exists(c):
return c
q = c
return os.path.expanduser('~')
class FileDialog(QObject):
def __init__(self, title=_('Choose Files'),
filters=[],
@ -620,6 +630,8 @@ class FileDialog(QObject):
os.path.expanduser(default_dir))
if not isinstance(initial_dir, basestring):
initial_dir = os.path.expanduser(default_dir)
if not initial_dir or not os.path.exists(initial_dir):
initial_dir = select_initial_dir(initial_dir)
self.selected_files = []
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
with SanitizeLibraryPath():