4

In my code, I have lines like this:

Builder builder = new Builder();
builder.AddFromFile(gladefile);
FileChooserDialog dialog =
    (FileChooserDialog) builder.GetObject("dialog");

FileFilter[] filters = new FileFilter[2];
filters[0] = new FileFilter();
filters[0].Name = "Some filter";
filters[0].AddPattern("*.someextension");
filters[1] = new FileFilter();
filters[1].Name = "All files";
filters[1].AddPattern("*");

foreach (FileFilter filter in filters)
    dialog.AddFilter(filter);
dialog.Filter = filters[0];
dialog.SetFilename(defaultFile);

Is there a way to set up these filters in Glade, rather than doing it manually?

Matthew
  • 28,056
  • 26
  • 104
  • 170

2 Answers2

3

It is possible now. The code snippet should probably look something like this:

    builder = Gtk.Builder()
    builder.add_objects_from_file("***name of glade file****.glade",
        ("filechooserdialog1", "filefilter1"))
    dialog = self.builder.get_object("filechooserdialog1")
    filefilter = self.builder.get_object("filefilter1")
    dialog.add_filter(filefilter)

enter image description here

enter image description here

tobias47n9e
  • 2,233
  • 3
  • 28
  • 54
2

No. You can create a file filter object in glade (version 3.6 and up) and add it to the dialog, but since you can't actually set the name or pattern of the file filter, it's fairly useless.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Oh well, alright. Do you know if there are any plans to allow you to set the name or pattern? – Matthew Nov 10 '09 at 15:30
  • I don't know, but it's probably not up to Glade. Glade (and GtkBuilder) let you set the properties of GObjects, but the file filter stuff isn't implemented as GObject properties. So I wouldn't count on it. – ptomato Nov 10 '09 at 16:44
  • You can set the pattern since GTK+ 3.0 (https://gitlab.gnome.org/GNOME/gtk/commit/031a09225461eb53f44d27d993c46dc9a11e2cc6). The name can be set from the id of the object in the XML, though I am proposing a name property for that (https://gitlab.gnome.org/GNOME/gtk/merge_requests/376). I have proposed setting the filter list in https://gitlab.gnome.org/GNOME/gtk/merge_requests/380. – Robert Ancell Oct 08 '18 at 03:43