[chronojump] Encoder load set, current set row is selected



commit 155c59d382a48268a79f37b9440a65d855a19473
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Apr 28 17:51:03 2015 +0200

    Encoder load set, current set row is selected

 src/gui/encoder.cs       |    4 +++
 src/gui/genericWindow.cs |    8 +++++++
 src/utilGtk.cs           |   50 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 4af9399..da095c7 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1210,6 +1210,10 @@ public partial class ChronoJumpWindow
                genericWin.SetComboLabel(Catalog.GetString("Change the owner of selected set") + 
                                " (" + Catalog.GetString("code") + ":" + Catalog.GetString("name") + ")");
                genericWin.ShowEditRow(false);
+
+               //select row corresponding to current signal
+               genericWin.SelectRowWithID(0, Convert.ToInt32(encoderSignalUniqueID)); //colNum, id
+               
                genericWin.CommentColumn = 9;
        
                genericWin.ShowButtonCancel(true);
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index ea05a89..f3fccb7 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -483,6 +483,14 @@ public class GenericWindow
                        treeview.ButtonReleaseEvent += on_treeview_button_release_event;
                }
        }
+
+       public void SelectRowWithID(int colNum, int id) 
+       {
+               if(id <= 0)
+                       return;
+
+               UtilGtk.TreeviewSelectRowWithID(treeview, store, colNum, id, true); //last boolean is 'scroll 
to row'
+       }
        
        public void MarkActiveCurves(string [] checkboxes) 
        {
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 1b277e9..6915978 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -227,6 +227,56 @@ public class UtilGtk
                return -1;
        }
 
+       //finds the row number (starting at 0) of a cell (usually an uniqueID in col 0)
+       private static int getRowNumOfThisID(Gtk.TreeStore store, int colNum, int searchedID) {
+               TreeIter iter;
+               int count = 0;
+               bool iterOk = store.GetIterFirst(out iter);
+               while(iterOk) {
+                       int thisID = Convert.ToInt32((string) store.GetValue (iter, colNum));
+                       if(thisID == searchedID)
+                               return count;
+                       
+                       count ++;
+                       store.IterNext(ref iter);
+               }
+               return -1;
+       }
+
+       //selects a row that has an uniqueID (usually at col 0)
+       public static void TreeviewSelectRowWithID(Gtk.TreeView tv, Gtk.TreeStore store, int colNum, int id, 
bool scrollToRow)
+       {
+               if(id <= 0)
+                       return;
+
+               int rowNum = getRowNumOfThisID(store, colNum, id);
+               if(rowNum == -1)
+                       return;
+
+               //set the selected
+               int count = 0;
+               TreeIter iter;
+               bool iterOk = store.GetIterFirst(out iter);
+               while(iterOk) {
+                       if(count == rowNum) {
+                               //1 select row
+                               tv.Selection.SelectIter(iter);
+               
+                               //2 scroll to that row
+                               if(scrollToRow) {
+                                       TreePath path = store.GetPath (iter);
+                                       LogB.Debug(path.ToString());
+                                       tv.ScrollToCell (path, tv.Columns[0], true, 0, 0);
+                               }
+
+                               return;
+                       }
+                       
+                       count ++;
+                       store.IterNext(ref iter);
+               }
+       }
+
        public static Gtk.TreeStore RemoveRow (Gtk.TreeView tv, Gtk.TreeStore store) {
                TreeModel model;
                TreeIter iter1;


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