[longomatch] Fix adding/deleting categories



commit a64998b0fe525aa218e09fb9b7cec04b6ce90e4d
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Aug 28 17:54:10 2011 +0200

    Fix adding/deleting categories

 LongoMatch/Gui/Component/TemplatesEditorBase.cs   |   18 +---
 LongoMatch/Interfaces/ITemplates.cs               |    4 +-
 LongoMatch/Store/Templates/CategoriesTemplate.cs  |  103 +++++++++++----------
 LongoMatch/Store/Templates/SubCategoryTemplate.cs |    4 +
 LongoMatch/Store/Templates/TeamTemplate.cs        |   26 +++---
 5 files changed, 79 insertions(+), 76 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/TemplatesEditorBase.cs b/LongoMatch/Gui/Component/TemplatesEditorBase.cs
index e1ca812..840dbba 100644
--- a/LongoMatch/Gui/Component/TemplatesEditorBase.cs
+++ b/LongoMatch/Gui/Component/TemplatesEditorBase.cs
@@ -117,6 +117,12 @@ namespace LongoMatch.Gui.Component
 		protected void UpdateModel() {
 			Template = Template;
 		}
+		
+		protected void AddItem(int item_index) {
+			Template.AddDefaultItem(item_index);
+			UpdateModel();
+			Edited = true;
+		}
 
 		protected virtual void RemoveSelected() {
 			UpdateModel();
@@ -127,8 +133,6 @@ namespace LongoMatch.Gui.Component
 
 		protected abstract void EditSelected();
 		
-		protected abstract void AddItem(int item);
-
 		protected override void OnNewAfter(object sender, EventArgs args) {
 			AddItem(template.IndexOf(selected[0])+1);
 		}
@@ -219,11 +223,6 @@ namespace LongoMatch.Gui.Component
 			}
 		}
 		
-		protected override void AddItem(int index) {
-			UpdateModel();
-			Edited = true;
-		}
-
 		protected override void RemoveSelected (){
 			if(Project != null) {
 				MessageDialog dialog = new MessageDialog((Gtk.Window)this.Toplevel,DialogFlags.Modal,MessageType.Question,
@@ -325,11 +324,6 @@ namespace LongoMatch.Gui.Component
 			AddUpperWidget(box);
 		}
 		
-		protected override void AddItem(int index) {
-			UpdateModel();
-			Edited = true;
-		}
-
 		protected override void EditSelected() {
 			LongoMatch.Gui.Dialog.EditPlayerDialog dialog = new LongoMatch.Gui.Dialog.EditPlayerDialog();
 			dialog.Player=selected[0];
diff --git a/LongoMatch/Interfaces/ITemplates.cs b/LongoMatch/Interfaces/ITemplates.cs
index 4f054f6..bf3524b 100644
--- a/LongoMatch/Interfaces/ITemplates.cs
+++ b/LongoMatch/Interfaces/ITemplates.cs
@@ -27,7 +27,9 @@ namespace LongoMatch.Interfaces
 		string Name {get; set;}
 	}
 	
-	public interface ITemplate<T>: ITemplate, IList<T> {}
+	public interface ITemplate<T>: ITemplate, IList<T> {
+		void AddDefaultItem (int index);
+	}
 	
 	public interface ITemplateProvider
 	{
diff --git a/LongoMatch/Store/Templates/CategoriesTemplate.cs b/LongoMatch/Store/Templates/CategoriesTemplate.cs
index 5500a0c..7a28538 100644
--- a/LongoMatch/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch/Store/Templates/CategoriesTemplate.cs
@@ -52,6 +52,56 @@ namespace LongoMatch.Store.Templates
 		public void Save(string filePath) {
 			SerializableObject.Save(this, filePath);
 		}
+		
+		public void AddDefaultItem (int index) {
+			PlayerSubCategory localplayers, visitorplayers;
+			TagSubCategory period;
+			TeamSubCategory team;
+			Color c = new Color((Byte)255, (Byte)0, (Byte)0);
+			HotKey h = new HotKey();
+			
+			team = new TeamSubCategory {
+				Name = Catalog.GetString("Team"),
+				AllowMultiple = false,
+				FastTag = true};
+			team.Add(Team.LOCAL);
+			team.Add(Team.VISITOR);
+			
+			localplayers = new PlayerSubCategory {
+				Name = Catalog.GetString("Local Team Players"),
+				AllowMultiple = true,
+				FastTag = true};
+			localplayers.Add(Team.LOCAL);
+			
+			visitorplayers = new PlayerSubCategory {
+				Name = Catalog.GetString("Visitor Team Players"),
+				AllowMultiple = true,
+				FastTag = true};
+			visitorplayers.Add(Team.VISITOR);	
+			
+			period = new TagSubCategory {
+				Name = Catalog.GetString("Period"),
+				AllowMultiple = false,
+				FastTag = true,
+			};
+			period.Add("1");
+			period.Add("2");
+			
+			Category cat =  new Category {
+				Name = "Category " + index,
+				Color = c,
+				Start = new Time{Seconds = 10},
+				Stop = new Time {Seconds = 10},
+				SortMethod = SortMethodType.SortByStartTime,
+				HotKey = h,
+				Position = index-1,
+			};
+			cat.SubCategories.Add(team);
+			cat.SubCategories.Add(localplayers);
+			cat.SubCategories.Add(visitorplayers);
+			cat.SubCategories.Add(period);
+			Insert(index, cat);
+		}
 
 		public static Categories Load(string filePath) {
 			return SerializableObject.Load<Categories>(filePath);
@@ -64,57 +114,8 @@ namespace LongoMatch.Store.Templates
 		}
 
 		private void FillDefaultTemplate(int count) {
-			Color c = new Color((Byte)255, (Byte)0, (Byte)0);
-			HotKey h = new HotKey();
-
-
-			for(int i=1; i<=count; i++) {
-				PlayerSubCategory localplayers, visitorplayers;
-				TagSubCategory period;
-				TeamSubCategory team;
-
-				team = new TeamSubCategory {
-					Name = Catalog.GetString("Team"),
-					AllowMultiple = false,
-					FastTag = true};
-				team.Add(Team.LOCAL);
-				team.Add(Team.VISITOR);
-				
-				localplayers = new PlayerSubCategory {
-					Name = Catalog.GetString("Local Team Players"),
-					AllowMultiple = true,
-					FastTag = true};
-			    localplayers.Add(Team.LOCAL);
-			    
-				visitorplayers = new PlayerSubCategory {
-					Name = Catalog.GetString("Visitor Team Players"),
-					AllowMultiple = true,
-					FastTag = true};
-				visitorplayers.Add(Team.VISITOR);	
-				
-				period = new TagSubCategory {
-					Name = Catalog.GetString("Period"),
-					AllowMultiple = false,
-					FastTag = true,
-				};
-				period.Add("1");
-				period.Add("2");
-
-				Category cat =  new Category {
-					Name = "Category " + i,
-					Color = c,
-					Start = new Time{Seconds = 10},
-					Stop = new Time {Seconds = 10},
-					SortMethod = SortMethodType.SortByStartTime,
-					HotKey = h,
-					Position = i-1,
-				};
-				cat.SubCategories.Add(team);
-				cat.SubCategories.Add(localplayers);
-				cat.SubCategories.Add(visitorplayers);
-				cat.SubCategories.Add(period);
-				Add(cat);
-			}
+			for(int i=1; i<=count; i++)
+				AddDefaultItem(i);
 		}
 	}
 }
diff --git a/LongoMatch/Store/Templates/SubCategoryTemplate.cs b/LongoMatch/Store/Templates/SubCategoryTemplate.cs
index ac24a0d..0d007d5 100644
--- a/LongoMatch/Store/Templates/SubCategoryTemplate.cs
+++ b/LongoMatch/Store/Templates/SubCategoryTemplate.cs
@@ -32,6 +32,10 @@ namespace LongoMatch.Store.Templates
 		public SubCategoryTemplate() {}
 
 		public SubCategoryTemplate(IEnumerable<string> tags): base (tags) {}
+		
+		public void AddDefaultItem (int index) {
+			throw new Exception("Not implemented yet");
+		}
 
 		public void Save(string filePath) {
 			SerializableObject.Save(this, filePath);
diff --git a/LongoMatch/Store/Templates/TeamTemplate.cs b/LongoMatch/Store/Templates/TeamTemplate.cs
index a970a60..49f5ae2 100644
--- a/LongoMatch/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch/Store/Templates/TeamTemplate.cs
@@ -53,6 +53,18 @@ namespace LongoMatch.Store.Templates
 		public void Save(string filePath) {
 			SerializableObject.Save(this, filePath);
 		}
+		
+		public void AddDefaultItem (int i) {
+			Insert(i, new Player {
+					Name = "Player " + i,
+					Birthday = new DateTime(),
+					Height = 1.80f,
+					Weight = 80,
+					Number = i,
+					Position = "",
+					Photo = null,
+					Playing = true,});
+		}
 
 		public static TeamTemplate Load(string filePath) {
 			return SerializableObject.Load<TeamTemplate>(filePath);
@@ -66,18 +78,8 @@ namespace LongoMatch.Store.Templates
 
 		private void FillDefaultTemplate(int playersCount) {
 			Clear();
-			for(int i=1; i<=playersCount; i++) {
-				Add(new Player {
-					Name = "Player " + i,
-					Birthday = new DateTime(),
-					Height = 1.80f,
-					Weight = 80,
-					Number = i,
-					Position = "",
-					Photo = null,
-					Playing = true,
-				});
-			}
+			for(int i=1; i<=playersCount; i++)
+				AddDefaultItem(i);
 		}
 	}
 }



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