diff --git a/ChangeLog b/ChangeLog index e35369b44..cf1775214 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ 2005-12-24 Don Allingham + * src/Bookmarks.py: get bookmark menu working + * src/EditPlace.py: menu tracking * src/DisplayState.py: recent file support * src/ViewManager.py: recent file support diff --git a/src/Bookmarks.py b/src/Bookmarks.py index 71afb42d9..30eedcc85 100644 --- a/src/Bookmarks.py +++ b/src/Bookmarks.py @@ -31,6 +31,7 @@ __version__ = "$Revision$" # #------------------------------------------------------------------------- from gettext import gettext as _ +from cStringIO import StringIO #------------------------------------------------------------------------- # @@ -53,10 +54,16 @@ import ListModel # Bookmarks # #------------------------------------------------------------------------- + +_top = '''''' +_btm = '''''' + +DISABLED = -1 + class Bookmarks : "Handle the bookmarks interface for Gramps" - def __init__(self,db,bookmarks): + def __init__(self,dbstate,uimanager,bookmarks): """ Creates a the bookmark editor. @@ -64,13 +71,40 @@ class Bookmarks : menu - parent menu to attach users callback - task to connect to the menu item as a callback """ - self.db = db + self.dbstate = dbstate + self.uimanager = uimanager self.bookmarks = bookmarks + self.active = DISABLED + self.action_group = gtk.ActionGroup('Bookmarks') self.redraw() def redraw(self): """Create the pulldown menu""" - pass + f = StringIO() + f.write(_top) + + count = 0 + if self.active != DISABLED: + self.uimanager.remove_ui(self.active) + self.uimanager.remove_action_group(self.action_group) + self.active = DISABLED + + actions = [] + for item in self.bookmarks: + person = self.dbstate.db.get_person_from_handle(item) + name = NameDisplay.displayer.display(person) + action_id = "BM:%s" % item + f.write('' % action_id) + label = "%s [%s]" % (name,person.gramps_id) + func = make_callback(item,self.dbstate.change_active_handle) + actions.append((action_id,None,label,None,None,func)) + count +=1 + f.write(_btm) + self.action_group.add_actions(actions) + self.uimanager.insert_action_group(self.action_group,1) + self.active = self.uimanager.add_ui_from_string(f.getvalue()) + print f.getvalue() + f.close() def add(self,person_handle): """appends the person to the bottom of the bookmarks""" @@ -144,7 +178,7 @@ class Bookmarks : """ self.draw_window() for person_handle in self.bookmarks: - person = self.db.get_person_from_handle(person_handle) + person = self.dbstate.db.get_person_from_handle(person_handle) if person: name = NameDisplay.displayer.display(person) gramps_id = person.get_gramps_id() @@ -193,3 +227,6 @@ class Bookmarks : """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('gramps-nav') self.response = self.top.run() + +def make_callback(n,f): + return lambda x: f(n) diff --git a/src/DisplayState.py b/src/DisplayState.py index 7787f0297..e3b36a2bc 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -65,7 +65,7 @@ class History(GrampsDb.GrampsDBCallback): def clear(self): self.history = [] - self.mistory = [] + self.mhistory = [] self.index = -1 self.lock = False @@ -366,7 +366,6 @@ class RecentDocsMenu: self.state = state def load(self,item): - print item name = item.get_path() dbtype = item.get_mime() @@ -390,7 +389,9 @@ class RecentDocsMenu: self.active = DISABLED actions = [] - for item in gramps_rf.gramps_recent_files: + rfiles = gramps_rf.gramps_recent_files + rfiles.sort(by_time) + for item in rfiles: try: filename = os.path.basename(item.get_path()).replace('_','__') filetype = get_mime_type(item.get_path()) @@ -411,6 +412,9 @@ class RecentDocsMenu: def make_callback(n,f): return lambda x: f(n) +def by_time(a,b): + return cmp(b.get_time(),a.get_time()) + #------------------------------------------------------------------------- # # Gramps Managed Window class diff --git a/src/EditPlace.py b/src/EditPlace.py index af90983a0..0b75d3255 100644 --- a/src/EditPlace.py +++ b/src/EditPlace.py @@ -67,10 +67,10 @@ from WindowUtils import GladeIf #------------------------------------------------------------------------- class EditPlace(DisplayState.ManagedWindow): - def __init__(self,place,dbstate,uistate,trace=[]): + def __init__(self,place,dbstate,uistate,track=[]): self.dbstate = dbstate self.uistate = uistate - self.trace = [] + self.track = [] self.ref_not_loaded = place and place.get_handle() self.idle = None @@ -219,7 +219,7 @@ class EditPlace(DisplayState.ManagedWindow): self.gladeif.connect('del_url', 'clicked', self.on_delete_url_clicked) self.sourcetab = Sources.SourceTab( - self.state, self.ui_state, self.track, + self.state, self.uistate, self.track, self.srcreflist,self, self.top_window,self.top,self.slist, self.top_window.get_widget('add_src'), @@ -252,7 +252,7 @@ class EditPlace(DisplayState.ManagedWindow): self.top.show() - DisplayState.ManagedWindow.__init__(self, uistate, [], place) + DisplayState.ManagedWindow.__init__(self, uistate, self.track, place) self.pdmap = {} self.build_pdmap() diff --git a/src/ViewManager.py b/src/ViewManager.py index 964bf40eb..9c1689671 100644 --- a/src/ViewManager.py +++ b/src/ViewManager.py @@ -62,6 +62,7 @@ import Navigation import TipOfDay import Bookmarks import RecentFiles +import NameDisplay #------------------------------------------------------------------------- # @@ -110,7 +111,7 @@ uidefault = ''' - + @@ -271,7 +272,7 @@ class ViewManager: ('EditMenu', None, '_Edit'), ('GoMenu', None, '_Go'), ('BookMenu', None, '_Bookmarks'), - ('AddBook', gtk.STOCK_INDEX, '_Add bookmark', 'd'), + ('AddBook', gtk.STOCK_INDEX, '_Add bookmark', 'd', None, self.add_bookmark), ('EditBook', None, '_Edit bookmarks', 'b'), ('GoToBook', gtk.STOCK_JUMP_TO, '_Go to bookmark'), ('ReportsMenu',None, '_Reports'), @@ -643,7 +644,6 @@ class ViewManager: 'to the selected file.')) try: - print self.load_database, filename, callback, mode if self.load_database(filename,callback,mode=mode): if filename[-1] == '/': filename = filename[:-1] @@ -716,15 +716,14 @@ class ViewManager: return True def setup_bookmarks(self): - self.bookmarks = Bookmarks.Bookmarks(self.state.db,self.state.db.get_bookmarks()) + self.bookmarks = Bookmarks.Bookmarks(self.state,self.uimanager, + self.state.db.get_bookmarks()) - def on_add_bookmark_activate(self,obj): - return - if self.active_person: - self.bookmarks.add(self.active_person.get_handle()) - name = NameDisplay.displayer.display(self.active_person) - self.status_text(_("%s has been bookmarked") % name) - gobject.timeout_add(5000,self.modify_statusbar) + def add_bookmark(self,obj): + if self.state.active: + self.bookmarks.add(self.state.active.get_handle()) + name = NameDisplay.displayer.display(self.state.active) + self.uistate.push_message(_("%s has been bookmarked") % name) else: WarningDialog(_("Could Not Set a Bookmark"), _("A bookmark could not be set because " @@ -733,22 +732,6 @@ class ViewManager: def on_edit_bookmarks_activate(self,obj): self.bookmarks.edit() - def bookmark_callback(self,obj,person_handle): - old_person = self.active_person - person = self.state.db.get_person_from_handle(person_handle) - try: - self.change_active_person(person) - self.update_display(0) - self.goto_active_person() - except TypeError: - WarningDialog(_("Could not go to a Person"), - _("Either stale bookmark or broken history " - "caused by IDs reorder.")) - self.clear_history() - self.change_active_person(old_person) - self.update_display(0) - self.goto_active_person() - def find_initial_person(self): person = self.state.db.get_default_person() if not person: