diff --git a/ChangeLog b/ChangeLog index 16c1229b3..ad309c8bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-05-11 Eric Butler + + * gtk/Gtk.metadata : add IEnumerable iface to ListStore. + * gtk/ListStore.cs : add GetEnumerator. + * gtk/Makefile.am : add file. + * gtk/TreeEnumerator.cs : root node enumerator for a TreeModel. + 2005-05-11 Mike Kestner * gtk/Widget.custom : manual ListMnemonicLabels implementation to diff --git a/doc/en/Gtk/ListStore.xml b/doc/en/Gtk/ListStore.xml index 2ce668797..2e4b57cc2 100644 --- a/doc/en/Gtk/ListStore.xml +++ b/doc/en/Gtk/ListStore.xml @@ -1497,5 +1497,23 @@ The above example creates a new three columns list store. The types of the colum To be added + + + Method + + System.Collections.IEnumerator + + + + + Returns a for the current instance. + + a + + If the elements of the current instance are modified while an enumeration is in progress, a call to or throws . + + + - \ No newline at end of file + + diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 680831038..7f0c9b0ec 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -249,6 +249,7 @@ 1 label ScrollAdjustmentsSet + 1 1 out diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom index 4c8f2d1ed..192368c5a 100644 --- a/gtk/ListStore.custom +++ b/gtk/ListStore.custom @@ -164,3 +164,9 @@ { DefaultSortFunc = sort_func; } + + public IEnumerator GetEnumerator() + { + return new TreeEnumerator(this); + } + diff --git a/gtk/Makefile.am b/gtk/Makefile.am index b5ec986d5..41a7548c6 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -24,6 +24,7 @@ sources = \ ThreadNotify.cs \ ToggleActionEntry.cs \ Timeout.cs \ + TreeEnumerator.cs \ TreeNodeAttribute.cs \ TreeNode.cs \ TreeNodeValueAttribute.cs diff --git a/gtk/TreeEnumerator.cs b/gtk/TreeEnumerator.cs new file mode 100644 index 000000000..bfe8aa646 --- /dev/null +++ b/gtk/TreeEnumerator.cs @@ -0,0 +1,85 @@ +// TreeEnumerator.cs - .NET-style Enumerator for TreeModel classes +// +// Author: Eric Butler +// +// Copyright (c) 2005 Eric Butler +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +using System; +using System.Collections; + +namespace Gtk +{ + internal class TreeEnumerator : IEnumerator + { + private Gtk.TreeIter iter; + private Gtk.TreeModel model; + private bool reset = true; + private bool changed = false; + + public TreeEnumerator (TreeModel model) + { + this.model = model; + + model.RowChanged += model_changed; + model.RowDeleted += model_changed; + model.RowInserted += model_changed; + model.RowsReordered += model_changed; + } + + public object Current + { + get { + if (reset == false) { + object[] row = new object[model.NColumns]; + for (int x = 0; x < model.NColumns; x++) { + row[x] = model.GetValue(iter, x); + } + return row; + } else { + throw new InvalidOperationException("Enumerator not started."); + } + } + } + + public bool MoveNext() + { + if (changed == false) { + if (reset == true) { + reset = false; + return model.GetIterFirst(out iter); + } else { + return model.IterNext(ref iter); + } + } else { + throw new InvalidOperationException("List has changed."); + } + } + + public void Reset() + { + reset = true; + changed = false; + } + + private void model_changed(object o, EventArgs args) + { + changed = true; + } + } +} +