[longomatch/redesign3] Use radio buttons for subcategories that don't allow multiple selections



commit f4a80de381dc45c8b00d2ca4ead80bc962d2d625
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Aug 21 23:42:59 2011 +0200

    Use radio buttons for subcategories that don't allow multiple selections

 LongoMatch/Gui/Component/PlayersTaggerWidget.cs |    7 +++++--
 LongoMatch/Gui/Component/StringTaggerWidget.cs  |   17 ++++++++++++++---
 LongoMatch/Gui/Dialog/PlayersSelectionDialog.cs |   18 +++++++++++++++---
 LongoMatch/Gui/Dialog/TaggerDialog.cs           |    3 ++-
 4 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/PlayersTaggerWidget.cs b/LongoMatch/Gui/Component/PlayersTaggerWidget.cs
index 891d037..5511ff6 100644
--- a/LongoMatch/Gui/Component/PlayersTaggerWidget.cs
+++ b/LongoMatch/Gui/Component/PlayersTaggerWidget.cs
@@ -30,12 +30,15 @@ namespace LongoMatch.Gui.Component
 	{
 		private List<PlayerTag> players;
 		private TeamTemplate template;
+		private bool allowMultiple;
 		
-		public PlayersTaggerWidget (String subcategoryName, TeamTemplate template, List<PlayerTag> players) {
+		public PlayersTaggerWidget (String subcategoryName, bool allowMultiple,
+		                            TeamTemplate template, List<PlayerTag> players) {
 			this.Build ();
 			editbutton.Clicked += OnEditClicked;
 			this.players = players;
 			this.template = template;
+			this.allowMultiple = allowMultiple;
 			CategoryLabel.Markup = "<b>" + subcategoryName + "</b>";
 			LoadTagsLabel();
 		}
@@ -47,7 +50,7 @@ namespace LongoMatch.Gui.Component
 		
 		protected virtual void OnEditClicked (object sender, System.EventArgs e)
 		{
-			PlayersSelectionDialog dialog = new PlayersSelectionDialog();
+			PlayersSelectionDialog dialog = new PlayersSelectionDialog(allowMultiple);
 			dialog.TransientFor = this.Toplevel as Gtk.Window;
 			dialog.Template = template;
 			dialog.SelectedPlayers = players;
diff --git a/LongoMatch/Gui/Component/StringTaggerWidget.cs b/LongoMatch/Gui/Component/StringTaggerWidget.cs
index a5a3b49..eab6dfd 100644
--- a/LongoMatch/Gui/Component/StringTaggerWidget.cs
+++ b/LongoMatch/Gui/Component/StringTaggerWidget.cs
@@ -29,6 +29,7 @@ namespace LongoMatch.Gui.Component
 	{
 		private Dictionary<StringTag, CheckButton> dict;
 		private List<StringTag> tags;
+		private RadioButton firstRB;
 		string subcategory;
 		
 		public StringTaggerWidget ()
@@ -42,7 +43,7 @@ namespace LongoMatch.Gui.Component
 				subcategory = value.Name;
 				Title = subcategory;
 				foreach (string tag in value)
-					AddTagWidget(new StringTag{Value=tag});
+					AddTagWidget(new StringTag{Value=tag}, !value.AllowMultiple);
 			}
 		}
 		
@@ -59,8 +60,18 @@ namespace LongoMatch.Gui.Component
 			}
 		}
 		
-		private void AddTagWidget (StringTag tag){
-			var button = new CheckButton(tag.Value);
+		private void AddTagWidget (StringTag tag, bool radio){
+			CheckButton button;
+			
+			if (radio) {
+				if (firstRB == null) 
+					button = firstRB = new RadioButton (tag.Value);
+				else
+					button = new RadioButton(firstRB, tag.Value);
+			} else {
+				button = new CheckButton(tag.Value);
+			}
+			
 			button.Toggled += delegate(object sender, EventArgs e) {
 				if (button.Active) {
 					if (!tags.Contains(tag))
diff --git a/LongoMatch/Gui/Dialog/PlayersSelectionDialog.cs b/LongoMatch/Gui/Dialog/PlayersSelectionDialog.cs
index 9b8f88c..d44bb14 100644
--- a/LongoMatch/Gui/Dialog/PlayersSelectionDialog.cs
+++ b/LongoMatch/Gui/Dialog/PlayersSelectionDialog.cs
@@ -32,11 +32,14 @@ namespace LongoMatch.Gui.Dialog
 		TeamTemplate template;
 		List<PlayerTag> selectedPlayers;
 		Dictionary<CheckButton, PlayerTag> checkButtonsDict;
-
-		public PlayersSelectionDialog()
+		bool useRadioButtons;
+		RadioButton firstRB;
+		
+		public PlayersSelectionDialog(bool useRadioButtons)
 		{
 			this.Build();
 			checkButtonsDict = new Dictionary<CheckButton, PlayerTag>();
+			this.useRadioButtons = useRadioButtons;
 		}
 		
 		public TeamTemplate Template {
@@ -70,7 +73,16 @@ namespace LongoMatch.Gui.Dialog
 			table1.NRows =(uint) 10;
 
 			foreach(PlayerTag player in playersList) {
-				CheckButton button = new CheckButton();
+				CheckButton button;
+				
+				if (useRadioButtons) {
+					if (firstRB == null)
+						button = firstRB = new RadioButton("");
+					else
+						button = new RadioButton(firstRB);
+				} else {
+					button = new CheckButton();
+				}
 				button.Label = player.Value.Number + "-" + player.Value.Name;
 				button.Name = i.ToString();
 				button.Toggled += OnButtonToggled;
diff --git a/LongoMatch/Gui/Dialog/TaggerDialog.cs b/LongoMatch/Gui/Dialog/TaggerDialog.cs
index b5f486f..4d8c645 100644
--- a/LongoMatch/Gui/Dialog/TaggerDialog.cs
+++ b/LongoMatch/Gui/Dialog/TaggerDialog.cs
@@ -76,7 +76,8 @@ namespace LongoMatch.Gui.Dialog
 			else
 				template = visitorTeamTemplate;
 			
-			PlayersTaggerWidget widget = new PlayersTaggerWidget(subcat.Name, template, tags);
+			PlayersTaggerWidget widget = new PlayersTaggerWidget(subcat.Name, subcat.AllowMultiple,
+			                                                     template, tags);
 			widget.Show();
 			playersbox.PackStart(widget, false, true, 0);
 		}



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