don't let user create decks with certain characters

This commit is contained in:
Damien Elmes 2011-01-21 09:55:12 +09:00
parent 49e2526c58
commit 94311153c8

View file

@ -924,15 +924,28 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
if not self.inMainWindow() and not path: return if not self.inMainWindow() and not path: return
if not self.saveAndClose(hideWelcome=True): return if not self.saveAndClose(hideWelcome=True): return
register = not path register = not path
bad = ":/\\"
name = _("mydeck")
if not path: if not path:
if not prompt: if not prompt:
prompt = _("Please give your deck a name:") prompt = _("Please give your deck a name:")
name = ui.utils.getOnlyText( while 1:
prompt, default=_("mydeck"), title=_("New Deck")) name = ui.utils.getOnlyText(
if not name: prompt, default=name, title=_("New Deck"))
return if not name:
if not name.endswith(".anki"): return
name += ".anki" found = False
for c in bad:
if c in name:
ui.utils.showInfo(
_("Sorry, '%s' can't be used in deck names.") % c)
found = True
break
if found:
continue
if not name.endswith(".anki"):
name += ".anki"
break
path = os.path.join(self.documentDir, name) path = os.path.join(self.documentDir, name)
if os.path.exists(path): if os.path.exists(path):
if ui.utils.askUser(_("That deck already exists. Overwrite?"), if ui.utils.askUser(_("That deck already exists. Overwrite?"),