[chronojump] comboSelectRuns done! and cjCombo refactored
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] comboSelectRuns done! and cjCombo refactored
- Date: Sat, 8 Oct 2016 22:47:19 +0000 (UTC)
commit 14967aae4fb38d37f825ef5cce1862d8c2c6de41
Author: Xavier de Blas <xaviblas gmail com>
Date: Sun Oct 9 00:46:41 2016 +0200
comboSelectRuns done! and cjCombo refactored
src/gui/chronojump.cs | 57 +++++++++++++++++++-----------------------
src/gui/cjCombo.cs | 57 +++++++++++++++++++++++++++----------------
src/gui/run.cs | 9 +++----
src/sqlite/runType.cs | 49 +++++++++++++++++++++++++++++++++++++
src/sqlite/usefulObjects.cs | 25 +++++++++++++++++++
5 files changed, 140 insertions(+), 57 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 62cf701..e3fae8c 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -166,8 +166,10 @@ public partial class ChronoJumpWindow
[Widget] Gtk.ComboBox combo_select_runs;
[Widget] Gtk.ComboBox combo_select_runs_interval;
- CjComboSelectJumps comboSelectJumps; //new since 1.6.3. Using gui/cjCombo.cs
- CjComboSelectJumpsRj comboSelectJumpsRj; //new since 1.6.3. Using gui/cjCombo.cs
+ //new since 1.6.3. Using gui/cjCombo.cs
+ CjComboSelectJumps comboSelectJumps;
+ CjComboSelectJumpsRj comboSelectJumpsRj;
+ CjComboSelectRuns comboSelectRuns;
[Widget] Gtk.ComboBox combo_result_jumps;
[Widget] Gtk.ComboBox combo_result_jumps_rj;
@@ -1941,7 +1943,6 @@ public partial class ChronoJumpWindow
* --------------------------------------------------------
*/
- string [] selectRunsString;
string [] selectRunsIntervalString;
// ---------------- combo_select ----------------------
@@ -1972,32 +1973,16 @@ public partial class ChronoJumpWindow
}
}
- private void createComboSelectRuns(bool create) {
+ private void createComboSelectRuns(bool create)
+ {
if(create)
- combo_select_runs = ComboBox.NewText ();
-
- string [] runTypes = SqliteRunType.SelectRunTypes("", false); //without allrunsname, not only
name
- selectRunsString = new String [runTypes.Length];
- string [] runNamesToCombo = new String [runTypes.Length];
- int i =0;
- foreach(string runType in runTypes) {
- string [] j = runType.Split(new char[] {':'});
- string nameTranslated = Catalog.GetString(j[1]);
- selectRunsString[i] =
- j[0] + ":" + j[1] + ":" + nameTranslated + ":" + //uniqueID, name,
nameTranslated
- j[2] + ":" + j[3]; //distance,
description
- runNamesToCombo[i] = nameTranslated;
- i++;
- }
-
- UtilGtk.ComboUpdate(combo_select_runs, runNamesToCombo, "");
- combo_select_runs.Active = 0;
- combo_select_runs.Changed += new EventHandler (on_combo_select_runs_changed);
-
- if(create) {
- hbox_combo_select_runs.PackStart(combo_select_runs, true, true, 0);
- hbox_combo_select_runs.ShowAll();
- combo_select_runs.Sensitive = false;
+ {
+ comboSelectRuns = new CjComboSelectRuns(combo_select_runs, hbox_combo_select_runs);
+ combo_select_runs = comboSelectRuns.Combo;
+ combo_select_runs.Changed += new EventHandler (on_combo_select_runs_changed);
+ } else {
+ comboSelectRuns.Fill();
+ combo_select_runs = comboSelectRuns.Combo;
}
}
@@ -5945,7 +5930,7 @@ LogB.Debug("X");
private void on_run_type_add_accepted (object o, EventArgs args) {
LogB.Information("ACCEPTED Add new run type");
if(runTypeAddWin.InsertedSimple) {
- createComboSelectRuns(false); //this will update also the selectRunsString
+ createComboSelectRuns(false);
UtilGtk.ComboUpdate(combo_result_runs,
SqliteRunType.SelectRunTypes(Constants.AllRunsName, true), "");
//without filter, only select name
@@ -6023,10 +6008,20 @@ LogB.Debug("X");
extra_window_jumps_rj_initialize(new JumpType("RJ(j)"));
}
- private void on_deleted_run_type (object o, EventArgs args) {
+ private void on_deleted_run_type (object o, EventArgs args)
+ {
+ string translatedName = comboSelectRuns.GetNameTranslated(runsMoreWin.SelectedEventName);
+ combo_select_runs = comboSelectRuns.DeleteValue(translatedName);
+
+ UtilGtk.ComboDelThisValue(combo_result_runs, translatedName);
+ combo_result_runs.Active = 0;
+
extra_window_runs_initialize(new RunType("Custom"));
}
- private void on_deleted_run_i_type (object o, EventArgs args) {
+
+ private void on_deleted_run_i_type (object o, EventArgs args)
+ {
+ //TODO
extra_window_runs_interval_initialize(new RunType("byLaps"));
}
diff --git a/src/gui/cjCombo.cs b/src/gui/cjCombo.cs
index 3a8c533..c941d8b 100644
--- a/src/gui/cjCombo.cs
+++ b/src/gui/cjCombo.cs
@@ -34,9 +34,23 @@ public class CjCombo
{
combo = ComboBox.NewText ();
}
-
- public virtual void Fill()
+
+ protected virtual void select()
+ {
+ }
+
+ //if we just need to update values, call only this method
+ public void Fill()
{
+ select();
+
+ string [] namesToCombo = new String [l_types.Count];
+ int i =0;
+ foreach(SelectTypes type in l_types)
+ namesToCombo[i++] = type.NameTranslated;
+
+ UtilGtk.ComboUpdate(combo, namesToCombo, "");
+ combo.Active = 0;
}
protected void package()
@@ -110,21 +124,12 @@ public class CjComboSelectJumps : CjCombo
create();
Fill();
- package();
+ package();
}
- //if we just need to update values, call only this method
- public override void Fill()
+ protected override void select()
{
l_types = (List<object>) SqliteJumpType.SelectJumpTypesNew(false, "", "", false); //without
alljumpsname, without filter, not only name
-
- string [] namesToCombo = new String [l_types.Count];
- int i =0;
- foreach(SelectJumpTypes type in l_types)
- namesToCombo[i++] = type.NameTranslated;
-
- UtilGtk.ComboUpdate(combo, namesToCombo, "");
- combo.Active = 0;
}
}
@@ -140,17 +145,27 @@ public class CjComboSelectJumpsRj : CjCombo
package();
}
- //if we just need to update values, call only this method
- public override void Fill()
+ protected override void select()
{
l_types = (List<object>) SqliteJumpType.SelectJumpRjTypesNew("", false); //without
alljumpsname, not only name
+ }
+}
- string [] namesToCombo = new String [l_types.Count];
- int i =0;
- foreach(SelectJumpRjTypes type in l_types)
- namesToCombo[i++] = type.NameTranslated;
+public class CjComboSelectRuns : CjCombo
+{
+ public CjComboSelectRuns(Gtk.ComboBox combo_select_runs, Gtk.HBox hbox_combo_select_runs)
+ {
+ this.combo = combo_select_runs;
+ this.hbox = hbox_combo_select_runs;
- UtilGtk.ComboUpdate(combo, namesToCombo, "");
- combo.Active = 0;
+ create();
+ Fill();
+ package();
+ }
+
+ protected override void select()
+ {
+ l_types = (List<object>) SqliteRunType.SelectRunTypesNew("", false); //without allrunsname,
not only name
}
}
+
diff --git a/src/gui/run.cs b/src/gui/run.cs
index b1272d2..b3cfe37 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -930,7 +930,7 @@ partial class ChronoJumpWindow
private void on_extra_window_runs_test_changed(object o, EventArgs args)
{
- string runEnglishName = Util.FindOnArray(':',2,1, UtilGtk.ComboGetActive(combo_select_runs),
selectRunsString);
+ string runEnglishName = comboSelectRuns.GetSelectedNameEnglish();
currentRunType = createRunType(runEnglishName, true);
extra_window_runs_initialize(currentRunType);
@@ -1052,11 +1052,10 @@ partial class ChronoJumpWindow
}
}
- private void on_more_runs_update_test (object o, EventArgs args) {
+ private void on_more_runs_update_test (object o, EventArgs args)
+ {
currentEventType = new RunType(runsMoreWin.SelectedEventName);
- string runTranslatedName = Util.FindOnArray(':',1,2, runsMoreWin.SelectedEventName,
selectRunsString);
-
- combo_select_runs.Active = UtilGtk.ComboMakeActive(combo_select_runs, runTranslatedName);
+ comboSelectRuns.MakeActive(runsMoreWin.SelectedEventName);
}
private void on_more_runs_interval_update_test (object o, EventArgs args) {
diff --git a/src/sqlite/runType.cs b/src/sqlite/runType.cs
index a157711..614792f 100644
--- a/src/sqlite/runType.cs
+++ b/src/sqlite/runType.cs
@@ -22,6 +22,7 @@ using System;
using System.Data;
using System.IO;
using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
using Mono.Data.Sqlite;
@@ -175,6 +176,54 @@ class SqliteRunType : Sqlite
return myRunType;
}
+ //use SelectRunTypes object. Since 1.6.3
+ public static List<object> SelectRunTypesNew(string allRunsName, bool onlyName)
+ {
+ //allRunsName: add and "allRunsName" value
+ //onlyName: return only type name
+
+ string whereString = "";
+
+ Sqlite.Open();
+ dbcmd.CommandText = "SELECT * " +
+ " FROM " + Constants.RunTypeTable +
+ whereString +
+ " ORDER BY uniqueID";
+
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ List<object> types = new List<object>();
+
+ SelectRunTypes type;
+ if(allRunsName != "") {
+ type = new SelectRunTypes(allRunsName);
+ types.Add(type);
+ }
+
+ while(reader.Read()) {
+ if(onlyName) {
+ type = new SelectRunTypes(reader[1].ToString());
+ } else {
+ type = new SelectRunTypes(
+ Convert.ToInt32(reader[0]), //uniqueID
+ reader[1].ToString(), //nameEnglish
+
Convert.ToDouble(Util.ChangeDecimalSeparator(reader[2].ToString())), //distance
+ reader[3].ToString() //description
+ );
+ }
+ types.Add(type);
+ }
+
+ reader.Close();
+ Sqlite.Close();
+
+ return types;
+ }
+ //on newly cereated code use above method
public static string[] SelectRunTypes(string allRunsName, bool onlyName)
{
//allRunsName: add and "allRunsName" value
diff --git a/src/sqlite/usefulObjects.cs b/src/sqlite/usefulObjects.cs
index 2a91113..6b45da5 100644
--- a/src/sqlite/usefulObjects.cs
+++ b/src/sqlite/usefulObjects.cs
@@ -82,3 +82,28 @@ public class SelectJumpRjTypes : SelectJumpTypes
}
}
+public class SelectRunTypes : SelectTypes
+{
+ public double Distance;
+ public string Description;
+
+ //needed for inheritance
+ public SelectRunTypes()
+ {
+ }
+
+ public SelectRunTypes(string nameEnglish)
+ {
+ this.NameEnglish = nameEnglish;
+ }
+
+ public SelectRunTypes(int id, string nameEnglish, double distance, string description)
+ {
+ this.Id = id;
+ this.NameEnglish = nameEnglish;
+ this.NameTranslated = Catalog.GetString(nameEnglish);
+ this.Distance = distance;
+ this.Description = description;
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]