mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -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.d = deck
|
||||||
self.onFinish = onFinish
|
self.onFinish = onFinish
|
||||||
self.origMod = self.d.modified
|
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 = ankiqt.forms.deckproperties.Ui_DeckProperties()
|
||||||
self.dialog.setupUi(self)
|
self.dialog.setupUi(self)
|
||||||
self.dialog.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
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)
|
r = self.loadDeck(path, interactive=False, sync=False)
|
||||||
if r:
|
if r:
|
||||||
return r
|
return r
|
||||||
self.onNew(initial=True)
|
|
||||||
|
|
||||||
def getDefaultDir(self, save=False):
|
def getDefaultDir(self, save=False):
|
||||||
"Try and get default dir from most recently opened file."
|
"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?
|
# FIXME: no longer necessary?
|
||||||
return self.app.activeWindow() == self
|
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.inMainWindow() and not path: return
|
||||||
if not self.saveAndClose(hideWelcome=True): return
|
if not self.saveAndClose(hideWelcome=True): return
|
||||||
if initial:
|
register = not path
|
||||||
path = os.path.join(self.documentDir, "mydeck.anki")
|
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):
|
if os.path.exists(path):
|
||||||
# load mydeck instead
|
if ui.utils.askUser(_("That deck already exists. Overwrite?"),
|
||||||
return self.loadDeck(path)
|
defaultno=True):
|
||||||
|
os.unlink(path)
|
||||||
|
else:
|
||||||
|
return
|
||||||
self.deck = DeckStorage.Deck(path)
|
self.deck = DeckStorage.Deck(path)
|
||||||
self.deck.initUndo()
|
self.deck.initUndo()
|
||||||
self.deck.addModel(BasicModel())
|
self.deck.addModel(BasicModel())
|
||||||
self.deck.save()
|
self.deck.save()
|
||||||
|
if register:
|
||||||
|
self.updateRecentFiles(self.deck.path)
|
||||||
self.browserLastRefreshed = 0
|
self.browserLastRefreshed = 0
|
||||||
self.moveToState("initial")
|
self.moveToState("initial")
|
||||||
|
|
||||||
|
@ -1948,12 +1961,13 @@ learnt today")
|
||||||
|
|
||||||
def onImport(self):
|
def onImport(self):
|
||||||
if self.deck is None:
|
if self.deck is None:
|
||||||
self.onNew()
|
self.onNew(prompt=_("""\
|
||||||
if not self.deck.path:
|
Importing copies cards to the current deck,
|
||||||
self.showToolTip(_("""\
|
so we need to create a new deck first.
|
||||||
Please choose a name for this deck. After saving, the importing \
|
|
||||||
window will open."""))
|
Please give your deck a name:"""))
|
||||||
self.onSaveAs()
|
if not self.deck:
|
||||||
|
return
|
||||||
if self.deck.path:
|
if self.deck.path:
|
||||||
ui.importing.ImportDialog(self)
|
ui.importing.ImportDialog(self)
|
||||||
|
|
||||||
|
@ -2174,9 +2188,6 @@ it to your friends.
|
||||||
return
|
return
|
||||||
if self.deck and not self.deck.syncName:
|
if self.deck and not self.deck.syncName:
|
||||||
if interactive:
|
if interactive:
|
||||||
if not self.deck.path:
|
|
||||||
ui.utils.showInfo(_("Please save the deck first."))
|
|
||||||
return
|
|
||||||
if (not self.config['mediaLocation']
|
if (not self.config['mediaLocation']
|
||||||
and self.deck.s.scalar("select 1 from media limit 1")):
|
and self.deck.s.scalar("select 1 from media limit 1")):
|
||||||
ui.utils.showInfo(_("""\
|
ui.utils.showInfo(_("""\
|
||||||
|
@ -2943,7 +2954,7 @@ to work with this version of Anki."""))
|
||||||
# chdir if dir exists
|
# chdir if dir exists
|
||||||
dir = deck.mediaDir()
|
dir = deck.mediaDir()
|
||||||
# update location
|
# update location
|
||||||
deck.setVar("mediaLocation", next)
|
deck.setVar("mediaLocation", next, mod=False)
|
||||||
if dir and prefix == "dropbox":
|
if dir and prefix == "dropbox":
|
||||||
self.setupDropbox(deck)
|
self.setupDropbox(deck)
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ def showText(txt, parent=None, type="text"):
|
||||||
diag.setMinimumWidth(500)
|
diag.setMinimumWidth(500)
|
||||||
diag.exec_()
|
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."
|
"Show a yes/no question. Return true if yes."
|
||||||
if not parent:
|
if not parent:
|
||||||
parent = ankiqt.mw
|
parent = ankiqt.mw
|
||||||
|
@ -69,8 +69,12 @@ def askUser(text, parent=None, help=""):
|
||||||
if help:
|
if help:
|
||||||
sb |= QMessageBox.Help
|
sb |= QMessageBox.Help
|
||||||
while 1:
|
while 1:
|
||||||
|
if defaultno:
|
||||||
|
default = QMessageBox.No
|
||||||
|
else:
|
||||||
|
default = QMessageBox.Yes
|
||||||
r = QMessageBox.question(parent, "Anki", text, sb,
|
r = QMessageBox.question(parent, "Anki", text, sb,
|
||||||
QMessageBox.Yes)
|
default)
|
||||||
if r == QMessageBox.Help:
|
if r == QMessageBox.Help:
|
||||||
openWikiLink(help)
|
openWikiLink(help)
|
||||||
else:
|
else:
|
||||||
|
@ -117,9 +121,10 @@ def askUserDialog(text, buttons, parent=None, help=""):
|
||||||
|
|
||||||
class GetTextDialog(QDialog):
|
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)
|
QDialog.__init__(self, parent, Qt.Window)
|
||||||
self.setWindowTitle("Anki")
|
self.setWindowTitle(title)
|
||||||
self.question = question
|
self.question = question
|
||||||
self.help = help
|
self.help = help
|
||||||
self.qlabel = QLabel(question)
|
self.qlabel = QLabel(question)
|
||||||
|
@ -128,6 +133,9 @@ class GetTextDialog(QDialog):
|
||||||
if not edit:
|
if not edit:
|
||||||
edit = QLineEdit()
|
edit = QLineEdit()
|
||||||
self.l = edit
|
self.l = edit
|
||||||
|
if default:
|
||||||
|
self.l.setText(default)
|
||||||
|
self.l.selectAll()
|
||||||
v.addWidget(self.l)
|
v.addWidget(self.l)
|
||||||
buts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel
|
buts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel
|
||||||
if help:
|
if help:
|
||||||
|
@ -152,10 +160,11 @@ class GetTextDialog(QDialog):
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
QDesktopServices.openUrl(QUrl(ankiqt.appWiki + self.help))
|
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:
|
if not parent:
|
||||||
parent = ankiqt.mw
|
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_()
|
ret = d.exec_()
|
||||||
return (unicode(d.l.text()), ret)
|
return (unicode(d.l.text()), ret)
|
||||||
|
|
||||||
|
|
|
@ -3375,7 +3375,7 @@
|
||||||
<string>&Import...</string>
|
<string>&Import...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="statusTip">
|
<property name="statusTip">
|
||||||
<string>Import cards from text files, Anki files and more</string>
|
<string>Import cards into the current deck</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionGraphs">
|
<action name="actionGraphs">
|
||||||
|
|
Loading…
Reference in a new issue