[chronojump] RunEncoder exercise deleted done. and improvements on edit



commit cda2d5bed21a7a1ea6af597d6a7c836de76b28af
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Oct 4 18:49:02 2019 +0200

    RunEncoder exercise deleted done. and improvements on edit

 glade/app1.glade           | 53 +++++++++++++++++++++-------
 src/gui/chronojumpIcons.cs |  3 ++
 src/gui/forceSensor.cs     | 10 +-----
 src/gui/runEncoder.cs      | 87 ++++++++++++++++++++++++++++------------------
 4 files changed, 98 insertions(+), 55 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index f2bc73fb..850060bc 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -7211,6 +7211,29 @@ EncoderInertialCapture</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkButton" 
id="button_run_encoder_exercise_delete">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <property name="has_tooltip">True</property>
+                                                            <property name="tooltip" translatable="yes">Add 
exercise type</property>
+                                                            <signal name="clicked" 
handler="on_button_run_encoder_exercise_delete_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_run_encoder_exercise_delete">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="stock">gtk-new</property>
+                                                            <property name="icon-size">2</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -21915,6 +21938,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -23863,6 +23889,18 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -23899,18 +23937,6 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -30860,6 +30886,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/gui/chronojumpIcons.cs b/src/gui/chronojumpIcons.cs
index 3acb482e..83c0fecb 100644
--- a/src/gui/chronojumpIcons.cs
+++ b/src/gui/chronojumpIcons.cs
@@ -185,6 +185,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_race_encoder_capture_recalculate;
        [Widget] Gtk.Image image_run_encoder_exercise_edit;
        [Widget] Gtk.Image image_run_encoder_exercise_add;
+       [Widget] Gtk.Image image_run_encoder_exercise_delete;
 
        //video play icons
        [Widget] Gtk.Image image_video_play_this_test;
@@ -597,6 +598,8 @@ public partial class ChronoJumpWindow
                image_session_delete.Pixbuf = pixbuf;
                image_encoder_exercise_delete.Pixbuf = pixbuf;
                image_force_sensor_exercise_delete.Pixbuf = pixbuf;
+               image_run_encoder_exercise_delete.Pixbuf = pixbuf;
+
 
                image_button_cancel.Pixbuf = pixbuf;
                image_encoder_capture_cancel.Pixbuf = pixbuf;
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 3a05feb9..374d6b3d 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -321,6 +321,7 @@ public partial class ChronoJumpWindow
                        if(ex is System.IO.IOException || ex is System.TimeoutException)
                        {
                                LogB.Information(errorMessage);
+//portFS.Close(); //TODO: seguir investigant
                                portFSOpened = false;
                                return false;
                        }
@@ -2309,8 +2310,6 @@ LogB.Information(" fs R ");
 
                        genericWin.ShowTextview();
                        genericWin.ShowTreeview();
-
-                       genericWin.Button_accept.Clicked += new 
EventHandler(on_button_force_sensor_exercise_do_not_delete);
                } else {
                        //forceSensor table has not records of this exercise. Delete exercise
                        SqliteForceSensorExercise.Delete(false, ex.UniqueID);
@@ -2322,13 +2321,6 @@ LogB.Information(" fs R ");
                }
        }
 
-       //accept does not save changes, just closes window
-       void on_button_force_sensor_exercise_do_not_delete (object o, EventArgs args)
-       {
-               genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_force_sensor_exercise_do_not_delete);
-               genericWin.HideAndNull();
-       }
-
        // -------------------------------- end of exercise stuff --------------------
 
        // -------------------------------- options, laterality and comment stuff -------------
diff --git a/src/gui/runEncoder.cs b/src/gui/runEncoder.cs
index 80265626..2f3e6e2a 100644
--- a/src/gui/runEncoder.cs
+++ b/src/gui/runEncoder.cs
@@ -1158,7 +1158,7 @@ LogB.Information(" re R ");
                ArrayList a2 = new ArrayList();
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
-               a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(ex.Name); //name can be 
changed (opposite to encoder), because we use always the uniqueID
+               a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(ex.Name);
                bigArray.Add(a1);
 
                a2.Add(Constants.GenericWindowShow.ENTRY2); a2.Add(true); a2.Add(ex.Description);
@@ -1169,12 +1169,11 @@ LogB.Information(" re R ");
                genericWin.LabelEntry2 = Catalog.GetString("Description");
 
                genericWin.ShowButtonCancel(false);
-
-               genericWin.ShowButtonDelete(true);
-               genericWin.Button_delete.Clicked += new EventHandler(on_button_run_encoder_exercise_delete);
+               genericWin.HideOnAccept = false;
 
                genericWin.uniqueID = ex.UniqueID;
 
+               genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_run_encoder_exercise_edit_accepted);
                genericWin.Button_accept.Clicked += new 
EventHandler(on_button_run_encoder_exercise_edit_accepted);
                genericWin.ShowNow();
        }
@@ -1198,9 +1197,9 @@ LogB.Information(" re R ");
                genericWin.LabelEntry2 = Catalog.GetString("Description");
 
                genericWin.SetButtonAcceptLabel(Catalog.GetString("Add"));
