[longomatch/redesign: 79/82] Add treeview for subcategories



commit 2d4ac6ce669735f83d901d978db57258c48879ba
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Mar 13 20:38:43 2011 +0100

    Add treeview for subcategories

 LongoMatch/Gui/TreeView/SubCategoriesTreeView.cs |   83 ++++++++++++++++++++++
 LongoMatch/Handlers/Handlers.cs                  |    3 +
 2 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch/Gui/TreeView/SubCategoriesTreeView.cs b/LongoMatch/Gui/TreeView/SubCategoriesTreeView.cs
new file mode 100644
index 0000000..096ce4b
--- /dev/null
+++ b/LongoMatch/Gui/TreeView/SubCategoriesTreeView.cs
@@ -0,0 +1,83 @@
+// 
+//  Copyright (C) 2011 Andoni Morales Alastruey
+// 
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+// 
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//  
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+// 
+using System;
+using System.Collections.Generic;
+using Gtk;
+using Mono.Unix;
+using LongoMatch.Handlers;
+using LongoMatch.Store;
+
+namespace LongoMatch.Gui.TreeView
+{
+
+	[System.ComponentModel.Category("LongoMatch")]
+	[System.ComponentModel.ToolboxItem(true)]
+	public class SubCategoriesTreeView: Gtk.TreeView
+	{
+		public event SubCategoryHandler SubCategoryClicked;
+		public event SubCategoriesHandler SubCategoriesSelected;
+		
+		public SubCategoriesTreeView ()
+		{
+			RowActivated += OnTreeviewRowActivated;
+			Selection.Changed += OnSelectionChanged;
+			Selection.Mode =  SelectionMode.Multiple;
+
+			Gtk.TreeViewColumn subcatColumn = new Gtk.TreeViewColumn();
+			subcatColumn.Title = Catalog.GetString("SubCategory");
+			Gtk.CellRendererText subcatCell = new Gtk.CellRendererText();
+			subcatColumn.PackStart(subcatCell, true);
+			subcatColumn.SetCellDataFunc(subcatCell, new Gtk.TreeCellDataFunc(RenderSubCat));
+			AppendColumn(subcatColumn);
+		}
+		
+		private void RenderSubCat(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
+		{
+			SubCategory cat = (SubCategory) model.GetValue(iter, 0);
+
+			(cell as Gtk.CellRendererText).Text = cat.Name;
+		}
+		
+		protected virtual void OnSelectionChanged(object o, System.EventArgs e) {
+			TreeIter iter;
+			List<SubCategory> list;
+			TreePath[] pathArray;
+
+			list = new List<SubCategory>();
+			pathArray = Selection.GetSelectedRows();
+
+			for(int i=0; i< pathArray.Length; i++) {
+				Model.GetIterFromString(out iter, pathArray[i].ToString());
+				list.Add((SubCategory) Model.GetValue(iter, 0));
+			}
+			if(SubCategoriesSelected != null)
+				SubCategoriesSelected(list);
+		}
+
+		protected virtual void OnTreeviewRowActivated(object o, Gtk.RowActivatedArgs args)
+		{
+			Gtk.TreeIter iter;
+			Model.GetIter(out iter, args.Path);
+			SubCategory subcat = (SubCategory)Model.GetValue(iter, 0);
+
+			if(SubCategoryClicked != null)
+				SubCategoryClicked(subcat);
+		}
+	}
+}
+
diff --git a/LongoMatch/Handlers/Handlers.cs b/LongoMatch/Handlers/Handlers.cs
index bbf0f3b..e724c00 100644
--- a/LongoMatch/Handlers/Handlers.cs
+++ b/LongoMatch/Handlers/Handlers.cs
@@ -85,6 +85,9 @@ namespace LongoMatch.Handlers
 
 	public delegate void CategoryHandler(Category category);
 	public delegate void CategoriesHandler(List<Category> categoriesList);
+	
+	public delegate void SubCategoryHandler(SubCategory subCategory);
+	public delegate void SubCategoriesHandler(List<SubCategory> subCategoriesList);
 
 	public delegate void ProjectsSelectedHandler(List<ProjectDescription> projects);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]