diff --git a/ChangeLog b/ChangeLog index 6cc6d571a..4b43a8faa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-06-24 Alex Roitman + * src/gramps_main.py (on_import_activate,on_export_activate): + Add methods. + * src/Plugins.py (build_import_menu,build_export_menu): Remove; + (register_export): Change to the new scheme. + * src/gramps.glade: Add handlers to Import and Export menus. + Rename Export to Save As..., add icons. + 2004-06-23 Alex Roitman * src/ArgHandler.py (handle_args): Add import callback call. * src/gramps_main.py: Use open filters, mime types, and handlers diff --git a/src/Plugins.py b/src/Plugins.py index 09866a915..adfdc811a 100644 --- a/src/Plugins.py +++ b/src/Plugins.py @@ -460,18 +460,18 @@ def reload_plugins(obj): # Plugin registering # #------------------------------------------------------------------------- -def register_export(task, name): - """Register an export filter, taking the task and name""" - _exports.append((task, name)) - -#def register_import(task, name): -# """Register an import filter, taking the task and name""" -# _imports.append((task, name)) +def register_export(task, ffilter, pattern_list=None): + """ + Register an export filter, taking the task, file filter, + and the list of patterns for the filename matching. + """ + if pattern_list: + _exports.append((task, ffilter, pattern_list)) def register_import(task, ffilter, mime=None): """Register an import filter, taking the task and file filter""" if mime: - _imports.append((task, ffilter, mime)) + _imports.append((task, ffilter, mime)) def register_report(task, name, category=_("Uncategorized"), @@ -641,36 +641,6 @@ def build_report_menu(top_menu,callback): def build_tools_menu(top_menu,callback): build_menu(top_menu,_tools,callback) -#------------------------------------------------------------------------- -# -# build_export_menu -# -#------------------------------------------------------------------------- -def build_export_menu(top_menu,callback): - myMenu = gtk.Menu() - - for report in _exports: - item = gtk.MenuItem("%s..." % report[1]) - item.connect("activate", callback ,report[0]) - item.show() - myMenu.append(item) - top_menu.set_submenu(myMenu) - -#------------------------------------------------------------------------- -# -# build_import_menu -# -#------------------------------------------------------------------------- -def build_import_menu(top_menu,callback): - myMenu = gtk.Menu() - - for report in _imports: - item = gtk.MenuItem("%s..." % report[1]) - item.connect("activate", callback ,report[0]) - item.show() - myMenu.append(item) - top_menu.set_submenu(myMenu) - #------------------------------------------------------------------------- # # get_text_doc_menu diff --git a/src/gramps.glade b/src/gramps.glade index 97bfc8ddc..97d428721 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -56,7 +56,7 @@ - + True gtk-new 1 @@ -78,7 +78,7 @@ - + True gtk-open 1 @@ -98,23 +98,39 @@ - + True - _Import + _Import... True + + + + + + True + gtk-convert + 1 + 0.5 + 0.5 + 0 + 0 + + True - _Export + Save _As... True + + - + True - gtk-convert + gtk-save-as 1 0.5 0.5 @@ -140,7 +156,7 @@ - + True gtk-quit 1 @@ -175,7 +191,7 @@ - + True gtk-undo 1 @@ -212,7 +228,7 @@ - + True gtk-add 1 @@ -235,7 +251,7 @@ - + True gtk-remove 1 @@ -273,7 +289,7 @@ - + True gtk-find 1 @@ -295,7 +311,7 @@ - + True gtk-convert 1 @@ -322,7 +338,7 @@ - + True gtk-preferences 1 @@ -343,7 +359,7 @@ - + True gtk-properties 1 @@ -364,7 +380,7 @@ - + True gtk-home 1 @@ -450,7 +466,7 @@ - + True gtk-index 1 @@ -472,7 +488,7 @@ - + True gnome-stock-book-open 1 @@ -545,7 +561,7 @@ - + True gtk-help 1 @@ -566,7 +582,7 @@ - + True gnome-stock-book-open 1 @@ -593,7 +609,7 @@ - + True gtk-jump-to 1 @@ -614,7 +630,7 @@ - + True gnome-stock-mail 1 @@ -668,7 +684,7 @@ - + True gnome-stock-about 1 diff --git a/src/gramps_main.py b/src/gramps_main.py index d3373f73f..a332c4f4c 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -315,6 +315,8 @@ class Gramps: "on_notebook1_switch_page" : self.on_views_switch_page, "on_ok_button1_clicked" : self.on_ok_button1_clicked, "on_open_activate" : self.on_open_activate, + "on_import_activate" : self.on_import_activate, + "on_export_activate" : self.on_export_activate, "on_pedigree1_activate" : self.on_pedigree1_activate, "on_person_list1_activate" : self.on_person_list1_activate, "on_main_key_release_event" : self.on_main_key_release_event, @@ -714,8 +716,6 @@ class Gramps: Plugins.build_report_menu(self.report_menu,self.menu_report) Plugins.build_tools_menu(self.tools_menu,self.menu_tools) - Plugins.build_export_menu(export_menu,self.export_callback) - Plugins.build_import_menu(import_menu,self.import_callback) self.RelClass = Plugins.relationship_class self.relationship = self.RelClass(self.db) @@ -1465,7 +1465,7 @@ class Gramps: def on_open_activate(self,obj): - choose = gtk.FileChooserDialog('Open GRAMPS database', + choose = gtk.FileChooserDialog(_('GRAMPS: Open database'), self.topWindow, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, @@ -1520,6 +1520,115 @@ class Gramps: _('The type "%s" is not in the list of known file types') % filetype ) choose.destroy() + def on_import_activate(self,obj): + choose = gtk.FileChooserDialog(_('GRAMPS: Import database'), + self.topWindow, + gtk.FILE_CHOOSER_ACTION_OPEN, + (gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) + + # Always add automatic (macth all files) filter + filter = gtk.FileFilter() + filter.set_name(_('Automatic')) + filter.add_pattern('*') + choose.add_filter(filter) + +# FIXME: Uncomment when we have grdb importer +# +# # Always add native format filter +# filter = gtk.FileFilter() +# filter.set_name(_('GRAMPS databases')) +# filter.add_mime_type('application/x-gramps') +# choose.add_filter(filter) + + for (importData,filter,mime_type) in Plugins._imports: + choose.add_filter(filter) + + if GrampsCfg.lastfile: + choose.set_filename(GrampsCfg.lastfile) + + response = choose.run() + if response == gtk.RESPONSE_OK: + filename = choose.get_filename() + filename = os.path.normpath(os.path.abspath(filename)) + filetype = gnome.vfs.get_mime_type(filename) + (junk,the_file) = os.path.split(filename) + +# FIXME: Uncomment when we have grdb importer +# +# if filetype == 'application/x-gramps': +# if self.auto_save_load(filename) == 0: +# DbPrompter.DbPrompter(self,0,self.topWindow) +# else: + if True: + opened = 0 + for (importData,filter,mime_type) in Plugins._imports: + if filetype == mime_type or the_file == mime_type: + importData(self.db,filename) + self.import_tool_callback() + opened = 1 + break + if not opened: + ErrorDialog( _("Could not open file: %s") % filename, + _('The type "%s" is not in the list of known file types') % filetype ) + choose.destroy() + + def on_export_activate(self,obj): + choose = gtk.FileChooserDialog(_('GRAMPS: Export database'), + self.topWindow, + gtk.FILE_CHOOSER_ACTION_SAVE, + (gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) + + # Always add automatic (macth all files) filter + filter = gtk.FileFilter() + filter.set_name(_('By extension')) + filter.add_pattern('*') + choose.add_filter(filter) + +# FIXME: Uncomment when we have grdb importer +# +# # Always add native format filter +# filter = gtk.FileFilter() +# filter.set_name(_('GRAMPS databases')) +# filter.add_mime_type('application/x-gramps') +# choose.add_filter(filter) + + for (exportData,filter,pattern_list) in Plugins._exports: + choose.add_filter(filter) + + if GrampsCfg.lastfile: + choose.set_filename(GrampsCfg.lastfile) + + response = choose.run() + if response == gtk.RESPONSE_OK: + filename = choose.get_filename() + filename = os.path.normpath(os.path.abspath(filename)) + (junk,the_file) = os.path.split(filename) + +# FIXME: Uncomment when we have grdb importer +# +# if filetype == 'application/x-gramps': +# if self.auto_save_load(filename) == 0: +# DbPrompter.DbPrompter(self,0,self.topWindow) +# else: + if True: + opened = 0 + for (exportData,filter,pattern_list) in Plugins._exports: + for pattern in pattern_list: + if filter.filter((filename,None,None,None)): + exportData(self.db,filename) + opened = 1 + break + if not opened: + ErrorDialog( _("Could not write file: %s") % filename, + _('The type is not in the list of known file types') ) + choose.destroy() + def on_revert_activate(self,obj): pass