Merge pull request #265 from Arthur-Milchior/reopenEdit

The note in curentEdit is not changed until the window is closed.
This commit is contained in:
Damien Elmes 2018-12-03 16:41:56 +10:00 committed by GitHub
commit a2b8d24352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -49,6 +49,7 @@ from anki.utils import checksum
# -- setting silentlyClose=True to have it close immediately
# -- define a closeWithCallback() method
# - have the window opened via aqt.dialogs.open(<name>, self)
# - have a method reopen(*args), called if the user ask to open the window a second time. Arguments passed are the same than for original opening.
#- make preferences modal? cmd+q does wrong thing
@ -74,6 +75,8 @@ class DialogManager:
instance.setWindowState(instance.windowState() & ~Qt.WindowMinimized)
instance.activateWindow()
instance.raise_()
if hasattr(instance,"reopen"):
instance.reopen(*args)
return instance
else:
instance = creator(*args)

View file

@ -3,11 +3,13 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import *
from aqt.utils import tooltip
import aqt.editor
from aqt.utils import saveGeom, restoreGeom
from anki.hooks import addHook, remHook
from anki.utils import isMac
class EditCurrent(QDialog):
def __init__(self, mw):
@ -34,8 +36,8 @@ class EditCurrent(QDialog):
def onReset(self):
# lazy approach for now: throw away edits
try:
n = self.mw.reviewer.card.note()
n.load()
n = self.editor.note
n.load()#reload in case the model changed
except:
# card's been deleted
remHook("reset", self.onReset)
@ -46,6 +48,10 @@ class EditCurrent(QDialog):
return
self.editor.setNote(n)
def reopen(self,mw):
tooltip("Please finish editing the existing card first.")
self.onReset()
def reject(self):
self.saveAndClose()