From 80d537958e5611cb74cb80d1e4b77e831e5cbfb7 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 28 Jun 2012 19:12:05 +0100 Subject: [PATCH] Fixed: CPToolbar delegate toolbarDefaultItemIdentifiers: is optional. This fix makes it possible for a toolbar defined in a cib to have a delegate set without defining `toolbarDefaultItemIdentifiers:` like in Cocoa. You might be implementing other delegate methods. --- AppKit/CPToolbar.j | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index 4c7429638..f2283e7a5 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -314,13 +314,17 @@ var CPToolbarsByIdentifier = nil, // _defaultItems may have been loaded from Cib _itemIdentifiers = [_defaultItems valueForKey:@"itemIdentifier"] || []; - if (_delegate) + if ([_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)]) { var itemIdentifiersFromDelegate = [[_delegate toolbarDefaultItemIdentifiers:self] mutableCopy]; + // If we get items both from the Cib and from the delegate method, put the delegate items before the + // Cib ones. if (itemIdentifiersFromDelegate) - _itemIdentifiers = [_itemIdentifiers arrayByAddingObjectsFromArray:itemIdentifiersFromDelegate]; + _itemIdentifiers = [itemIdentifiersFromDelegate arrayByAddingObjectsFromArray:_itemIdentifiers]; } + // If we didn't load from a cib and the delegate hasn't been set yet, we'll just work with an empty list + // at this point. var index = 0, count = [_itemIdentifiers count];