From 56ccc9e5e7cfa1c7d88fe3884f12eaa696fa60a3 Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 7 Feb 2001 23:13:32 +0000 Subject: [PATCH] Restore the selected cells in reload column git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9046 72102866-910b-0410-8b05-ffd578937521 --- Source/NSBrowser.m | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Source/NSBrowser.m b/Source/NSBrowser.m index 4f1fbbc33..281e77b47 100644 --- a/Source/NSBrowser.m +++ b/Source/NSBrowser.m @@ -1024,6 +1024,10 @@ static float scrollerWidth; // == [NSScroller scrollerWidth] - (void)reloadColumn: (int)column { id bc; + NSArray *selectedCells; + NSMatrix *matrix; + int i, count, max; + int *selectedIndexes = NULL; #if defined NSBTRACE_reloadColumn || defined NSBTRACE_all fprintf(stderr, "NSBrowser - (void)reloadColumn: %d\n", column); @@ -1049,10 +1053,47 @@ static float scrollerWidth; // == [NSScroller scrollerWidth] return; } + // Save the index of the previously selected cells + matrix = [self matrixInColumn: column]; + selectedCells = [matrix selectedCells]; + count = [selectedCells count]; + if (count > 0) + { + selectedIndexes = NSZoneMalloc (NSDefaultMallocZone (), + sizeof (int) * count); + for (i = 0; i < count; i++) + { + NSCell *cell = [selectedCells objectAtIndex: i]; + int sRow, sColumn; + + [matrix getRow: &sRow column: &sColumn ofCell: cell]; + selectedIndexes[i] = sRow; + } + } + + // Perform the data load [self _performLoadOfColumn: column]; [self _adjustMatrixOfColumn: column]; + // Restore the selected cells + if (count > 0) + { + matrix = [self matrixInColumn: column]; + max = [matrix numberOfRows]; + for (i = 0; i < count; i++) + { + // Abort when it stops making sense + if (selectedIndexes[i] > max) + { + break; + } + + [matrix selectCellAtRow: selectedIndexes[i] column: 0]; + } + NSZoneFree (NSDefaultMallocZone (), selectedIndexes); + } + // set last column loaded [self setLastColumn: column]; }