more exporting fixes
- make sure we default to last saved export location - make sure we filter out backslash - use fname not initial_path, because we're not passing in a path
This commit is contained in:
parent
246bd27eb3
commit
ea2dfaf59c
@ -68,19 +68,15 @@ class ExportDialog(QDialog):
|
||||
return
|
||||
else:
|
||||
verbatim = False
|
||||
|
||||
# Get deck name and remove invalid filename characters
|
||||
deck_name = self.decks[self.frm.deck.currentIndex()]
|
||||
deck_name = re.sub('[/?<>\:*|"^]', '_', deck_name)
|
||||
|
||||
deck_name = re.sub('[\\\\/?<>:*|"^]', '_', deck_name)
|
||||
filename = os.path.join(aqt.mw.pm.base,
|
||||
'{}.apkg'.format(deck_name))
|
||||
|
||||
while 1:
|
||||
file = getSaveFile(
|
||||
self, _("Export"), "export",
|
||||
self.exporter.key, self.exporter.ext,
|
||||
initial_path=filename)
|
||||
file = getSaveFile(self, _("Export"), "export",
|
||||
self.exporter.key, self.exporter.ext,
|
||||
fname=filename)
|
||||
if not file:
|
||||
return
|
||||
if checkInvalidFilename(os.path.basename(file), dirsep=False):
|
||||
|
18
aqt/utils.py
18
aqt/utils.py
@ -252,28 +252,22 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None):
|
||||
d.exec_()
|
||||
return ret and ret[0]
|
||||
|
||||
def getSaveFile(parent, title, dir_description, key, ext,
|
||||
initial_path=None):
|
||||
def getSaveFile(parent, title, dir_description, key, ext, fname=None):
|
||||
"""Ask the user for a file to save. Use DIR_DESCRIPTION as config
|
||||
variable. The file dialog will open with an initial path of
|
||||
INITIAL_PATH (this may be the path of a file or directory)."""
|
||||
|
||||
if initial_path is None:
|
||||
initial_path = aqt.mw.pm.base
|
||||
|
||||
variable. The file dialog will default to open with FNAME."""
|
||||
config_key = dir_description + 'Directory'
|
||||
base = aqt.mw.pm.profile.get(config_key, aqt.mw.pm.base)
|
||||
path = os.path.join(base, fname)
|
||||
file = unicode(QFileDialog.getSaveFileName(
|
||||
parent, title, initial_path, "{0} (*{1})".format(key, ext),
|
||||
parent, title, path, "{0} (*{1})".format(key, ext),
|
||||
options=QFileDialog.DontConfirmOverwrite))
|
||||
if file:
|
||||
# add extension
|
||||
if not file.lower().endswith(ext):
|
||||
file += ext
|
||||
|
||||
# save new default
|
||||
config_key = dir_description + 'Directory'
|
||||
dir = os.path.dirname(file)
|
||||
aqt.mw.pm.profile[config_key] = dir
|
||||
|
||||
# check if it exists
|
||||
if os.path.exists(file):
|
||||
if not askUser(
|
||||
|
Loading…
Reference in New Issue
Block a user