view TreeUtils.cs @ 13:245677d0d47e

Re #26: Add GTK wrapper methods * Compact tabs in a notebook even more
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Aug 2010 19:37:49 +0000
parents 14ce41d2f9bd
children f6126047dd8c
line wrap: on
line source

//  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;
		}
	}
}