[chronojump] Doing 695726



commit 9dacc71511a7a6df572b0716be69275721c7cf40
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Mar 13 19:43:50 2013 +0100

    Doing 695726

 src/encoder.cs           |   27 +++++++----
 src/gui/encoder.cs       |   38 ++++++++++++--
 src/gui/genericWindow.cs |  121 ++++++++++++++++++++++++++++++++++++----------
 3 files changed, 146 insertions(+), 40 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 6a31ffe..fdb8282 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -309,15 +309,24 @@ public class EncoderSQL
                return str;
        }
 
-       public string [] ToStringArray (int count) {
-               string [] str = new String [7];
-               str[0] = uniqueID;
-               str[1] = count.ToString();
-               str[2] = exerciseName;
-               str[3] = ecconLong;
-               str[4] = extraWeight;
-               str[5] = GetDate(true);
-               str[6] = description;
+       public string [] ToStringArray (int count, bool checkboxes) {
+               int all = 7;
+               if(checkboxes)
+                       all = 8;
+
+               string [] str = new String [all];
+               int i=0;
+               str[i++] = uniqueID;
+       
+               if(checkboxes)
+                       str[i++] = "";  //checkboxes
+       
+               str[i++] = count.ToString();
+               str[i++] = exerciseName;
+               str[i++] = ecconLong;
+               str[i++] = extraWeight;
+               str[i++] = GetDate(true);
+               str[i++] = description;
                return str;
        }
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 1855ea9..f6131b9 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -413,11 +413,12 @@ public partial class ChronoJumpWindow
                foreach(EncoderSQL es in data) {
                        checkboxes[count++] = es.future1;
                        Log.WriteLine(checkboxes[count-1]);
-                       dataPrint.Add(es.ToStringArray(count));
+                       dataPrint.Add(es.ToStringArray(count,true));
                }
        
                string [] columnsString = {
                        Catalog.GetString("ID"),
+                       "",                             //checkboxes
                        Catalog.GetString("Curve"),
                        Catalog.GetString("Exercise"),
                        Catalog.GetString("Contraction"),
@@ -447,7 +448,7 @@ public partial class ChronoJumpWindow
                                string.Format(Catalog.GetString("Saved curves of athlete {0} on this 
session."), 
                                        currentPerson.Name), bigArray);
 
-               genericWin.SetTreeview(columnsString, true, dataPrint, new ArrayList());
+               genericWin.SetTreeview(columnsString, true, dataPrint, new ArrayList(), true);
                genericWin.AddOptionsToComboCheckBoxesOptions(encoderExercisesNames);
                genericWin.CreateComboCheckBoxes();
                genericWin.MarkActiveCurves(checkboxes);
@@ -455,6 +456,8 @@ public partial class ChronoJumpWindow
                genericWin.SetButtonAcceptSensitive(true);
                //manage selected, unselected curves
                genericWin.Button_accept.Clicked += new EventHandler(on_encoder_show_curves_done);
+               genericWin.Button_row_edit.Clicked += new EventHandler(on_encoder_show_curves_row_edit);
+               genericWin.Button_row_delete.Clicked += new EventHandler(on_encoder_show_curves_row_delete);
 
                //used when we don't need to read data, 
                //and we want to ensure next window will be created at needed size
@@ -501,6 +504,17 @@ public partial class ChronoJumpWindow
                encoderButtonsSensitive(encoderSensEnumStored);
        }
        
+       protected void on_encoder_show_curves_row_edit (object o, EventArgs args) {
+               Log.WriteLine("row edit at show curves");
+               Log.WriteLine(genericWin.TreeviewSelectedUniqueID.ToString());
+       }
+       
+       protected void on_encoder_show_curves_row_delete (object o, EventArgs args) {
+               Log.WriteLine("row delete at show curves");
+               Log.WriteLine(genericWin.TreeviewSelectedUniqueID.ToString());
+       }
+       
+       
        void on_button_encoder_analyze_data_compare_clicked (object o, EventArgs args) 
        {
                if(Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
@@ -572,7 +586,7 @@ public partial class ChronoJumpWindow
                                string.Format(Catalog.GetString("Select persons to compare to {0}."), 
                                        currentPerson.Name), bigArray);
 
-               genericWin.SetTreeview(columnsString, true, data, nonSensitiveRows);
+               genericWin.SetTreeview(columnsString, true, data, nonSensitiveRows,false);
                genericWin.CreateComboCheckBoxes();
                genericWin.MarkActiveCurves(checkboxes);
                genericWin.ShowButtonCancel(false);
@@ -671,7 +685,7 @@ public partial class ChronoJumpWindow
                        dataConverted.Add(encPS.ToStringArray());
                }
 
-               genericWin.SetTreeview(columnsString, true, dataConverted, nonSensitiveRows);
+               genericWin.SetTreeview(columnsString, true, dataConverted, nonSensitiveRows,false);
                genericWin.CreateComboCheckBoxes();
                genericWin.MarkActiveCurves(checkboxes);
                genericWin.ShowButtonCancel(false);
@@ -713,7 +727,7 @@ public partial class ChronoJumpWindow
                ArrayList dataPrint = new ArrayList();
                int count = 1;
                foreach(EncoderSQL es in data) 
-                       dataPrint.Add(es.ToStringArray(count++));
+                       dataPrint.Add(es.ToStringArray(count++,false));
                
                string [] columnsString = {
                        Catalog.GetString("ID"),
@@ -729,11 +743,13 @@ public partial class ChronoJumpWindow
                                string.Format(Catalog.GetString("Select signal of athlete {0} on this 
session."), 
                                        currentPerson.Name), Constants.GenericWindowShow.TREEVIEW);
 
-               genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList());
+               genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList(), true);
                genericWin.ShowButtonCancel(true);
                genericWin.SetButtonAcceptLabel(Catalog.GetString("Load"));
                genericWin.SetButtonAcceptSensitive(false);
                genericWin.Button_accept.Clicked += new EventHandler(on_encoder_load_signal_accepted);
+               genericWin.Button_row_edit.Clicked += new EventHandler(on_encoder_load_signal_row_edit);
+               genericWin.Button_row_delete.Clicked += new EventHandler(on_encoder_load_signal_row_delete);
        }
        
        protected void on_encoder_load_signal_accepted (object o, EventArgs args)
@@ -774,6 +790,16 @@ public partial class ChronoJumpWindow
                        new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("Sorry, file not 
found"));
        }
        
+       protected void on_encoder_load_signal_row_edit (object o, EventArgs args) {
+               Log.WriteLine("row edit at load signal");
+               Log.WriteLine(genericWin.TreeviewSelectedUniqueID.ToString());
+       }
+       
+       protected void on_encoder_load_signal_row_delete (object o, EventArgs args) {
+               Log.WriteLine("row delete at load signal");
+               Log.WriteLine(genericWin.TreeviewSelectedUniqueID.ToString());
+       }
+       
        void on_button_encoder_export_all_curves_clicked (object o, EventArgs args) 
        {
                checkFile();
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index 90c8c18..849d044 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -55,6 +55,10 @@ public class GenericWindow
        [Widget] Gtk.Button button_accept;
        [Widget] Gtk.Button button_cancel;
        
+       //treeview fake buttons
+       [Widget] Gtk.Button button_row_edit;
+       [Widget] Gtk.Button button_row_delete;
+       
        [Widget] Gtk.Box hbox_entry2;
        [Widget] Gtk.Label label_entry2;
        [Widget] Gtk.Entry entry2;
@@ -75,6 +79,7 @@ public class GenericWindow
        //used when we don't need to read data, 
        //and we want to ensure next window will be created at needed size
        public bool DestroyOnAccept;
+       public int TreeviewSelectedUniqueID;
 
        public GenericWindow ()
        {
@@ -275,29 +280,29 @@ public class GenericWindow
                        if(selected == Catalog.GetString("All")) {
                                do {
                                        if(! Util.FoundInArrayList(nonSensitiveRows, i))
-                                               store.SetValue (iter, 0, true);
+                                               store.SetValue (iter, 1, true);
                                        i++;
                                } while ( store.IterNext(ref iter) );
                        } else if(selected == Catalog.GetString("Invert")) {
                                bool val;
                                do {
                                        if(! Util.FoundInArrayList(nonSensitiveRows, i)) {
-                                               val = (bool) store.GetValue (iter, 0);
-                                               store.SetValue (iter, 0, !val);
+                                               val = (bool) store.GetValue (iter, 1);
+                                               store.SetValue (iter, 1, !val);
                                        }
                                        i++;
                                } while ( store.IterNext(ref iter) );
                        } else if(selected == Catalog.GetString("None")) {
                                do {
-                                       store.SetValue (iter, 0, false);
+                                       store.SetValue (iter, 1, false);
                                } while ( store.IterNext(ref iter) );
                        } else {        //encoderExercises
                                do {
                                        if(selected == (string) store.GetValue (iter, 2) &&
                                                        ! Util.FoundInArrayList(nonSensitiveRows, i))
-                                               store.SetValue (iter, 0, true);
+                                               store.SetValue (iter, 1, true);
                                        else
-                                               store.SetValue (iter, 0, false);
+                                               store.SetValue (iter, 1, false);
                                        i++;
                                } while ( store.IterNext(ref iter) );
                        }
@@ -317,7 +322,7 @@ public class GenericWindow
        
        //data is an ArrayList of strings[], each string [] is a row, each of its strings is a column
        public void SetTreeview(string [] columnsString, bool addCheckbox, 
-                       ArrayList data, ArrayList myNonSensitiveRows) 
+                       ArrayList data, ArrayList myNonSensitiveRows, bool contextMenu) 
        {
                //adjust window to be bigger
                generic_window.Resizable = true;
@@ -330,13 +335,15 @@ public class GenericWindow
 
                nonSensitiveRows = myNonSensitiveRows;
                
-               if(addCheckbox)
-                       createCheckboxes(treeview);
-
                foreach (string [] line in data) 
                        store.AppendValues (line);
 
                treeview.CursorChanged += on_treeview_cursor_changed; 
+               if(contextMenu) {
+                       button_row_edit = new Gtk.Button();
+                       button_row_delete = new Gtk.Button();
+                       treeview.ButtonReleaseEvent += on_treeview_button_release_event;
+               }
        }
        
        public void MarkActiveCurves(string [] checkboxes) 
@@ -347,22 +354,22 @@ public class GenericWindow
                if(okIter) {
                        do {
                                if(checkboxes[count++] == "active")
-                                       store.SetValue (iter, 0, true);
+                                       store.SetValue (iter, 1, true);
                        } while ( store.IterNext(ref iter) );
                }
        }
        
        private TreeStore getStore (int columns, bool addCheckbox)
        {
-               if(addCheckbox)
-                       columns++;
+               //if(addCheckbox)
+               //      columns++;
 
                //prepares the TreeStore for required columns
                Type [] types = new Type [columns];
 
                for (int i=0; i < columns; i++) {
-                       if(addCheckbox && i == 0)
-                               types[0] = typeof (bool);
+                       if(addCheckbox && i == 1)
+                               types[1] = typeof (bool);
                        else
                                types[i] = typeof (string);
                }
@@ -375,12 +382,17 @@ public class GenericWindow
                treeviewRemoveColumns();
                treeview.HeadersVisible=true;
                int i=0;
-               bool visible = false;
+               //bool visible = false;
+               bool visible = true;
                foreach(string myCol in columnsString) {
-                       UtilGtk.CreateCols(treeview, store, myCol, i++, visible);
-                       if(i == 1)      //first columns: ID, is hidden
-                               store.SetSortFunc (0, UtilGtk.IdColumnCompare);
+                       if(addCheckbox && i == 1)
+                               createCheckboxes(treeview);
+                       else
+                               UtilGtk.CreateCols(treeview, store, myCol, i, visible);
+//                     if(i == 1)      //first columns: ID, is hidden
+//                             store.SetSortFunc (0, UtilGtk.IdColumnCompare);
                        visible = true;
+                       i++;
                }
        }
        
