Common File Format Chooser
Applications supporting multiple file formats needs a file-format chooser in their file saving dialog. Several GNOME apps implement very similiar file-format choosers - so it makes sense to me, to add this widget to GTK+ (see Bug 440431, Thread on gtk-devel). The code is commited to libegg: http://svn.gnome.org/viewcvs/libegg/trunk/libegg/fileformatchooser/
Suggested API
Usage Example
Federicos Checklist
- ✔ API to modify the list of formats
guint egg_file_format_chooser_add_format (EggFileFormatChooser *self, guint parent, const gchar *name, const gchar *icon, ...) G_GNUC_NULL_TERMINATED; void egg_file_format_chooser_remove_format (EggFileFormatChooser *self, guint format);
- A format consists of name, icon, extensions and surrogate key.
void egg_file_format_chooser_set_format (EggFileFormatChooser *self, guint format); guint egg_file_format_chooser_get_format (EggFileFormatChooser *self, const gchar *filename);
- The widget emits a signal called "selection-changed".
- The application shall handle this with the help of this little API:
gchar* egg_file_format_chooser_append_suffix (EggFileFormatChooser *self, guint format, const gchar *filename);
✔ How do we deal with API explosion? See Havoc's mail. We can probably have a GtkFileChooserFileFormat object onto which we can add more API later if needed.
The format chooser is a separate widget. A separate GtkFileChooserFileFormat object also was my favorite, but it has been rejected by the community due the boilerplate overhead it might introduce.
- For attaching custom data the following API exists:
void egg_file_format_chooser_set_format_data (EggFileFormatChooser *self, guint format, gpointer data, GDestroyNotify destroy); gpointer egg_file_format_chooser_get_format_data (EggFileFormatChooser *self, guint format);
Screenshots
Existing Widgets
GIMP
GIMP uses a special file chooser dialog:
http://svn.gnome.org/svn/gimp/trunk/app/widgets/gimpfiledialog.c
http://svn.gnome.org/svn/gimp/trunk/app/widgets/gimpfiledialog.h
The dialog embbeds a specialized tree view using plug-in provided callbacks to build its model:
http://svn.gnome.org/svn/gimp/trunk/app/widgets/gimpfileprocview.c
http://svn.gnome.org/svn/gimp/trunk/app/widgets/gimpfileprocview.h
I like the look, but the API is very GIMP specific.
Dia
Dia directly uses GtkFileChooserDialog and builds its file format chooser ad-hoc:
It looks very old fashioned and therefore would greatly benefit from some common widget.
Inkscape
Inkscape used the GtkFileChooserDialog wrapper of gtkmm and builds its file format chooser ad-hoc:
OpenOffice.org
OpenOffice.org uses a pretty tree view similiar to the one used by GIMP. Unfortunatly I have/had no clue where to look for the source code of its implementation. That project is just too large for mortals like me.
Gnumeric
Gnumeric uses a drop-down list.
GNOME Sound-Recorder
Moves file format selection into the main window: