mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-27 20:57:40 +00:00
Merge pull request #1818 from t00f/master
New: tableView:shouldReorderColumn:toColumn: CPTableView delegate method
This commit is contained in:
@@ -229,6 +229,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
||||
CGPoint _previousTrackingLocation;
|
||||
int _activeColumn;
|
||||
int _pressedColumn;
|
||||
int _lastDragDestinationColumnIndex;
|
||||
|
||||
BOOL _isResizing;
|
||||
BOOL _isDragging;
|
||||
@@ -417,6 +418,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
||||
|
||||
- (void)startTrackingTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
|
||||
{
|
||||
_lastDragDestinationColumnIndex = -1;
|
||||
[self _setPressedColumn:aColumnIndex];
|
||||
}
|
||||
|
||||
@@ -455,7 +457,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
||||
|
||||
- (BOOL)_shouldDragTableColumn:(int)aColumnIndex at:(CGPoint)aPoint
|
||||
{
|
||||
return [_tableView allowsColumnReordering] && ABS(aPoint.x - _mouseDownLocation.x) >= 10.0;
|
||||
return ABS(aPoint.x - _mouseDownLocation.x) >= 10.0 && [_tableView _shouldReorderColumn:aColumnIndex toColumn:-1];
|
||||
}
|
||||
|
||||
- (CGRect)_headerRectOfLastVisibleColumn
|
||||
@@ -503,9 +505,12 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
||||
|
||||
- (void)_moveColumn:(int)aFromIndex toColumn:(int)aToIndex
|
||||
{
|
||||
[_tableView moveColumn:aFromIndex toColumn:aToIndex];
|
||||
_activeColumn = aToIndex;
|
||||
_pressedColumn = _activeColumn;
|
||||
if ([_tableView _shouldReorderColumn:aFromIndex toColumn:aToIndex])
|
||||
{
|
||||
[_tableView moveColumn:aFromIndex toColumn:aToIndex];
|
||||
_activeColumn = aToIndex;
|
||||
_pressedColumn = _activeColumn;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)draggedView:(CPView)aView beganAt:(CGPoint)aPoint
|
||||
@@ -541,14 +546,21 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
||||
|
||||
var hoveredColumn = [self columnAtPoint:hoverPoint];
|
||||
|
||||
if (hoveredColumn !== -1)
|
||||
if (hoveredColumn !== _lastDragDestinationColumnIndex && hoveredColumn !== -1)
|
||||
{
|
||||
var columnRect = [self headerRectOfColumn:hoveredColumn],
|
||||
columnCenterPoint = [self convertPoint:CGPointMake(CGRectGetMidX(columnRect), CGRectGetMidY(columnRect)) fromView:self];
|
||||
|
||||
if (hoveredColumn < _activeColumn && hoverPoint.x < columnCenterPoint.x)
|
||||
{
|
||||
[self _moveColumn:_activeColumn toColumn:hoveredColumn];
|
||||
_lastDragDestinationColumnIndex = hoveredColumn;
|
||||
}
|
||||
else if (hoveredColumn > _activeColumn && hoverPoint.x > columnCenterPoint.x)
|
||||
{
|
||||
[self _moveColumn:_activeColumn toColumn:hoveredColumn];
|
||||
_lastDragDestinationColumnIndex = hoveredColumn;
|
||||
}
|
||||
}
|
||||
|
||||
_previousTrackingLocation = aPoint;
|
||||
|
||||
@@ -83,6 +83,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;
|
||||
@@ -1067,6 +1068,23 @@ 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
|
||||
@@ -2660,6 +2678,8 @@ Informs the delegate that the tableview selection has changed.
|
||||
@section movingandresizingcolumns 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
|
||||
@@ -2814,6 +2834,9 @@ 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
|
||||
|
||||
@@ -45,4 +45,12 @@ CPLogRegister(CPLogConsole);
|
||||
return String((row + 1) * [[tableColumn identifier] intValue]);
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(CPTableView)tableView shouldReorderColumn:(int)columnIndex toColumn:(int)newColumnIndex
|
||||
{
|
||||
if (columnIndex === 0 || newColumnIndex === 4)
|
||||
return NO;
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
File diff suppressed because one or more lines are too long
@@ -2,13 +2,13 @@
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1050</int>
|
||||
<string key="IBDocument.SystemVersion">12C60</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">2843</string>
|
||||
<string key="IBDocument.AppKitVersion">1187.34</string>
|
||||
<string key="IBDocument.HIToolboxVersion">625.00</string>
|
||||
<string key="IBDocument.SystemVersion">12D78</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
|
||||
<string key="IBDocument.AppKitVersion">1187.37</string>
|
||||
<string key="IBDocument.HIToolboxVersion">626.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="NS.object.0">2843</string>
|
||||
<string key="NS.object.0">3084</string>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -74,7 +74,7 @@
|
||||
<string key="NSFrameSize">{644, 290}</string>
|
||||
<reference key="NSSuperview" ref="331394667"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="347610108"/>
|
||||
<reference key="NSNextKeyView" ref="480583225"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<bool key="NSControlAllowsExpansionToolTips">YES</bool>
|
||||
@@ -335,7 +335,7 @@
|
||||
<string key="NSFrame">{{502, 17}, {15, 275}}</string>
|
||||
<reference key="NSSuperview" ref="1048514227"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="480583225"/>
|
||||
<reference key="NSNextKeyView"/>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<reference key="NSTarget" ref="1048514227"/>
|
||||
<string key="NSAction">_doScroller:</string>
|
||||
@@ -347,7 +347,7 @@
|
||||
<string key="NSFrame">{{1, 291}, {644, 16}}</string>
|
||||
<reference key="NSSuperview" ref="1048514227"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView"/>
|
||||
<reference key="NSNextKeyView" ref="347610108"/>
|
||||
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
|
||||
<int key="NSsFlags">1</int>
|
||||
<reference key="NSTarget" ref="1048514227"/>
|
||||
@@ -425,6 +425,14 @@
|
||||
</object>
|
||||
<int key="connectionID">500</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">delegate</string>
|
||||
<reference key="source" ref="86489736"/>
|
||||
<reference key="destination" ref="635946545"/>
|
||||
</object>
|
||||
<int key="connectionID">513</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@@ -657,7 +665,7 @@
|
||||
<reference key="dict.values" ref="0"/>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">512</int>
|
||||
<int key="maxID">513</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
||||
Reference in New Issue
Block a user