# HG changeset patch # User IBBoard # Date 1252094887 0 # Node ID 14ce41d2f9bd0e3323609eb756f8587cc7d320a5 # Parent d92d11bd48085816405bb7f9e74d066d24c94ece * 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) no-open-ticket diff -r d92d11bd4808 -r 14ce41d2f9bd IBBoard.GtkSharp.csproj --- a/IBBoard.GtkSharp.csproj Fri Aug 28 18:45:06 2009 +0000 +++ b/IBBoard.GtkSharp.csproj Fri Sep 04 20:08:07 2009 +0000 @@ -30,6 +30,7 @@ + diff -r d92d11bd4808 -r 14ce41d2f9bd TreeUtils.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TreeUtils.cs Fri Sep 04 20:08:07 2009 +0000 @@ -0,0 +1,40 @@ +// This file (TreeUtils.cs) is a part of the IBBoard.GtkSharp project and is copyright 2009 IBBoard +// +// 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. +// + +using System; +using Gtk; + +namespace IBBoard.GtkSharp +{ + /// + /// Utility methods for working with GTK TreeViews and TreeModels + /// + public class TreeUtils + { + public static object GetItemAtPath(TreeView tree, TreePath path) + { + TreeModel model = tree.Model; + TreeIter iter; + model.GetIter(out iter, path); + return model.GetValue(iter, 0); + } + + public static object GetSelectedItem(TreeView tree) + { + TreeSelection selection = tree.Selection; + TreeModel model; + TreeIter iter; + object selected = null; + + if (selection.CountSelectedRows() > 0) + { + selection.GetSelected(out model, out iter); + selected = model.GetValue(iter, 0); + } + + return selected; + } + } +}