From 1077cceb7107aea7565bee3549b6cea9ee48d33c Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Tue, 30 Nov 2004 02:16:30 +0000 Subject: [PATCH] * src/gramps_main.py: Support for re-building Open Recent submenu and opening files from it. * src/ArgHandler.py: Rebuild recent menu after adding to recent. * src/DbPrompter.py (open_native): Add function. * src/RecentFiles.py (remove_filename): Add function. svn: r3767 --- gramps2/ChangeLog | 7 ++++ gramps2/src/ArgHandler.py | 1 + gramps2/src/DbPrompter.py | 69 ++++++++++++++++++++++---------------- gramps2/src/RecentFiles.py | 26 +++++++++++--- gramps2/src/gramps_main.py | 14 ++++++-- 5 files changed, 82 insertions(+), 35 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 4856c8dc5..b35363312 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2004-11-29 Alex Roitman + * src/gramps_main.py: Support for re-building Open Recent submenu + and opening files from it. + * src/ArgHandler.py: Rebuild recent menu after adding to recent. + * src/DbPrompter.py (open_native): Add function. + * src/RecentFiles.py (remove_filename): Add function. + 2004-11-28 Alex Roitman * src/plugins/PatchNames.py: Typo. * src/plugins/ChangeNames.py: Correct description. diff --git a/gramps2/src/ArgHandler.py b/gramps2/src/ArgHandler.py index 366c2033b..bc6767531 100644 --- a/gramps2/src/ArgHandler.py +++ b/gramps2/src/ArgHandler.py @@ -261,6 +261,7 @@ class ArgHandler: if success: # Add the file to the recent items RecentFiles.recent_files(filename,filetype) + self.parent.build_recent_menu() return if self.imports: diff --git a/gramps2/src/DbPrompter.py b/gramps2/src/DbPrompter.py index 82f743369..eb74319c1 100644 --- a/gramps2/src/DbPrompter.py +++ b/gramps2/src/DbPrompter.py @@ -175,33 +175,9 @@ class ExistingDbPrompter: if response == gtk.RESPONSE_OK: filename = choose.get_filename() filetype = gnome.vfs.get_mime_type(filename) - (the_path,the_file) = os.path.split(filename) - GrampsGconfKeys.save_last_import_dir(the_path) - - success = False - if filetype == const.app_gramps: - choose.destroy() - self.parent.db = GrampsBSDDB.GrampsBSDDB() - msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps") - msg_top = msgxml.get_widget('load_message') - self.parent.read_file(filename) - msg_top.destroy() - success = True - elif filetype == const.app_gramps_xml: - choose.destroy() - self.parent.db = GrampsXMLDB.GrampsXMLDB() - self.parent.read_file(filename) - success = True - elif filetype == const.app_gedcom: - choose.destroy() - self.parent.db = GrampsGEDDB.GrampsGEDDB() - self.parent.read_file(filename) - success = True - - if success: - # Add the file to the recent items - RecentFiles.recent_files(filename,filetype) + choose.destroy() + if open_native(self.parent,filename,filetype): return True # The above native formats did not work, so we need to @@ -209,7 +185,6 @@ class ExistingDbPrompter: # and create an empty native database to import data in for (importData,mime_filter,mime_type,native_format) in Plugins._imports: if filetype == mime_type or the_file == mime_type: - choose.destroy() QuestionDialog.OkDialog( _("Opening non-native format"), _("New gramps database has to be set up " "when opening non-native formats. The " @@ -225,7 +200,7 @@ class ExistingDbPrompter: return False QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename, _('The type "%s" is not in the list of known file types') % filetype ) - choose.destroy() + #choose.destroy() return False #------------------------------------------------------------------------- @@ -382,8 +357,46 @@ class NewNativeDbPrompter: self.parent.read_file(filename) # Add the file to the recent items RecentFiles.recent_files(filename,const.app_gramps) + self.parent.build_recent_menu() return True else: choose.destroy() return False return False + +#------------------------------------------------------------------------- +# +# Helper function +# +#------------------------------------------------------------------------- +def open_native(parent,filename,filetype): + """ + Open native database and return the status. + """ + + (the_path,the_file) = os.path.split(filename) + GrampsGconfKeys.save_last_import_dir(the_path) + + success = False + if filetype == const.app_gramps: + parent.db = GrampsBSDDB.GrampsBSDDB() + msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps") + msg_top = msgxml.get_widget('load_message') + parent.read_file(filename) + msg_top.destroy() + success = True + elif filetype == const.app_gramps_xml: + parent.db = GrampsXMLDB.GrampsXMLDB() + parent.read_file(filename) + success = True + elif filetype == const.app_gedcom: + parent.db = GrampsGEDDB.GrampsGEDDB() + parent.read_file(filename) + success = True + + if success: + # Add the file to the recent items + RecentFiles.recent_files(filename,filetype) + parent.build_recent_menu() + + return success diff --git a/gramps2/src/RecentFiles.py b/gramps2/src/RecentFiles.py index 4a792d653..7c1aae407 100644 --- a/gramps2/src/RecentFiles.py +++ b/gramps2/src/RecentFiles.py @@ -224,6 +224,18 @@ class GrampsRecentFiles: # so simply inserting a new item in the beginning self.gramps_recent_files.insert(0,item2add) + def remove_filename(self,filename): + # First we need to walk the existing items to see + # if our item is already there + found = False + for index in range(len(self.gramps_recent_files)): + if self.gramps_recent_files[index].get_path() == filename: + # Found it -- break here and pop that item + found = True + break + if found: + self.gramps_recent_files.pop(index) + def save(self): """ Attempt saving into XML. @@ -370,7 +382,7 @@ class GrampsRecentParser: #------------------------------------------------------------------------- # -# Helper function +# Helper functions # #------------------------------------------------------------------------- def recent_files(filename,filetype): @@ -398,7 +410,13 @@ def recent_files(filename,filetype): gramps_rf.add(gramps_item) gramps_rf.save() +def remove_filename(filename): +# GNOME will deal with missing item on its own -- who are we, mere mortals, +# to tell GNOME what do to? +# gnome_rf = GnomeRecentFiles() +# gnome_rf.remove_uri(uri) +# gnome_rf.save() - - - + gramps_rf = GrampsRecentFiles() + gramps_rf.remove_filename(filename) + gramps_rf.save() diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 185a93732..6d9415d7d 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -419,13 +419,21 @@ class Gramps: index = index + 1 name = os.path.basename(item.get_path()) menu_item = gtk.MenuItem(name,False) - menu_item.connect("activate",self.recent_callback,item.get_path()) + menu_item.connect("activate",self.recent_callback, + item.get_path(),item.get_mime()) menu_item.show() recent_menu.append(menu_item) self.open_recent.set_submenu(recent_menu) - def recent_callback(self,obj,filename): - print "Will open %s when finished" % filename + def recent_callback(self,obj,filename,filetype): + if os.path.exists(filename): + DbPrompter.open_native(self,filename,filetype) + else: + ErrorDialog(_('File does not exist'), + _("The file %s cannot be found. " + "It will be removed from the list of recent files.") % filename ) + RecentFiles.remove_filename(filename) + self.build_recent_menu() def undo_callback(self,text): if text == None: