[chronojump] Encoder exercise delete on separate button (not on edit)



commit de88a012598b8069408bc7f605bf71bdc263c3ae
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Oct 4 13:15:16 2019 +0200

    Encoder exercise delete on separate button (not on edit)

 glade/app1.glade           | 56 +++++++++++++++++++++++++++++++++++-----------
 src/encoder.cs             |  9 ++++++++
 src/gui/chronojumpIcons.cs |  4 +++-
 src/gui/encoder.cs         | 45 ++++++++++++++++++++++++-------------
 4 files changed, 84 insertions(+), 30 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index d8e7105d..b270464a 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -21889,6 +21889,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -23837,18 +23840,6 @@ 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>
@@ -23885,6 +23876,18 @@ 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>
@@ -24290,7 +24293,7 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkFrame" id="frame4">
+                                                            <widget class="GtkFrame" 
id="frame_encoder_exercise_config">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="border_width">4</property>
@@ -24398,6 +24401,30 @@ Concentric</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkButton" 
id="button_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 
new exercise</property>
+                                                            <property name="relief">half</property>
+                                                            <signal name="clicked" 
handler="on_button_encoder_exercise_delete_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_encoder_exercise_delete">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            <property name="icon-size">2</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -30807,6 +30834,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 380f3256..af5e502b 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -1035,6 +1035,15 @@ public class EncoderExercise
                        ressistance + "," + description + "," + speed1RM.ToString();
        }
 
+       public int UniqueID
+       {
+               get { return uniqueID; }
+       }
+       public string Name
+       {
+               get { return name; }
+       }
+
        ~EncoderExercise() {}
 }
 
diff --git a/src/gui/chronojumpIcons.cs b/src/gui/chronojumpIcons.cs
index add0311a..43608916 100644
--- a/src/gui/chronojumpIcons.cs
+++ b/src/gui/chronojumpIcons.cs
@@ -139,8 +139,9 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_encoder_capture_1set;
        [Widget] Gtk.Image image_encoder_capture_cont;
        [Widget] Gtk.Image image_encoder_capture_execute;
-       [Widget] Gtk.Image image_encoder_exercise_add;
        [Widget] Gtk.Image image_encoder_exercise_edit;
+       [Widget] Gtk.Image image_encoder_exercise_add;
+       [Widget] Gtk.Image image_encoder_exercise_delete;
        [Widget] Gtk.Image image_encoder_1RM_info;
        //[Widget] Gtk.Image image_encoder_exercise_close;
        [Widget] Gtk.Image image_inertial_rolled;
@@ -593,6 +594,7 @@ public partial class ChronoJumpWindow
                image_run_type_delete_simple.Pixbuf = pixbuf;
                image_run_type_delete_intervallic.Pixbuf = pixbuf;
                image_session_delete.Pixbuf = pixbuf;
+               image_encoder_exercise_delete.Pixbuf = pixbuf;
 
                image_button_cancel.Pixbuf = pixbuf;
                image_encoder_capture_cancel.Pixbuf = pixbuf;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 7c92e12d..e15c3d28 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -4580,9 +4580,6 @@ public partial class ChronoJumpWindow
                */
                genericWin.ShowButtonCancel(false);
                
-               genericWin.ShowButtonDelete(true);
-               genericWin.Button_delete.Clicked += new EventHandler(on_button_encoder_exercise_delete);
-               
                genericWin.nameUntranslated = ex.name;
                genericWin.uniqueID = ex.uniqueID;
                
@@ -4720,18 +4717,37 @@ public partial class ChronoJumpWindow
                combo_encoder_exercise_analyze.Active = 
UtilGtk.ComboMakeActive(combo_encoder_exercise_analyze, name);
        }
        
-       void on_button_encoder_exercise_delete (object o, EventArgs args) 
+       void on_button_encoder_exercise_delete_clicked (object o, EventArgs args)
        {
+               if(! selectedEncoderExerciseExists())
+               {
+                       new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Need to 
create/select an exercise."));
+                       return;
+               }
+
                EncoderExercise ex = (EncoderExercise) SqliteEncoder.SelectEncoderExercises(
-                               false, genericWin.uniqueID, false)[0];
+                               false, getExerciseIDFromEncoderCombo(exerciseCombos.CAPTURE), false)[0];
+
                if(ex.IsPredefined()) {
                        new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Sorry, 
predefined exercises cannot be deleted."));
                        return;
                }
 
-               ArrayList array = SqliteEncoder.SelectEncoderSetsOfAnExercise(false, genericWin.uniqueID); 
//dbconOpened, exerciseID
+               ArrayList array = SqliteEncoder.SelectEncoderSetsOfAnExercise(false, ex.UniqueID); 
//dbconOpened, exerciseID
+
+               if(array.Count > 0)
+               {
+                       //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
+                       genericWin = GenericWindow.Show(Catalog.GetString("Exercise"),
+                                       Catalog.GetString("Encoder 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:"));
@@ -4749,19 +4765,15 @@ public partial class ChronoJumpWindow
 
                        genericWin.ShowTextview();
                        genericWin.ShowTreeview();
-                       genericWin.ShowButtonDelete(false);
-                       genericWin.DeletingExerciseHideSomeWidgets();
-               
-                       genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_encoder_exercise_edit_accepted);
+
+                       //accept does not save changes, just closes window
                        genericWin.Button_accept.Clicked += new 
EventHandler(on_button_encoder_exercise_do_not_delete);
                } else {
                        //encoder table has not records of this exercise
                        //delete exercise
-                       Sqlite.Delete(false, Constants.EncoderExerciseTable, genericWin.uniqueID);
+                       Sqlite.Delete(false, Constants.EncoderExerciseTable, ex.UniqueID);
                        //delete 1RM records of this exercise
-                       Sqlite.DeleteFromAnInt(false, Constants.Encoder1RMTable, "exerciseID", 
genericWin.uniqueID);
-
-                       genericWin.HideAndNull();
+                       Sqlite.DeleteFromAnInt(false, Constants.Encoder1RMTable, "exerciseID", ex.UniqueID);
 
                        createEncoderComboExerciseAndAnalyze();
                        combo_encoder_exercise_capture.Active = 0;
@@ -4772,7 +4784,8 @@ public partial class ChronoJumpWindow
        }
 
        //accept does not save changes, just closes window
-       void on_button_encoder_exercise_do_not_delete (object o, EventArgs args) {
+       void on_button_encoder_exercise_do_not_delete (object o, EventArgs args)
+       {
                genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_encoder_exercise_do_not_delete);
                genericWin.HideAndNull();
        }


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