mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-14 14:41:28 +00:00
CPPredicateEditor: bindings compatibility. Send control action only after a UI interaction to prevent sending unwanted notifications to the binder.
Send action through the responder chain even if target or action is nil. CPControl relies on this to send updates to the binder.
This commit is contained in:
@@ -86,10 +86,18 @@
|
||||
{
|
||||
if (theBinding == CPValueBinding)
|
||||
return [CPPredicateEditorValueBinder class];
|
||||
|
||||
|
||||
return [super _binderClassForBinding:theBinding];
|
||||
}
|
||||
|
||||
- (id)_replacementKeyPathForBinding:(CPString)aBinding
|
||||
{
|
||||
if (aBinding == CPValueBinding)
|
||||
return @"predicate";
|
||||
|
||||
return [super _replacementKeyPathForBinding:aBinding];
|
||||
}
|
||||
|
||||
- (void)_initRuleEditorShared
|
||||
{
|
||||
[super _initRuleEditorShared];
|
||||
@@ -250,13 +258,17 @@
|
||||
{
|
||||
var ov = [self objectValue];
|
||||
if ((ov == nil) != (objectValue == nil) || ![ov isEqual:objectValue])
|
||||
{
|
||||
[self _setPredicate:objectValue];
|
||||
[self _reflectPredicate:objectValue];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_reflectPredicate:(id)predicate
|
||||
{
|
||||
var animation = _currentAnimation;
|
||||
_currentAnimation = nil;
|
||||
_sendAction = NO;
|
||||
|
||||
if (predicate != nil)
|
||||
{
|
||||
@@ -358,9 +370,7 @@
|
||||
|
||||
- (void)_updatePredicate
|
||||
{
|
||||
[self willChangeValueForKey:@"objectValue"];
|
||||
[self _updatePredicateFromRows];
|
||||
[self didChangeValueForKey:@"objectValue"];
|
||||
}
|
||||
|
||||
- (void)_updatePredicateFromRows
|
||||
@@ -384,7 +394,7 @@
|
||||
else
|
||||
predicate = [[CPCompoundPredicate alloc] initWithType:[self _compoundPredicateTypeForRootRows] subpredicates:subpredicates];
|
||||
|
||||
[super _setPredicate:predicate];
|
||||
[self _setPredicate:predicate];
|
||||
}
|
||||
|
||||
- (id)_predicateFromRowItem:(id)rowItem
|
||||
@@ -525,7 +535,7 @@ var CPPredicateTemplatesKey = @"CPPredicateTemplates";
|
||||
@implementation CPPredicateEditorValueBinder : CPBinder
|
||||
{
|
||||
}
|
||||
// temporary fix. See https://github.com/cacaodev/cappuccino/commits/CPKeyValueBinding for CPbinder fix.
|
||||
// temporary fix. See https://github.com/cacaodev/cappuccino/commits/CPKeyValueBinding for CPbinder fix.
|
||||
- (void)setValueFor:(CPString)aBinding
|
||||
{
|
||||
var destination = [_info objectForKey:CPObservedObjectKey],
|
||||
@@ -536,11 +546,11 @@ var CPPredicateTemplatesKey = @"CPPredicateTemplates";
|
||||
var isMarker = CPIsControllerMarker(newValue);
|
||||
if (isMarker)
|
||||
newValue = [options objectForKey:newValue];
|
||||
|
||||
|
||||
if (!isMarker || newValue == nil)
|
||||
newValue = [self transformValue:newValue withOptions:options];
|
||||
|
||||
[_source setValue:newValue forKey:aBinding];
|
||||
[_source _reflectPredicate:newValue];
|
||||
}
|
||||
|
||||
- (void)reverseSetValueFor:(CPString)aBinding
|
||||
@@ -551,7 +561,7 @@ var CPPredicateTemplatesKey = @"CPPredicateTemplates";
|
||||
newValue = [_source valueForKeyPath:aBinding];
|
||||
|
||||
newValue = [self reverseTransformValue:newValue withOptions:options];
|
||||
|
||||
|
||||
[destination removeObserver:self forKeyPath:keyPath];
|
||||
[destination setValue:newValue forKeyPath:keyPath];
|
||||
[destination addObserver:self forKeyPath:keyPath options:CPKeyValueObservingOptionNew context:aBinding];
|
||||
|
||||
@@ -84,6 +84,7 @@ var itemsContext = "items",
|
||||
BOOL _disallowEmpty;
|
||||
BOOL _delegateWantsValidation;
|
||||
BOOL _editable;
|
||||
BOOL _sendAction;
|
||||
|
||||
Class _rowClass;
|
||||
|
||||
@@ -120,8 +121,8 @@ var itemsContext = "items",
|
||||
BOOL _isKeyDown;
|
||||
BOOL _nestingModeDidChange;
|
||||
|
||||
id _standardLocalizer @accessors(property=standardLocalizer);
|
||||
id _itemsAndValuesToAddForRowType;
|
||||
_CPRuleEditorLocalizer _standardLocalizer @accessors(property=standardLocalizer);
|
||||
CPDictionary _itemsAndValuesToAddForRowType;
|
||||
}
|
||||
|
||||
/*! @cond */
|
||||
@@ -177,6 +178,7 @@ var itemsContext = "items",
|
||||
_delegateWantsValidation = YES;
|
||||
_suppressKeyDownHandling = NO;
|
||||
_nestingModeDidChange = NO;
|
||||
_sendAction = YES;
|
||||
_itemsAndValuesToAddForRowType = {};
|
||||
var animation = [[CPViewAnimation alloc] initWithDuration:0.5 animationCurve:CPAnimationEaseInOut];
|
||||
[self setAnimation:animation];
|
||||
@@ -1288,7 +1290,11 @@ TODO: implement
|
||||
}
|
||||
|
||||
[self removeRowsAtIndexes:rowindexes includeSubrows:YES];
|
||||
[self _postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification indexes:rowindexes]; // indexes should include childs
|
||||
|
||||
[self _updatePredicate];
|
||||
[self _sendRuleAction];
|
||||
[self _postRuleOptionChangedNotification];
|
||||
[self _postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification indexes:rowindexes];
|
||||
}
|
||||
|
||||
- (CPArray)_rootRowsArray
|
||||
@@ -1391,14 +1397,12 @@ TODO: implement
|
||||
// for CPRuleEditorNestingModeSimple only
|
||||
|
||||
var rowIndexEvent = [slice rowIndex],
|
||||
rowTypeEvent = [self rowTypeForRow:rowIndexEvent];
|
||||
rowTypeEvent = [self rowTypeForRow:rowIndexEvent],
|
||||
insertIndex = rowIndexEvent + 1;
|
||||
|
||||
var parentRowIndex = (rowTypeEvent == CPRuleEditorRowTypeCompound) ? rowIndexEvent:[self parentRowForRow:rowIndexEvent];
|
||||
|
||||
[self insertRowAtIndex:rowIndexEvent + 1 withType:type asSubrowOfRow:parentRowIndex animate:YES];
|
||||
|
||||
// [self _reconfigureSubviewsAnimate:YES];
|
||||
// [self _updatePredicate];
|
||||
[self insertRowAtIndex:insertIndex withType:type asSubrowOfRow:parentRowIndex animate:YES];
|
||||
}
|
||||
|
||||
- (id)_insertNewRowAtIndex:(int)insertIndex ofType:(CPRuleEditorRowType)rowtype withParentRow:(int)parentRowIndex
|
||||
@@ -1426,6 +1430,11 @@ TODO: implement
|
||||
var relInsertIndex = insertIndex - parentRowIndex - 1;
|
||||
[subrowsObjects insertObject:row atIndex:relInsertIndex];
|
||||
|
||||
[self _updatePredicate];
|
||||
[self _sendRuleAction];
|
||||
[self _postRuleOptionChangedNotification];
|
||||
[self _postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification indexes:[CPIndexSet indexSetWithIndex:insertIndex]];
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -1502,10 +1511,7 @@ TODO: implement
|
||||
}
|
||||
|
||||
[self _changedRowArray:newRows withOldRowArray:oldRows forParent:object];
|
||||
|
||||
[self _reconfigureSubviewsAnimate:[self _wantsRowAnimations]];
|
||||
[self _postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification indexes:[change objectForKey:CPKeyValueChangeIndexesKey]];
|
||||
|
||||
}
|
||||
else if (context == itemsContext)
|
||||
{
|
||||
@@ -1546,7 +1552,9 @@ TODO: implement
|
||||
|
||||
var slice = [_slices objectAtIndex:aRow];
|
||||
[slice _reconfigureSubviews];
|
||||
[self _sendRuleAction];
|
||||
|
||||
[self _updatePredicate];
|
||||
[self _sendRuleAction];
|
||||
[self _postRuleOptionChangedNotification];
|
||||
}
|
||||
|
||||
@@ -1664,10 +1672,10 @@ TODO: implement
|
||||
{
|
||||
[self unbind:aBinding];
|
||||
[self _setBoundDataSource:observableController withKeyPath:aKeyPath options:options];
|
||||
|
||||
|
||||
[_rowCache removeAllObjects];
|
||||
[_slices removeAllObjects];
|
||||
|
||||
|
||||
var newRows = [CPArray array];
|
||||
var oldRows = [self _rootRowsArray];
|
||||
[self _changedRowArray:newRows withOldRowArray:oldRows forParent:_boundArrayOwner];
|
||||
@@ -2235,6 +2243,11 @@ TODO: implement
|
||||
- (void)draggedView:(CPView)dragView endedAt:(CPPoint)aPoint operation:(CPDragOperation)operation
|
||||
{
|
||||
_draggingRows = nil;
|
||||
|
||||
[self _updatePredicate];
|
||||
[self _sendRuleAction];
|
||||
[self _postRuleOptionChangedNotification];
|
||||
[self _postRowCountChangedNotificationOfType:CPRuleEditorRowsDidChangeNotification indexes:nil]; // FIXME
|
||||
}
|
||||
|
||||
- (BOOL)wantsPeriodicDraggingUpdates
|
||||
@@ -2258,16 +2271,13 @@ TODO: implement
|
||||
|
||||
- (void)_postRuleOptionChangedNotification
|
||||
{
|
||||
[self reloadPredicate];
|
||||
[self _sendRuleAction];
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPRuleEditorRulesDidChangeNotification object:self];
|
||||
}
|
||||
|
||||
- (void)_postRowCountChangedNotificationOfType:(CPString)notificationName indexes:indexes
|
||||
{
|
||||
[self reloadPredicate];
|
||||
[self _sendRuleAction];
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:notificationName object:self userInfo:[CPDictionary dictionaryWithObject:indexes forKey:"indexes"]];
|
||||
var userInfo = [CPDictionary dictionaryWithObject:indexes forKey:"indexes"];
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:notificationName object:self userInfo:userInfo];
|
||||
}
|
||||
|
||||
- (CPIndexSet)_globalIndexesForSubrowIndexes:(CPIndexSet)indexes ofParentObject:(id)parentRowObject
|
||||
@@ -2304,8 +2314,8 @@ TODO: implement
|
||||
var action = [self action],
|
||||
target = [self target];
|
||||
|
||||
if (action && target)
|
||||
[self sendAction:action to:target];
|
||||
CPLogConsole(_cmd);
|
||||
[self sendAction:action to:target];
|
||||
}
|
||||
|
||||
- (BOOL)_sendsActionOnIncompleteTextChange
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -3443,14 +3443,6 @@
|
||||
</object>
|
||||
<int key="connectionID">1435</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">predicateEditorAction:</string>
|
||||
<reference key="source" ref="773916665"/>
|
||||
<reference key="destination" ref="407607490"/>
|
||||
</object>
|
||||
<int key="connectionID">1436</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: selection.predicate</string>
|
||||
@@ -3470,7 +3462,7 @@
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">1437</int>
|
||||
<int key="connectionID">1439</int>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
@@ -5072,7 +5064,7 @@
|
||||
<nil key="activeLocalization"/>
|
||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">1437</int>
|
||||
<int key="maxID">1439</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
||||
Reference in New Issue
Block a user