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: Andre <email@hidden>
- Date: Tue, 31 Jan 2006 10:07:00 -0800
Hamish Allan wrote:
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, its just more convenient thats all, to have it right under the
window.... I guess its a personal pref.
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):
Thats a much better solution that what I did!
- (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];
}
I see I see, yea, for some reason I looked at node.h file.h etc but
neglected to pay attention to what this was doing in
CustomBrowserCell.h...
Also, I assumed how the bindings would be set up, I didn't notice
content values were also set to arrangedObjects....
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];
}
Yep, I can do something like this no prob.
with the following in Node.m:
- (NSString *)textForBrowser
{
return [[self path] lastPathComponent];
}
Best wishes,
Hamish
...learn something new every day.... thanks a lot.
Best of luck to you.
Andre
email@hidden
_______________________________________________
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