[longomatch/redesign3] Fix creation of team models



commit ed78c72cb7d4e568b5ceb7017a40c890e7920016
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Aug 18 23:57:15 2011 +0200

    Fix creation of team models

 LongoMatch/Gui/MainWindow.cs |   10 ++++++++++
 LongoMatch/Store/Project.cs  |   37 ++++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 15 deletions(-)
---
diff --git a/LongoMatch/Gui/MainWindow.cs b/LongoMatch/Gui/MainWindow.cs
index 4b8d634..83c893f 100644
--- a/LongoMatch/Gui/MainWindow.cs
+++ b/LongoMatch/Gui/MainWindow.cs
@@ -176,12 +176,22 @@ namespace LongoMatch.Gui
 			playlistwidget2.Stop();
 			treewidget1.Project=project;
 			tagstreewidget1.Project = project;
+			UpdateTeamsModels(project);
 			buttonswidget1.Categories = project.Categories;
 			hkManager.Categories=project.Categories;
 			KeyPressEvent += hotkeysListener;
 			MakeActionsSensitive(true,projectType);
 			ShowWidgets();
 		}
+		
+		private void UpdateTeamsModels(Project project) {
+			TreeStore local, visitor;
+			
+			project.GetPlayersModel (out local, out visitor);
+			localplayerslisttreewidget.SetTeam(project.LocalTeamTemplate, local);
+			visitorplayerslisttreewidget.SetTeam(project.VisitorTeamTemplate, visitor);
+			
+		}
 
 		private void SaveCaptureProject() {
 			PreviewMediaFile file;
diff --git a/LongoMatch/Store/Project.cs b/LongoMatch/Store/Project.cs
index 05b3a27..87e667a 100644
--- a/LongoMatch/Store/Project.cs
+++ b/LongoMatch/Store/Project.cs
@@ -253,29 +253,36 @@ namespace LongoMatch.Store
 		}
 		#endregion
 
-		#region Private Methods
-		private TreeStore GetPlayersModel(Team team) {
-			Dictionary<Player, TreeIter> dict = new Dictionary<Player, TreeIter>();
-			TreeStore store = new TreeStore(typeof(object));
-			TeamTemplate template;
-
-			if(team == Team.NONE)
-				return store;
+		public void GetPlayersModel(out TreeStore localTeam, out TreeStore visitorTeam) {
+			Dictionary<Player, TreeIter> localDict = new Dictionary<Player, TreeIter>();
+			Dictionary<Player, TreeIter> visitorDict = new Dictionary<Player, TreeIter>();
 			
-			template = team == Team.LOCAL?LocalTeamTemplate:VisitorTeamTemplate;
+			localTeam = new TreeStore(typeof(object));
+			visitorTeam = new TreeStore(typeof(object));
+
+			foreach(var player in LocalTeamTemplate) {
+				/* Add a root in the tree with the option name */
+				var iter = localTeam.AppendValues(player);
+				localDict.Add(player, iter);
+			}
 			
-			foreach(var player in template) {
+			foreach(var player in VisitorTeamTemplate) {
 				/* Add a root in the tree with the option name */
-				var iter = store.AppendValues(player);
-				dict.Add(player, iter);
+				var iter = visitorTeam.AppendValues(player);
+				visitorDict.Add(player, iter);
 			}
 			
 			foreach (var play in timeline) {
-				foreach (var player in play.Players.AllUniqueElements)
-					store.AppendValues(dict[player.Value], new object[1] {play});
+				foreach (var player in play.Players.AllUniqueElements) {
+					if (localDict.ContainsKey(player.Value))
+						localTeam.AppendValues(localDict[player.Value], new object[1] {play});
+					else
+						visitorTeam.AppendValues(visitorDict[player.Value], new object[1] {play});
+				}
 			}
-			return store;
 		}
+
+		#region Private Methods
 		#endregion
 	}
 }



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