mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
release old deck when cramming, don't load deck on open
This commit is contained in:
parent
913cc9712d
commit
f8efd35a52
1 changed files with 12 additions and 11 deletions
|
@ -578,12 +578,15 @@ class AnkiQt(QMainWindow):
|
||||||
# New files, loading & saving
|
# New files, loading & saving
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
def onClose(self):
|
||||||
|
cramming = self.deck is not None and self.deck.name() == "cram"
|
||||||
|
self.saveAndClose(exit=cramming)
|
||||||
|
if cramming:
|
||||||
|
self.loadRecent(0)
|
||||||
|
|
||||||
def saveAndClose(self, exit=False):
|
def saveAndClose(self, exit=False):
|
||||||
"(Auto)save and close. Prompt if necessary. True if okay to proceed."
|
"(Auto)save and close. Prompt if necessary. True if okay to proceed."
|
||||||
cramming = False
|
|
||||||
if self.deck is not None:
|
if self.deck is not None:
|
||||||
oldName = self.deck.name()
|
|
||||||
cramming = oldName == "cram"
|
|
||||||
# sync (saving automatically)
|
# sync (saving automatically)
|
||||||
if self.config['syncOnClose'] and self.deck.syncName and not cramming:
|
if self.config['syncOnClose'] and self.deck.syncName and not cramming:
|
||||||
self.syncDeck(False, reload=False)
|
self.syncDeck(False, reload=False)
|
||||||
|
@ -607,10 +610,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.deck.rollback()
|
self.deck.rollback()
|
||||||
self.deck = None
|
self.deck = None
|
||||||
if not exit:
|
if not exit:
|
||||||
if cramming:
|
self.moveToState("noDeck")
|
||||||
self.loadRecent(0)
|
|
||||||
else:
|
|
||||||
self.moveToState("noDeck")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def onNew(self):
|
def onNew(self):
|
||||||
|
@ -1014,14 +1014,15 @@ class AnkiQt(QMainWindow):
|
||||||
self.deck.save()
|
self.deck.save()
|
||||||
# open tmp deck
|
# open tmp deck
|
||||||
import tempfile
|
import tempfile
|
||||||
dir = tempfile.mkdtemp(prefix="anki-cram")
|
ndir = tempfile.mkdtemp(prefix="anki-cram")
|
||||||
path = os.path.join(dir, "cram.anki")
|
path = os.path.join(ndir, "cram.anki")
|
||||||
from anki.exporting import AnkiExporter
|
from anki.exporting import AnkiExporter
|
||||||
e = AnkiExporter(self.deck)
|
e = AnkiExporter(self.deck)
|
||||||
if s:
|
if s:
|
||||||
e.limitTags = parseTags(s)
|
e.limitTags = parseTags(s)
|
||||||
e.exportInto(path)
|
e.exportInto(path)
|
||||||
# load
|
self.deck.close()
|
||||||
|
self.deck = None
|
||||||
self.loadDeck(path)
|
self.loadDeck(path)
|
||||||
self.config['recentDeckPaths'].pop(0)
|
self.config['recentDeckPaths'].pop(0)
|
||||||
self.deck.newCardsPerDay = 999999
|
self.deck.newCardsPerDay = 999999
|
||||||
|
@ -1223,7 +1224,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.connect(m.actionOpenSamples, s, self.onOpenSamples)
|
self.connect(m.actionOpenSamples, s, self.onOpenSamples)
|
||||||
self.connect(m.actionSave, s, self.onSave)
|
self.connect(m.actionSave, s, self.onSave)
|
||||||
self.connect(m.actionSaveAs, s, self.onSaveAs)
|
self.connect(m.actionSaveAs, s, self.onSaveAs)
|
||||||
self.connect(m.actionClose, s, self.saveAndClose)
|
self.connect(m.actionClose, s, self.onClose)
|
||||||
self.connect(m.actionExit, s, self, SLOT("close()"))
|
self.connect(m.actionExit, s, self, SLOT("close()"))
|
||||||
self.connect(m.actionSyncdeck, s, self.syncDeck)
|
self.connect(m.actionSyncdeck, s, self.syncDeck)
|
||||||
self.connect(m.actionDeckProperties, s, self.onDeckProperties)
|
self.connect(m.actionDeckProperties, s, self.onDeckProperties)
|
||||||
|
|
Loading…
Reference in a new issue