Skip to content

Commit

Permalink
Handle CPValueBinding in the custom binder. Added a CPImageView with …
Browse files Browse the repository at this point in the history
…CPValueBinding to the test app.

Removed setBackgroundColor:gray for placeholders because it's a bad idea (non cocoa and need to restore bg when the value != placeholder).
  • Loading branch information
cacaodev committed Apr 8, 2012
1 parent b6a173c commit 1e9958c
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 17 deletions.
11 changes: 6 additions & 5 deletions AppKit/CPImageView.j
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var CPImageViewEmptyPlaceholderImage = nil;

+ (Class)_binderClassForBinding:(CPString)theBinding
{
if (theBinding == CPValueURLBinding || theBinding == CPValuePathBinding)
if (theBinding == CPValueBinding || theBinding == CPValueURLBinding || theBinding == CPValuePathBinding)
return [CPImageViewValueBinder class];

return [super _binderClassForBinding:theBinding];
Expand Down Expand Up @@ -489,14 +489,15 @@ var CPImageViewEmptyPlaceholderImage = nil;
}

[_source setImage:nil];
[_source setBackgroundColor:[CPColor lightGrayColor]];
}
else
{
newValue = [self transformValue:newValue withOptions:options];

var image = [[CPImage alloc] initWithContentsOfFile:newValue];
[_source setImage:image];

if (theBinding != CPValueBinding)
newValue = [[CPImage alloc] initWithContentsOfFile:newValue];

[_source setImage:newValue];
}
}

Expand Down
10 changes: 8 additions & 2 deletions Tests/Manual/CPImageViewbindingsTest/AppController.j
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
request = [CPURLRequest requestWithURL:path],
connection = [CPURLConnection connectionWithRequest:request delegate:self];

[theWindow setFullBridge:YES];
[theWindow setFullPlatformWindow:YES];
}

- (void)connection:(CPURLConnection)connection didReceiveData:(CPString)dataString
Expand All @@ -34,7 +34,13 @@
var data = [[CPData alloc] initWithRawString:dataString],
theRows = [CPPropertyListSerialization propertyListFromData:data format:CPPropertyListXMLFormat_v1_0];

[self setContent:theRows];
// Add a CPImage to the model to test CPValueBinding.
var path = [[CPBundle mainBundle] pathForResource:@"value.jpg"],
image = [[CPImage alloc] initWithContentsOfFile:path],
dict = [CPDictionary dictionaryWithObject:image forKey:@"image"];
[theRows addObject:dict];

[self setContent:theRows];
}

@end
5 changes: 3 additions & 2 deletions Tests/Manual/CPImageViewbindingsTest/Resources/MainMenu.cib

Large diffs are not rendered by default.

