Skip to content

Commit

Permalink
Add helpers to expand/collapse outline rows on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBuckley committed Jul 27, 2013
1 parent 3d11840 commit 65ba661
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 4 deletions.
14 changes: 14 additions & 0 deletions gem/lib/frank-cucumber/frank_mac_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def show_menu( selector )
perform_action_on_selector( 'FEX_showMenu', selector )
end

def expand_row( selector )
perform_action_on_selector( 'FEX_expand', selector )
end

def collapse_row( selector )
perform_action_on_selector( 'FEX_collapse', selector )
end

def row_is_expanded( selector )
successes = frankly_map( selector, "FEX_isExpanded" )
return false if successes == nil or successes.empty?
return !successes.include?(false)
end

end

end
Expand Down
20 changes: 20 additions & 0 deletions src/FEXTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,24 @@ - (id) value
return _value;
}

- (BOOL) FEX_simulateClick
{
return [_row FEX_simulateClick];
}

- (BOOL) FEX_isExpanded
{
return [_row FEX_isExpanded];
}

- (BOOL) FEX_expand
{
return [_row FEX_expand];
}

- (BOOL) FEX_collapse
{
return [_row FEX_collapse];
}

@end
8 changes: 7 additions & 1 deletion src/FEXTableRow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
@interface FEXTableRow : NSView
{
NSTableView* _table;
NSUInteger _index;
}

- (id) initWithFrame: (NSRect) frame table: (NSTableView*) table;
- (id) initWithFrame: (NSRect) frame table: (NSTableView*) table index: (NSUInteger) index;

- (NSTableView*) table;

- (BOOL) FEX_simulateClick;
- (BOOL) FEX_isExpanded;
- (BOOL) FEX_expand;
- (BOOL) FEX_collapse;

@end
58 changes: 57 additions & 1 deletion src/FEXTableRow.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

@implementation FEXTableRow

- (id) initWithFrame: (NSRect) frame table: (NSTableView*) table
- (id) initWithFrame: (NSRect) frame table: (NSTableView*) table index: (NSUInteger) index
{
self = [super initWithFrame: frame];
if (self) {
_table = table;
_index = index;
}

return self;
Expand All @@ -41,4 +42,59 @@ - (NSTableView*) table
return _table;
}

- (BOOL) FEX_simulateClick
{
[_table selectRowIndexes: [NSIndexSet indexSetWithIndex: _index] byExtendingSelection: NO];
return YES;
}

- (BOOL) FEX_isExpanded
{
BOOL returnValue = NO;

if ([_table isKindOfClass: [NSOutlineView class]])
{
id item = [(NSOutlineView*) _table itemAtRow: _index];
returnValue = [(NSOutlineView*) _table isItemExpanded: item];
}

return returnValue;
}

- (BOOL) FEX_expand
{
BOOL returnValue = NO;

if ([_table isKindOfClass: [NSOutlineView class]])
{
returnValue = YES;

id item = [(NSOutlineView*) _table itemAtRow: _index];
if (![(NSOutlineView*) _table isItemExpanded: item])
{
[(NSOutlineView*) _table expandItem: item];
}
}

return returnValue;
}

- (BOOL) FEX_collapse
{
BOOL returnValue = NO;

if ([_table isKindOfClass: [NSOutlineView class]])
{
returnValue = YES;

id item = [(NSOutlineView*) _table itemAtRow: _index];
if ([(NSOutlineView*) _table isItemExpanded: item])
{
[(NSOutlineView*) _table collapseItem: item];
}
}

return returnValue;
}

@end
103 changes: 101 additions & 2 deletions src/NSObject+FrankAutomation.m
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,98 @@ - (id) FEX_parent
return parent;
}

- (BOOL) FEX_isExpanded
{
return [[self superview] FEX_isExpanded];
}

- (BOOL) FEX_expand
{
return [[self superview] FEX_expand];
}

- (BOOL) FEX_collapse
{
return [[self superview] FEX_collapse];
}

@end

static const NSString* FEX_TableAttribute = @"FEX_TableAttribute";
static const NSString* FEX_IndexAttribute = @"FEX_IndexAttribute";


@implementation NSTableRowView (FrankAutomation)

- (void) FEX_setTable: (NSTableView*) table
{
objc_setAssociatedObject(self, FEX_TableAttribute, table, OBJC_ASSOCIATION_ASSIGN);
}

- (void) FEX_setIndex: (NSUInteger) index
{
objc_setAssociatedObject(self, FEX_IndexAttribute, [NSNumber numberWithInteger: index], OBJC_ASSOCIATION_RETAIN);
}

- (BOOL) FEX_isExpanded
{
BOOL returnValue = NO;

NSTableView* table = objc_getAssociatedObject(self, FEX_TableAttribute);

if ([table isKindOfClass: [NSOutlineView class]])
{
NSUInteger index = [objc_getAssociatedObject(self, FEX_IndexAttribute) integerValue];

id item = [(NSOutlineView*) table itemAtRow: index];
returnValue = [(NSOutlineView*) table isItemExpanded: item];
}

return returnValue;
}

- (BOOL) FEX_expand
{
BOOL returnValue = NO;

NSTableView* table = objc_getAssociatedObject(self, FEX_TableAttribute);

if ([table isKindOfClass: [NSOutlineView class]])
{
NSUInteger index = [objc_getAssociatedObject(self, FEX_IndexAttribute) integerValue];
returnValue = YES;

id item = [(NSOutlineView*) table itemAtRow: index];
if (![(NSOutlineView*) table isItemExpanded: item])
{
[(NSOutlineView*) table expandItem: item];
}
}

return returnValue;
}

- (BOOL) FEX_collapse
{
BOOL returnValue = NO;

NSTableView* table = objc_getAssociatedObject(self, FEX_TableAttribute);

if ([table isKindOfClass: [NSOutlineView class]])
{
NSUInteger index = [objc_getAssociatedObject(self, FEX_IndexAttribute) integerValue];
returnValue = YES;

id item = [(NSOutlineView*) table itemAtRow: index];
if ([(NSOutlineView*) table isItemExpanded: item])
{
[(NSOutlineView*) table collapseItem: item];
}
}

return returnValue;
}

@end

@implementation NSTableView (FrankAutomation)
Expand Down Expand Up @@ -570,7 +662,8 @@ - (NSArray*) FEX_children
rowRect = NSIntersectionRect(rowRect, visibleRect);

FEXTableRow* row = [[[FEXTableRow alloc] initWithFrame: rowRect
table: self] autorelease];
table: self
index: rowNum] autorelease];

for (NSUInteger colNum = 0; colNum < [self numberOfColumns]; ++colNum)
{
Expand All @@ -585,6 +678,9 @@ - (NSArray*) FEX_children
{
if (colNum == 0)
{
[(NSTableRowView*) [cellValue superview] FEX_setTable: self];
[(NSTableRowView*) [cellValue superview] FEX_setIndex: rowNum];

[children addObject: [cellValue superview]];
}
}
Expand Down Expand Up @@ -662,6 +758,8 @@ - (NSArray*) FEX_children

if (rowView != nil)
{
[(NSTableRowView*) rowView FEX_setTable: self];
[(NSTableRowView*) rowView FEX_setIndex: rowNum];
[children addObject: rowView];
}
else
Expand All @@ -670,7 +768,8 @@ - (NSArray*) FEX_children
rowRect = NSIntersectionRect(rowRect, visibleRect);

FEXTableRow* row = [[[FEXTableRow alloc] initWithFrame: rowRect
table: self] autorelease];
table: self
index: rowNum] autorelease];

id item = [self itemAtRow: rowNum];

Expand Down

0 comments on commit 65ba661

Please sign in to comment.