-
                genericWin.HideOnAccept = false;
 
+               genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_run_encoder_exercise_add_accepted);
                genericWin.Button_accept.Clicked += new 
EventHandler(on_button_run_encoder_exercise_add_accepted);
                genericWin.ShowNow();
        }
@@ -1233,37 +1232,70 @@ LogB.Information(" re R ");
                        LogB.Information("run_encoder_exercise_do - Trying to edit: " + name);
 
                if(name == "")
+               {
                        genericWin.SetLabelError(Catalog.GetString("Error: Missing name of exercise."));
+                       return false;
+               }
                else if (adding && Sqlite.Exists(false, Constants.RunEncoderExerciseTable, name))
+               {
                        genericWin.SetLabelError(string.Format(Catalog.GetString(
                                                        "Error: An exercise named '{0}' already exists."), 
name));
-               else {
-                       if(adding)
-                               SqliteRunEncoderExercise.Insert(false, -1, name, genericWin.Entry2Selected);
-                       else {
-                               RunEncoderExercise ex = new RunEncoderExercise(genericWin.uniqueID, name, 
genericWin.Entry2Selected);
-                               SqliteRunEncoderExercise.Update(false, ex);
-                       }
+                       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.RunEncoderExerciseTable, 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));
 
-                       fillRunEncoderExerciseCombo(name);
+                               return false;
+                       }
+               }
 
-                       LogB.Information("done");
-                       return true;
+               if(adding)
+                       SqliteRunEncoderExercise.Insert(false, -1, name, genericWin.Entry2Selected);
+               else {
+                       RunEncoderExercise ex = new RunEncoderExercise(genericWin.uniqueID, name, 
genericWin.Entry2Selected);
+                       SqliteRunEncoderExercise.Update(false, ex);
                }
 
-               return false;
+               fillRunEncoderExerciseCombo(name);
+               LogB.Information("done");
+               return true;
        }
 
        //based on: on_button_encoder_exercise_delete
        //maybe unify them on the future
-       void on_button_run_encoder_exercise_delete (object o, EventArgs args)
+       void on_button_run_encoder_exercise_delete_clicked (object o, EventArgs args)
        {
-               int exerciseID = genericWin.uniqueID;
+               if(UtilGtk.ComboGetActive(combo_run_encoder_exercise) == "")
+               {
+                       new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Need to 
create/select an exercise."));
+                       return;
+               }
+
+               RunEncoderExercise ex = (RunEncoderExercise) SqliteRunEncoderExercise.Select (
+                                false, getExerciseIDFromAnyCombo(combo_run_encoder_exercise, 
runEncoderComboExercisesString, false), false)[0];
+
+               LogB.Information("selected exercise: " + ex.ToString());
 
                //1st find if there are sets with this exercise
-               ArrayList array = SqliteRunEncoder.SelectRowsOfAnExercise(false, exerciseID);
+               ArrayList array = SqliteRunEncoder.SelectRowsOfAnExercise(false, ex.UniqueID);
+
+               if(array.Count > 0)
+               {
+                       genericWin = GenericWindow.Show(Catalog.GetString("Exercise"),
+                                       Catalog.GetString("Exercise name:"), 
Constants.GenericWindowShow.ENTRY, false);
+
+                       genericWin.EntrySelected = ex.Name;
+
+                       //just one button to exit and with ESC accelerator
+                       genericWin.ShowButtonAccept(false);
+                       genericWin.SetButtonCancelLabel(Catalog.GetString("Close"));
 
-               if(array.Count > 0) {
                        //there are some records of this exercise on encoder table, do not delete
                        genericWin.SetTextview(
                                        Catalog.GetString("Sorry, this exercise cannot be deleted until these 
tests are deleted:"));
@@ -1281,16 +1313,9 @@ LogB.Information(" re R ");
 
                        genericWin.ShowTextview();
                        genericWin.ShowTreeview();
-                       genericWin.ShowButtonDelete(false);
-                       genericWin.DeletingExerciseHideSomeWidgets();
-
-                       genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_run_encoder_exercise_edit_accepted);
-                       genericWin.Button_accept.Clicked += new 
EventHandler(on_button_run_encoder_exercise_do_not_delete);
                } else {
                        //runEncoder table has not records of this exercise. Delete exercise
-                       SqliteRunEncoderExercise.Delete(false, exerciseID);
-
-                       genericWin.HideAndNull();
+                       SqliteRunEncoderExercise.Delete(false, ex.UniqueID);
 
                        fillRunEncoderExerciseCombo("");
                        combo_run_encoder_exercise.Active = 0;
@@ -1298,12 +1323,6 @@ LogB.Information(" re R ");
                        new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Exercise 
deleted."));
                }
        }
-
-       //accept does not save changes, just closes window
-       void on_button_run_encoder_exercise_do_not_delete (object o, EventArgs args) {
-               genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_run_encoder_exercise_do_not_delete);
-               genericWin.HideAndNull();
-       }
        // -------------------------------- end of exercise stuff --------------------
 
 }


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