diff --git a/AppKit/CPOutlineView.j b/AppKit/CPOutlineView.j index 141b7dbe8..eb057f470 100644 --- a/AppKit/CPOutlineView.j +++ b/AppKit/CPOutlineView.j @@ -55,7 +55,7 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ CPOutlineViewDelegate_outlineView_shouldSelectItem_ = 1 << 2; CPOutlineViewDelegate_outlineView_heightOfRowByItem_ = 1 << 3; - +CPOutlineViewDropOnItemIndex = -1; @implementation CPOutlineView : CPTableView { @@ -342,7 +342,13 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ if (!itemInfo) return nil; - return itemInfo.parent; + var parent = itemInfo.parent; + + // Check if the parent is the root item because we never return the actual root item + if (itemInfo[[parent UID]] === _rootItemInfo) + parent = nil; + + return parent; } - (CGRect)frameOfOutlineDataViewAtColumn:(CPInteger)aColumn row:(CPInteger)aRow @@ -500,14 +506,52 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ return [super frameOfDataViewAtColumn:aColumn row:aRow]; } +- (void)setDropItem:(id)theItem dropChildIndex:(int)theIndex +{ + // var dropRow = [self rowForItem:theItem], + // dropOperation = CPTableViewDropOn; + // + // if (theIndex !== CPOutlineViewDropOnItemIndex) + // { + // dropOperation = CPTableViewDropAbove; + // + // var itemInfo = _itemInfosForItems[[theItem UID]]; + // + // if (!itemInfo) + // itemInfo = _rootItemInfo; + // + // var children = itemInfo.children; + // + // if (theIndex < [children count]) + // { + // childItem = [children objectAtIndex:theIndex]; + // itemInfo = _itemInfosForItems[[childItem UID]]; + // dropRow = itemInfo.row; + // } + // else + // { + // // We dropped outside of the range of children for this item + // // Determine the tableviews dropped row indexes by asking for the row index of the last item + 1 + // dropRow = [self rowForItem:[children lastObject]] + 1; + // } + // + // // CPLog.debug(@"changed drop operation: %i", dropOperation); + // } + // + // CPLog.debug(@"set drop row: %i operation: %i", dropRow, dropOperation); + // + // [self setDropRow:dropRow dropOperation:dropOperation]; + +} + - (id)_parentItemForRow:(int)theLowerRow andUpperRow:(int)theUpperRow atMouseOffset:(float)theXOffset { var level = [self levelForRow:theLowerRow], upperLevel = [self levelForRow:theUpperRow]; // If the row above us has a higher level the item can be added to multiple parent items - // Determine which one by looping through all possible parents and return the first one - // which indentation level is larger than the current x offset + // Determine which one by looping through all possible parents and return the first + // of which the indentation level is larger than the current x offset if (upperLevel > level) { while (level !== 0) @@ -516,7 +560,10 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_ // See if this item's indentation level matches the mouse offset if (theXOffset > (level + 1) * [self indentationPerLevel]) + { + // CPLog.debug(@"parent for item: %@ : %@", anItem, parent); return [self parentForItem:[self itemAtRow:theUpperRow]]; + } // Check the next parent theUpperRow = [self rowForItem:[self parentForItem:[self itemAtRow:theUpperRow]]]; @@ -863,15 +910,15 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt var parentItem = [_outlineView _parentItemForRow:theRow andUpperRow:theRow - 1 atMouseOffset:theXOffset], itemInfo = (parentItem !== nil) ? _outlineView._itemInfosForItems[[parentItem UID]] : _outlineView._rootItemInfo, children = itemInfo.children; - - childIndex = [children indexOfObject:[_outlineView itemAtRow:theRow]]; + + childIndex = [children indexOfObject:[_outlineView itemAtRow:theRow]]; if (childIndex === CPNotFound) childIndex = children.length; } else if (theDropOperation === CPTableViewDropOn) childIndex = -1; - + return childIndex; } @@ -889,11 +936,11 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt { if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_validateDrop_proposedItem_proposedChildIndex_)) return CPDragOperationNone; - + var location = [_outlineView convertPoint:[theInfo draggingLocation] fromView:nil], childIndex = [self _childIndexForDropOperation:theOperation row:theRow offset:location.x], parentItem = [self _parentItemForDropOperation:theOperation row:theRow offset:location.x]; - + return [_outlineView._outlineViewDataSource outlineView:_outlineView validateDrop:theInfo proposedItem:parentItem proposedChildIndex:childIndex]; } diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index e8c7deee3..d5568a72e 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1163,7 +1163,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; var row = FLOOR(y / (_rowHeight + _intercellSpacing.height)); - if (row >= _numberOfRows) + if (row > _numberOfRows) return -1; return row; @@ -2332,7 +2332,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; // begin the drag is the datasource lets us, we've move at least +-3px vertical or horizontal, or we're dragging from selected rows and we haven't begun a drag session if ( - !canSelect || (!_isSelectingSession && + (!_isSelectingSession && (_implementedDataSourceMethods & CPTableViewDataSource_tableView_writeRowsWithIndexes_toPasteboard_) && ( (lastPoint.x - aPoint.x > 3 || (_verticalMotionCanDrag && ABS(lastPoint.y - aPoint.y) > 3)) @@ -2530,12 +2530,12 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; var row = [self rowAtPoint:theDragPoint], rowRect = [self rectOfRow:row]; - + // If there is no (the default) or to little inter cell spacing we create some room for the CPTableViewDropAbove indicator // This probably doesn't work if the row height is smaller than or around 5.0 if ([self intercellSpacing].height < 5.0) rowRect = CPRectInset(rowRect, 0.0, 5.0 - [self intercellSpacing].height); - + if (CGRectContainsPoint(rowRect, theDragPoint)) return CPTableViewDropOn; @@ -2576,7 +2576,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; { if (theLowerRowIndex > [self numberOfRows]) theLowerRowIndex = [self numberOfRows]; - + return [self rectOfRow:theLowerRowIndex]; } @@ -2589,20 +2589,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; var row = [self _proposedRowAtPoint:location], dragOperation = [self _validateDrop:sender proposedRow:row proposedDropOperation:dropOperation]; exposedClipRect = [self exposedClipRect]; - + if(_retargetedDropRow !== nil) row = _retargetedDropRow; - - //if the user forces -1 then we should highlight the whole tableview - // var rowRect = CPRectMakeZero(); - // if(_retargetedDropRow === -1 || row === -1) - // rowRect = [self exposedClipRect]; - // else - // rowRect = [self rectOfRow:row]; - // - // visibleWidth = _CGRectGetWidth(exposedClipRect); - // - // rowRect = _CGRectMake(_CGRectGetMinX(exposedClipRect), rowRect.origin.y, visibleWidth, rowRect.size.height); var rect = CPRectMakeZero(); @@ -2615,6 +2604,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; else rect = [self _rectForDropHighlightViewOnRow:row]; + CPLog.debug(@"dropped row: %i", row); [_dropOperationFeedbackView setDropOperation:row !== -1 ? dropOperation : CPDragOperationNone]; [_dropOperationFeedbackView setHidden:(dragOperation == CPDragOperationNone)]; [_dropOperationFeedbackView setFrame:rect]; @@ -3044,11 +3034,13 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey", CGContextSetStrokeColor(context, [CPColor colorWithHexString:@"4886ca"]); CGContextSetLineWidth(context, 3); - - if (currentRow === -1) - CGContextStrokeRect(context, [self bounds]); - - else if(dropOperation === CPTableViewDropOn) + + if (currentRow === -1) + { + CGContextStrokeRect(context, [self bounds]); + } + + else if (dropOperation === CPTableViewDropOn) { //if row is selected don't fill and stroke white var selectedRows = [tableView selectedRowIndexes]; @@ -3100,6 +3092,7 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey", CGContextStrokePath(context); //CGContextStrokeLineSegments(context, [aRect.origin.x + 8, aRect.origin.y + 8, 300 , aRect.origin.y + 8]); } + } @end diff --git a/Tests/Manual/CPOutlineViewTest/AppController.j b/Tests/Manual/CPOutlineViewTest/AppController.j index 9683b8846..314d6783a 100644 --- a/Tests/Manual/CPOutlineViewTest/AppController.j +++ b/Tests/Manual/CPOutlineViewTest/AppController.j @@ -270,6 +270,7 @@ CustomOutlineViewDragType = @"CustomOutlineViewDragType"; theItem = [self menu]; CPLog.debug(@"validate item: %@ at index: %i", theItem, theIndex); + [anOutlineView setDropItem:theItem dropChildIndex:theIndex]; return CPDragOperationEvery; } diff --git a/Tests/Manual/TableTest/AppController.j b/Tests/Manual/TableTest/AppController.j index 74d949c1b..59617ce2e 100644 --- a/Tests/Manual/TableTest/AppController.j +++ b/Tests/Manual/TableTest/AppController.j @@ -55,6 +55,7 @@ CPLogRegister(CPLogConsole); [iconColumn setDataView:iconView]; [tableView addTableColumn:iconColumn]; + [tableView setVerticalMotionCanBeginDrag:YES]; iconImage = [[CPImage alloc] initWithContentsOfFile:"http://cappuccino.org/images/favicon.png" size:CGSizeMake(16,16)];