mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
AppKit: Begin double-click editing only when a data source or binding accepts the value
Returning a flag constant instead of evaluating it allowed tables and outlines to initiate double-click edits even when neither the data source nor a binding supported storing the value. - CPTableView: Evaluate the setObjectValue capability against implemented data source methods rather than returning a static flag constant. - CPTableView: Track click slop on all clicks to ensure bound tables correctly reject edits after pointer movement. - CPOutlineView: Test whether the outline data source implements -outlineView:setObjectValue:forTableColumn:byItem: rather than inheriting the table view check. - CPTableViewInteractionTest: Add tests covering read-only data sources, bound tables, and movements within and beyond click slop thresholds. - CPOutlineViewInteractionTest: Add tests for outline data sources with and without -outlineView:setObjectValue:forTableColumn:byItem:.
This commit is contained in:
1 parent
9f76d9146f
commit
4f16e876b0
5 files changed
+208
-12
No files matched your search
@@ -2380,6 +2380,17 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
return _implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_objectValue_forTableColumn_byItem_;
|
||||
}
|
||||
|
||||
/*
|
||||
The outline view is its own table data source and implements
|
||||
tableView:setObjectValue:forTableColumn:row: for every outline data source. The table's
|
||||
check therefore answered YES, and a double click started an edit, although the outline
|
||||
data source could not store the value.
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToSetObjectValueForTableColumnRow
|
||||
{
|
||||
return _implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_setObjectValue_forTableColumn_byItem_;
|
||||
}
|
||||
|
||||
- (BOOL)_delegateRespondsToViewForTableColumn
|
||||
{
|
||||
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_viewForTableColumn_item_;
|
||||
|
||||
@@ -61,7 +61,12 @@
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToSetObjectValueForTableColumnRow
|
||||
{
|
||||
return CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_;
|
||||
/*
|
||||
The method returned the flag constant instead of testing it against the implemented
|
||||
methods, so it answered YES for every data source. A double click then started an edit
|
||||
that neither the data source nor a content binding could store.
|
||||
*/
|
||||
return _implementedDataSourceMethods & CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -72,8 +72,13 @@
|
||||
_startTrackingPoint = aPoint;
|
||||
_startTrackingTimestamp = new Date();
|
||||
|
||||
if ([self _dataSourceRespondsToSetObjectValueForTableColumnRow])
|
||||
_trackingPointMovedOutOfClickSlop = NO;
|
||||
/*
|
||||
The table tracked the click slop only for a data source that implements
|
||||
tableView:setObjectValue:forTableColumn:row:. A table that edits through its content
|
||||
binding needs the slop too, because the slop decides whether a double click starts
|
||||
an edit. The table now tracks it for every click.
|
||||
*/
|
||||
_trackingPointMovedOutOfClickSlop = NO;
|
||||
|
||||
// if the table has drag support then we use mouseUp to select a single row.
|
||||
// otherwise it uses mouse down.
|
||||
@@ -193,8 +198,8 @@
|
||||
[self _updateSelectionWithMouseAtRow:row];
|
||||
}
|
||||
|
||||
if ([self _dataSourceRespondsToSetObjectValueForTableColumnRow]
|
||||
&& !_trackingPointMovedOutOfClickSlop)
|
||||
// Track the click slop for every table; see -startTrackingAt:.
|
||||
if (!_trackingPointMovedOutOfClickSlop)
|
||||
{
|
||||
var CLICK_SPACE_DELTA = 5.0; // Stolen from AppKit/Platform/DOM/CPPlatformWindow+DOM.j
|
||||
if (ABS(aPoint.x - _startTrackingPoint.x) > CLICK_SPACE_DELTA
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
An outline view adds a parent to every row, so it reports a drag by item and a drop
|
||||
by parent item and child index. Selection and editing come from CPTableView, and
|
||||
CPTableViewInteractionTest.j covers them. These tests cover what an outline view
|
||||
changes.
|
||||
changes, including the outline data source's part in deciding whether a double click
|
||||
starts an edit.
|
||||
*/
|
||||
|
||||
var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
@@ -130,6 +131,46 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
An outline data source that stores an edited value.
|
||||
*/
|
||||
@implementation _CPOutlineInteractionEditingDataSource : _CPOutlineInteractionDataSource
|
||||
{
|
||||
CPArray editedItems @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
editedItems = [];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView setObjectValue:(id)aValue forTableColumn:(CPTableColumn)aColumn byItem:(id)anItem
|
||||
{
|
||||
editedItems.push(anItem);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
A delegate that permits every edit, so that only the data source decides whether a
|
||||
double click starts one.
|
||||
*/
|
||||
@implementation _CPOutlineInteractionEditingDelegate : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(CPOutlineView)anOutlineView shouldEditTableColumn:(CPTableColumn)aColumn item:(id)anItem
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPOutlineInteractionDraggingInfo : CPObject
|
||||
{
|
||||
CPPasteboard draggingPasteboard @accessors;
|
||||
@@ -187,6 +228,11 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
}
|
||||
|
||||
- (void)sendMouse:(CPEventType)aType atPoint:(CGPoint)aPoint
|
||||
{
|
||||
[self sendMouse:aType atPoint:aPoint clicks:1];
|
||||
}
|
||||
|
||||
- (void)sendMouse:(CPEventType)aType atPoint:(CGPoint)aPoint clicks:(int)aClickCount
|
||||
{
|
||||
var event = [CPEvent mouseEventWithType:aType
|
||||
location:[outlineView convertPoint:aPoint toView:nil]
|
||||
@@ -195,7 +241,7 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
windowNumber:[theWindow windowNumber]
|
||||
context:nil
|
||||
eventNumber:0
|
||||
clickCount:1
|
||||
clickCount:aClickCount
|
||||
pressure:0];
|
||||
|
||||
[CPApp sendEvent:event];
|
||||
@@ -345,4 +391,40 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
[self assertFalse:[outlineView isItemExpanded:@"C"]];
|
||||
}
|
||||
|
||||
// MARK: Editing
|
||||
|
||||
/*
|
||||
Makes the outline column editable, gives the outline view a delegate that permits every
|
||||
edit, and sends a double click on an item.
|
||||
*/
|
||||
- (void)doubleClickToEditItem:(id)anItem
|
||||
{
|
||||
var point = [self pointInItem:anItem];
|
||||
|
||||
[[outlineView outlineTableColumn] setEditable:YES];
|
||||
[outlineView setDelegate:[[_CPOutlineInteractionEditingDelegate alloc] init]];
|
||||
|
||||
[self sendMouse:CPLeftMouseDown atPoint:point clicks:1];
|
||||
[self sendMouse:CPLeftMouseUp atPoint:point clicks:1];
|
||||
[self sendMouse:CPLeftMouseDown atPoint:point clicks:2];
|
||||
[self sendMouse:CPLeftMouseUp atPoint:point clicks:2];
|
||||
}
|
||||
|
||||
- (void)testDoubleClickDoesNotStartAnEditThatTheDataSourceCannotStore
|
||||
{
|
||||
[self doubleClickToEditItem:@"B"];
|
||||
|
||||
[self assert:CPNotFound equals:[outlineView editedRow]];
|
||||
}
|
||||
|
||||
- (void)testDoubleClickStartsAnEditThatTheDataSourceCanStore
|
||||
{
|
||||
dataSource = [[_CPOutlineInteractionEditingDataSource alloc] init];
|
||||
[outlineView setDataSource:dataSource];
|
||||
|
||||
[self doubleClickToEditItem:@"B"];
|
||||
|
||||
[self assert:[outlineView rowForItem:@"B"] equals:[outlineView editedRow]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -49,10 +49,12 @@ var InteractionDragType = @"InteractionDragType";
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPTableInteractionDataSource : CPObject
|
||||
/*
|
||||
A data source that supplies values but cannot store an edited value.
|
||||
*/
|
||||
@implementation _CPTableInteractionReadOnlyDataSource : CPObject
|
||||
{
|
||||
CPArray rows @accessors;
|
||||
CPArray editedValues @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -60,10 +62,7 @@ var InteractionDragType = @"InteractionDragType";
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
rows = [@"Zero", @"One", @"Two", @"Three", @"Four"];
|
||||
editedValues = [];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -78,6 +77,23 @@ var InteractionDragType = @"InteractionDragType";
|
||||
return rows[aRow];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPTableInteractionDataSource : _CPTableInteractionReadOnlyDataSource
|
||||
{
|
||||
CPArray editedValues @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
editedValues = [];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)tableView:(CPTableView)aTableView setObjectValue:(id)aValue forTableColumn:(CPTableColumn)aColumn row:(int)aRow
|
||||
{
|
||||
editedValues.push({ @"row": aRow, @"value": aValue });
|
||||
@@ -597,6 +613,83 @@ var InteractionDragType = @"InteractionDragType";
|
||||
[self assert:CPNotFound equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
/*
|
||||
Removes the data source and binds the column to an array controller. The table then
|
||||
stores an edited value through its content binding.
|
||||
*/
|
||||
- (void)useBindings
|
||||
{
|
||||
var arrayController = [[CPArrayController alloc] initWithContent:[
|
||||
@{ @"name": @"Zero" },
|
||||
@{ @"name": @"One" },
|
||||
@{ @"name": @"Two" },
|
||||
@{ @"name": @"Three" },
|
||||
@{ @"name": @"Four" }
|
||||
]];
|
||||
|
||||
dataSource = nil;
|
||||
[tableView setDataSource:nil];
|
||||
[tableColumn bind:CPValueBinding toObject:arrayController withKeyPath:@"arrangedObjects.name" options:nil];
|
||||
[tableView reloadData];
|
||||
}
|
||||
|
||||
/*
|
||||
Sends a double click on a row whose second mouse-down moves the given distance before
|
||||
the mouse-up.
|
||||
*/
|
||||
- (void)doubleClickRow:(int)aRow movingBy:(float)aDistance
|
||||
{
|
||||
var start = [self pointInRow:aRow],
|
||||
end = CGPointMake(start.x + aDistance, start.y);
|
||||
|
||||
[self sendEvent:[self mouseEvent:CPLeftMouseDown atPoint:start flags:0 clicks:2]];
|
||||
[self sendEvent:[self mouseEvent:CPLeftMouseDragged atPoint:end flags:0 clicks:2]];
|
||||
[self sendEvent:[self mouseEvent:CPLeftMouseUp atPoint:end flags:0 clicks:2]];
|
||||
}
|
||||
|
||||
- (void)testDoubleClickDoesNotStartAnEditThatNothingCanStore
|
||||
{
|
||||
[self useDataSource:[[_CPTableInteractionReadOnlyDataSource alloc] init]];
|
||||
[self clickRow:1];
|
||||
[self clickPoint:[self pointInRow:1] flags:0 clicks:2];
|
||||
|
||||
[self assert:CPNotFound equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
- (void)testDoubleClickStartsEditingInABoundTable
|
||||
{
|
||||
[self useBindings];
|
||||
[self clickRow:1];
|
||||
[self clickPoint:[self pointInRow:1] flags:0 clicks:2];
|
||||
|
||||
[self assert:1 equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
- (void)testAMoveWithinTheClickSlopStillStartsAnEdit
|
||||
{
|
||||
[self clickRow:1];
|
||||
[self doubleClickRow:1 movingBy:3.0];
|
||||
|
||||
[self assert:1 equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
- (void)testAMoveBeyondTheClickSlopDoesNotStartAnEdit
|
||||
{
|
||||
[self clickRow:1];
|
||||
[self doubleClickRow:1 movingBy:10.0];
|
||||
|
||||
[self assert:CPNotFound equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
- (void)testAMoveBeyondTheClickSlopDoesNotStartAnEditInABoundTable
|
||||
{
|
||||
[self useBindings];
|
||||
[self clickRow:1];
|
||||
[self doubleClickRow:1 movingBy:10.0];
|
||||
|
||||
[self assert:CPNotFound equals:[tableView editedRow]];
|
||||
}
|
||||
|
||||
// MARK: Starting a drag
|
||||
|
||||
- (void)dragFromRow:(int)aRow toPoint:(CGPoint)aPoint
|
||||
|
||||
Reference in new issue
Block a user