@@ -420,7 +432,8 @@ public class GenericWindow
 
                TreeViewColumn column = new TreeViewColumn ("", crt, "active", 0);
                column.Clickable = true;
-               tv.InsertColumn (column, 0);
+               tv.AppendColumn (column);
+               
        }
        
        //if column == 0 returns checkboxes column. If is 1 returns column 1...
@@ -435,18 +448,18 @@ public class GenericWindow
                if(okIter) {
                        do {
                                if(column == 0) {
-                                       if((bool) store.GetValue (iter, 0))
+                                       if((bool) store.GetValue (iter, 1))
                                                checkboxes[count++] = "active";
                                        else
                                                checkboxes[count++] = "inactive";
                                }
                                else
-                                       if((bool) store.GetValue (iter, 0) || ! onlyActive)
+                                       if((bool) store.GetValue (iter, 1) || ! onlyActive)
                                                checkboxes[count++] = ((string) store.GetValue (iter, 
column));
                                
                        } while ( store.IterNext(ref iter) );
                }
-               if(column == 0)
+               if(column == 1)
                        return checkboxes;
                else {
                        string [] checkboxesWithoutGaps = new string[count];
@@ -457,7 +470,7 @@ public class GenericWindow
        }
 
        protected void ItemToggled(object o, ToggledArgs args) {
-               int column = 0;
+               int column = 1;
                TreeIter iter;
                if (store.GetIter (out iter, new TreePath(args.Path))) 
                {
@@ -478,7 +491,55 @@ public class GenericWindow
                        }
                }
        }
