[chronojump] Encoder exercises can be renamed
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder exercises can be renamed
- Date: Fri, 4 Oct 2019 13:54:15 +0000 (UTC)
commit 08b3b1a8ce3dd32cea29f480dae2ccf0756c5ac8
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Oct 4 15:53:50 2019 +0200
Encoder exercises can be renamed
src/encoder.cs | 19 +++++++++++++++-
src/gui/encoder.cs | 56 ++++++++++++++++++++++++++++++++----------------
src/gui/genericWindow.cs | 2 +-
3 files changed, 56 insertions(+), 21 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 173ea95d..307bc1b5 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -568,7 +568,8 @@ public class EncoderSignal
//related to encoderSignalCurve table
-public class EncoderSignalCurve {
+public class EncoderSignalCurve
+{
public int uniqueID;
public int signalID;
public int curveID;
@@ -1046,6 +1047,22 @@ public class EncoderExercise
{
get { return name; }
}
+ public int PercentBodyWeight
+ {
+ get { return percentBodyWeight; }
+ }
+ public string Ressistance
+ {
+ get { return ressistance; }
+ }
+ public string Description
+ {
+ get { return description; }
+ }
+ public double Speed1RM
+ {
+ get { return speed1RM; }
+ }
~EncoderExercise() {}
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 03cda5d6..d926b7aa 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -4537,9 +4537,7 @@ public partial class ChronoJumpWindow
string exerciseName = ex.name;
//0 is the widgget to show; 1 is the editable; 2 id default value
- //name cannot be changed because we have to detect if new name already exists, check problems
with translations,
- //but most important, if user can change name and then click delete, it will be a mess to
confirm that the type "newname" or "oldname" will be deleted
- a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(false); a1.Add(exerciseName);
+ a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(exerciseName);
bigArray.Add(a1);
a2.Add(Constants.GenericWindowShow.SPININT); a2.Add(true); a2.Add("");
@@ -4557,6 +4555,8 @@ public partial class ChronoJumpWindow
genericWin = GenericWindow.Show(Catalog.GetString("Delete exercise"),
false, Catalog.GetString("Encoder exercise name:"), bigArray);
+
+ genericWin.uniqueID = ex.UniqueID;
genericWin.LabelSpinInt = Catalog.GetString("Displaced body weight") + " (%)";
//genericWin.SetSpinRange(ex.percentBodyWeight, ex.percentBodyWeight); //done this because
IsEditable does not affect the cursors
@@ -4577,7 +4577,7 @@ public partial class ChronoJumpWindow
*/
genericWin.ShowButtonCancel(false);
- genericWin.nameUntranslated = ex.name;
+ //genericWin.nameUntranslated = ex.name;
genericWin.uniqueID = ex.uniqueID;
genericWin.Button_accept.Clicked += new
EventHandler(on_button_encoder_exercise_edit_accepted);
@@ -4664,28 +4664,46 @@ public partial class ChronoJumpWindow
LogB.Information("Trying to edit: " + name);
if(name == "")
+ {
genericWin.SetLabelError(Catalog.GetString("Error: Missing name of exercise."));
+ return false;
+ }
else if (adding && Sqlite.Exists(false, Constants.EncoderExerciseTable, name))
+ {
genericWin.SetLabelError(string.Format(Catalog.GetString(
"Error: An exercise named '{0}' already exists."),
name));
- else {
- if(adding)
- SqliteEncoder.InsertExercise(false, -1, name, genericWin.SpinIntSelected,
- genericWin.Entry2Selected, genericWin.Entry3Selected,
- Util.ConvertToPoint(genericWin.SpinDouble2Selected)
- );
- else
- SqliteEncoder.UpdateExercise(false, genericWin.nameUntranslated, name,
genericWin.SpinIntSelected,
- genericWin.Entry2Selected, genericWin.Entry3Selected,
- Util.ConvertToPoint(genericWin.SpinDouble2Selected)
- );
+ return false;
+ }
+ else if (! adding) //if we are editing
+ {
+ //if we edit, check that this name does not exists (on other exercise, on current
editing exercise is obviously fine)
+ int getIdOfThis = Sqlite.ExistsAndGetUniqueID(false, Constants.EncoderExerciseTable,
name); //if not exists will be -1
+ if(getIdOfThis != -1 && getIdOfThis != genericWin.uniqueID)
+ {
+ genericWin.SetLabelError(string.Format(Catalog.GetString(
+ "Error: An exercise named '{0}' already
exists."), name));
- updateEncoderExercisesGui(name);
- LogB.Information("done");
- return true;
+ return false;
+ }
}
- return false;
+ if(adding)
+ SqliteEncoder.InsertExercise(false, -1, name, genericWin.SpinIntSelected,
+ genericWin.Entry2Selected, genericWin.Entry3Selected,
+ Util.ConvertToPoint(genericWin.SpinDouble2Selected)
+ );
+ else {
+ EncoderExercise ex = new EncoderExercise(genericWin.uniqueID,
+ genericWin.EntrySelected,
+ genericWin.SpinIntSelected,
+ genericWin.Entry2Selected, genericWin.Entry3Selected,
+ genericWin.SpinDouble2Selected);
+ SqliteEncoder.UpdateExercise(false, ex);
+ }
+
+ updateEncoderExercisesGui(name);
+ LogB.Information("done");
+ return true;
}
private void updateEncoderExercisesGui(string name)
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index bb6156d7..876e7546 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -116,7 +116,7 @@ public class GenericWindow
private int commentColumn;
public int uniqueID; //used on encoder & forceSensor edit exercise
- public string nameUntranslated; //used on encoder edit exercise
+ public string nameUntranslated; //used on encoder edit exercise //TODO: remove this, now is
used on gui/encoder (but disappearing) and on runEncoder
public enum Types { UNDEFINED, ENCODER_SESSION_LOAD,
ENCODER_SEL_REPS_IND_CURRENT_SESS, ENCODER_SEL_REPS_IND_ALL_SESS,
ENCODER_SEL_REPS_GROUP_CURRENT_SESS };
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]