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:

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);
    ✔ FIXME: what does each format consist of? (name, icon, what else?)
    • A format consists of name, icon, extensions and surrogate key.
    ✔ API to set the current/default format
    • void  egg_file_format_chooser_set_format (EggFileFormatChooser *self,
                                                guint                 format);
      guint egg_file_format_chooser_get_format (EggFileFormatChooser *self,
                                                const gchar          *filename);
    ✔ Signal to know when the user selects a different format. If this is the GIMP and the user selects "JPEG" for saving, then the GIMP will want to add widgets to the save dialog to let the user configure JPEG-specific saving options (compression, comment, etc.).
    • The widget emits a signal called "selection-changed".
    ✔ Do we want a "filename extension" field for each format? And then, an "[ ] Add filename extension automatically" checkbox? Or is it up to the app?
    • 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.

    ✔ How do we make the GUI scale to apps like Gnumeric or OOo, which support zillions of formats?
    • 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);


format-chooser-collapsed.png format-chooser-expanded.png

Existing Widgets


gimp-collapsed.png gimp-expanded.png

GIMP uses a special file chooser dialog:

The dialog embbeds a specialized tree view using plug-in provided callbacks to build its model:

I like the look, but the API is very GIMP specific.



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 used the GtkFileChooserDialog wrapper of gtkmm and builds its file format chooser ad-hoc: 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.

oowriter-collapsed.png oowriter-expanded.png


Gnumeric uses a drop-down list.


GNOME Sound-Recorder

Moves file format selection into the main window:


Projects/GTK/FileFormatChooser (last edited 2018-12-05 15:46:30 by EmmanueleBassi)