-       
+
+       private void on_treeview_button_release_event (object o, ButtonReleaseEventArgs args) {
+               //TreeviewSelectedUniqueID = -1;
+
+                Gdk.EventButton e = args.Event;
+                Gtk.TreeView tv = (Gtk.TreeView) o;
+               TreeModel model = treeview.Model;
+               if (e.Button == 3) {
+                       TreeIter iter = new TreeIter();
+                       //TreeModel myModel = tv.Model;
+                       if (tv.Selection.GetSelected (out model, out iter)) {
+/*
+Log.WriteLine((string) store.GetValue (iter, 0));
+//Log.WriteLine((string) store.GetValue (iter, 1));
+Log.WriteLine((string) store.GetValue (iter, 2));
+Log.WriteLine((string) store.GetValue (iter, 3));
+*/
+                               //TreeviewSelectedUniqueID = Convert.ToInt32((string) store.GetValue (iter, 
0));
+                               TreeviewSelectedUniqueID = Convert.ToInt32((string) store.GetValue (iter, 0));
+                               treeviewContextMenu();
+                       }
+               }
+       }
+
+       private void treeviewContextMenu() {
+               Menu myMenu = new Menu ();
+               Gtk.MenuItem myItem;
+
+               myItem = new MenuItem ( Catalog.GetString("Edit selected") );
+               myItem.Activated += on_edit_selected_clicked;
+               myMenu.Attach( myItem, 0, 1, 0, 1 );
+
+
+               myItem = new MenuItem ( Catalog.GetString("Delete selected") );
+               myItem.Activated += on_delete_selected_clicked;
+               myMenu.Attach( myItem, 0, 1, 1, 2 );
+
+               myMenu.Popup();
+               myMenu.ShowAll();
+       }
+
+       private void on_edit_selected_clicked (object o, EventArgs args) {
+               button_row_edit.Click();
+       }
+
+       private void on_delete_selected_clicked (object o, EventArgs args) {
+               button_row_delete.Click();
+       }
+
        
        public void SetButtonAcceptLabel(string str) {
                button_accept.Label=str;
@@ -526,6 +587,16 @@ public class GenericWindow
                get { return button_accept; }
        }
                
+       public Button Button_row_edit {
+               set { button_row_edit = value; }
+               get { return button_row_edit; }
+       }
+               
+       public Button Button_row_delete {
+               set { button_row_delete = value; }
+               get { return button_row_delete; }
+       }
+               
        public string EntrySelected {
                set { entry.Text = value; }
                get { return entry.Text.ToString(); }


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