Before

1// TreeEnumerator.cs - .NET-style Enumerator for ITreeModel classes
2//
3// Author: Eric Butler <eric@extremeboredom.net>
4//
5// Copyright (c) 2005 Eric Butler
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of version 2 of the Lesser GNU General
9// Public License as published by the Free Software Foundation.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this program; if not, write to the
18// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19// Boston, MA 02111-1307, USA.
20
21
22using System;
23using System.Collections;
24
25namespace Gtk
26{
27 internal class TreeEnumerator : IEnumerator
28 {
29 private Gtk.TreeIter iter;
30 private Gtk.ITreeModel model;
31 private bool reset = true;
32 private bool changed = false;
33
34 public TreeEnumerator (ITreeModel model)
35 {
36 this.model = model;
37
38 model.RowChanged += new RowChangedHandler (row_changed);
39 model.RowDeleted += new RowDeletedHandler (row_deleted);
40 model.RowInserted += new RowInsertedHandler (row_inserted);
41 model.RowsReordered += new RowsReorderedHandler (rows_reordered);
42 }
43
44 public object Current
45 {
46 get {
47 if (reset == false) {
48 object[] row = new object[model.NColumns];
49 for (int x = 0; x < model.NColumns; x++) {
50 row[x] = model.GetValue(iter, x);
51 }
52 return row;
53 } else {
54 throw new InvalidOperationException("Enumerator not started.");
55 }
56 }
57 }
58
59 public bool MoveNext()
60 {
61 if (changed == false) {
62 if (reset == true) {
63 reset = false;
64 return model.GetIterFirst(out iter);
65 } else {
66 return model.IterNext(ref iter);
67 }
68 } else {
69 throw new InvalidOperationException("List has changed.");
70 }
71 }
72
73 public void Reset()
74 {
75 reset = true;
76 changed = false;
77 }
78
79 private void row_changed(object o, RowChangedArgs args)
80 {
81 changed = true;
82 }
83
84 private void row_deleted(object o, RowDeletedArgs args)
85 {
86 changed = true;
87 }
88
89 private void row_inserted(object o, RowInsertedArgs args)
90 {
91 changed = true;
92 }
93
94 private void rows_reordered(object o, RowsReorderedArgs args)
95 {
96 changed = true;
97 }
98 }
99}
100
101

After

1// TreeEnumerator.cs - .NET-style Enumerator for ITreeModel classes
2//
3// Author: Eric Butler <eric@extremeboredom.net>
4//
5// Copyright (c) 2005 Eric Butler
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of version 2 of the Lesser GNU General
9// Public License as published by the Free Software Foundation.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this program; if not, write to the
18// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19// Boston, MA 02111-1307, USA.
20
21
22using System;
23using System.Collections;
24
25namespace Gtk {
26 internal class TreeEnumerator : IEnumerator {
27 private Gtk.TreeIter iter;
28 private Gtk.ITreeModel model;
29 private bool reset = true;
30 private bool changed = false;
31
32 public TreeEnumerator(ITreeModel model) {
33 this.model = model;
34
35 model.RowChanged += new RowChangedHandler(row_changed);
36 model.RowDeleted += new RowDeletedHandler(row_deleted);
37 model.RowInserted += new RowInsertedHandler(row_inserted);
38 model.RowsReordered += new RowsReorderedHandler(rows_reordered);
39 }
40
41 public object Current {
42 get {
43 if (reset == false) {
44 object[] row = new object[model.NColumns];
45 for (int x = 0; x < model.NColumns; x++) {
46 row[x] = model.GetValue(iter, x);
47 }
48 return row;
49 } else {
50 throw new InvalidOperationException("Enumerator not started.");
51 }
52 }
53 }
54
55 public bool MoveNext() {
56 if (changed == false) {
57 if (reset == true) {
58 reset = false;
59 return model.GetIterFirst(out iter);
60 } else {
61 return model.IterNext(ref iter);
62 }
63 } else {
64 throw new InvalidOperationException("List has changed.");
65 }
66 }
67
68 public void Reset() {
69 reset = true;
70 changed = false;
71 }
72
73 private void row_changed(object o, RowChangedArgs args) {
74 changed = true;
75 }
76
77 private void row_deleted(object o, RowDeletedArgs args) {
78 changed = true;
79 }
80
81 private void row_inserted(object o, RowInsertedArgs args) {
82 changed = true;
83 }
84
85 private void rows_reordered(object o, RowsReorderedArgs args) {
86 changed = true;
87 }
88 }
89}

Before

compilation_unit
comment "// TreeEnumerator.cs - .NET-style Enumerator for ITreeModel "...
comment "//"
comment "// Author: Eric Butler <eric@extremeboredom.net>"
comment "//"
comment "// Copyright (c) 2005 Eric Butler"
comment "//"
comment "// This program is free software; you can redistribute it an"...
comment "// modify it under the terms of version 2 of the Lesser GNU "...
comment "// Public License as published by the Free Software Foundati"...
comment "//"
comment "// This program is distributed in the hope that it will be u"...
comment "// but WITHOUT ANY WARRANTY; without even the implied warran"...
comment "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See"...
comment "// Lesser General Public License for more details."
comment "//"
comment "// You should have received a copy of the GNU Lesser General"...
comment "// License along with this program; if not, write to the"
comment "// Free Software Foundation, Inc., 59 Temple Place - Suite 3"...
comment "// Boston, MA 02111-1307, USA."
using_directive
using "using"
identifier "System"
; ";"
using_directive
using "using"
qualified_name
identifier "System"
. "."
identifier "Collections"
; ";"
namespace_declaration (+482 nodes collapsed)

After

compilation_unit
comment "// TreeEnumerator.cs - .NET-style Enumerator for ITreeModel "...
comment "//"
comment "// Author: Eric Butler <eric@extremeboredom.net>"
comment "//"
comment "// Copyright (c) 2005 Eric Butler"
comment "//"
comment "// This program is free software; you can redistribute it an"...
comment "// modify it under the terms of version 2 of the Lesser GNU "...
comment "// Public License as published by the Free Software Foundati"...
comment "//"
comment "// This program is distributed in the hope that it will be u"...
comment "// but WITHOUT ANY WARRANTY; without even the implied warran"...
comment "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See"...
comment "// Lesser General Public License for more details."
comment "//"
comment "// You should have received a copy of the GNU Lesser General"...
comment "// License along with this program; if not, write to the"
comment "// Free Software Foundation, Inc., 59 Temple Place - Suite 3"...
comment "// Boston, MA 02111-1307, USA."
using_directive
using "using"
identifier "System"
; ";"
using_directive
using "using"
qualified_name
identifier "System"
. "."
identifier "Collections"
; ";"
namespace_declaration (+482 nodes collapsed)