From 6a689dc3df96cf0c59b3db76166a6be2cea7d0fd Mon Sep 17 00:00:00 2001 From: Nicholas Small Date: Wed, 30 Jun 2010 12:00:20 -0400 Subject: [PATCH 1/3] Fix for asking the wrong object for -_replacementKeyPathForBinding: when creating a new binding. --- AppKit/CPKeyValueBinding.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index 3aabc98a6..a926cdd2b 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -263,7 +263,7 @@ var CPBindingOperationAnd = 0, // CPLog.warn("No binding exposed on "+self+" for "+aBinding); [self unbind:aBinding]; - [[CPKeyValueBinding alloc] initWithBinding:[anObject _replacementKeyPathForBinding:aBinding] name:aBinding to:anObject keyPath:aKeyPath options:options from:self]; + [[CPKeyValueBinding alloc] initWithBinding:[self _replacementKeyPathForBinding:aBinding] name:aBinding to:anObject keyPath:aKeyPath options:options from:self]; } - (CPDictionary)infoForBinding:(CPString)aBinding From 21a9ae4c456993fcfdd93c1ea241472adb1f72ec Mon Sep 17 00:00:00 2001 From: Nicholas Small Date: Wed, 30 Jun 2010 12:03:03 -0400 Subject: [PATCH 2/3] Make CPTableView work with selectionIndexes binding. --- AppKit/CPTableView.j | 51 +++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 480c01373..d40747df6 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -882,6 +882,22 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; [self _noteSelectionDidChange]; } +- (void)_setSelectedRowIndexes:(CPIndexSet)rows +{ + var previousSelectedIndexes = [_selectedRowIndexes copy]; + + _lastSelectedRow = ([rows count] > 0) ? [rows lastIndex] : -1; + _selectedRowIndexes = [rows copy]; + + [self _updateHighlightWithOldRows:previousSelectedIndexes newRows:_selectedRowIndexes]; + [_tableDrawView display]; // FIXME: should be setNeedsDisplayInRect:enclosing rect of new (de)selected rows + // but currently -drawRect: is not implemented here + + [[CPKeyValueBinding getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectedRowIndexes"]; + + [self _noteSelectionDidChange]; +} + /*! Sets the row selection using indexes. @param rows a CPIndexSet of rows to select @@ -902,20 +918,16 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; [_headerView setNeedsDisplay:YES]; } - var previousSelectedIndexes = [_selectedRowIndexes copy]; - + var newSelectedIndexes; if (shouldExtendSelection) - [_selectedRowIndexes addIndexes:rows]; + { + newSelectedIndexes = [_selectedRowIndexes copy]; + [newSelectedIndexes addIndexes:rows]; + } else - _selectedRowIndexes = [rows copy]; + newSelectedIndexes = [rows copy]; - // update last selected row - _lastSelectedRow = ([rows count] > 0) ? [rows lastIndex] : -1; - - [self _updateHighlightWithOldRows:previousSelectedIndexes newRows:_selectedRowIndexes]; - [_tableDrawView display]; // FIXME: should be setNeedsDisplayInRect:enclosing rect of new (de)selected rows - // but currently -drawRect: is not implemented here - [self _noteSelectionDidChange]; + [self _setSelectedRowIndexes:newSelectedIndexes]; } - (void)_updateHighlightWithOldRows:(CPIndexSet)oldRows newRows:(CPIndexSet)newRows @@ -3427,14 +3439,23 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; @implementation CPTableView (Bindings) +- (CPString)_replacementKeyPathForBinding:(CPString)aBinding +{ + if (aBinding === @"selectionIndexes") + return @"selectedRowIndexes"; + + return [super _replacementKeyPathForBinding:aBinding]; +} + - (void)_establishBindingsIfUnbound:(id)destination { if ([[self infoForBinding:@"content"] objectForKey:CPObservedObjectKey] !== destination) - { [self bind:@"content" toObject:destination withKeyPath:@"arrangedObjects" options:nil]; - //[self bind:@"sortDescriptors" toObject:destination withKeyPath:@"sortDescriptors" options:nil]; - //[self bind:@"selectionIndexes" toObject:destination withKeyPath:@"selectionIndexes" options:nil]; - } + + if ([[self infoForBinding:@"selectionIndexes"] objectForKey:CPObservedObjectKey] !== destination) + [self bind:@"selectionIndexes" toObject:destination withKeyPath:@"selectionIndexes" options:nil]; + + //[self bind:@"sortDescriptors" toObject:destination withKeyPath:@"sortDescriptors" options:nil]; } - (void)setContent:(CPArray)content From e385321f95ec76e1c6afa2282b927f2c97b09fb5 Mon Sep 17 00:00:00 2001 From: Nicholas Small Date: Wed, 30 Jun 2010 22:28:02 -0400 Subject: [PATCH 3/3] CPArrayController -selectedObjects returns a CPObservableArray. --- AppKit/CPArrayController.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index 5fefb58c8..c11206f79 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -335,7 +335,7 @@ { var objects = [[self arrangedObjects] objectsAtIndexes:[self selectionIndexes]]; - return objects || [_CPObservableArray array]; + return [_CPObservableArray arrayWithArray:(objects || [])]; } - (BOOL)setSelectedObjects:(CPArray)objects