[longomatch/statebar: 10/13] Move templates editor to a different file



commit df8789d86af95d9cf10fb630353d2a4b559a0d3a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Sep 18 21:00:05 2011 +0200

    Move templates editor to a different file

 .../Gui/Component/CategoriesTemplateEditor.cs      |  125 +++++++++++
 LongoMatch/Gui/Component/TeamTemplateEditor.cs     |  171 ++++++++++++++
 LongoMatch/Gui/Component/TemplatesEditorBase.cs    |  236 --------------------
 LongoMatch/LongoMatch.mdp                          |    2 +
 LongoMatch/Makefile.am                             |    2 +
 5 files changed, 300 insertions(+), 236 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/CategoriesTemplateEditor.cs b/LongoMatch/Gui/Component/CategoriesTemplateEditor.cs
new file mode 100644
index 0000000..fcfd06d
--- /dev/null
+++ b/LongoMatch/Gui/Component/CategoriesTemplateEditor.cs
@@ -0,0 +1,125 @@
+// 
+//  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 System.IO;
+using Gdk;
+using Gtk;
+using Mono.Unix;
+using Stetic;
+using LongoMatch.Common;
+using LongoMatch.Gui.Dialog;
+using LongoMatch.Interfaces;
+using LongoMatch.IO;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+namespace LongoMatch.Gui.Component
+{
+	public class CategoriesTemplateEditorWidget: TemplatesEditorWidget<Categories, Category> 
+	{
+		private CategoriesTreeView categoriestreeview;
+		private List<HotKey> hkList;
+
+		public CategoriesTemplateEditorWidget (): base()
+		{
+			hkList = new List<HotKey>();
+			categoriestreeview = new CategoriesTreeView();
+			categoriestreeview.CategoryClicked += this.OnCategoryClicked;
+			categoriestreeview.CategoriesSelected += this.OnCategoriesSelected;
+			AddTreeView(categoriestreeview);
+		}
+		
+		public override Categories Template {
+			get {
+				return template;
+			}
+			set {
+				template = value;
+				Edited = false;
+				Gtk.TreeStore categoriesListStore = new Gtk.TreeStore(typeof(Category));
+				hkList.Clear();
+
+				foreach(var cat in template) {
+					categoriesListStore.AppendValues(cat);
+					try {
+						hkList.Add(cat.HotKey);
+					} catch {}; //Do not add duplicated hotkeys
+				}
+				categoriestreeview.Model = categoriesListStore;
+				ButtonsSensitive = false;
+			}
+		}
+		
+		protected override void RemoveSelected (){
+			if(Project != null) {
+				MessageDialog dialog = new MessageDialog((Gtk.Window)this.Toplevel,DialogFlags.Modal,MessageType.Question,
+				                                         ButtonsType.YesNo,true,
+				                                         Catalog.GetString("You are about to delete a category and all the plays added to this category. Do you want to proceed?"));
+				if(dialog.Run() == (int)ResponseType.Yes) {
+					try {
+						foreach(var cat in selected)
+							Project.RemoveCategory (cat);
+					} catch {
+						MessagePopup.PopupMessage(this,MessageType.Warning,
+						                          Catalog.GetString("A template needs at least one category"));
+					}
+				}
+				dialog.Destroy();
+			} else {
+				foreach(Category cat in selected) {
+					if(template.Count == 1) {
+						MessagePopup.PopupMessage(this,MessageType.Warning,
+						                          Catalog.GetString("A template needs at least one category"));
+					} else
+						template.Remove(cat);
+				}
+			}	
+			base.RemoveSelected();
+		}
+		
+		protected override void EditSelected() {
+			EditCategoryDialog dialog = new EditCategoryDialog();
+			dialog.Category = selected[0];
+			dialog.HotKeysList = hkList;
+			dialog.TransientFor = (Gtk.Window) Toplevel;
+			dialog.Run();
+			dialog.Destroy();
+			Edited = true;
+		}
+		private void OnCategoryClicked(Category cat)
+		{
+			selected = new List<Category> ();
+			selected.Add (cat);
+			EditSelected();
+		}
+
+		private void OnCategoriesSelected(List<Category> catList)
+		{
+			selected = catList;
+			if(catList.Count == 0)
+				ButtonsSensitive = false;
+			else if(catList.Count == 1) {
+				ButtonsSensitive = true;
+			}
+			else {
+				MultipleSelection();
+			}
+		}
+	}
+}
diff --git a/LongoMatch/Gui/Component/TeamTemplateEditor.cs b/LongoMatch/Gui/Component/TeamTemplateEditor.cs
new file mode 100644
index 0000000..0ba91c6
--- /dev/null
+++ b/LongoMatch/Gui/Component/TeamTemplateEditor.cs
@@ -0,0 +1,171 @@
+// 
+//  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 System.IO;
+using Gdk;
+using Gtk;
+using Mono.Unix;
+using Stetic;
+using LongoMatch.Common;
+using LongoMatch.Gui.Dialog;
+using LongoMatch.Interfaces;
+using LongoMatch.IO;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+namespace LongoMatch.Gui.Component
+{
+	public class TeamTemplateEditorWidget: TemplatesEditorWidget<TeamTemplate, Player>
+	{	
+		PlayerPropertiesTreeView treeview;
+		Entry teamentry;
+		Gtk.Image shieldImage;
+		VBox box;
+		
+		public TeamTemplateEditorWidget () {
+			treeview = new PlayerPropertiesTreeView(); 
+			treeview.PlayerClicked += this.OnPlayerClicked;
+			treeview.PlayersSelected += this.OnPlayersSelected;
+			AddTreeView(treeview);
+			AddTeamNamesWidget();
+			
+		}
+		
+		public override  TeamTemplate Template {
+			get {
+				return template;
+			}
+			set {
+				template= value;
+				Edited = false;
+				Gtk.TreeStore playersListStore = new Gtk.TreeStore(typeof(Player));
+				foreach(Player player in template)
+					playersListStore.AppendValues(player);
+				treeview.Model=playersListStore;
+				teamentry.Text = template.TeamName;
+				if (template.Shield != null) {
+					shieldImage.Pixbuf = template.Shield;
+				}
+				box.Sensitive = true;
+			}
+		}
+		
+		private void AddTeamNamesWidget () {
+			Gtk.Frame sframe, tframe;
+			EventBox ebox;
+			
+			sframe = new Gtk.Frame("<b>" + Catalog.GetString("Shield") + "</b>");
+			(sframe.LabelWidget as Label).UseMarkup = true;
+			sframe.ShadowType = ShadowType.None;
+			tframe = new Gtk.Frame("<b>" + Catalog.GetString("Team Name") + "</b>");
+			(tframe.LabelWidget as Label).UseMarkup = true;
+			tframe.ShadowType = ShadowType.None;
+			
+			ebox = new EventBox();
+			ebox.ButtonPressEvent += OnImageClicked;
+			
+			shieldImage = new Gtk.Image();
+			shieldImage.Pixbuf = IconLoader.LoadIcon(this, "gtk-execute", IconSize.Dialog);
+			box = new VBox();
+			
+			teamentry = new Entry ();
+			teamentry.Changed += delegate(object sender, EventArgs e) {
+				Template.TeamName = teamentry.Text;
+			};
+			
+			sframe.Add(ebox);
+			ebox.Add(shieldImage);
+			tframe.Add(teamentry);
+			
+			box.PackStart (sframe, false, false, 0);
+			box.PackStart (tframe, false, false, 0);
+			box.ShowAll();
+			box.Sensitive = false;
+			AddUpperWidget(box);
+		}
+		
+		protected override void EditSelected() {
+			LongoMatch.Gui.Dialog.EditPlayerDialog dialog = new LongoMatch.Gui.Dialog.EditPlayerDialog();
+			dialog.Player=selected[0];
+			dialog.TransientFor = (Gtk.Window) Toplevel;
+			dialog.Run();
+			dialog.Destroy();
+			Edited = true;
+		}
+		
+		protected virtual void OnImageClicked (object sender, EventArgs args)
+		{
+			Pixbuf shield;
+			
+			shield = ImageUtils.OpenImage((Gtk.Window)this.Toplevel);
+			if (shield != null) {
+				Template.Shield = shield;
+				shieldImage.Pixbuf = shield;
+			}
+		}
+
+		protected virtual void OnPlayerClicked(Player player)
+		{
+			selected = new List<Player>();
+			selected.Add(player);
+			EditSelected();
+		}
+
+		protected virtual void OnPlayersSelected(List<Player> players)
+		{
+			selected = players;
+			
+			if(selected.Count == 0) {
+				ButtonsSensitive = false;
+			} else if(selected.Count == 1) {
+				ButtonsSensitive = true;
+			} else {
+				MultipleSelection();
+			}
+		}
+		
+		protected override void RemoveSelected (){
+			if(Project != null) {
+				MessageDialog dialog = new MessageDialog((Gtk.Window)this.Toplevel,DialogFlags.Modal,MessageType.Question,
+				                                         ButtonsType.YesNo,true,
+				                                         Catalog.GetString("You are about to delete a player and all " +
+				                                         	"its tags. Do you want to proceed?"));
+				if(dialog.Run() == (int)ResponseType.Yes) {
+					try {
+						foreach(var player in selected)
+							Project.RemovePlayer (template, player);
+					} catch {
+						MessagePopup.PopupMessage(this,MessageType.Warning,
+						                          Catalog.GetString("A template needs at least one category"));
+					}
+				}
+				dialog.Destroy();
+			} else {
+				try {
+					foreach(var player in selected)
+					Template.Remove(player);
+				} catch {
+					MessagePopup.PopupMessage(this,MessageType.Warning,
+					                          Catalog.GetString("A template needs at least one category"));
+				}
+			}
+			base.RemoveSelected();
+		}
+	}
+}
diff --git a/LongoMatch/Gui/Component/TemplatesEditorBase.cs b/LongoMatch/Gui/Component/TemplatesEditorBase.cs
index 0cd41aa..2e5f9ca 100644
--- a/LongoMatch/Gui/Component/TemplatesEditorBase.cs
+++ b/LongoMatch/Gui/Component/TemplatesEditorBase.cs
@@ -18,18 +18,12 @@
 //
 using System;
 using System.Collections.Generic;
-using System.IO;
-using Gdk;
 using Gtk;
 using Mono.Unix;
-using Stetic;
 
-using LongoMatch.Common;
 using LongoMatch.Gui.Dialog;
 using LongoMatch.Interfaces;
-using LongoMatch.IO;
 using LongoMatch.Store;
-using LongoMatch.Store.Templates;
 
 
 namespace LongoMatch.Gui.Component
@@ -190,234 +184,4 @@ namespace LongoMatch.Gui.Component
 		}
 	}
 	
-	public class CategoriesTemplateEditorWidget: TemplatesEditorWidget<Categories, Category> 
-	{
-		private CategoriesTreeView categoriestreeview;
-		private List<HotKey> hkList;
-
-		public CategoriesTemplateEditorWidget (): base()
-		{
-			hkList = new List<HotKey>();
-			categoriestreeview = new CategoriesTreeView();
-			categoriestreeview.CategoryClicked += this.OnCategoryClicked;
-			categoriestreeview.CategoriesSelected += this.OnCategoriesSelected;
-			AddTreeView(categoriestreeview);
-		}
-		
-		public override Categories Template {
-			get {
-				return template;
-			}
-			set {
-				template = value;
-				Edited = false;
-				Gtk.TreeStore categoriesListStore = new Gtk.TreeStore(typeof(Category));
-				hkList.Clear();
-
-				foreach(var cat in template) {
-					categoriesListStore.AppendValues(cat);
-					try {
-						hkList.Add(cat.HotKey);
-					} catch {}; //Do not add duplicated hotkeys
-				}
-				categoriestreeview.Model = categoriesListStore;
-				ButtonsSensitive = false;
-			}
-		}
-		
-		protected override void RemoveSelected (){
-			if(Project != null) {
-				MessageDialog dialog = new MessageDialog((Gtk.Window)this.Toplevel,DialogFlags.Modal,MessageType.Question,
-				                                         ButtonsType.YesNo,true,
-				                                         Catalog.GetString("You are about to delete a category and all the plays added to this category. Do you want to proceed?"));
-				if(dialog.Run() == (int)ResponseType.Yes) {
-					try {
-						foreach(var cat in selected)
-							Project.RemoveCategory (cat);
-					} catch {
-						MessagePopup.PopupMessage(this,MessageType.Warning,
-						                          Catalog.GetString("A template needs at least one category"));
-					}
-				}
-				dialog.Destroy();
-			} else {
-				foreach(Category cat in selected) {
-					if(template.Count == 1) {
-						MessagePopup.PopupMessage(this,MessageType.Warning,
-						                          Catalog.GetString("A template needs at least one category"));
-					} else
-						template.Remove(cat);
-				}
-			}	
-			base.RemoveSelected();
-		}
-		
-		protected override void EditSelected() {
-			EditCategoryDialog dialog = new EditCategoryDialog();
-			dialog.Category = selected[0];
-			dialog.HotKeysList = hkList;
-			dialog.TransientFor = (Gtk.Window) Toplevel;
-			dialog.Run();
-			dialog.Destroy();
-			Edited = true;
-		}
-		private void OnCategoryClicked(Category cat)
-		{
-			selected = new List<Category> ();
-			selected.Add (cat);
-			EditSelected();
-		}
-
-		private void OnCategoriesSelected(List<Category> catList)
-		{
-			selected = catList;
-			if(catList.Count == 0)
-				ButtonsSensitive = false;
-			else if(catList.Count == 1) {
-				ButtonsSensitive = true;
-			}
-			else {
-				MultipleSelection();
-			}
-		}
-	}
-	
-	
-	public class TeamTemplateEditorWidget: TemplatesEditorWidget<TeamTemplate, Player>
-	{	
-		PlayerPropertiesTreeView treeview;
-		Entry teamentry;
-		Gtk.Image shieldImage;
-		VBox box;
-		
-		public TeamTemplateEditorWidget () {
-			treeview = new PlayerPropertiesTreeView(); 
-			treeview.PlayerClicked += this.OnPlayerClicked;
-			treeview.PlayersSelected += this.OnPlayersSelected;
-			AddTreeView(treeview);
-			AddTeamNamesWidget();
-			
-		}
-		
-		public override  TeamTemplate Template {
-			get {
-				return template;
-			}
-			set {
-				template= value;
-				Edited = false;
-				Gtk.TreeStore playersListStore = new Gtk.TreeStore(typeof(Player));
-				foreach(Player player in template)
-					playersListStore.AppendValues(player);
-				treeview.Model=playersListStore;
-				teamentry.Text = template.TeamName;
-				if (template.Shield != null) {
-					shieldImage.Pixbuf = template.Shield;
-				}
-				box.Sensitive = true;
-			}
-		}
-		
-		private void AddTeamNamesWidget () {
-			Gtk.Frame sframe, tframe;
-			EventBox ebox;
-			
-			sframe = new Gtk.Frame("<b>" + Catalog.GetString("Shield") + "</b>");
-			(sframe.LabelWidget as Label).UseMarkup = true;
-			sframe.ShadowType = ShadowType.None;
-			tframe = new Gtk.Frame("<b>" + Catalog.GetString("Team Name") + "</b>");
-			(tframe.LabelWidget as Label).UseMarkup = true;
-			tframe.ShadowType = ShadowType.None;
-			
-			ebox = new EventBox();
-			ebox.ButtonPressEvent += OnImageClicked;
-			
-			shieldImage = new Gtk.Image();
-			shieldImage.Pixbuf = IconLoader.LoadIcon(this, "gtk-execute", IconSize.Dialog);
-			box = new VBox();
-			
-			teamentry = new Entry ();
-			teamentry.Changed += delegate(object sender, EventArgs e) {
-				Template.TeamName = teamentry.Text;
-			};
-			
-			sframe.Add(ebox);
-			ebox.Add(shieldImage);
-			tframe.Add(teamentry);
-			
-			box.PackStart (sframe, false, false, 0);
-			box.PackStart (tframe, false, false, 0);
-			box.ShowAll();
-			box.Sensitive = false;
-			AddUpperWidget(box);
-		}
-		
-		protected override void EditSelected() {
-			LongoMatch.Gui.Dialog.EditPlayerDialog dialog = new LongoMatch.Gui.Dialog.EditPlayerDialog();
-			dialog.Player=selected[0];
-			dialog.TransientFor = (Gtk.Window) Toplevel;
-			dialog.Run();
-			dialog.Destroy();
-			Edited = true;
-		}
-		
-		protected virtual void OnImageClicked (object sender, EventArgs args)
-		{
-			Pixbuf shield;
-			
-			shield = ImageUtils.OpenImage((Gtk.Window)this.Toplevel);
-			if (shield != null) {
-				Template.Shield = shield;
-				shieldImage.Pixbuf = shield;
-			}
-		}
-
-		protected virtual void OnPlayerClicked(Player player)
-		{
-			selected = new List<Player>();
-			selected.Add(player);
-			EditSelected();
-		}
-
-		protected virtual void OnPlayersSelected(List<Player> players)
-		{
-			selected = players;
-			
-			if(selected.Count == 0) {
-				ButtonsSensitive = false;
-			} else if(selected.Count == 1) {
-				ButtonsSensitive = true;
-			} else {
-				MultipleSelection();
-			}
-		}
-		
-		protected override void RemoveSelected (){
-			if(Project != null) {
-				MessageDialog dialog = new MessageDialog((Gtk.Window)this.Toplevel,DialogFlags.Modal,MessageType.Question,
-				                                         ButtonsType.YesNo,true,
-				                                         Catalog.GetString("You are about to delete a player and all " +
-				                                         	"its tags. Do you want to proceed?"));
-				if(dialog.Run() == (int)ResponseType.Yes) {
-					try {
-						foreach(var player in selected)
-							Project.RemovePlayer (template, player);
-					} catch {
-						MessagePopup.PopupMessage(this,MessageType.Warning,
-						                          Catalog.GetString("A template needs at least one category"));
-					}
-				}
-				dialog.Destroy();
-			} else {
-				try {
-					foreach(var player in selected)
-					Template.Remove(player);
-				} catch {
-					MessagePopup.PopupMessage(this,MessageType.Warning,
-					                          Catalog.GetString("A template needs at least one category"));
-				}
-			}
-			base.RemoveSelected();
-		}
-	}
 }
diff --git a/LongoMatch/LongoMatch.mdp b/LongoMatch/LongoMatch.mdp
index edf1b74..2282c44 100644
--- a/LongoMatch/LongoMatch.mdp
+++ b/LongoMatch/LongoMatch.mdp
@@ -190,6 +190,8 @@
     <File subtype="Code" buildaction="Compile" name="Gui/Component/TeamTaggerWidget.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/ITag.cs" />
     <File subtype="Code" buildaction="Compile" name="Common/Images.cs" />
+    <File subtype="Code" buildaction="Compile" name="Gui/Component/CategoriesTemplateEditor.cs" />
+    <File subtype="Code" buildaction="Compile" name="Gui/Component/TeamTemplateEditor.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/LongoMatch/Makefile.am b/LongoMatch/Makefile.am
index a4040cf..0931b81 100644
--- a/LongoMatch/Makefile.am
+++ b/LongoMatch/Makefile.am
@@ -59,6 +59,7 @@ SOURCES = \
 	gtk-gui/LongoMatch.Gui.Popup.TransparentDrawingArea.cs \
 	Gui/Component/ButtonsWidget.cs \
 	Gui/Component/CategoriesScale.cs \
+	Gui/Component/CategoriesTemplateEditor.cs \
 	Gui/Component/CategoryProperties.cs \
 	Gui/Component/DrawingToolBox.cs \
 	Gui/Component/DrawingWidget.cs \
@@ -74,6 +75,7 @@ SOURCES = \
 	Gui/Component/TaggerWidget.cs \
 	Gui/Component/TagsTreeWidget.cs \
 	Gui/Component/TeamTaggerWidget.cs \
+	Gui/Component/TeamTemplateEditor.cs \
 	Gui/Component/TemplatesEditorBase.cs \
 	Gui/Component/TimeLineWidget.cs \
 	Gui/Component/TimeReferenceWidget.cs \



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