Re: I think I have found a big bug in NSBrowser
Re: I think I have found a big bug in NSBrowser
- Subject: Re: I think I have found a big bug in NSBrowser
- From: Hamish Allan <email@hidden>
- Date: Tue, 31 Jan 2006 11:00:53 +0000
On 31 Jan 2006, at 01:53, Andre wrote:
I think it implements the console so one can operate on paths etc
and drag it to the console, I've used it a few times with
subversion, which has been a huge time saver.
But you can already drag files from Finder.app and drop them as
pathnames into Terminal.app...
Yea, I want to implement both actually. I use the representedObject
to choose what icon I'm gonna display in the browser. Depending on
the underlying object, or one of its values, I can grab the
appropriate icon. The trouble is that the value binding is just for
display, and thats all that is set in the cell. So how to get the
object it represents is a puzzle.
The way I did it was, a very bad thing to do, but was to bind to a
category made to NSObject that wrapped the pointer to the
underlying object in an NSValue. - (NSValue *)selfAddress; So then
in the browser delegate, I check the objectValue, extract the
pointer from the valye, reset the object value (string title) of
the cell from the pointed to object, then set the object value of
the cell from the pointer, then get the icon. So from the outside,
it looks like I have the represented object value, but actually its
just hiding in the value binding! Not something I'm "happy" about
having to do though....
Perhaps I'm misunderstanding you, but the object value of the cell
does not have to be the string title. Look at the way it's done in
NSBrowserBugWorkarounds -- the NSBrowser's contentValues binding is
set to arrangedObjects (rather than
arrangedObjects.path.lastPathComponent which would provide the string
value) and so the Node gets passed directly. Then the
CustomBrowserCell just retrieves the properties it's interested in
(such as icon):
- (void)setObjectValue:(id)value
{
if ([value isKindOfClass:[Node class]])
{
[self setImage:[value icon]];
[self setLeaf:[value isLeaf]];
[super setObjectValue:[[value path] lastPathComponent]];
}
else
[super setObjectValue:value];
}
More generically, you could write the above function like this:
- (void)setObjectValue:(id)value
{
if ([value respondsToSelector:@selector(icon)])
[self setImage:[value icon]];
if ([value respondsToSelector:@selector(isLeaf)])
[self setLeaf:[value isLeaf]];
if ([value respondsToSelector:@selector(textForBrowser)])
[super setObjectValue:[value textForBrowser]];
else
[super setObjectValue:value];
}
with the following in Node.m:
- (NSString *)textForBrowser
{
return [[self path] lastPathComponent];
}
Best wishes,
Hamish
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden