[chronojump] TagSession sort alphabetical (no case), insert works on alphabetical row



commit 79ffa5cd3ab8cd7c33076463e03a3036a3d3c1c4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Dec 1 17:22:21 2020 +0100

    TagSession sort alphabetical (no case), insert works on alphabetical row

 src/gui/app1/encoder.cs                  |  2 +-
 src/gui/app1/session/tagSessionSelect.cs | 12 ++----------
 src/gui/executeAuto.cs                   |  6 +++---
 src/gui/genericWindow.cs                 | 29 +++++++++++++++++++++++++++--
 src/sqlite/tagSession.cs                 |  4 ++--
 src/utilGtk.cs                           | 10 +++++-----
 6 files changed, 40 insertions(+), 23 deletions(-)
---
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index af37eb59..a928ed6d 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -1201,7 +1201,7 @@ public partial class ChronoJumpWindow
                int uniqueID = SqliteEncoder.Insert1RM(false, currentPerson.UniqueID, 
currentSession.UniqueID, 
                                getExerciseIDFromEncoderCombo (exerciseCombos.CAPTURE), 
genericWin.SpinDouble2Selected);
 
-               genericWin.Row_add(new string[] {
+               genericWin.Row_add_beginning_or_end (new string[] {
                                uniqueID.ToString(), currentPerson.Name, 
UtilGtk.ComboGetActive(combo_encoder_exercise_capture),
                                d.ToString(), currentSession.DateShort
                                }, true
diff --git a/src/gui/app1/session/tagSessionSelect.cs b/src/gui/app1/session/tagSessionSelect.cs
index a0ae7ee9..5a7ec94c 100644
--- a/src/gui/app1/session/tagSessionSelect.cs
+++ b/src/gui/app1/session/tagSessionSelect.cs
@@ -208,18 +208,10 @@ public class TagSessionSelect
 
                TagSession ts = new TagSession(-1, nameNew, "#000000", "");
                int uniqueID = ts.InsertSQL(false);
+               genericWin.Entry2Selected = "";
 
-               /*
                //update treeview
-               genericWin.on_edit_selected_done_update_treeview();
-               */
-               genericWin.Row_add(new string[] { uniqueID.ToString(), "", ts.Name }, false );
-               //aixo no acaba d'anar bé pq el seu checkbox no va després, potser el millor és refer el 
treeview, a veure que es fa al delete
-               //i si no el refa, com a mínim que afegeixi la row en ordre alfabètic
-
-//TODO: Add button should only be active when entry2 changed, can check "on_entries_changed"
-
-               genericWin.Entry2Selected = "";
+               genericWin.Row_add_alphabetical (new string[] { uniqueID.ToString(), "", ts.Name }, 2);
        }
 
        private void on_tag_session_win_row_edit (object o, EventArgs args)
diff --git a/src/gui/executeAuto.cs b/src/gui/executeAuto.cs
index 7ed7ba6a..e842cb93 100644
--- a/src/gui/executeAuto.cs
+++ b/src/gui/executeAuto.cs
@@ -417,17 +417,17 @@ public class ExecuteAutoWindow
                {
                        treeviewSerie1Array.Add(tc);
                        UtilGtk.TreeviewAddRow(treeview_serie1, store_serie1, 
-                                       new String [] { treeviewSerie1Array.Count.ToString(), tc.trName }, 
false ); //at end
+                                       new String [] { treeviewSerie1Array.Count.ToString(), tc.trName }, -1 
); //at end
                } else if(treeviewNum == 2) 
                {
                        treeviewSerie2Array.Add(tc);
                        UtilGtk.TreeviewAddRow(treeview_serie2, store_serie2, 
-                                       new String [] { treeviewSerie2Array.Count.ToString(), tc.trName }, 
false ); //at end
+                                       new String [] { treeviewSerie2Array.Count.ToString(), tc.trName }, -1 
); //at end
                } else 
                {       //treeviewNum == 3
                        treeviewSerie3Array.Add(tc);
                        UtilGtk.TreeviewAddRow(treeview_serie3, store_serie3, 
-                                       new String [] { treeviewSerie3Array.Count.ToString(), tc.trName }, 
false ); //at end
+                                       new String [] { treeviewSerie3Array.Count.ToString(), tc.trName }, -1 
); //at end
                }
                
                button_save.Sensitive = (treeviewSerie1Array.Count > 0 && 
entry_save_name.Text.ToString().Length > 0);
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index d03d0472..40491372 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -975,8 +975,33 @@ public class GenericWindow
        }
 
        //add row to treeview
-       public void Row_add(string [] row, bool atBeginning) {
-               UtilGtk.TreeviewAddRow(treeview, store, row, atBeginning);
+       public void Row_add_beginning_or_end (string [] row, bool atBeginning)
+       {
+               if(atBeginning)
+                       UtilGtk.TreeviewAddRow(treeview, store, row, 0);
+               else
+                       UtilGtk.TreeviewAddRow(treeview, store, row, -1);
+       }
+       //columnAlphabetical is the column that is going to be checked
+       public void Row_add_alphabetical (string [] row, int columnAlphabetical)
+       {
+               int rowToInsert = 0;
+               Gtk.TreeIter iter;
+               bool okIter = store.GetIterFirst(out iter);
+               if(okIter) {
+                       do {
+                               string word = (string) store.GetValue (iter, columnAlphabetical);
+                               LogB.Information(string.Format("row[columnAphabetical]: {0}, word: {1}, 
compare: {2}",
+                                                       row[columnAlphabetical], word, 
row[columnAlphabetical].ToLower().CompareTo(word.ToLower()) > 0));
+                               if(row[columnAlphabetical].ToLower().CompareTo(word.ToLower()) > 0)
+                                       rowToInsert ++;
+                               else
+                                       break;
+                       } while ( store.IterNext(ref iter) );
+               }
+
+               LogB.Information("Row to insert: " + rowToInsert.ToString());
+               UtilGtk.TreeviewAddRow(treeview, store, row, rowToInsert);
        }
        
        public void ShowTextview() {
diff --git a/src/sqlite/tagSession.cs b/src/sqlite/tagSession.cs
index be0de32b..eeeea302 100644
--- a/src/sqlite/tagSession.cs
+++ b/src/sqlite/tagSession.cs
@@ -78,7 +78,7 @@ class SqliteTagSession : Sqlite
                if(uniqueID != -1)
                        uniqueIDStr = " WHERE " + table + ".uniqueID = " + uniqueID;
 
-               dbcmd.CommandText = selectStr + uniqueIDStr + " Order BY " + table + ".name";
+               dbcmd.CommandText = selectStr + uniqueIDStr + " Order BY LOWER(" + table + ".name)";
 
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -179,7 +179,7 @@ class SqliteSessionTagSession : Sqlite
 
                dbcmd.CommandText = "SELECT tagSession.* FROM tagSession, sessionTagSession " +
                        "WHERE tagSession.uniqueID = sessionTagSession.tagSessionID AND " +
-                       "sessionTagSession.sessionID = " + sessionID + " ORDER BY NAME";
+                       "sessionTagSession.sessionID = " + sessionID + " ORDER BY LOWER(NAME)";
 
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 9df682e8..5b0c68f7 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -414,15 +414,15 @@ public class UtilGtk
                return tv;
        }
 
-       //startOrEnd is true at start, false at end
-       public static void TreeviewAddRow(Gtk.TreeView tv, TreeStore store, string [] row, bool startOrEnd) {
+       //position 0 is start, -1 is end
+       public static void TreeviewAddRow(Gtk.TreeView tv, TreeStore store, string [] row, int position) {
                TreeIter iter = new TreeIter();
                store.GetIterFirst(out iter);
                
-               if(startOrEnd)
-                       iter = store.InsertWithValues(0,row);
-               else
+               if(position == -1)
                        iter = store.AppendValues(row);
+               else
+                       iter = store.InsertWithValues(position, row);
 
                //scroll treeview if needed
                TreePath path = store.GetPath (iter);


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