[longomatch/redesign: 55/82] Make templates inherite from List<>



commit e5bb4d31701a65e63da6da43457af2ddbf3ecb07
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sat Jan 29 16:26:01 2011 +0100

    Make templates inherite from List<>

 LongoMatch/Gui/Component/ButtonsWidget.cs          |    2 +-
 LongoMatch/Gui/Component/PlaysListTreeWidget.cs    |    2 +-
 LongoMatch/Gui/Component/ProjectTemplateWidget.cs  |   14 ++--
 LongoMatch/Gui/Component/TeamTemplateWidget.cs     |    2 +-
 LongoMatch/Gui/Component/TimeLineWidget.cs         |    2 +-
 LongoMatch/Handlers/HotKeysManager.cs              |    2 +-
 LongoMatch/Store/Project.cs                        |    6 +-
 LongoMatch/Store/Templates/CategoriesTemplate.cs   |   64 +-------------------
 .../Store/Templates/SubCategoriesTemplates.cs      |   24 +-------
 LongoMatch/Store/Templates/TeamTemplate.cs         |   33 ++---------
 10 files changed, 25 insertions(+), 126 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/ButtonsWidget.cs b/LongoMatch/Gui/Component/ButtonsWidget.cs
index 6b9d1b8..37434a1 100644
--- a/LongoMatch/Gui/Component/ButtonsWidget.cs
+++ b/LongoMatch/Gui/Component/ButtonsWidget.cs
@@ -78,7 +78,7 @@ namespace LongoMatch.Gui.Component
 				for (int i=0;i<sectionsCount;i++) {
 					Button b = new Button();
 					Label l = new Label();
-					Category cat = value.CategoriesList[i];
+					Category cat = value[i];
 
 					uint row_top =(uint)(i/table1.NColumns);
 					uint row_bottom = (uint) row_top+1 ;
diff --git a/LongoMatch/Gui/Component/PlaysListTreeWidget.cs b/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
index 403e58d..5d09f07 100644
--- a/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
+++ b/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
@@ -136,7 +136,7 @@ namespace LongoMatch.Gui.Component
 		}
 		
 		private string CategoryPath(Category cat){
-			return project.Categories.CategoriesList.IndexOf(cat).ToString();
+			return project.Categories.IndexOf(cat).ToString();
 		}
 
 		protected virtual void OnTimeNodeChanged(TimeNode tNode,object val) {
diff --git a/LongoMatch/Gui/Component/ProjectTemplateWidget.cs b/LongoMatch/Gui/Component/ProjectTemplateWidget.cs
index 1df0aaa..90d5767 100644
--- a/LongoMatch/Gui/Component/ProjectTemplateWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectTemplateWidget.cs
@@ -65,7 +65,7 @@ namespace LongoMatch.Gui.Component
 				Gtk.TreeStore categoriesListStore = new Gtk.TreeStore(typeof(Category));
 				hkList.Clear();
 				
-				foreach (var cat in categories.CategoriesList){
+				foreach (var cat in categories){
 					categoriesListStore.AppendValues(cat);
 					try {
 						hkList.Add(cat.HotKey);
@@ -108,10 +108,10 @@ namespace LongoMatch.Gui.Component
 
 			if (project != null) {
 				/* Editing a project template */
-				project.Categories.AddCategoryAtPos(index,tn);
+				project.Categories.Insert(index,tn);
 			} else {
 				/* Editing a template in the templates editor */
-				categories.AddCategoryAtPos(index,tn);
+				categories.Insert(index,tn);
 			}
 			UpdateModel();
 			Edited = true;
@@ -125,7 +125,7 @@ namespace LongoMatch.Gui.Component
 				if (dialog.Run() == (int)ResponseType.Yes){
 					try {
 						foreach (Category cat in selectedCategories)
-							project.Categories.RemoveCategory(cat);
+							project.Categories.Remove(cat);
 					} catch {
 						MessagePopup.PopupMessage(this,MessageType.Warning,
 						                          Catalog.GetString("A template needs at least one category"));
@@ -139,7 +139,7 @@ namespace LongoMatch.Gui.Component
 						MessagePopup.PopupMessage(this,MessageType.Warning,
 						                          Catalog.GetString("A template needs at least one category"));
 					} else 
-						categories.RemoveCategory(cat);
+						categories.Remove(cat);
 				}
 			}
 			UpdateModel();
@@ -168,11 +168,11 @@ namespace LongoMatch.Gui.Component
 		}
 		
 		protected virtual void OnNewAfter(object sender, EventArgs args) {
-			AddCategory(categories.CategoriesList.IndexOf(selectedCategories[0])+1);
+			AddCategory(categories.IndexOf(selectedCategories[0])+1);
 		}
 
 		protected virtual void OnNewBefore(object sender, EventArgs args) {
-			AddCategory(categories.CategoriesList.IndexOf(selectedCategories[0]));
+			AddCategory(categories.IndexOf(selectedCategories[0]));
 		}
 
 		protected virtual void OnRemove(object sender, EventArgs args) {
diff --git a/LongoMatch/Gui/Component/TeamTemplateWidget.cs b/LongoMatch/Gui/Component/TeamTemplateWidget.cs
index 47e0988..d591b70 100644
--- a/LongoMatch/Gui/Component/TeamTemplateWidget.cs
+++ b/LongoMatch/Gui/Component/TeamTemplateWidget.cs
@@ -45,7 +45,7 @@ namespace LongoMatch.Gui.Component
 				this.template= value;
 				edited = false;
 				Gtk.TreeStore playersListStore = new Gtk.TreeStore(typeof(Player));
-				foreach (Player player in template.PlayersList)
+				foreach (Player player in template)
 					playersListStore.AppendValues(player);
 				playerpropertiestreeview1.Model=playersListStore;
 			}
diff --git a/LongoMatch/Gui/Component/TimeLineWidget.cs b/LongoMatch/Gui/Component/TimeLineWidget.cs
index 54dc801..f84b652 100644
--- a/LongoMatch/Gui/Component/TimeLineWidget.cs
+++ b/LongoMatch/Gui/Component/TimeLineWidget.cs
@@ -164,7 +164,7 @@ namespace LongoMatch.Gui.Component {
 				vbox1.PackStart(tr,false,false,0);
 				tr.Show();
 				
-				foreach (Category cat in  categories.CategoriesList) {
+				foreach (Category cat in  categories) {
 					List<Play> playsList = value.PlaysInCategory(cat);
 					TimeScale ts = new TimeScale(cat, playsList,frames);
 					tsList[cat] = ts;
diff --git a/LongoMatch/Handlers/HotKeysManager.cs b/LongoMatch/Handlers/HotKeysManager.cs
index bd15413..236ce9f 100644
--- a/LongoMatch/Handlers/HotKeysManager.cs
+++ b/LongoMatch/Handlers/HotKeysManager.cs
@@ -44,7 +44,7 @@ namespace LongoMatch.Handlers
 				dic.Clear();
 				if (value == null)
 					return;
-				foreach (Category cat in value.CategoriesList) {
+				foreach (Category cat in value) {
 					if (cat.HotKey.Defined &&
 					                !dic.ContainsKey(cat.HotKey))
 						dic.Add(cat.HotKey, cat);
diff --git a/LongoMatch/Store/Project.cs b/LongoMatch/Store/Project.cs
index 966c999..86a1be3 100644
--- a/LongoMatch/Store/Project.cs
+++ b/LongoMatch/Store/Project.cs
@@ -168,7 +168,7 @@ namespace LongoMatch.Store
 		public void RemoveCategory(Category category) {
 			if (Categories.Count == 1)
 				throw new Exception("You can't remove the last Section");
-			Categories.RemoveCategory(category);
+			Categories.Remove(category);
 			
 			/* query for all the plays with this Category */
 			var plays = 
@@ -213,7 +213,7 @@ namespace LongoMatch.Store
 				from play in playsList
 					group play by play.Category;
 			
-			foreach (Category cat in Categories.CategoriesList){
+			foreach (Category cat in Categories){
 				Gtk.TreeIter iter = dataFileListStore.AppendValues(cat);
 				itersDic.Add(cat, iter);
 			} 
@@ -297,7 +297,7 @@ namespace LongoMatch.Store
 			TreeStore dataFileListStore = new TreeStore(typeof(object));
 			
 			/* For all the players in the team */
-			foreach (var player in team.PlayersList){
+			foreach (var player in team){
 				/* Add a root in the tree with the player */
 				var iter = dataFileListStore.AppendValues(player);
 				/* Query the plays where this player is in the list of players*/
diff --git a/LongoMatch/Store/Templates/CategoriesTemplate.cs b/LongoMatch/Store/Templates/CategoriesTemplate.cs
index 3ee39a6..9ed678d 100644
--- a/LongoMatch/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch/Store/Templates/CategoriesTemplate.cs
@@ -36,71 +36,13 @@ namespace LongoMatch.Store.Templates
 	/// The <see cref="LongoMatch.DB.Project"/> must handle all the changes
 	/// </summary>
 	[Serializable]
-	public class Categories
+	public class Categories: List<Category>
 	{
-		private List<Category> categoriesList;
-
 
 		/// <summary>
 		/// Creates a new template
 		/// </summary>
-		public Categories()
-		{
-			categoriesList = new List<Category>();
-		}
-
-		/// <summary>
-		/// Clear the template
-		/// </summary>
-		public void Clear() {
-			categoriesList.Clear();
-		}
-
-		/// <summary>
-		/// Adds a new analysis category to the template
-		/// </summary>
-		/// <param name="tn">
-		/// A <see cref="Category"/>: category to add
-		/// </param>
-		public void AddCategory(Category category) {
-			categoriesList.Add(category);
-		}
-		
-		public void AddCategoryAtPos(int pos, Category category) {
-			categoriesList.Insert(pos, category);
-		}
-
-		/// <summary>
-		/// Delete a category from the templates using the it's index
-		/// </summary>
-		/// <param name="index">
-		/// A <see cref="System.Int32"/>: position of the category to delete
-		/// </param>
-		public void RemoveCategory(Category category) {
-			categoriesList.Remove(category);
-		}
-
-		//// <value>
-		/// Number of categories
-		/// </value>
-		public int Count {
-			get {
-				return categoriesList.Count;
-			}
-		}
-
-		//// <value>
-		/// Ordered list with all the categories
-		/// </value>
-		public List<Category> CategoriesList {
-			set {
-				categoriesList.Clear();
-				categoriesList = value;
-			}
-			get {
-				return categoriesList;
-			}
-		}
+		public Categories() {}
 
 		public void Save(string filePath){
 			SerializableObject.Save(this, filePath);
@@ -161,7 +103,7 @@ namespace LongoMatch.Store.Templates
 				cat.SubCategories.Add(team);
 				cat.SubCategories.Add(localplayers);
 				cat.SubCategories.Add(visitorplayers);
-				AddCategory(cat);
+				Add(cat);
 			}
 		}
 	}
diff --git a/LongoMatch/Store/Templates/SubCategoriesTemplates.cs b/LongoMatch/Store/Templates/SubCategoriesTemplates.cs
index c933deb..d5a1d98 100644
--- a/LongoMatch/Store/Templates/SubCategoriesTemplates.cs
+++ b/LongoMatch/Store/Templates/SubCategoriesTemplates.cs
@@ -25,31 +25,11 @@ namespace LongoMatch.Store.Templates
 {
 
 	[Serializable]
-	public class SubCategoriesTemplate
+	public class SubCategoriesTemplate: List<SubCategory>
 	{
-		List<SubCategory> subCategories;
 		
-		public SubCategoriesTemplate()
-		{
-			subCategories = new List<SubCategory>();
-		}
-
-		public bool AddSubcategory(SubCategory subCat) {
-			if (subCategories.Contains(subCat))
-				return false;
-			else
-				subCategories.Add(subCat);
-			return true;
-		}
+		public SubCategoriesTemplate() {}
 
-		public bool RemoveSubCategory (SubCategory subCat) {
-			return subCategories.Remove(subCat);
-		}
-		
-		public int Count (){
-			return subCategories.Count;
-		}
-		
 		public void Save(string filePath){
 			SerializableObject.Save(this, filePath);
 		}
diff --git a/LongoMatch/Store/Templates/TeamTemplate.cs b/LongoMatch/Store/Templates/TeamTemplate.cs
index f273da5..ebb008a 100644
--- a/LongoMatch/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch/Store/Templates/TeamTemplate.cs
@@ -25,49 +25,25 @@ namespace LongoMatch.Store.Templates
 {
 	[Serializable]
 
-	public class TeamTemplate
+	public class TeamTemplate: List<Player>
 	{
-		private List<Player> playersList;
-
-		public TeamTemplate() {
-			playersList = new List<Player>();
-		}
+		public TeamTemplate() {}
 		
 		public String TeamName{
 			get;
 			set;
 		}
 
-		public List<Player> PlayersList{
-			get {
-				return playersList;
-			}
-		}
-		
 		public List<Player> PlayingPlayersList{
 			get {
 				var players = 
-					from player in playersList
+					from player in this
 						where player.Playing == true
 						select player;
 				return players.ToList() as List<Player>;
 			}
 		}
 
-		public void Clear() {
-			playersList.Clear();
-		}
-
-		public int PlayersCount {
-			get {
-				return playersList.Count;
-			}
-		}
-
-		public void AddPlayer(Player player) {
-			playersList.Add(player);
-		}
-
 		public void Save(string filePath){
 			SerializableObject.Save(this, filePath);
 		}
@@ -83,8 +59,9 @@ namespace LongoMatch.Store.Templates
 		}
 		
 		private void FillDefaultTemplate(int playersCount) {
+			Clear();
 			for (int i=1; i<=playersCount;i++) {
-				playersList.Add(new Player{
+				Add(new Player{
 					Name = "Player " + i,
 					Birthday = new DateTime(),
 					Height = 1.80f,



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