Skip to content

Commit

Permalink
Select outline view item parent with left key.
Browse files Browse the repository at this point in the history
If there's a single item selected and it's not expanded, pressing the left arrow key on the keyboard now selects the item's parent unless the delegate vetoes.
  • Loading branch information
aljungberg committed Mar 25, 2012
1 parent 1a8fc7f commit 5351bf7
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions AppKit/CPOutlineView.j
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
CPOutlineViewCoalesceSelectionNotificationStateOn = 1,
CPOutlineViewCoalesceSelectionNotificationStateDid = 2;

#define SHOULD_SELECT_ITEM(anOutlineView, anItem) (!((anOutlineView)._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldSelectItem_) || [(anOutlineView)._outlineViewDelegate outlineView:(anOutlineView) shouldSelectItem:(anItem)])

/*!
@ingroup appkit
@class CPOutlineView
Expand Down Expand Up @@ -1472,7 +1474,6 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
}


- (void)keyDown:(CPEvent)anEvent
{
var character = [anEvent charactersIgnoringModifiers],
Expand All @@ -1496,20 +1497,39 @@ var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
for (; i < c; i++)
items.push([self itemAtRow:indexes[i]]);


if (character === CPRightArrowFunctionKey)
{
for (var i = 0; i < c; i++)
[self expandItem:items[i]];
}
else if (character === CPLeftArrowFunctionKey)
{
// When a single, collapsed item is selected and the left arrow key is pressed, the parent
// should be selected if possible.
if (c == 1)
{
var theItem = items[0];
if (![self isItemExpanded:theItem])
{
var parent = [self parentForItem:theItem],
shouldSelect = parent && SHOULD_SELECT_ITEM(self, parent);
if (shouldSelect)
{
var rowIndex = [self rowForItem:parent];
[self selectRowIndexes:[CPIndexSet indexSetWithIndex:rowIndex] byExtendingSelection:NO];
[self scrollRowToVisible:rowIndex];
return;
}
}
}

for (var i = 0; i < c; i++)
[self collapseItem:items[i]];
}

[super keyDown:anEvent];
}

@end

// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever...
Expand Down Expand Up @@ -1820,10 +1840,7 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt

- (BOOL)tableView:(CPTableView)theTableView shouldSelectRow:(int)theRow
{
if ((_outlineView._implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_shouldSelectItem_))
return [_outlineView._outlineViewDelegate outlineView:_outlineView shouldSelectItem:[_outlineView itemAtRow:theRow]];

return YES;
return SHOULD_SELECT_ITEM(_outlineView, [_outlineView itemAtRow:theRow]);
}

- (BOOL)tableView:(CPTableView)aTableView shouldEditTableColumn:(CPTableColumn)aColumn row:(int)aRow
Expand Down

0 comments on commit 5351bf7

Please sign in to comment.