Commit 8ff71d3f8567e68f925a9300f73b8e58cccc39eb
- Diff rendering mode:
- inline
- side by side
Sources/ListStore.cs
(45 / 0)
|   | |||
| 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 | |||
| 20 | using System; | ||
| 21 | using Gtk; | ||
| 22 | |||
| 23 | namespace 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 | } |
Sources/TreeModel.cs
(27 / 0)
|   | |||
| 49 | 49 | ||
| 50 | 50 | return iter; | |
| 51 | 51 | } | |
| 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 | } | ||
| 52 | 79 | } | |
| 53 | 80 | } |
gtk-sharp-me.csproj
(1 / 0)
|   | |||
| 46 | 46 | <Compile Include="Sources\TreeModel.cs" /> | |
| 47 | 47 | <Compile Include="Sources\TreeView.cs" /> | |
| 48 | 48 | <Compile Include="Sources\CellRenderer.cs" /> | |
| 49 | <Compile Include="Sources\ListStore.cs" /> | ||
| 49 | 50 | </ItemGroup> | |
| 50 | 51 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | |
| 51 | 52 | </Project> |

