在我的代码中,我有这样的行:
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);
有没有办法在Glade中设置这些过滤器,而不是手动完成?
答案 0 :(得分:3)
现在可以。代码段应该看起来像这样:
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)
答案 1 :(得分:2)
没有。您可以在glade(版本3.6及更高版本)中创建文件过滤器对象并将其添加到对话框中,但由于您无法实际设置文件过滤器的名称或模式,因此它无用。