[chronojump] cjCombo refactored
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] cjCombo refactored
- Date: Fri, 7 Oct 2016 22:53:19 +0000 (UTC)
commit 625d3c31a9060d3efadcf15f9a3fe6fd75e45ef2
Author: Xavier de Blas <xaviblas gmail com>
Date: Sat Oct 8 00:52:41 2016 +0200
cjCombo refactored
src/gui/cjCombo.cs | 93 ++++++++++++++++--------------------------
src/sqlite/jumpType.cs | 4 +-
src/sqlite/usefulObjects.cs | 11 ++++-
3 files changed, 47 insertions(+), 61 deletions(-)
---
diff --git a/src/gui/cjCombo.cs b/src/gui/cjCombo.cs
index 6368427..e4e1e78 100644
--- a/src/gui/cjCombo.cs
+++ b/src/gui/cjCombo.cs
@@ -27,6 +27,9 @@ public class CjCombo
protected Gtk.ComboBox combo;
protected Gtk.HBox hbox;
+ protected List<object> l_types;
+
+
protected void create()
{
combo = ComboBox.NewText ();
@@ -43,23 +46,47 @@ public class CjCombo
combo.Sensitive = false;
}
- public virtual string GetSelectedNameEnglish()
+ public string GetSelectedNameEnglish()
{
+ string nameTranslatedSelected = UtilGtk.ComboGetActive(combo);
+ foreach(SelectTypes type in l_types)
+ if(type.NameTranslated == nameTranslatedSelected)
+ return type.NameEnglish;
+
return "";
}
- public virtual Gtk.ComboBox SelectById(int id)
+ public Gtk.ComboBox SelectById(int id)
{
+ int pos = 0;
+ foreach(SelectTypes type in l_types)
+ {
+ if(type.Id == id)
+ {
+ combo.Active = pos;
+ break;
+ }
+
+ pos ++;
+ }
+
return combo;
}
-
- public virtual string GetNameTranslated(string nameEnglish)
+
+ public string GetNameTranslated(string nameEnglish)
{
+ foreach(SelectTypes type in l_types)
+ if(type.NameEnglish == nameEnglish)
+ return type.NameTranslated;
+
return "";
}
-
- public virtual void MakeActive(string nameEnglish)
+
+ public void MakeActive(string nameEnglish)
{
+ foreach(SelectTypes type in l_types)
+ if(type.NameTranslated == nameEnglish)
+ combo.Active = UtilGtk.ComboMakeActive(combo, type.NameTranslated);
}
public Gtk.ComboBox DeleteValue(string nameTranslated)
@@ -76,8 +103,6 @@ public class CjCombo
public class CjComboSelectJumps : CjCombo
{
- List<SelectJumpTypes> jumpTypes;
-
public CjComboSelectJumps(Gtk.ComboBox combo_select_jumps, Gtk.HBox hbox_combo_select_jumps)
{
this.combo = combo_select_jumps;
@@ -93,61 +118,15 @@ public class CjComboSelectJumps : CjCombo
//if we just need to update values, call only this method
public override void Fill()
{
- jumpTypes = SqliteJumpType.SelectJumpTypesNew(false, "", "", false); //without alljumpsname,
without filter, not only name
+ l_types = (List<object>) SqliteJumpType.SelectJumpTypesNew(false, "", "", false); //without
alljumpsname, without filter, not only name
- string [] jumpNamesToCombo = new String [jumpTypes.Count];
+ string [] jumpNamesToCombo = new String [l_types.Count];
int i =0;
- foreach(SelectJumpTypes jumpType in jumpTypes)
+ foreach(SelectJumpTypes jumpType in l_types)
jumpNamesToCombo[i++] = jumpType.NameTranslated;
UtilGtk.ComboUpdate(combo, jumpNamesToCombo, "");
combo.Active = 0;
}
- //TODO: refactor this. Move it to parent class
- public override string GetSelectedNameEnglish()
- {
- string nameTranslatedSelected = UtilGtk.ComboGetActive(combo);
- foreach(SelectJumpTypes jumpType in jumpTypes)
- if(jumpType.NameTranslated == nameTranslatedSelected)
- return jumpType.NameEnglish;
-
- return "";
- }
-
- //TODO: refactor this. Move it to parent class
- public Gtk.ComboBox SelectById(int id)
- {
- int pos = 0;
- foreach(SelectJumpTypes jumpType in jumpTypes)
- {
- if(jumpType.Id == id)
- {
- combo.Active = pos;
- break;
- }
-
- pos ++;
- }
-
- return combo;
- }
-
- //TODO: refactor this. Move it to parent class
- public override string GetNameTranslated(string nameEnglish)
- {
- foreach(SelectJumpTypes jumpType in jumpTypes)
- if(jumpType.NameEnglish == nameEnglish)
- return jumpType.NameTranslated;
-
- return "";
- }
-
- //TODO: refactor this. Move it to parent class
- public override void MakeActive(string nameEnglish)
- {
- foreach(SelectJumpTypes jumpType in jumpTypes)
- if(jumpType.NameTranslated == nameEnglish)
- combo.Active = UtilGtk.ComboMakeActive(combo, jumpType.NameTranslated);
- }
}
diff --git a/src/sqlite/jumpType.cs b/src/sqlite/jumpType.cs
index 96bfb8a..f04ddf9 100644
--- a/src/sqlite/jumpType.cs
+++ b/src/sqlite/jumpType.cs
@@ -240,7 +240,7 @@ class SqliteJumpType : Sqlite
}
//use SelectJumpTypes object. Since 1.6.3
- public static List<SelectJumpTypes> SelectJumpTypesNew(bool dbconOpened, string allJumpsName, string
filter, bool onlyName)
+ public static List<object> SelectJumpTypesNew(bool dbconOpened, string allJumpsName, string filter,
bool onlyName)
{
//allJumpsName: add and "allJumpsName" value
//filter:
@@ -267,7 +267,7 @@ class SqliteJumpType : Sqlite
SqliteDataReader reader;
reader = dbcmd.ExecuteReader();
- List<SelectJumpTypes> jumpTypes = new List<SelectJumpTypes>();
+ List<object> jumpTypes = new List<object>();
int count = new int();
count = 0;
diff --git a/src/sqlite/usefulObjects.cs b/src/sqlite/usefulObjects.cs
index 393f30d..dbaccb3 100644
--- a/src/sqlite/usefulObjects.cs
+++ b/src/sqlite/usefulObjects.cs
@@ -21,11 +21,19 @@
using System;
using Mono.Unix;
-public class SelectJumpTypes
+public class SelectTypes
{
public int Id;
public string NameEnglish;
public string NameTranslated;
+
+ public SelectTypes()
+ {
+ }
+}
+
+public class SelectJumpTypes : SelectTypes
+{
public bool StartIn;
public bool HasWeight;
public string Description;
@@ -44,6 +52,5 @@ public class SelectJumpTypes
this.HasWeight = hasWeight;
this.Description = description;
}
-
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]