* 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
This commit is contained in:
Alex Roitman 2004-11-30 02:16:30 +00:00
parent 0d121bca70
commit 1077cceb71
5 changed files with 82 additions and 35 deletions

View File

@ -1,3 +1,10 @@
2004-11-29 Alex Roitman <shura@alex.neuro.umn.edu>
* 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 <shura@alex.neuro.umn.edu> 2004-11-28 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/PatchNames.py: Typo. * src/plugins/PatchNames.py: Typo.
* src/plugins/ChangeNames.py: Correct description. * src/plugins/ChangeNames.py: Correct description.

View File

@ -261,6 +261,7 @@ class ArgHandler:
if success: if success:
# Add the file to the recent items # Add the file to the recent items
RecentFiles.recent_files(filename,filetype) RecentFiles.recent_files(filename,filetype)
self.parent.build_recent_menu()
return return
if self.imports: if self.imports:

View File

@ -175,33 +175,9 @@ class ExistingDbPrompter:
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = choose.get_filename() filename = choose.get_filename()
filetype = gnome.vfs.get_mime_type(filename) filetype = gnome.vfs.get_mime_type(filename)
(the_path,the_file) = os.path.split(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() choose.destroy()
self.parent.db = GrampsBSDDB.GrampsBSDDB() if open_native(self.parent,filename,filetype):
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)
return True return True
# The above native formats did not work, so we need to # 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 # and create an empty native database to import data in
for (importData,mime_filter,mime_type,native_format) in Plugins._imports: for (importData,mime_filter,mime_type,native_format) in Plugins._imports:
if filetype == mime_type or the_file == mime_type: if filetype == mime_type or the_file == mime_type:
choose.destroy()
QuestionDialog.OkDialog( _("Opening non-native format"), QuestionDialog.OkDialog( _("Opening non-native format"),
_("New gramps database has to be set up " _("New gramps database has to be set up "
"when opening non-native formats. The " "when opening non-native formats. The "
@ -225,7 +200,7 @@ class ExistingDbPrompter:
return False return False
QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename, QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename,
_('The type "%s" is not in the list of known file types') % filetype ) _('The type "%s" is not in the list of known file types') % filetype )
choose.destroy() #choose.destroy()
return False return False
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -382,8 +357,46 @@ class NewNativeDbPrompter:
self.parent.read_file(filename) self.parent.read_file(filename)
# Add the file to the recent items # Add the file to the recent items
RecentFiles.recent_files(filename,const.app_gramps) RecentFiles.recent_files(filename,const.app_gramps)
self.parent.build_recent_menu()
return True return True
else: else:
choose.destroy() choose.destroy()
return False return False
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

View File

@ -224,6 +224,18 @@ class GrampsRecentFiles:
# so simply inserting a new item in the beginning # so simply inserting a new item in the beginning
self.gramps_recent_files.insert(0,item2add) 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): def save(self):
""" """
Attempt saving into XML. Attempt saving into XML.
@ -370,7 +382,7 @@ class GrampsRecentParser:
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Helper function # Helper functions
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def recent_files(filename,filetype): def recent_files(filename,filetype):
@ -398,7 +410,13 @@ def recent_files(filename,filetype):
gramps_rf.add(gramps_item) gramps_rf.add(gramps_item)
gramps_rf.save() 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()

View File

@ -419,13 +419,21 @@ class Gramps:
index = index + 1 index = index + 1
name = os.path.basename(item.get_path()) name = os.path.basename(item.get_path())
menu_item = gtk.MenuItem(name,False) 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() menu_item.show()
recent_menu.append(menu_item) recent_menu.append(menu_item)
self.open_recent.set_submenu(recent_menu) self.open_recent.set_submenu(recent_menu)
def recent_callback(self,obj,filename): def recent_callback(self,obj,filename,filetype):
print "Will open %s when finished" % filename 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): def undo_callback(self,text):
if text == None: if text == None: