[chronojump] CjComboGeneric: to be easier to use for any purpose



commit f80e8eb34cb59a935e6a79cc90d8f1d8b170cf5c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Aug 7 13:54:45 2020 +0200

    CjComboGeneric: to be easier to use for any purpose

 src/gui/cjCombo.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
---
diff --git a/src/gui/cjCombo.cs b/src/gui/cjCombo.cs
index 759d0974..37c26be6 100644
--- a/src/gui/cjCombo.cs
+++ b/src/gui/cjCombo.cs
@@ -76,6 +76,12 @@ public class CjCombo
        {
                select();
 
+               if(l_types == null || l_types.Count == 0)
+               {
+                       UtilGtk.ComboDelAll(combo);
+                       return;
+               }
+
                string [] namesToCombo = new String [l_types.Count];
                int i =0;
                foreach(SelectTypes type in l_types)
@@ -104,6 +110,19 @@ public class CjCombo
                hbox.ShowAll();
                combo.Sensitive = false;
        }
+
+       public int GetSelectedId()
+       {
+               if(l_types == null || l_types.Count == 0)
+                       return -1;
+
+               string nameTranslatedSelected = UtilGtk.ComboGetActive(combo);
+               foreach(SelectTypes type in l_types)
+                       if(type.NameTranslated == nameTranslatedSelected)
+                               return type.Id;
+
+               return -1;
+       }
        
        public string GetSelectedNameEnglish()
        {
@@ -158,6 +177,15 @@ public class CjCombo
        public Gtk.ComboBox Combo {
                get { return combo; }
        }
+
+       public int Count {
+               get { return l_types.Count; }
+       }
+
+       //to assign l_types on CjComboGeneric
+       public List<object> L_types {
+               set { l_types = value; }
+       }
 }
 
 
@@ -263,3 +291,25 @@ public class CjComboForceSensorPorts : CjCombo
                        l_types.Add(str);
        }
 }
+
+//------------ generic -------------
+
+public class CjComboGeneric : CjCombo
+{
+       public CjComboGeneric (Gtk.ComboBox combo, Gtk.HBox hbox_combo)
+       {
+               this.combo = combo;
+               this.hbox = hbox_combo;
+
+               create();
+               Fill();
+               package();
+       }
+
+       //select does nothing, use the L_types accessor on base class
+       /*
+       protected override void select()
+       {
+       }
+       */
+}


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