diff --git a/ChangeLog b/ChangeLog index d6782b601..a1631dba6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-05-19 Don Allingham + * src/ImageSelect.py: undo messages + * src/MediaView.py: undo messages + * src/RelLib.py: use db for undo status + 2004-05-19 Don Allingham * various: undo messages diff --git a/src/ImageSelect.py b/src/ImageSelect.py index 7138cddc2..17d7338b1 100644 --- a/src/ImageSelect.py +++ b/src/ImageSelect.py @@ -258,7 +258,7 @@ class Gallery(ImageSelect): self.dataobj.set_media_list(self.old_media_list) trans = self.db.start_transaction() 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): """ @@ -802,7 +802,7 @@ class LocalMediaProperties: trans = self.db.start_transaction() 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): """Display the relevant portion of GRAMPS manual""" @@ -1027,7 +1027,7 @@ class GlobalMediaProperties: self.update() trans = self.db.start_transaction() 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): """Display the relevant portion of GRAMPS manual""" @@ -1136,6 +1136,6 @@ class DeleteMediaQuery: self.db.commit_place(p,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: self.update() diff --git a/src/MediaView.py b/src/MediaView.py index 7b2953596..ad1f1175f 100644 --- a/src/MediaView.py +++ b/src/MediaView.py @@ -312,7 +312,7 @@ class MediaView: else: trans = self.db.start_transaction() self.db.remove_object(mobj.get_id(),trans) - self.db.add_transaction(trans) + self.db.add_transaction(trans,_("Remove Media Object")) self.build_tree() def is_object_used(self,mobj): @@ -384,7 +384,7 @@ class MediaView: photo.set_path(name) self.db.commit_media_object(photo,trans) - self.db.add_transaction(trans) + self.db.add_transaction(trans,_("Add Media Object")) if GrampsCfg.globalprop: ImageSelect.GlobalMediaProperties(self.db,photo,self.load_media) @@ -416,7 +416,7 @@ class MediaView: return self.db.commit_media_object(photo,trans) - self.db.add_transaction(trans) + self.db.add_transaction(trans,_("Add Media Object")) if GrampsCfg.globalprop: ImageSelect.GlobalMediaProperties(self.db,photo,None) diff --git a/src/RelLib.py b/src/RelLib.py index de8a405c4..4401efee7 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -35,6 +35,7 @@ import os import os.path import types from gettext import gettext as _ +import cPickle #------------------------------------------------------------------------- # @@ -64,6 +65,8 @@ EVENT_KEY = 3 MEDIA_KEY = 4 PLACE_KEY = 5 +UNDO_SIZE = 1000 + #------------------------------------------------------------------------- # # ID regular expression @@ -533,7 +536,7 @@ class Location: self.phone = "" 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): """sets the city name of the Location object""" @@ -2656,7 +2659,8 @@ class GrampsDB: def new(self): """initializes the GrampsDB to empty values""" - self.translist = [] + self.undoindex = -1 + self.translist = [None] * UNDO_SIZE self.smap_index = 0 self.emap_index = 0 self.pmap_index = 0 @@ -2671,11 +2675,16 @@ class GrampsDB: self.genderStats = GenderStats () def start_transaction(self,msg=""): - return Transaction(msg) + return Transaction(msg,self.undodb) def add_transaction(self,transaction,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: self.undolabel.set_sensitive(1) label = self.undolabel.get_children()[0] @@ -2683,13 +2692,15 @@ class GrampsDB: label.set_use_underline(1) def undo(self): - if len(self.translist) == 0: + if self.undoindex == -1: return - transaction = self.translist.pop() + transaction = self.translist[self.undoindex] - subitems = transaction.get_data() + self.undoindex -= 1 + subitems = transaction.get_recnos() 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 data == None: del self.person_map[gid] @@ -2723,11 +2734,11 @@ class GrampsDB: if self.undolabel: label = self.undolabel.get_children()[0] - if len(self.translist) == 0: + if self.undoindex == -1: label.set_text(_("_Undo")) self.undolabel.set_sensitive(0) else: - transaction = self.translist[-1] + transaction = self.translist[self.undoindex] label.set_text(_("_Undo %s") % transaction.get_description()) self.undolabel.set_sensitive(1) label.set_use_underline(1) @@ -3542,8 +3553,11 @@ class GrampsDB: #------------------------------------------------------------------------- class Transaction: - def __init__(self,msg): + def __init__(self,msg,db): self.data = [] + self.db = db + self.first = None + self.last = None def get_description(self): return self.msg @@ -3552,16 +3566,22 @@ class Transaction: self.msg = msg 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): - return self.data + def get_recnos(self): + return range (self.first, self.last+1) + + def get_record(self,id): + return cPickle.loads(self.db[id]) def __len__(self): return len(self.data) 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 val: print "PERSON %s change" % gid @@ -3592,3 +3612,4 @@ class Transaction: print "PLACE %s change" % gid else: print "PLACE %s remove" % gid +