135 changes: 128 additions & 7 deletions Tests/Manual/CPImageViewbindingsTest/Resources/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
</object>
<int key="NSResizingMask">3</int>
<bool key="NSIsResizeable">YES</bool>
<bool key="NSIsEditable">YES</bool>
<reference key="NSTableView" ref="117414317"/>
</object>
<object class="NSTableColumn" id="516759045">
Expand All @@ -162,7 +161,7 @@
<object class="NSTableHeaderCell" key="NSHeaderCell">
<int key="NSCellFlags">75584576</int>
<int key="NSCellFlags2">2048</int>
<string key="NSContents"/>
<string key="NSContents">CPImage</string>
<reference key="NSSupport" ref="26"/>
<reference key="NSBackgroundColor" ref="1006639902"/>
<reference key="NSTextColor" ref="550243613"/>
Expand All @@ -178,7 +177,6 @@
</object>
<int key="NSResizingMask">3</int>
<bool key="NSIsResizeable">YES</bool>
<bool key="NSIsEditable">YES</bool>
<reference key="NSTableView" ref="117414317"/>
</object>
</object>
Expand Down Expand Up @@ -312,22 +310,22 @@
<string key="NSFrame">{{637, 210}, {149, 131}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<reference key="NSNextKeyView" ref="255391143"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSAntiCompressionPriority">{250, 750}</string>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="243127685">
<int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">272629760</int>
<string type="base64-UTF8" key="NSContents">RWRpdGFibGUKQ1BWYWx1ZVVSTEJpbmRpbmcuA</string>
<object class="NSFont" key="NSSupport">
<object class="NSFont" key="NSSupport" id="611501944">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">13</double>
<int key="NSfFlags">16</int>
</object>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="781739936"/>
<object class="NSColor" key="NSBackgroundColor">
<object class="NSColor" key="NSBackgroundColor" id="779730611">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">controlColor</string>
Expand All @@ -336,6 +334,59 @@
<reference key="NSTextColor" ref="782996589"/>
</object>
</object>
<object class="NSImageView" id="255391143">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
<object class="NSMutableSet" key="NSDragTypes">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="set.sortedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>Apple PDF pasteboard type</string>
<string>Apple PICT pasteboard type</string>
<string>Apple PNG pasteboard type</string>
<string>NSFilenamesPboardType</string>
<string>NeXT Encapsulated PostScript v1.2 pasteboard type</string>
<string>NeXT TIFF v4.0 pasteboard type</string>
</object>
</object>
<string key="NSFrame">{{421, 33}, {201, 149}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="461563582"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSImageCell" key="NSCell" id="859090164">
<int key="NSCellFlags">270532608</int>
<int key="NSCellFlags2">0</int>
<string key="NSCellIdentifier">_NS:9</string>
<int key="NSAlign">0</int>
<int key="NSScale">3</int>
<int key="NSStyle">2</int>
<bool key="NSAnimates">NO</bool>
</object>
<bool key="NSEditable">YES</bool>
</object>
<object class="NSTextField" id="461563582">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{637, 48}, {149, 131}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSAntiCompressionPriority">{250, 750}</string>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="580587949">
<int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">272629760</int>
<string type="base64-UTF8" key="NSContents">RWRpdGFibGUKQ1BWYWx1ZUJpbmRpbmcuA</string>
<reference key="NSSupport" ref="611501944"/>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="461563582"/>
<reference key="NSBackgroundColor" ref="779730611"/>
<reference key="NSTextColor" ref="782996589"/>
</object>
</object>
</object>
<string key="NSFrameSize">{794, 370}</string>
<reference key="NSSuperview"/>
Expand Down Expand Up @@ -410,6 +461,22 @@
</object>
<int key="connectionID">474</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects.image.className</string>
<reference key="source" ref="516759045"/>
<reference key="destination" ref="191071672"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="516759045"/>
<reference key="NSDestination" ref="191071672"/>
<string key="NSLabel">value: arrangedObjects.image.className</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">arrangedObjects.image.className</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">505</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">valueURL: selection.url</string>
Expand All @@ -426,6 +493,22 @@
</object>
<int key="connectionID">479</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: selection.image</string>
<reference key="source" ref="255391143"/>
<reference key="destination" ref="191071672"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="255391143"/>
<reference key="NSDestination" ref="191071672"/>
<string key="NSLabel">value: selection.image</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">selection.image</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">503</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -473,6 +556,8 @@
<reference ref="318333122"/>
<reference ref="380387729"/>
<reference ref="781739936"/>
<reference ref="255391143"/>
<reference ref="461563582"/>
</object>
<reference key="parent" ref="972006081"/>
</object>
Expand Down Expand Up @@ -579,6 +664,34 @@
<reference key="object" ref="243127685"/>
<reference key="parent" ref="781739936"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">497</int>
<reference key="object" ref="255391143"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="859090164"/>
</object>
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">498</int>
<reference key="object" ref="461563582"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="580587949"/>
</object>
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">499</int>
<reference key="object" ref="580587949"/>
<reference key="parent" ref="461563582"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">500</int>
<reference key="object" ref="859090164"/>
<reference key="parent" ref="255391143"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand Down Expand Up @@ -607,6 +720,10 @@
<string>471.IBPluginDependency</string>
<string>495.IBPluginDependency</string>
<string>496.IBPluginDependency</string>
<string>497.IBPluginDependency</string>
<string>498.IBPluginDependency</string>
<string>499.IBPluginDependency</string>
<string>500.IBPluginDependency</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -632,6 +749,10 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
Expand All @@ -646,7 +767,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">496</int>
<int key="maxID">505</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</dict>
<dict>
<key>url</key>
<string>Resources/cappuccino.jpeg</string>
<string>Resources/valueURL.jpg</string>
</dict>
</array>
</plist>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1e9958c

Please sign in to comment.