Re: Source list group item indentation
Re: Source list group item indentation
- Subject: Re: Source list group item indentation
- From: "Pete Callaway" <email@hidden>
- Date: Thu, 17 Jan 2008 08:34:08 +0000
> Subject: Re: Source list group item indentation
>
> On 16 Jan 2008, at 18:08, Corbin Dunn wrote:
>
> >
> > On Jan 16, 2008, at 2:23 AM, Kyle Sluder wrote:
> >
> >> (Sorry if you're getting this twice, I'm an idiot and forgot to set
> >> the From option.)
> >>
> >> On Jan 15, 2008 6:15 PM, Corbin Dunn <email@hidden> wrote:
> >>> I realize the release notes are rather long, but they are a good
> >>> read.
> >>> Especially for controls/components that you use.
> >>
> >> I did read them, but obviously not closely enough. ;)
> >>
> >> To be honest, this seems like The Wrong Way(tm) to do it. It seems
> >> far more appropriate for the delegate to provide this information,
> >> and
> >> thus suffer from the tight coupling with the data source. Filed as
> >> r.
> >> 5690092.
> >
> > Thank you for logging the bug! This is the best way to get things
> > like this changed.
> >
> > For others, Kyle is basically asking that the option to show a
> > disclosure triangle be determined by a delegate method. That is an
> > excellent it, and it is something we have wanted to do. It was more
> > of a timing issue for why it wasn't done.
> >
> > thanks,
> > corbin
> >
>
> I'm a little unsure of the netiquette here, as I have a nice solution
> BUT *it is someone else's code* and I don't know who/where from!
> Explanation follows, but please don't credit me for it.
>
> Subclass NSOutlineView, and override the following method:
>
> - (NSRect)frameOfOutlineCellAtRow:(NSInteger)row
> {
> // Default to show triangle
> BOOL showTriangle = YES;
>
> // See if delegate responds to new selector
> if ([[self delegate]
> respondsToSelector
> :@selector(outlineView:shouldShowDisclosureTriangleForItem:)])
> {
> // Perform selector using objc_msgSend() to avoid
> compiler warnings
> SEL selector =
> @selector(outlineView:shouldShowDisclosureTriangleForItem:);
> id item = [self itemAtRow:row];
>
> showTriangle = (objc_msgSend([self delegate], selector,
> self, item) !
> = 0x00);
> }
>
> if (!showTriangle)
> {
> // If not showing triangle, return empty rect
> return NSZeroRect;
> }
> else
> {
> // else return default value
> return [super frameOfOutlineCellAtRow:row];
> }
> }
>
>
> Then, replace your outline views in IB with your custom one, and the
> delegate can implement:
>
> - (void)outlineView:(NSOutlineView *)
> shouldShowDisclosureTriangleForItem:(id)item
>
> to decide whether or not to show the triangle.
>
> --Ben
>
That looks like the code from my blog - I'm just glad it's proven
useful to people. It's nice to be able to "give something back" to the
list.
I'm relatively new to Cocoa development so hadn't considered Corbin's
point about the selector naming possibly clashing with future API
updates. Hamish's suggestion of implementing an NSObject category is
also something that hadn't crossed my mind. I'll update my blog
incorporating these changes (http://blog.petecallaway.net) soon.
Cheers,
Pete
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden