4665: Aborted transactions appear in the undo history

svn: r16697
This commit is contained in:
Michiel Nauta 2011-02-22 16:03:11 +00:00
parent 8473d5a1be
commit e99e492a1b
2 changed files with 43 additions and 25 deletions

View File

@ -54,6 +54,18 @@ class DbWriteFailure(Exception):
def messages(self): def messages(self):
return self.value, self.value2 return self.value, self.value2
class DbTransactionCancel(Exception):
"""
Error used to indicate that a transaction needs to be canceled,
for example becuase it is lengthy and the users requests so.
"""
def __init__(self, value):
Exception.__init__(self)
self.value = value
def __str__(self):
return self.value
class DbVersionError(Exception): class DbVersionError(Exception):
""" """
Error used to report that a file could not be read because it is written Error used to report that a file could not be read because it is written

View File

@ -43,7 +43,7 @@ import gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
from gen.lib import Tag from gen.lib import Tag
from gen.db import DbTxn from gen.db import DbTxn, DbTransactionCancel
from gui.dbguielement import DbGUIElement from gui.dbguielement import DbGUIElement
from ListModel import ListModel, NOSORT, COLOR, INTEGER from ListModel import ListModel, NOSORT, COLOR, INTEGER
import const import const
@ -269,14 +269,16 @@ class Tags(DbGUIElement):
pmon.add_op(status) pmon.add_op(status)
tag = self.db.get_tag_from_handle(tag_handle) tag = self.db.get_tag_from_handle(tag_handle)
msg = _('Tag Selection (%s)') % tag.get_name() msg = _('Tag Selection (%s)') % tag.get_name()
try:
with DbTxn(msg, self.db) as trans: with DbTxn(msg, self.db) as trans:
for object_handle in selected: for object_handle in selected:
status.heartbeat() status.heartbeat()
if status.should_cancel(): if status.should_cancel():
break raise DbTransactionCancel("User requests cancelation "
"of the transaction.")
view.add_tag(trans, object_handle, tag_handle) view.add_tag(trans, object_handle, tag_handle)
if status.was_cancelled(): except DbTransactionCancel:
self.db.transaction_abort(trans) pass
status.end() status.end()
def cb_menu_position(menu, button): def cb_menu_position(menu, button):
@ -325,9 +327,12 @@ class OrganizeTagsDialog(object):
break break
# Save changed priority values # Save changed priority values
try:
with DbTxn(_('Change Tag Priority'), self.db) as trans: with DbTxn(_('Change Tag Priority'), self.db) as trans:
if not self.__change_tag_priority(trans): if not self.__change_tag_priority(trans):
self.db.transaction_abort(trans) raise DbTransactionCancel("There was nothing to change.")
except DbTransactionCancel:
pass
self.top.destroy() self.top.destroy()
@ -505,21 +510,22 @@ class OrganizeTagsDialog(object):
pmon.add_op(status) pmon.add_op(status)
msg = _('Delete Tag (%s)') % tag_name msg = _('Delete Tag (%s)') % tag_name
with DbTxn(_('Change Tag Priority'), self.db) as trans: try:
with DbTxn(msg, self.db) as trans:
for classname, handle in links: for classname, handle in links:
status.heartbeat() status.heartbeat()
if status.should_cancel(): if status.should_cancel():
break raise DbTransactionCancel("User requests "
"cancelation of the transaction.")
obj = fnc[classname][0](handle) # get from handle obj = fnc[classname][0](handle) # get from handle
obj.remove_tag(tag_handle) obj.remove_tag(tag_handle)
fnc[classname][1](obj, trans) # commit fnc[classname][1](obj, trans) # commit
self.db.remove_tag(tag_handle, trans) self.db.remove_tag(tag_handle, trans)
self.__change_tag_priority(trans) self.__change_tag_priority(trans)
if status.was_cancelled():
self.db.transaction_abort(trans)
else:
store.remove(iter_) store.remove(iter_)
except DbTransactionCancel:
pass
status.end() status.end()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------