[chronojump] Safer updateComboEncoderAnalyzeCurveNumSavedReps



commit 7ab68ffdf721ac8de7bdbe00e5d4ae29529eb8dd
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 30 17:14:52 2016 +0200

    Safer updateComboEncoderAnalyzeCurveNumSavedReps

 src/gui/encoder.cs |   13 +++++++------
 src/utilEncoder.cs |   11 ++++-------
 src/utilGtk.cs     |    9 +++++++++
 3 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 359fc14..b10b428 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1638,7 +1638,7 @@ public partial class ChronoJumpWindow
                                        getExerciseIDFromCombo(exerciseCombos.ANALYZE),
                                        "curve", EncoderSQL.Eccons.ALL, 
                                        false, true);
-                       updateComboEncoderAnalyzeCurveNumSavedReps(data, encSelReps.RepsActive);
+                       updateComboEncoderAnalyzeCurveNumSavedReps(data);
                } //interperson and intersession modes don't use combo_encoder_analyze_curve_num_combo
                
                if(radio_encoder_analyze_individual_all_sessions.Active) {
@@ -1676,17 +1676,18 @@ public partial class ChronoJumpWindow
                        UtilGtk.ComboMakeActive(combo_encoder_analyze_curve_num_combo, 
activeCurvesList[defaultValue]);
        }
        //saved repetitions
-       private void updateComboEncoderAnalyzeCurveNumSavedReps (ArrayList data, int activeCurvesNum) 
+       private void updateComboEncoderAnalyzeCurveNumSavedReps (ArrayList data)
        {
                string [] checkboxes = new string[data.Count]; //to store active or inactive status of curves
                int count = 0;
                foreach(EncoderSQL eSQL in data) {
                        checkboxes[count++] = eSQL.status;
                }
-               string [] activeCurvesList = UtilEncoder.GetActiveCheckboxesList(checkboxes, activeCurvesNum);
-               UtilGtk.ComboUpdate(combo_encoder_analyze_curve_num_combo, activeCurvesList, "");
-               combo_encoder_analyze_curve_num_combo.Active = 
-                       UtilGtk.ComboMakeActive(combo_encoder_analyze_curve_num_combo, activeCurvesList[0]);
+               List<int> activeCurvesList = UtilEncoder.GetActiveCheckboxesList(checkboxes);
+               UtilGtk.ComboUpdate(combo_encoder_analyze_curve_num_combo, activeCurvesList);
+               if(activeCurvesList.Count > 0)
+                       combo_encoder_analyze_curve_num_combo.Active = 
+                               UtilGtk.ComboMakeActive(combo_encoder_analyze_curve_num_combo, 
activeCurvesList[0].ToString());
        }
 
 
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 0287e13..b2a4608 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -22,6 +22,7 @@ using System;
 //using System.Data;
 using System.Text; //StringBuilder
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 using System.Diagnostics;      //for detect OS and for Process
 using System.IO;               //for detect OS
 using Mono.Unix;
@@ -813,16 +814,12 @@ public class UtilEncoder
                return countActiveCurves;
        }
        
-       public static string [] GetActiveCheckboxesList(string [] checkboxes, int activeCurvesNum) {
-               if(activeCurvesNum == 0)
-                       return Util.StringToStringArray("");
-
-               string [] activeCurvesList = new String[activeCurvesNum];
+       public static List<int> GetActiveCheckboxesList(string [] checkboxes) {
+               List<int> activeCurvesList = new List<int>();
                int i=0;
-               int j=0;
                foreach(string cb in checkboxes) {
                        if(cb == "active")
-                               activeCurvesList[j++] = (i+1).ToString();
+                               activeCurvesList.Add(i+1);
                        i++;
                }
                return activeCurvesList;
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 4674489..72c170b 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -152,6 +152,15 @@ public class UtilGtk
                        myCombo.AppendText (str);
        }
        
+       public static void ComboUpdate(ComboBox myCombo, List<int> list) {
+               //1stdelete combo values
+               comboDelAll(myCombo);
+
+               //2nd put new values
+               foreach (int l in list)
+                       myCombo.AppendText (l.ToString());
+       }
+       
        public static void ComboUpdate(ComboBox myCombo, List<double> list) {
                //1stdelete combo values
                comboDelAll(myCombo);


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