Mercurial > repos > IBBoard.GtkSharp
annotate TreeUtils.cs @ 39:35b88b848524
* Add simple dialog to add basic widgets to for use in WarFoundry
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 18 Oct 2011 20:58:49 +0100 |
parents | f6126047dd8c |
children |
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 | 39 |
40 /// <summary> | |
41 /// Gets the <see cref="TreeIter"/> for an item in a tree, or the Zero TreeIter if the item can't be found | |
42 /// </summary> | |
43 /// <returns> | |
44 /// The TreeIter for the item, or TreeIter.Zero if it can't be found | |
45 /// </returns> | |
46 /// <param name='tree'> | |
47 /// The <see cref="TreeView"/> to search the model of | |
48 /// </param> | |
49 /// <param name='item'> | |
50 /// The item to find in the model | |
51 /// </param> | |
52 public static TreeIter GetItemIter(TreeView tree, object item) | |
53 { | |
54 TreeModel model = tree.Model; | |
55 TreeIter iter; | |
56 model.GetIterFirst(out iter); | |
57 TreeIter itemIter = TreeIter.Zero; | |
58 | |
59 do | |
60 { | |
61 if (model.GetValue(iter, 0).Equals(item)) | |
62 { | |
63 itemIter = iter; | |
64 break; | |
65 } | |
66 } | |
67 while (model.IterNext(ref iter)); | |
68 | |
69 return itemIter; | |
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 } |