cancel sync if user elects to keep unsaved card content (#705)

This commit is contained in:
Damien Elmes 2013-04-11 19:23:32 +09:00
parent c44cf32dc2
commit 0994bd332c
4 changed files with 20 additions and 5 deletions

View file

@ -55,11 +55,15 @@ class DialogManager(object):
self._dialogs[name] = [self._dialogs[name][0], None]
def closeAll(self):
"True if all closed successfully."
for (n, (creator, instance)) in self._dialogs.items():
if instance:
if not instance.canClose():
return False
instance.forceClose = True
instance.close()
self.close(n)
return True
dialogs = DialogManager()

View file

@ -441,6 +441,9 @@ class Browser(QMainWindow):
self.mw.maybeReset()
evt.accept()
def canClose(self):
return True
def keyPressEvent(self, evt):
"Show answer on RET or register answer."
if evt.key() == Qt.Key_Escape:

View file

@ -64,3 +64,6 @@ class EditCurrent(QDialog):
self.mw.moveToState("review")
saveGeom(self, "editcurrent")
aqt.dialogs.close("EditCurrent")
def canClose(self):
return True

View file

@ -226,9 +226,10 @@ To import into a password protected profile, please open the profile before atte
if not self.pm.profile:
# already unloaded
return
self.state = "profileManager"
runHook("unloadProfile")
self.unloadCollection()
if not self.unloadCollection():
return
self.state = "profileManager"
self.onSync(auto=True, reload=False)
self.pm.profile['mainWindowGeom'] = self.saveGeometry()
self.pm.profile['mainWindowState'] = self.saveState()
@ -257,14 +258,17 @@ how to restore from a backup.""")
self.moveToState("deckBrowser")
def unloadCollection(self):
"True if unload successful."
if self.col:
self.closeAllCollectionWindows()
if not self.closeAllCollectionWindows():
return
self.maybeOptimize()
self.col.close()
self.col = None
self.progress.start(immediate=True)
self.backup()
self.progress.finish()
return True
# Backup and auto-optimize
##########################################################################
@ -469,7 +473,7 @@ title="%s">%s</button>''' % (
self.form.centralwidget.setLayout(self.mainLayout)
def closeAllCollectionWindows(self):
aqt.dialogs.closeAll()
return aqt.dialogs.closeAll()
# Components
##########################################################################
@ -521,7 +525,8 @@ title="%s">%s</button>''' % (
if not auto or (self.pm.profile['syncKey'] and
self.pm.profile['autoSync']):
from aqt.sync import SyncManager
self.unloadCollection()
if not self.unloadCollection():
return
# set a sync state so the refresh timer doesn't fire while deck
# unloaded
self.state = "sync"