Re: [gtk-list] Re: file globbing



>the gtk_pattern functions - I think something like this would work for
>your example:
>
>GtkPatternSpec spec;
>DIR *dp;
>struct dirent *de;
>
>gtk_pattern_spec_init (&spec, "*.bar");
>
>dp = opendir ("/foo/bar");
>while (de = readdir (dp))
>{
>	if (gtk_pattern_match_string (&spec, g_basename (de))
>		printf ("%s\n", g_basename (de));
>}
>closedir (dp);
>
>
>Well, something like that - normally you'd check return values and all,
>but I'm lazy - you get the idea :)

Just a quick note: does anyone else think it silly that
GtkFileSelection doesn't use an optional boolean filter to decide if a
given candidate file should actually be listed ? The XForms file
selector does this, and its phenomenally useful. The idea that the
files you want listed are just a subset of those discovered by
readdir() seems very obvious to me, since it lets you pop up a
selector with the first level of selection already carried out
(e.g. just all ".html" files, or all file that start with "A", or all
files newer than a certain date, or whatever).

I did in fact hack GtkFileSelection to do this, but the interaction of
the filter (which takes const char *, and returns true/false) and the
completion functions was a pain. I came to the conclusion that the use
of completion functions in the FileSelection widget was a mistake, and
there should instead have been a non-globbing version which could be
used to derive a globbing one.

I ended up throwing the hack I did away, and wrote a much more generic
widget in C++, called Gtk_Selector, which takes uses this:

  typedef void (SelectorRefillFunction)(Gtk_CList&, void *);

Whenever the Selector wants to produce a list, or refresh its list, it
just calls this function, which fills the previously cleared CList as
it wishes to. 

For fileselection, I then use a refill function uses readdir() and its
cousins, and in turn accepts a simple boolean filter that gets the
(full) name of the file as its argument and returns true/false
depending on whether it should be included as part of the list.

I use this object all the time now, and it works for selections based
on filenames, internal objects, whatever, by just cooking up either a
new filter function, or, from time to time, a new refill function.

I suppose that at some point, I should implement my Gtk_Selector as a
GtkSelector, but I like the ease of C++ too much :)

-p



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]