mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-09 16:38:45 +00:00
Merge pull request #1996 from rgv151/master
PATCH: Implement shouldExpand/Collapse delegate for CPOutlineView
This commit is contained in:
commit
ed99833894
2 files changed
+78
No files matched your search
@@ -352,6 +352,10 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
|
||||
*/
|
||||
- (void)expandItem:(id)anItem expandChildren:(BOOL)shouldExpandChildren
|
||||
{
|
||||
if ([self _delegateRespondsToShouldExpandItem])
|
||||
if ([_outlineViewDelegate outlineView:self shouldExpandItem:anItem] == NO)
|
||||
return;
|
||||
|
||||
var itemInfo = null;
|
||||
|
||||
if (!anItem)
|
||||
@@ -427,6 +431,10 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
|
||||
if (!anItem)
|
||||
return;
|
||||
|
||||
if ([self _delegateRespondsToShouldCollapseItem])
|
||||
if ([_outlineViewDelegate outlineView:self shouldCollapseItem:anItem] == NO)
|
||||
return;
|
||||
|
||||
var itemInfo = _itemInfosForItems[[anItem UID]];
|
||||
|
||||
if (!itemInfo)
|
||||
@@ -1574,6 +1582,15 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
|
||||
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_;
|
||||
}
|
||||
|
||||
- (BOOL)_delegateRespondsToShouldExpandItem
|
||||
{
|
||||
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldExpandItem_;
|
||||
}
|
||||
|
||||
- (BOOL)_delegateRespondsToShouldCollapseItem
|
||||
{
|
||||
return _implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldCollapseItem_;
|
||||
}
|
||||
@end
|
||||
|
||||
// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever...
|
||||
|
||||
@@ -172,6 +172,43 @@
|
||||
[outlineView expandItem:".1"];
|
||||
}
|
||||
|
||||
- (void)testShouldExpandItemDelegate
|
||||
{
|
||||
var delegate = [TestShouldExpandItemDelegate new];
|
||||
// reset state
|
||||
[outlineView collapseItem:".1"];
|
||||
[self assertFalse:[outlineView isItemExpanded:".1"] message:".1 is collapsed by default"];
|
||||
[outlineView expandItem:".1"];
|
||||
[self assertTrue:[outlineView isItemExpanded:".1"] message:".1 is expanded, no restriction"];
|
||||
[outlineView collapseItem:".1"];
|
||||
[self assertFalse:[outlineView isItemExpanded:".1"] message:".1 is collapsed now"];
|
||||
|
||||
[outlineView setDelegate:delegate];
|
||||
|
||||
[outlineView expandItem:".1"];
|
||||
[self assertFalse:[outlineView isItemExpanded:".1"] message:".1 is still collapsed, cannot expand"];
|
||||
}
|
||||
|
||||
- (void)testShouldCollapseItemDelegate
|
||||
{
|
||||
var delegate = [TestShouldCollapseItemDelegate new];
|
||||
// reset state
|
||||
[outlineView collapseItem:".1"];
|
||||
|
||||
[self assertFalse:[outlineView isItemExpanded:".1"] message:".1 is collapsed by default"];
|
||||
[outlineView expandItem:".1"];
|
||||
[self assertTrue:[outlineView isItemExpanded:".1"] message: ".1 is now expanded"];
|
||||
[outlineView collapseItem:".1"];
|
||||
[self assertFalse:[outlineView isItemExpanded:".1"] message: ".1 is now collapsed, no restriction"];
|
||||
|
||||
[outlineView setDelegate:delegate];
|
||||
|
||||
[outlineView expandItem:".1"];
|
||||
[self assertTrue:[outlineView isItemExpanded:".1"] message:".1 is now expanded"];
|
||||
[outlineView collapseItem:".1"];
|
||||
[self assertTrue:[outlineView isItemExpanded:".1"] message:".1 is still expanded, cannot collapse"];
|
||||
}
|
||||
|
||||
/*!
|
||||
Test that the outline view archives properly.
|
||||
*/
|
||||
@@ -326,5 +363,29 @@
|
||||
[tester assert:0 equals:visibleRows.location];
|
||||
[tester assert:8 equals:visibleRows.length];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation TestShouldExpandItemDelegate : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(CPOutlineView)outlineView shouldExpandItem:(id)item
|
||||
{
|
||||
if (item == @".1")
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation TestShouldCollapseItemDelegate : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(CPOutlineView)outlineView shouldCollapseItem:(id)item
|
||||
{
|
||||
if (item == @".1")
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user