Commit 8ff71d3f8567e68f925a9300f73b8e58cccc39eb

Implement methods to come near generic collections interface.

The GetRow method returns an array of objects similar to the foreach
statement on the model.

The Find method implement the collection-style Find function, with a
predicate.

The RemoveAll method, directly inside the ListStore class, implements
predicate-based removal of objects.
  
1/*
2 * This file is part of GTK# Made Easy library.
3 * Copyright © 2009 Diego E. Pettenò <flameeyes@gmail.com>
4 *
5 * GTK# Made Easy is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * GTK# Made Easy is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with Portability.
17 * If not, see <http://www.gnu.org/licenses/>.
18 */
19
20using System;
21using Gtk;
22
23namespace GtkSharpME
24{
25 public static class ListStoreEx
26 {
27 public static int RemoveAll(this Gtk.ListStore model, Predicate<object[]> predicate)
28 {
29 TreeIter iter;
30 int count = 0;
31
32 if ( !model.GetIterFirst(out iter) )
33 return 0;
34
35 do {
36 if ( predicate(model.GetRow(iter)) ) {
37 model.Remove(ref iter);
38 count++;
39 }
40 } while ( model.IterNext(ref iter) );
41
42 return count;
43 }
44 }
45}
  
4949
5050 return iter;
5151 }
52
53 public static object[] GetRow(this Gtk.TreeModel model, Gtk.TreeIter iter)
54 {
55 object[] row = new object[model.NColumns];
56 for(int i = 0; i < model.NColumns; i++) {
57 row[i] = model.GetValue(iter, i);
58 }
59
60 return row;
61 }
62
63 public static object[] Find(this Gtk.TreeModel model, Predicate<object[]> predicate)
64 {
65 Gtk.TreeIter iter;
66
67 if ( !model.GetIterFirst(out iter) )
68 return null;
69
70 do {
71 object[] row = model.GetRow(iter);
72 if ( predicate(row) )
73 return row;
74
75 } while ( model.IterNext(ref iter) );
76
77 return null;
78 }
5279 }
5380}
  
4646 <Compile Include="Sources\TreeModel.cs" />
4747 <Compile Include="Sources\TreeView.cs" />
4848 <Compile Include="Sources\CellRenderer.cs" />
49 <Compile Include="Sources\ListStore.cs" />
4950 </ItemGroup>
5051 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5152</Project>