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) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Fri, 04 Sep 2009 20:08:07 +0000
parents d92d11bd4808
children d0e26a896d72
files IBBoard.GtkSharp.csproj TreeUtils.cs
diffstat 2 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
   <ItemGroup>
     <Compile Include="AssemblyInfo.cs" />
     <Compile Include="NotebookUtil.cs" />
+    <Compile Include="TreeUtils.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="COPYING.GPL" />
--- /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
+{
+	/// <summary>
+	/// Utility methods for working with GTK TreeViews and TreeModels
+	/// </summary>	
+	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;
+		}
+	}
+}