* src/ImageSelect.py: undo messages

* src/MediaView.py: undo messages
* src/RelLib.py: use db for undo status


svn: r3182
This commit is contained in:
Don Allingham 2004-05-20 00:12:14 +00:00
parent 79d9a39a9e
commit 0013617a90
4 changed files with 48 additions and 22 deletions

View File

@ -1,3 +1,8 @@
2004-05-19 Don Allingham <dallingham@users.sourceforge.net>
* src/ImageSelect.py: undo messages
* src/MediaView.py: undo messages
* src/RelLib.py: use db for undo status
2004-05-19 Don Allingham <dallingham@users.sourceforge.net> 2004-05-19 Don Allingham <dallingham@users.sourceforge.net>
* various: undo messages * various: undo messages

View File

@ -258,7 +258,7 @@ class Gallery(ImageSelect):
self.dataobj.set_media_list(self.old_media_list) self.dataobj.set_media_list(self.old_media_list)
trans = self.db.start_transaction() trans = self.db.start_transaction()
self.commit(self.dataobj,trans) self.commit(self.dataobj,trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Edit Media Object"))
def on_canvas1_event(self,obj,event): def on_canvas1_event(self,obj,event):
""" """
@ -802,7 +802,7 @@ class LocalMediaProperties:
trans = self.db.start_transaction() trans = self.db.start_transaction()
self.db.commit_media_object(self.object,trans) self.db.commit_media_object(self.object,trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Edit Media Object"))
def on_help_clicked(self, obj): def on_help_clicked(self, obj):
"""Display the relevant portion of GRAMPS manual""" """Display the relevant portion of GRAMPS manual"""
@ -1027,7 +1027,7 @@ class GlobalMediaProperties:
self.update() self.update()
trans = self.db.start_transaction() trans = self.db.start_transaction()
self.db.commit_media_object(self.object,trans) self.db.commit_media_object(self.object,trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Edit Media Object"))
def on_help_clicked(self, obj): def on_help_clicked(self, obj):
"""Display the relevant portion of GRAMPS manual""" """Display the relevant portion of GRAMPS manual"""
@ -1136,6 +1136,6 @@ class DeleteMediaQuery:
self.db.commit_place(p,trans) self.db.commit_place(p,trans)
self.db.remove_object(self.media.get_id(),trans) self.db.remove_object(self.media.get_id(),trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Remove Media Object"))
if self.update: if self.update:
self.update() self.update()

View File

@ -312,7 +312,7 @@ class MediaView:
else: else:
trans = self.db.start_transaction() trans = self.db.start_transaction()
self.db.remove_object(mobj.get_id(),trans) self.db.remove_object(mobj.get_id(),trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Remove Media Object"))
self.build_tree() self.build_tree()
def is_object_used(self,mobj): def is_object_used(self,mobj):
@ -384,7 +384,7 @@ class MediaView:
photo.set_path(name) photo.set_path(name)
self.db.commit_media_object(photo,trans) self.db.commit_media_object(photo,trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Add Media Object"))
if GrampsCfg.globalprop: if GrampsCfg.globalprop:
ImageSelect.GlobalMediaProperties(self.db,photo,self.load_media) ImageSelect.GlobalMediaProperties(self.db,photo,self.load_media)
@ -416,7 +416,7 @@ class MediaView:
return return
self.db.commit_media_object(photo,trans) self.db.commit_media_object(photo,trans)
self.db.add_transaction(trans) self.db.add_transaction(trans,_("Add Media Object"))
if GrampsCfg.globalprop: if GrampsCfg.globalprop:
ImageSelect.GlobalMediaProperties(self.db,photo,None) ImageSelect.GlobalMediaProperties(self.db,photo,None)

View File

@ -35,6 +35,7 @@ import os
import os.path import os.path
import types import types
from gettext import gettext as _ from gettext import gettext as _
import cPickle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -64,6 +65,8 @@ EVENT_KEY = 3
MEDIA_KEY = 4 MEDIA_KEY = 4
PLACE_KEY = 5 PLACE_KEY = 5
UNDO_SIZE = 1000
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# ID regular expression # ID regular expression
@ -533,7 +536,7 @@ class Location:
self.phone = "" self.phone = ""
def is_empty(self): def is_empty(self):
return self.city=="" and self.county=="" and self.state=="" and self.country=="" and self.postal=="" and self.phone=="" return not self.city and not self.county and not self.state and not self.country and not self.postal and not self.phone
def set_city(self,data): def set_city(self,data):
"""sets the city name of the Location object""" """sets the city name of the Location object"""
@ -2656,7 +2659,8 @@ class GrampsDB:
def new(self): def new(self):
"""initializes the GrampsDB to empty values""" """initializes the GrampsDB to empty values"""
self.translist = [] self.undoindex = -1
self.translist = [None] * UNDO_SIZE
self.smap_index = 0 self.smap_index = 0
self.emap_index = 0 self.emap_index = 0
self.pmap_index = 0 self.pmap_index = 0
@ -2671,11 +2675,16 @@ class GrampsDB:
self.genderStats = GenderStats () self.genderStats = GenderStats ()
def start_transaction(self,msg=""): def start_transaction(self,msg=""):
return Transaction(msg) return Transaction(msg,self.undodb)
def add_transaction(self,transaction,msg): def add_transaction(self,transaction,msg):
transaction.set_description(msg) transaction.set_description(msg)
self.translist.append(transaction) self.undoindex += 1
if self.undoindex == UNDO_SIZE:
self.translist = transaction[0:-1] + [ transaction ]
else:
self.translist[self.undoindex] = transaction
if self.undolabel: if self.undolabel:
self.undolabel.set_sensitive(1) self.undolabel.set_sensitive(1)
label = self.undolabel.get_children()[0] label = self.undolabel.get_children()[0]
@ -2683,13 +2692,15 @@ class GrampsDB:
label.set_use_underline(1) label.set_use_underline(1)
def undo(self): def undo(self):
if len(self.translist) == 0: if self.undoindex == -1:
return return
transaction = self.translist.pop() transaction = self.translist[self.undoindex]
subitems = transaction.get_data() self.undoindex -= 1
subitems = transaction.get_recnos()
subitems.reverse() subitems.reverse()
for (key, gid, data) in subitems: for record_id in subitems:
(key, gid, data) = transaction.get_record(record_id)
if key == PERSON_KEY: if key == PERSON_KEY:
if data == None: if data == None:
del self.person_map[gid] del self.person_map[gid]
@ -2723,11 +2734,11 @@ class GrampsDB:
if self.undolabel: if self.undolabel:
label = self.undolabel.get_children()[0] label = self.undolabel.get_children()[0]
if len(self.translist) == 0: if self.undoindex == -1:
label.set_text(_("_Undo")) label.set_text(_("_Undo"))
self.undolabel.set_sensitive(0) self.undolabel.set_sensitive(0)
else: else:
transaction = self.translist[-1] transaction = self.translist[self.undoindex]
label.set_text(_("_Undo %s") % transaction.get_description()) label.set_text(_("_Undo %s") % transaction.get_description())
self.undolabel.set_sensitive(1) self.undolabel.set_sensitive(1)
label.set_use_underline(1) label.set_use_underline(1)
@ -3542,8 +3553,11 @@ class GrampsDB:
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Transaction: class Transaction:
def __init__(self,msg): def __init__(self,msg,db):
self.data = [] self.data = []
self.db = db
self.first = None
self.last = None
def get_description(self): def get_description(self):
return self.msg return self.msg
@ -3552,16 +3566,22 @@ class Transaction:
self.msg = msg self.msg = msg
def add(self, type, gid, data): def add(self, type, gid, data):
self.data.append((type, gid, data)) self.last = self.db.append(cPickle.dumps((type,gid,data),1))
if self.first == None:
self.first = self.last
def get_data(self): def get_recnos(self):
return self.data return range (self.first, self.last+1)
def get_record(self,id):
return cPickle.loads(self.db[id])
def __len__(self): def __len__(self):
return len(self.data) return len(self.data)
def display(self): def display(self):
for (key,gid,val) in self.data: for record in self.get_recnos():
(key,gid,val) = self.get_record(record)
if key == PERSON_KEY: if key == PERSON_KEY:
if val: if val:
print "PERSON %s change" % gid print "PERSON %s change" % gid
@ -3592,3 +3612,4 @@ class Transaction:
print "PLACE %s change" % gid print "PLACE %s change" % gid
else: else:
print "PLACE %s remove" % gid print "PLACE %s remove" % gid