The note in curentEdit is not changed until the window is closed.

https://anki.tenderapp.com/discussions/ankidesktop/31105-reopening-an-edit-window
I added a «reopen» method, which I believe may be useful in other
cases too. I check whether the method exists before calling it, so
there should be no compatibility problem.
This commit is contained in:
Arthur-Milchior 2018-11-28 10:16:23 +01:00
parent 98adddde6f
commit b8523944ff
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 # -- setting silentlyClose=True to have it close immediately
# -- define a closeWithCallback() method # -- define a closeWithCallback() method
# - have the window opened via aqt.dialogs.open(<name>, self) # - 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 #- make preferences modal? cmd+q does wrong thing
@ -74,6 +75,8 @@ class DialogManager:
instance.setWindowState(instance.windowState() & ~Qt.WindowMinimized) instance.setWindowState(instance.windowState() & ~Qt.WindowMinimized)
instance.activateWindow() instance.activateWindow()
instance.raise_() instance.raise_()
if hasattr(instance,"reopen"):
instance.reopen(*args)
return instance return instance
else: else:
instance = creator(*args) instance = creator(*args)

View File

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