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()
with DbTxn(msg, self.db) as trans: try:
for object_handle in selected: with DbTxn(msg, self.db) as trans:
status.heartbeat() for object_handle in selected:
if status.should_cancel(): status.heartbeat()
break if status.should_cancel():
view.add_tag(trans, object_handle, tag_handle) raise DbTransactionCancel("User requests cancelation "
if status.was_cancelled(): "of the transaction.")
self.db.transaction_abort(trans) view.add_tag(trans, object_handle, tag_handle)
except DbTransactionCancel:
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
with DbTxn(_('Change Tag Priority'), self.db) as trans: try:
if not self.__change_tag_priority(trans): with DbTxn(_('Change Tag Priority'), self.db) as trans:
self.db.transaction_abort(trans) if not self.__change_tag_priority(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:
for classname, handle in links: with DbTxn(msg, self.db) as trans:
status.heartbeat() for classname, handle in links:
if status.should_cancel(): status.heartbeat()
break if status.should_cancel():
obj = fnc[classname][0](handle) # get from handle raise DbTransactionCancel("User requests "
obj.remove_tag(tag_handle) "cancelation of the transaction.")
fnc[classname][1](obj, trans) # commit obj = fnc[classname][0](handle) # get from handle
obj.remove_tag(tag_handle)
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()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------