annotate TreeUtils.cs @ 35:6624cf5822f7

* Update to VS.Net 2010 compatibility no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 07 Aug 2011 19:13:31 +0000
parents f6126047dd8c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (TreeUtils.cs) is a part of the IBBoard.GtkSharp project and is copyright 2009 IBBoard
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using Gtk;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 namespace IBBoard.GtkSharp
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// <summary>
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// Utility methods for working with GTK TreeViews and TreeModels
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// </summary>
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class TreeUtils
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public static object GetItemAtPath(TreeView tree, TreePath path)
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 TreeModel model = tree.Model;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 TreeIter iter;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 model.GetIter(out iter, path);
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 return model.GetValue(iter, 0);
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 public static object GetSelectedItem(TreeView tree)
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 TreeSelection selection = tree.Selection;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 TreeModel model;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 TreeIter iter;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 object selected = null;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 if (selection.CountSelectedRows() > 0)
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 {
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 selection.GetSelected(out model, out iter);
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 selected = model.GetValue(iter, 0);
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 }
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 return selected;
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 }
15
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
39
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
40 /// <summary>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
41 /// Gets the <see cref="TreeIter"/> for an item in a tree, or the Zero TreeIter if the item can't be found
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
42 /// </summary>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
43 /// <returns>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
44 /// The TreeIter for the item, or TreeIter.Zero if it can't be found
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
45 /// </returns>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
46 /// <param name='tree'>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
47 /// The <see cref="TreeView"/> to search the model of
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
48 /// </param>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
49 /// <param name='item'>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
50 /// The item to find in the model
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
51 /// </param>
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
52 public static TreeIter GetItemIter(TreeView tree, object item)
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
53 {
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
54 TreeModel model = tree.Model;
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
55 TreeIter iter;
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
56 model.GetIterFirst(out iter);
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
57 TreeIter itemIter = TreeIter.Zero;
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
58
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
59 do
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
60 {
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
61 if (model.GetValue(iter, 0).Equals(item))
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
62 {
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
63 itemIter = iter;
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
64 break;
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
65 }
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
66 }
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
67 while (model.IterNext(ref iter));
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
68
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
69 return itemIter;
f6126047dd8c Re #26: Add GTK wrapper methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
70 }
8
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 }
14ce41d2f9bd * Add TreeUtils to simplify TreeView handling in GTK# (GTK# = thin wrapper around GTK = looks like C calls = looks ugly and out of place and has far too many steps in an OO lang)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }