rename default deck to untitled, delete on saveas

This commit is contained in:
Damien Elmes 2008-12-11 00:19:19 +09:00
parent 82870a9a19
commit 5dc05735c5

View file

@ -1423,6 +1423,7 @@ Return new path, relative to media dir."""
oldMediaDir = self.mediaDir() oldMediaDir = self.mediaDir()
# flush old deck # flush old deck
self.s.flush() self.s.flush()
self.close()
# remove new deck if it exists # remove new deck if it exists
try: try:
os.unlink(newPath) os.unlink(newPath)
@ -1452,13 +1453,14 @@ Return new path, relative to media dir."""
# detach old db and commit # detach old db and commit
s("detach database old") s("detach database old")
newDeck.s.commit() newDeck.s.commit()
# close ourself, rebuild queue
self.s.close()
newDeck.refresh() newDeck.refresh()
newDeck.rebuildQueue() newDeck.rebuildQueue()
# move media # move media
if oldMediaDir: if oldMediaDir:
newDeck.renameMediaDir(oldMediaDir) newDeck.renameMediaDir(oldMediaDir)
if self.name().startswith("untitled"):
# remove old deck
os.unlink(self.path)
# and return the new deck object # and return the new deck object
return newDeck return newDeck
@ -1747,10 +1749,10 @@ class DeckStorage(object):
def newDeckPath(): def newDeckPath():
n = 2 n = 2
path = os.path.expanduser( path = os.path.expanduser(
os.path.join(newDeckDir, "mydeck.anki")) os.path.join(newDeckDir, "untitled.anki"))
while os.path.exists(path): while os.path.exists(path):
path = os.path.expanduser( path = os.path.expanduser(
os.path.join(newDeckDir, "mydeck%d.anki") % n) os.path.join(newDeckDir, "untitled%d.anki") % n)
n += 1 n += 1
return path return path
newDeckPath = staticmethod(newDeckPath) newDeckPath = staticmethod(newDeckPath)