mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
cancel sync if user elects to keep unsaved card content (#705)
This commit is contained in:
parent
c44cf32dc2
commit
0994bd332c
4 changed files with 20 additions and 5 deletions
|
@ -55,11 +55,15 @@ class DialogManager(object):
|
||||||
self._dialogs[name] = [self._dialogs[name][0], None]
|
self._dialogs[name] = [self._dialogs[name][0], None]
|
||||||
|
|
||||||
def closeAll(self):
|
def closeAll(self):
|
||||||
|
"True if all closed successfully."
|
||||||
for (n, (creator, instance)) in self._dialogs.items():
|
for (n, (creator, instance)) in self._dialogs.items():
|
||||||
if instance:
|
if instance:
|
||||||
|
if not instance.canClose():
|
||||||
|
return False
|
||||||
instance.forceClose = True
|
instance.forceClose = True
|
||||||
instance.close()
|
instance.close()
|
||||||
self.close(n)
|
self.close(n)
|
||||||
|
return True
|
||||||
|
|
||||||
dialogs = DialogManager()
|
dialogs = DialogManager()
|
||||||
|
|
||||||
|
|
|
@ -441,6 +441,9 @@ class Browser(QMainWindow):
|
||||||
self.mw.maybeReset()
|
self.mw.maybeReset()
|
||||||
evt.accept()
|
evt.accept()
|
||||||
|
|
||||||
|
def canClose(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def keyPressEvent(self, evt):
|
def keyPressEvent(self, evt):
|
||||||
"Show answer on RET or register answer."
|
"Show answer on RET or register answer."
|
||||||
if evt.key() == Qt.Key_Escape:
|
if evt.key() == Qt.Key_Escape:
|
||||||
|
|
|
@ -64,3 +64,6 @@ class EditCurrent(QDialog):
|
||||||
self.mw.moveToState("review")
|
self.mw.moveToState("review")
|
||||||
saveGeom(self, "editcurrent")
|
saveGeom(self, "editcurrent")
|
||||||
aqt.dialogs.close("EditCurrent")
|
aqt.dialogs.close("EditCurrent")
|
||||||
|
|
||||||
|
def canClose(self):
|
||||||
|
return True
|
||||||
|
|
15
aqt/main.py
15
aqt/main.py
|
@ -226,9 +226,10 @@ To import into a password protected profile, please open the profile before atte
|
||||||
if not self.pm.profile:
|
if not self.pm.profile:
|
||||||
# already unloaded
|
# already unloaded
|
||||||
return
|
return
|
||||||
self.state = "profileManager"
|
|
||||||
runHook("unloadProfile")
|
runHook("unloadProfile")
|
||||||
self.unloadCollection()
|
if not self.unloadCollection():
|
||||||
|
return
|
||||||
|
self.state = "profileManager"
|
||||||
self.onSync(auto=True, reload=False)
|
self.onSync(auto=True, reload=False)
|
||||||
self.pm.profile['mainWindowGeom'] = self.saveGeometry()
|
self.pm.profile['mainWindowGeom'] = self.saveGeometry()
|
||||||
self.pm.profile['mainWindowState'] = self.saveState()
|
self.pm.profile['mainWindowState'] = self.saveState()
|
||||||
|
@ -257,14 +258,17 @@ how to restore from a backup.""")
|
||||||
self.moveToState("deckBrowser")
|
self.moveToState("deckBrowser")
|
||||||
|
|
||||||
def unloadCollection(self):
|
def unloadCollection(self):
|
||||||
|
"True if unload successful."
|
||||||
if self.col:
|
if self.col:
|
||||||
self.closeAllCollectionWindows()
|
if not self.closeAllCollectionWindows():
|
||||||
|
return
|
||||||
self.maybeOptimize()
|
self.maybeOptimize()
|
||||||
self.col.close()
|
self.col.close()
|
||||||
self.col = None
|
self.col = None
|
||||||
self.progress.start(immediate=True)
|
self.progress.start(immediate=True)
|
||||||
self.backup()
|
self.backup()
|
||||||
self.progress.finish()
|
self.progress.finish()
|
||||||
|
return True
|
||||||
|
|
||||||
# Backup and auto-optimize
|
# Backup and auto-optimize
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -469,7 +473,7 @@ title="%s">%s</button>''' % (
|
||||||
self.form.centralwidget.setLayout(self.mainLayout)
|
self.form.centralwidget.setLayout(self.mainLayout)
|
||||||
|
|
||||||
def closeAllCollectionWindows(self):
|
def closeAllCollectionWindows(self):
|
||||||
aqt.dialogs.closeAll()
|
return aqt.dialogs.closeAll()
|
||||||
|
|
||||||
# Components
|
# Components
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -521,7 +525,8 @@ title="%s">%s</button>''' % (
|
||||||
if not auto or (self.pm.profile['syncKey'] and
|
if not auto or (self.pm.profile['syncKey'] and
|
||||||
self.pm.profile['autoSync']):
|
self.pm.profile['autoSync']):
|
||||||
from aqt.sync import SyncManager
|
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
|
# set a sync state so the refresh timer doesn't fire while deck
|
||||||
# unloaded
|
# unloaded
|
||||||
self.state = "sync"
|
self.state = "sync"
|
||||||
|
|
Loading…
Reference in a new issue