On 2007-02-05 09:04:47 -0800 Matt Rice <[EMAIL PROTECTED]> wrote:

On 2007-02-05 07:09:26 -0800 Matt Rice <[EMAIL PROTECTED]> wrote:

On 2007-02-04 09:19:24 -0800 Guenther Noack <[EMAIL PROTECTED]> wrote:

Hi!

Playing around with outline drag&drop, I found some other
selection-related issues in NSOutlineView:

- Inconsistency

The NSOutlineView method -noteNumberOfRowsChanged forgets about the
case where only one item is allowed to be selected. This leads to
inconsistencies within NSTableView which result in wrongly selected
rows in outline views. It can be fixed by adding this code snippet
before the -setFrame call:

if ([_selectedRows count] == 0) {
    _selectedRow = -1;
} else {
    _selectedRow = [_selectedRows lastIndex];
}


I really don't think that -noteNumberOfRowsChanged makes any sense for NSOutlineView because its a public method, and can be called seperate from -reloadData
at the beginning it goes

_numberOfRows = [_items count];

If -reloadData is not called... this doesn't go to the delegate to get the new number of rows well it really cant in any good way which would be more optimal than reloadData,
and I couldn't get this to do anything on a mac

Ok so i think i'm going to recant this and there were problems with the patch anyways...
it could be useful if you can get it to modify _items before calling
noteNumberOfRowsChanged then call setNeedsDisplayInRect: or something...

attached is a new patch which just removes the _selectedObjects,
and removes the subclassed implementation of noteNumberOfRowsChanged
and implements a private method to make NSTableViews implementation
work with NSOutlineView.


forgot to attach it

<NSOutlineView2.diff>
Index: NSTableView.m
===================================================================
--- NSTableView.m       (revision 24469)
+++ NSTableView.m       (working copy)
@@ -133,6 +133,7 @@
 
 - (BOOL) _isCellEditableColumn: (int) columnIndex
                           row: (int) rowIndex;
+- (int) _numRows;
 @end
 
 @interface NSTableView (SelectionHelper)
@@ -4728,7 +4729,7 @@
 */
 - (void) noteNumberOfRowsChanged
 {
-  _numberOfRows = [_dataSource numberOfRowsInTableView: self];
+  _numberOfRows = [self _numRows];
  
   /* If we are selecting rows, we have to check that we have no
      selected rows below the new end of the table */
@@ -6487,6 +6488,11 @@
     }
 }
 
+- (int) _numRows
+{
+  return [_dataSource numberOfRowsInTableView:self];
+}
+
 - (BOOL) _isDraggingSource
 {
   return [_dataSource respondsToSelector:
Index: NSOutlineView.m
===================================================================
--- NSOutlineView.m     (revision 24467)
+++ NSOutlineView.m     (working copy)
@@ -98,6 +98,7 @@
 - (void) _setObjectValue: (id)value
          forTableColumn: (NSTableColumn *)tb
                     row: (int) index;
+- (int) _numRows;
 @end
 
 // These methods are private...
@@ -150,7 +151,6 @@
                               64);
   _items = [[NSMutableArray alloc] init];
   _expandedItems = [[NSMutableArray alloc] init];
-  _selectedItems = [[NSMutableArray alloc] init];
   _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
                                   NSObjectMapValueCallBacks,
                                   64);
@@ -161,7 +161,6 @@
 {
   RELEASE(_items);
   RELEASE(_expandedItems);
-  RELEASE(_selectedItems);
 
   NSFreeMapTable(_itemDict);
   NSFreeMapTable(_levelOfItems);
@@ -227,7 +226,6 @@
   if ([self isExpandable: item] && [self isItemExpanded: item] && canCollapse)
     {
       NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
-      unsigned int row;
 
       [infoDict setObject: item forKey: @"NSObject"];
       
@@ -237,18 +235,6 @@
          object: self
          userInfo: infoDict];
       
-      // We save the selection
-      [_selectedItems removeAllObjects];
-      row = [_selectedRows firstIndex];
-      while (row != NSNotFound)
-        {
-         if ([self itemAtRow: row])
-           {
-             [_selectedItems addObject: [self itemAtRow: row]];
-           }
-         row = [_selectedRows indexGreaterThanIndex: row];
-       }
-
       // collapse...
       [self _closeItem: item];
 
@@ -316,7 +302,6 @@
       if (![self isItemExpanded: item] && canExpand)
        {
          NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
-         unsigned int row;
 
          [infoDict setObject: item forKey: @"NSObject"];
          
@@ -326,18 +311,6 @@
              object: self
              userInfo: infoDict];
          
-         // We save the selection
-         [_selectedItems removeAllObjects];
-         row = [_selectedRows firstIndex];
-         while (row != NSNotFound)
-           {
-             if ([self itemAtRow: row])
-               {
-                 [_selectedItems addObject: [self itemAtRow: row]];
-               }
-             row = [_selectedRows indexGreaterThanIndex: row];
-           }
-         
          // insert the root element, if necessary otherwise insert the
          // actual object.
          [self _openItem: item];
@@ -617,53 +590,7 @@
   return YES;
 }
 
-
 /**
- *  We override the super class's method.
- */
-- (void) noteNumberOfRowsChanged
-{
-  _numberOfRows = [_items count];
-
-  if (!_selectingColumns)
-    {
-      int i, count, row;
-      
-      /* We restore the selection */
-      [_selectedRows removeAllIndexes];
-      count = [_selectedItems count];
-
-      for (i = 0; i < count; i++)
-       {
-         row = [self rowForItem: [_selectedItems objectAtIndex: i]];
-
-         if (row >= 0 && row < _numberOfRows)
-           {
-             [_selectedRows addIndex: row];
-           }
-       }
-    }
-
-  [self setFrame: NSMakeRect (_frame.origin.x, 
-                             _frame.origin.y,
-                             _frame.size.width, 
-                             (_numberOfRows * _rowHeight) + 1)];
-  
-  /* If we are shorter in height than the enclosing clipview, we
-     should redraw us now. */
-  if (_super_view != nil)
-    {
-      NSRect superviewBounds; // Get this *after* [self setFrame:]
-      superviewBounds = [_super_view bounds];
-      if ((superviewBounds.origin.x <= _frame.origin.x) 
-          && (NSMaxY (superviewBounds) >= NSMaxY (_frame)))
-       {
-         [self setNeedsDisplay: YES];
-       }
-    }
-}
-
-/**
  * Sets the data source for this outline view. 
  */
 - (void) setDataSource: (id)anObject
@@ -782,7 +709,6 @@
                                   64);
       _items = [[NSMutableArray alloc] init];
       _expandedItems = [[NSMutableArray alloc] init];
-      _selectedItems = [[NSMutableArray alloc] init];
       _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
                                       NSObjectMapValueCallBacks,
                                       64);
@@ -816,7 +742,6 @@
                                   64);
       _items = [[NSMutableArray alloc] init];
       _expandedItems = [[NSMutableArray alloc] init];
-      _selectedItems = [[NSMutableArray alloc] init];
       _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
                                       NSObjectMapValueCallBacks,
                                       64); 
@@ -1706,6 +1631,11 @@
     }
 }
 
+- (int) _numRows
+{
+  return [_items count];
+}
+
 @end
 
 @implementation NSOutlineView (TableViewInternalPrivate)
@@ -1898,7 +1828,6 @@
       NSMapRemove(_itemDict, child); 
       [_items removeObject: child];
       [_expandedItems removeObject: child];
-      [_selectedItems removeObject: child];
     }
   [anarray removeAllObjects];
 }
_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to