From 77d2ebbda0669698c90c822a6bb32932a361db53 Mon Sep 17 00:00:00 2001 From: Christophe Serafin Date: Fri, 1 Mar 2013 11:57:24 +0100 Subject: [PATCH] adds shouldReorderColumn to CPTableView delegate methods --- AppKit/CPTableHeaderView.j | 2 +- AppKit/CPTableView.j | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 44c34e1ac..f828843df 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -455,7 +455,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal - (BOOL)_shouldDragTableColumn:(int)aColumnIndex at:(CGPoint)aPoint { - return [_tableView allowsColumnReordering] && ABS(aPoint.x - _mouseDownLocation.x) >= 10.0; + return [_tableView _shouldReorderColumn:aColumnIndex toColumn:-1] && ABS(aPoint.x - _mouseDownLocation.x) >= 10.0; } - (CGRect)_headerRectOfLastVisibleColumn diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 413468be5..6bc52d8f6 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -82,6 +82,7 @@ var CPTableViewDelegate_selectionShouldChangeInTableView_ CPTableViewDelegate_tableViewSelectionDidChange_ = 1 << 18, CPTableViewDelegate_tableViewSelectionIsChanging_ = 1 << 19, CPTableViewDelegate_tableViewMenuForTableColumn_Row_ = 1 << 20; + CPTableViewDelegate_tableView_shouldReorderColumn_toColumn_ = 1 << 21; //CPTableViewDraggingDestinationFeedbackStyles CPTableViewDraggingDestinationFeedbackStyleNone = -1; @@ -998,6 +999,21 @@ NOT YET IMPLEMENTED [self reloadDataForRowIndexes:_exposedRows columnIndexes:[CPIndexSet indexSetWithIndex:[_tableColumns indexOfObject:previouslyDraggedColumn]]]; } +/* + @ignore + Returns YES if the column at columnIndex can be reordered. + It can be possible if column reordering is allowed and if the tableview + delegate also accept the reordering +*/ +- (BOOL)_shouldReorderColumn:(int)columnIndex toColumn:(int)newColumnIndex +{ + if ([self allowsColumnReordering] + && _implementedDelegateMethods & CPTableViewDelegate_tableView_shouldReorderColumn_toColumn_) + return [_delegate tableView:self shouldReorderColumn:columnIndex toColumn:newColumnIndex]; + + return [self allowsColumnReordering]; +} + /* @ignore Same as moveColumn:toColumn: but doesn't trigger an autosave @@ -1011,6 +1027,9 @@ NOT YET IMPLEMENTED if (fromIndex === toIndex) return; + if (![self _shouldReorderColumn:fromIndex toColumn:toIndex]) + return; + if (_dirtyTableColumnRangeIndex < 0) _dirtyTableColumnRangeIndex = MIN(fromIndex, toIndex); else @@ -2575,6 +2594,8 @@ Informs the delegate that the tableview selection has changed. @section movingandresizingcolumsn Moving and Resizing Columns: Return YES if the column at a given index should move to a new column index, otherwise NO. +When a column is initially dragged by the user, the delegate is first called with a newColumnIndex value of -1 + @code - (BOOL)tableView:(CPTableView)tableView shouldReorderColumn:(int)columnIndex toColumn:(int)newColumnIndex; @endcode @@ -2726,6 +2747,10 @@ Your delegate can implement this method to avoid subclassing the tableview to ad if ([_delegate respondsToSelector:@selector(tableView:menuForTableColumn:row:)]) _implementedDelegateMethods |= CPTableViewDelegate_tableViewMenuForTableColumn_Row_; + if ([_delegate respondsToSelector:@selector(tableView:shouldReorderColumn:toColumn:)]) + _implementedDelegateMethods |= CPTableViewDelegate_tableView_shouldReorderColumn_toColumn_; + + if ([_delegate respondsToSelector:@selector(tableViewColumnDidMove:)]) [defaultCenter addObserver:_delegate