]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Merge branch 'tree2' of git://git.hohndel.org/subsurface
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Aug 2012 03:39:49 +0000 (20:39 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Aug 2012 03:39:49 +0000 (20:39 -0700)
Pull selection tracking fixes from Dirk Hohndel:
 "I just gave up on gtk tracking our selection.  Way too much pain.  The
  implementation below has seen some testing with the debugging code
  enabled and seems to work - but it needs more banging onto it, I'm
  sure.

  Ideally I'd like to leave the debug code in, ask people on the mailing
  list to play with it and report any inconsistencies.  After that I'll
  be happy to remove it again."

* 'tree2' of git://git.hohndel.org/subsurface:
  Stop relying on gtk to track which dives are selected

1  2 
divelist.c

diff --cc divelist.c
index de64bd88ceecf2b30ab91831382f30ee00666d8a,19ab600e8d6dec95121eb69b9221b4a74dc6dfab..0e1b40dd6f71abb64f9acd32082b6df06585875f
@@@ -79,6 -77,79 +79,78 @@@ static void dump_model(GtkListStore *st
  #endif
  
  static GList *selected_dives;
 -static int *selectiontracker;
+ static int st_size = 0;
+ gboolean is_in_st(int idx, int *atpos)
+ {
+       int i;
+       for (i = 0; i < amount_selected; i++)
+               if (selectiontracker[i] == idx) {
+                       if (atpos)
+                               *atpos = i;
+                       return TRUE;
+               }
+       return FALSE;
+ }
+ #if DEBUG_SELECTION_TRACKING
+ void dump_selection(void)
+ {
+       int i;
+       printf("currently selected are ");
+       for (i = 0; i < amount_selected; i++)
+               printf("%d ", selectiontracker[i]);
+       printf("\n");
+ }
+ #endif
+ void track_select(int idx)
+ {
+       if (idx < 0)
+               return;
+ #if DEBUG_SELECTION_TRACKING
+       printf("add %d to selection of %d entries\n", idx, amount_selected);
+ #endif
+       if (is_in_st(idx, NULL))
+               return;
+       if (amount_selected >= st_size) {
+               selectiontracker = realloc(selectiontracker, dive_table.nr * sizeof(int));
+               st_size = dive_table.nr;
+       }
+       selectiontracker[amount_selected] = idx;
+       amount_selected++;
+       if (amount_selected == 1)
+               selected_dive = idx;
+ #if DEBUG_SELECTION_TRACKING
+       printf("increased amount_selected to %d\n", amount_selected);
+       dump_selection();
+ #endif
+ }
+ void track_unselect(int idx)
+ {
+       if (idx < 0)
+               return;
+ #if DEBUG_SELECTION_TRACKING
+       printf("remove %d from selection of %d entries\n", idx, amount_selected);
+ #endif
+       int atpos;
+       if (! is_in_st(idx, &atpos))
+               return;
+       memmove(selectiontracker + atpos,
+               selectiontracker + atpos + 1,
+               (amount_selected - atpos - 1) * sizeof(int));
+       amount_selected--;
+ #if DEBUG_SELECTION_TRACKING
+       printf("removed %d at pos %d and decreased amount_selected to %d\n", idx, atpos, amount_selected);
+       dump_selection();
+ #endif
+ }
  
  /* when subsurface starts we want to have the last dive selected. So we simply
     walk to the first leaf (and skip the summary entries - which have negative