mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
Merge pull request #29 from hans/patch/618
default to deckname.apkg on single deck export (#618)
This commit is contained in:
commit
246bd27eb3
2 changed files with 26 additions and 6 deletions
|
@ -2,6 +2,8 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import aqt
|
import aqt
|
||||||
from aqt.utils import getSaveFile, tooltip, showWarning, askUser, \
|
from aqt.utils import getSaveFile, tooltip, showWarning, askUser, \
|
||||||
|
@ -66,10 +68,19 @@ class ExportDialog(QDialog):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
verbatim = False
|
verbatim = False
|
||||||
|
|
||||||
|
# Get deck name and remove invalid filename characters
|
||||||
|
deck_name = self.decks[self.frm.deck.currentIndex()]
|
||||||
|
deck_name = re.sub('[/?<>\:*|"^]', '_', deck_name)
|
||||||
|
|
||||||
|
filename = os.path.join(aqt.mw.pm.base,
|
||||||
|
'{}.apkg'.format(deck_name))
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
file = getSaveFile(
|
file = getSaveFile(
|
||||||
self, _("Export"), "export",
|
self, _("Export"), "export",
|
||||||
self.exporter.key, self.exporter.ext)
|
self.exporter.key, self.exporter.ext,
|
||||||
|
initial_path=filename)
|
||||||
if not file:
|
if not file:
|
||||||
return
|
return
|
||||||
if checkInvalidFilename(os.path.basename(file), dirsep=False):
|
if checkInvalidFilename(os.path.basename(file), dirsep=False):
|
||||||
|
|
19
aqt/utils.py
19
aqt/utils.py
|
@ -252,19 +252,28 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None):
|
||||||
d.exec_()
|
d.exec_()
|
||||||
return ret and ret[0]
|
return ret and ret[0]
|
||||||
|
|
||||||
def getSaveFile(parent, title, dir, key, ext):
|
def getSaveFile(parent, title, dir_description, key, ext,
|
||||||
"Ask the user for a file to save. Use DIR as config variable."
|
initial_path=None):
|
||||||
dirkey = dir+"Directory"
|
"""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(
|
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))
|
options=QFileDialog.DontConfirmOverwrite))
|
||||||
if file:
|
if file:
|
||||||
# add extension
|
# add extension
|
||||||
if not file.lower().endswith(ext):
|
if not file.lower().endswith(ext):
|
||||||
file += ext
|
file += ext
|
||||||
|
|
||||||
# save new default
|
# save new default
|
||||||
|
config_key = dir_description + 'Directory'
|
||||||
dir = os.path.dirname(file)
|
dir = os.path.dirname(file)
|
||||||
aqt.mw.pm.profile[dirkey] = dir
|
aqt.mw.pm.profile[config_key] = dir
|
||||||
|
|
||||||
# check if it exists
|
# check if it exists
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
if not askUser(
|
if not askUser(
|
||||||
|
|
Loading…
Reference in a new issue