mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
always save new decks to disk, improve importing
- instead of having various functions like importing & deck stats ask the user to save first, we ask the user for a deck name when they create a new deck - importing now explains why a new deck has to be created - don't bump deck mod time when setting media location
This commit is contained in:
parent
f41d2c2e0a
commit
38aac3d4ab
4 changed files with 43 additions and 26 deletions
|
@ -21,9 +21,6 @@ class DeckProperties(QDialog):
|
|||
self.d = deck
|
||||
self.onFinish = onFinish
|
||||
self.origMod = self.d.modified
|
||||
if not self.d.path:
|
||||
ui.utils.showInfo(_("Please save the deck first."))
|
||||
return
|
||||
self.dialog = ankiqt.forms.deckproperties.Ui_DeckProperties()
|
||||
self.dialog.setupUi(self)
|
||||
self.dialog.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
||||
|
|
|
@ -785,7 +785,6 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
|||
r = self.loadDeck(path, interactive=False, sync=False)
|
||||
if r:
|
||||
return r
|
||||
self.onNew(initial=True)
|
||||
|
||||
def getDefaultDir(self, save=False):
|
||||
"Try and get default dir from most recently opened file."
|
||||
|
@ -916,18 +915,32 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
|||
# FIXME: no longer necessary?
|
||||
return self.app.activeWindow() == self
|
||||
|
||||
def onNew(self, initial=False, path=None):
|
||||
def onNew(self, path=None, prompt=None):
|
||||
if not self.inMainWindow() and not path: return
|
||||
if not self.saveAndClose(hideWelcome=True): return
|
||||
if initial:
|
||||
path = os.path.join(self.documentDir, "mydeck.anki")
|
||||
register = not path
|
||||
if not path:
|
||||
if not prompt:
|
||||
prompt = _("Please give your deck a name:")
|
||||
name = ui.utils.getOnlyText(
|
||||
prompt, default=_("mydeck"), title=_("New Deck"))
|
||||
if not name:
|
||||
return
|
||||
if not name.endswith(".anki"):
|
||||
name += ".anki"
|
||||
path = os.path.join(self.documentDir, name)
|
||||
if os.path.exists(path):
|
||||
# load mydeck instead
|
||||
return self.loadDeck(path)
|
||||
if ui.utils.askUser(_("That deck already exists. Overwrite?"),
|
||||
defaultno=True):
|
||||
os.unlink(path)
|
||||
else:
|
||||
return
|
||||
self.deck = DeckStorage.Deck(path)
|
||||
self.deck.initUndo()
|
||||
self.deck.addModel(BasicModel())
|
||||
self.deck.save()
|
||||
if register:
|
||||
self.updateRecentFiles(self.deck.path)
|
||||
self.browserLastRefreshed = 0
|
||||
self.moveToState("initial")
|
||||
|
||||
|
@ -1948,12 +1961,13 @@ learnt today")
|
|||
|
||||
def onImport(self):
|
||||
if self.deck is None:
|
||||
self.onNew()
|
||||
if not self.deck.path:
|
||||
self.showToolTip(_("""\
|
||||
Please choose a name for this deck. After saving, the importing \
|
||||
window will open."""))
|
||||
self.onSaveAs()
|
||||
self.onNew(prompt=_("""\
|
||||
Importing copies cards to the current deck,
|
||||
so we need to create a new deck first.
|
||||
|
||||
Please give your deck a name:"""))
|
||||
if not self.deck:
|
||||
return
|
||||
if self.deck.path:
|
||||
ui.importing.ImportDialog(self)
|
||||
|
||||
|
@ -2174,9 +2188,6 @@ it to your friends.
|
|||
return
|
||||
if self.deck and not self.deck.syncName:
|
||||
if interactive:
|
||||
if not self.deck.path:
|
||||
ui.utils.showInfo(_("Please save the deck first."))
|
||||
return
|
||||
if (not self.config['mediaLocation']
|
||||
and self.deck.s.scalar("select 1 from media limit 1")):
|
||||
ui.utils.showInfo(_("""\
|
||||
|
@ -2943,7 +2954,7 @@ to work with this version of Anki."""))
|
|||
# chdir if dir exists
|
||||
dir = deck.mediaDir()
|
||||
# update location
|
||||
deck.setVar("mediaLocation", next)
|
||||
deck.setVar("mediaLocation", next, mod=False)
|
||||
if dir and prefix == "dropbox":
|
||||
self.setupDropbox(deck)
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ def showText(txt, parent=None, type="text"):
|
|||
diag.setMinimumWidth(500)
|
||||
diag.exec_()
|
||||
|
||||
def askUser(text, parent=None, help=""):
|
||||
def askUser(text, parent=None, help="", defaultno=False):
|
||||
"Show a yes/no question. Return true if yes."
|
||||
if not parent:
|
||||
parent = ankiqt.mw
|
||||
|
@ -69,8 +69,12 @@ def askUser(text, parent=None, help=""):
|
|||
if help:
|
||||
sb |= QMessageBox.Help
|
||||
while 1:
|
||||
if defaultno:
|
||||
default = QMessageBox.No
|
||||
else:
|
||||
default = QMessageBox.Yes
|
||||
r = QMessageBox.question(parent, "Anki", text, sb,
|
||||
QMessageBox.Yes)
|
||||
default)
|
||||
if r == QMessageBox.Help:
|
||||
openWikiLink(help)
|
||||
else:
|
||||
|
@ -117,9 +121,10 @@ def askUserDialog(text, buttons, parent=None, help=""):
|
|||
|
||||
class GetTextDialog(QDialog):
|
||||
|
||||
def __init__(self, parent, question, help=None, edit=None):
|
||||
def __init__(self, parent, question, help=None, edit=None, default=u"",
|
||||
title="Anki"):
|
||||
QDialog.__init__(self, parent, Qt.Window)
|
||||
self.setWindowTitle("Anki")
|
||||
self.setWindowTitle(title)
|
||||
self.question = question
|
||||
self.help = help
|
||||
self.qlabel = QLabel(question)
|
||||
|
@ -128,6 +133,9 @@ class GetTextDialog(QDialog):
|
|||
if not edit:
|
||||
edit = QLineEdit()
|
||||
self.l = edit
|
||||
if default:
|
||||
self.l.setText(default)
|
||||
self.l.selectAll()
|
||||
v.addWidget(self.l)
|
||||
buts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel
|
||||
if help:
|
||||
|
@ -152,10 +160,11 @@ class GetTextDialog(QDialog):
|
|||
def helpRequested(self):
|
||||
QDesktopServices.openUrl(QUrl(ankiqt.appWiki + self.help))
|
||||
|
||||
def getText(prompt, parent=None, help=None, edit=None):
|
||||
def getText(prompt, parent=None, help=None, edit=None, default=u"", title="Anki"):
|
||||
if not parent:
|
||||
parent = ankiqt.mw
|
||||
d = GetTextDialog(parent, prompt, help=help, edit=edit)
|
||||
d = GetTextDialog(parent, prompt, help=help, edit=edit,
|
||||
default=default, title=title)
|
||||
ret = d.exec_()
|
||||
return (unicode(d.l.text()), ret)
|
||||
|
||||
|
|
|
@ -3375,7 +3375,7 @@
|
|||
<string>&Import...</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Import cards from text files, Anki files and more</string>
|
||||
<string>Import cards into the current deck</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGraphs">
|
||||
|
|
Loading…
Reference in a new issue