default to deckname.apkg on single deck export (#618)

This commit is contained in:
Hans Engel 2013-05-18 09:24:53 -07:00
parent 85cb7ef47e
commit 9707786eea
2 changed files with 20 additions and 6 deletions

View File

@ -66,10 +66,15 @@ class ExportDialog(QDialog):
return
else:
verbatim = False
deck_name = self.decks[self.frm.deck.currentIndex()]
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)
self.exporter.key, self.exporter.ext,
initial_path=filename)
if not file:
return
if checkInvalidFilename(os.path.basename(file), dirsep=False):

View File

@ -252,19 +252,28 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None):
d.exec_()
return ret and ret[0]
def getSaveFile(parent, title, dir, key, ext):
"Ask the user for a file to save. Use DIR as config variable."
dirkey = dir+"Directory"
def getSaveFile(parent, title, dir_description, key, ext,
initial_path=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
file = unicode(QFileDialog.getSaveFileName(
parent, title, aqt.mw.pm.base, "{0} (*{1})".format(key, ext),
parent, title, initial_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[dirkey] = dir
aqt.mw.pm.profile[config_key] = dir
# check if it exists
if os.path.exists(file):
if not askUser(