enable undo/redo support

This commit is contained in:
Damien Elmes 2008-11-30 04:12:19 +09:00
parent ae93e54013
commit 30e106b4e6
5 changed files with 45 additions and 14 deletions

View file

@ -493,7 +493,10 @@ where id in (%s)""" % ",".join([
def deleteCards(self):
cards = self.selectedCards()
n = _("Delete Cards")
self.deck.setUndoStart(n)
self.deck.deleteCards(cards)
self.deck.setUndoEnd(n)
self.updateSearch()
def addTags(self):

View file

@ -144,12 +144,13 @@ An error occurred. Please copy the following message into a bug report.\n\n""" +
self.views = self.viewsBackup
self.viewsBackup = None
def reset(self):
def reset(self, count=True):
ui.dialogs.closeAll()
if self.deck:
self.deck.refresh()
self.deck.updateAllPriorities()
self.deck.rebuildCounts()
if count:
self.deck.updateAllPriorities()
self.deck.rebuildCounts()
self.deck.rebuildQueue()
self.moveToState("initial")
@ -971,12 +972,12 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
self.reset()
def onUndo(self):
# quick and dirty undo for now
self.currentCard = None
self.deck.s.flush()
self.lastCardBackup.toDB(self.deck.s)
self.deck.rebuildCounts()
self.reset()
self.deck.undo()
self.reset(count=False)
def onRedo(self):
self.deck.redo()
self.reset(count=False)
# Other menu operations
##########################################################################
@ -1243,6 +1244,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
"DeckProperties",
"ModelProperties",
"Undo",
"Redo",
"Export",
"MarkCard",
"Graphs",
@ -1297,6 +1299,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
self.connect(m.actionRepeatAnswerAudio, s, self.onRepeatAnswer)
self.connect(m.actionRepeatAudio, s, self.onRepeatAudio)
self.connect(m.actionUndo, s, self.onUndo)
self.connect(m.actionRedo, s, self.onRedo)
self.connect(m.actionCheckDatabaseIntegrity, s, self.onCheckDB)
self.connect(m.actionOptimizeDatabase, s, self.onOptimizeDB)
self.connect(m.actionMergeModels, s, self.onMergeModels)
@ -1357,7 +1360,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
self.mainWin.actionMarkCard.blockSignals(False)
def disableCardMenuItems(self):
self.mainWin.actionUndo.setEnabled(not not self.lastCard)
self.maybeEnableUndo()
self.mainWin.actionMarkCard.setEnabled(False)
self.mainWin.actionSuspendCard.setEnabled(False)
self.mainWin.actionRepeatQuestionAudio.setEnabled(False)
@ -1366,7 +1369,7 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
self.mainWin.actionEditCurrent.setEnabled(False)
def enableCardMenuItems(self):
self.mainWin.actionUndo.setEnabled(not not self.lastCard)
self.maybeEnableUndo()
self.mainWin.actionMarkCard.setEnabled(True)
self.mainWin.actionSuspendCard.setEnabled(True)
self.mainWin.actionRepeatQuestionAudio.setEnabled(
@ -1378,6 +1381,20 @@ To upgrade an old deck, download Anki 0.9.8.7."""))
self.mainWin.actionRepeatAnswerAudio.isEnabled())
self.mainWin.actionEditCurrent.setEnabled(True)
def maybeEnableUndo(self):
if self.deck and self.deck.undoStack:
self.mainWin.actionUndo.setText(_("Undo %s") %
self.deck.undoStack[-1][0])
self.mainWin.actionUndo.setEnabled(True)
else:
self.mainWin.actionUndo.setEnabled(False)
if self.deck and self.deck.redoStack:
self.mainWin.actionRedo.setText(_("Redo %s") %
self.deck.redoStack[-1][0])
self.mainWin.actionRedo.setEnabled(True)
else:
self.mainWin.actionRedo.setEnabled(False)
# Auto update
##########################################################################

View file

@ -619,7 +619,8 @@
<property name="title" >
<string>&amp;Edit</string>
</property>
<addaction name="actionUndoAnswer" />
<addaction name="actionUndo" />
<addaction name="actionRedo" />
<addaction name="separator" />
<addaction name="actionAddcards" />
<addaction name="actionEditCurrent" />
@ -1115,7 +1116,7 @@
<string>F5</string>
</property>
</action>
<action name="actionUndoAnswer" >
<action name="actionUndo" >
<property name="enabled" >
<bool>false</bool>
</property>
@ -1124,7 +1125,7 @@
<normaloff>:/icons/edit-undo.png</normaloff>:/icons/edit-undo.png</iconset>
</property>
<property name="text" >
<string>&amp;Undo last answer</string>
<string>&amp;Undo</string>
</property>
<property name="shortcut" >
<string>Ctrl+Z</string>
@ -1262,6 +1263,15 @@
<string>Ctrl+E</string>
</property>
</action>
<action name="actionRedo" >
<property name="icon" >
<iconset resource="../icons.qrc" >
<normaloff>:/icons/edit-redo.png</normaloff>:/icons/edit-redo.png</iconset>
</property>
<property name="text" >
<string>&amp;Redo</string>
</property>
</action>
</widget>
<resources>
<include location="../icons.qrc" />

View file

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/" >
<file>icons/edit-redo.png</file>
<file>icons/text-xml.png</file>
<file>icons/document-preview.png</file>
<file>icons/media-record.png</file>

BIN
icons/edit-redo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB