From 27cda34f8bcd0c681f89c1503a32ecc091cea032 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Sat, 17 Mar 2012 16:05:00 +0100 Subject: [PATCH] CPTableView: When columns or rows dragging ends, enqueue the dragged views so they can be available when you drag again the column if they haven't been unloaded before. The 2nd time you drag the same column/row, reduces -dragViewFor... duration by 90% according to webkit profiling. --- AppKit/CPTableHeaderView.j | 2 ++ AppKit/CPTableView.j | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 3155ae5c7..78355d2f7 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -486,6 +486,8 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal [self stopTrackingTableColumn:_activeColumn at:aLocation]; [self setNeedsDisplay:YES]; + + [_tableView _enqueueDraggingViews]; } - (BOOL)shouldResizeTableColumn:(int)aColumnIndex at:(CGPoint)aPoint diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 9d2dbcb4d..bad25921c 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -235,6 +235,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; CPDragOperation _dragOperationDefaultMask; int _retargetedDropRow; CPDragOperation _retargetedDropOperation; + CPArray _draggingViews; BOOL _disableAutomaticResizing @accessors(property=disableAutomaticResizing); BOOL _lastColumnShouldSnap; @@ -357,6 +358,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; [self addSubview:_tableDrawView]; _draggedColumn = nil; + _draggingViews = [CPArray array]; /* //gradients for the source list when CPTableView is NOT first responder or the window is NOT key // FIX ME: we need to actually implement this. @@ -2833,7 +2835,8 @@ Your delegate can implement this method to avoid subclassing the tableview to ad [tableColumn _prepareDataView:dataView forRow:row]; [view addSubview:dataView]; - + [_draggingViews addObject:dataView]; + row = [theDraggedRows indexGreaterThanIndex:row]; } } @@ -2874,6 +2877,7 @@ Your delegate can implement this method to avoid subclassing the tableview to ad [dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]]; [dragView addSubview:dataView]; + [_draggingViews addObject:dataView]; row = [_exposedRows indexGreaterThanIndex:row]; } @@ -4248,6 +4252,7 @@ Your delegate can implement this method to avoid subclassing the tableview to ad _retargetedDropRow = nil; _draggedRowIndexes = [CPIndexSet indexSet]; [_dropOperationFeedbackView removeFromSuperview]; + [self _enqueueDraggingViews]; } /* @@ -4436,6 +4441,16 @@ Your delegate can implement this method to avoid subclassing the tableview to ad [self draggedImage:aView endedAt:aLocation operation:anOperation]; } +- (void)_enqueueDraggingViews +{ + [_draggingViews enumerateObjectsUsingBlock:function(dataView, idx) + { + [self _enqueueReusableDataView:dataView]; + }]; + + [_draggingViews removeAllObjects]; +} + /*! @ignore */