[Mono-devel-list] gtk ComboBox questions...

Rafael Teixeira monoman at gmail.com
Mon Jul 25 11:36:01 EDT 2005


On 7/24/05, Todd Berman <tberman at off.net> wrote:
> On Sun, 2005-07-24 at 15:20 +1000, John BouAntoun wrote:
> > That brings up a good point.
> >
> > Not sure if this is still the case, but why in today's day and age (of C# and other great managed languages) is someone using IterNChildrend() (a strangely named function) to return a property that would be most obviously named Count (as with most other collections)?
> >
> I am not sure that makes sense given how TreeModel works.
> A TreeIter has no traceable association with its model. At least none
> that you can access via public API.
> And a TreeModel.Count property makes no sense in a true Tree context, as
> you rarely (if ever) care about the # of nodes in the tree, and are
> usually more interested in the # of children under a specific node.
> Which is exactly what IterNChildren is for.

What I think is confusing for most people is that ListStore is a
flattened TreeModel, So it has to follow all the "Tree-isms" without a
real need for all of them.

So a ListStore.Count property is something sensible but it can't be
inherited from TreeModel, which still is the type for the
ComboBox.Model property, so some casting has to be applied, what may
fail at runtime. To aggravate that TreeModel is in truth an interface
and thus should have be renamed in GTK# as ITreeModel.

I would create a an interface IListSore like this:

public interface IListModel : ITreeModel, IList {}

That would allow common idioms like:

i = combo.Model.Count;

foreach(object item in Combo.Model) ...


And have ComboBox.Model be of type IListModel and sure have ListStore
implement it instead of plain (I)TreeModel. That would make things
consistent with the base class library and so it would also make it
easier for non-Gtk-hardcores to learn GTK#.


> --Todd

Rafael "Monoman" Teixeira
I'm trying to become a "Rosh Gadol" before my own eyes. 
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
It hurts!

More information about the Mono-devel-list mailing list