mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
AppKit: Derive outline drag support from the outline data source
Relying on table view drag checks caused outlines to select rows on mouse-up and incorrectly accept drop preparation even when the outline data source lacked drag support. - CPOutlineView: Test whether the outline data source implements -outlineView:writeItems:toPasteboard: and -outlineView:validateDrop:proposedItem:proposedChildIndex: rather than relying on table view checks. - CPOutlineViewInteractionTest: Add tests covering row selection timing and drop preparation with and without outline data source drag support.
This commit is contained in:
1 parent
4f16e876b0
commit
38892b043b
2 files changed
+94
-11
No files matched your search
@@ -2391,6 +2391,26 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
return _implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_setObjectValue_forTableColumn_byItem_;
|
||||
}
|
||||
|
||||
/*
|
||||
The outline view implements tableView:writeRowsWithIndexes:toPasteboard: for every outline
|
||||
data source, so the table's check answered YES. Every outline therefore selected a row on
|
||||
mouse-up instead of mouse-down, as only a table that can start a drag does.
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToWriteRowsWithIndexesToPasteboard
|
||||
{
|
||||
return _implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_writeItems_toPasteboard_;
|
||||
}
|
||||
|
||||
/*
|
||||
The outline view implements tableView:validateDrop:proposedRow:proposedDropOperation: for
|
||||
every outline data source, so the table's check answered YES, and every outline accepted
|
||||
the preparation of a drop that its data source could not validate.
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToValidateDropProposedRowProposedDropOperation
|
||||
{
|
||||
return _implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_validateDrop_proposedItem_proposedChildIndex_;
|
||||
}
|
||||
|
||||
- (BOOL)_delegateRespondsToViewForTableColumn
|
||||
{
|
||||
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_viewForTableColumn_item_;
|
||||
|
||||
@@ -26,8 +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, including the outline data source's part in deciding whether a double click
|
||||
starts an edit.
|
||||
changes, including the outline data source's part in deciding when a click selects a
|
||||
row, whether a drop can be prepared and whether a double click starts an edit.
|
||||
*/
|
||||
|
||||
var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
@@ -47,15 +47,12 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPOutlineInteractionDataSource : CPObject
|
||||
/*
|
||||
An outline data source that supplies items and values, with no drag methods.
|
||||
*/
|
||||
@implementation _CPOutlineInteractionBasicDataSource : CPObject
|
||||
{
|
||||
id tree @accessors;
|
||||
CPArray writtenItems @accessors;
|
||||
CPArray validations @accessors;
|
||||
CPArray acceptedDrops @accessors;
|
||||
id retargetItem @accessors;
|
||||
id retargetIndex @accessors;
|
||||
BOOL shouldRetarget @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -70,8 +67,6 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
@"B": [],
|
||||
@"C": [@"C1"]
|
||||
};
|
||||
validations = [];
|
||||
acceptedDrops = [];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -102,6 +97,34 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
return anItem;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
An outline data source that writes dragged items and validates and accepts drops.
|
||||
*/
|
||||
@implementation _CPOutlineInteractionDataSource : _CPOutlineInteractionBasicDataSource
|
||||
{
|
||||
CPArray writtenItems @accessors;
|
||||
CPArray validations @accessors;
|
||||
CPArray acceptedDrops @accessors;
|
||||
id retargetItem @accessors;
|
||||
id retargetIndex @accessors;
|
||||
BOOL shouldRetarget @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
validations = [];
|
||||
acceptedDrops = [];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(CPOutlineView)anOutlineView writeItems:(CPArray)theItems toPasteboard:(CPPasteboard)aPasteboard
|
||||
{
|
||||
writtenItems = theItems;
|
||||
@@ -391,6 +414,46 @@ var OutlineInteractionDragType = @"OutlineInteractionDragType";
|
||||
[self assertFalse:[outlineView isItemExpanded:@"C"]];
|
||||
}
|
||||
|
||||
// MARK: Drag support
|
||||
|
||||
/*
|
||||
A table that can start a drag selects a row on mouse-up, so that a drag from an
|
||||
unselected row does not change the selection first. An outline must decide this from
|
||||
its own data source.
|
||||
*/
|
||||
- (void)testAnOutlineWithoutDragSupportSelectsOnMouseDown
|
||||
{
|
||||
[outlineView setDataSource:[[_CPOutlineInteractionBasicDataSource alloc] init]];
|
||||
[self sendMouse:CPLeftMouseDown atPoint:[self pointInItem:@"B"]];
|
||||
|
||||
[self assert:[outlineView rowForItem:@"B"] equals:[outlineView selectedRow]];
|
||||
}
|
||||
|
||||
- (void)testAnOutlineWithDragSupportSelectsOnMouseUp
|
||||
{
|
||||
var point = [self pointInItem:@"B"];
|
||||
|
||||
[self sendMouse:CPLeftMouseDown atPoint:point];
|
||||
|
||||
[self assert:CPNotFound equals:[outlineView selectedRow] message:@"mouse-down must not select"];
|
||||
|
||||
[self sendMouse:CPLeftMouseUp atPoint:point];
|
||||
|
||||
[self assert:[outlineView rowForItem:@"B"] equals:[outlineView selectedRow]];
|
||||
}
|
||||
|
||||
- (void)testAnOutlineWithoutDropSupportRefusesToPrepareADrop
|
||||
{
|
||||
[outlineView setDataSource:[[_CPOutlineInteractionBasicDataSource alloc] init]];
|
||||
|
||||
[self assertFalse:[outlineView prepareForDragOperation:[self draggingInfoAtPoint:[self pointInItem:@"B"]]]];
|
||||
}
|
||||
|
||||
- (void)testAnOutlineWithDropSupportPreparesADrop
|
||||
{
|
||||
[self assertTrue:[outlineView prepareForDragOperation:[self draggingInfoAtPoint:[self pointInItem:@"B"]]]];
|
||||
}
|
||||
|
||||
// MARK: Editing
|
||||
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user