A few more changes for CPToolbar nib2cib support and added beginnings of search field support.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I
2010-01-12 22:54:35 -08:00
parent 24b495ca43
commit e76ee3c96e
5 changed files with 177 additions and 229 deletions
+105 -81
View File
@@ -220,7 +220,7 @@ var CPToolbarConfigurationsByIdentifier = nil;
*/
- (void)setDelegate:(id)aDelegate
{
if (_delegate == aDelegate)
if (_delegate === aDelegate)
return;
_delegate = aDelegate;
@@ -252,19 +252,22 @@ var CPToolbarConfigurationsByIdentifier = nil;
/* @ignore */
- (void)_reloadToolbarItems
{
// As of OS X 10.5 (Leopard), toolbar items can be set in IB and a toolbar delegate is optional.
// Toolbar items can be combined from both IB and a delegate (see Apple's NSToolbar guide for IB, for more details).
// As of OS X 10.5 (Leopard), toolbar items can be set in IB and a
// toolbar delegate is optional. Toolbar items can be combined from
// both IB and a delegate (see Apple's NSToolbar guide for IB, for more details).
// _defaultItems may have been loaded from Nib
_itemIdentifiers = [_defaultItems valueForKey:"_itemIdentifier"];
if (_delegate)
{
var itemIdentifiersFromDelegate = [[_delegate toolbarDefaultItemIdentifiers:self] mutableCopy];
if(itemIdentifiersFromDelegate)
_itemIdentifiers = [_itemIdentifiers arrayByAddingObjectsFromArray:itemIdentifiersFromDelegate];
}
var count = [_itemIdentifiers count];
// _defaultItems may have been loaded from Cib
_itemIdentifiers = [_defaultItems valueForKey:@"itemIdentifier"] || [];
if (_delegate)
{
var itemIdentifiersFromDelegate = [[_delegate toolbarDefaultItemIdentifiers:self] mutableCopy];
if (itemIdentifiersFromDelegate)
_itemIdentifiers = [_itemIdentifiers arrayByAddingObjectsFromArray:itemIdentifiersFromDelegate];
}
var count = [_itemIdentifiers count];
_items = [];
@@ -275,17 +278,18 @@ var CPToolbarConfigurationsByIdentifier = nil;
var identifier = _itemIdentifiers[index],
item = [CPToolbarItem _standardItemWithItemIdentifier:identifier];
// May come from a Cib.
if (!item)
item = [_identifiedItems objectForKey:identifier]; // may have been loaded from Nib
item = [_identifiedItems objectForKey:identifier];
if (!item && _delegate)
item = [_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES];
item = [item copy];
if (item == nil)
if (item === nil)
[CPException raise:CPInvalidArgumentException
reason:sprintf(@"_delegate %s returned nil toolbar item returned for identifier %s", _delegate, identifier)];
reason:@"Toolbar delegate " + _delegate + " returned nil toolbar item for identifier \"" + identifier + "\""];
item._toolbar = self;
@@ -296,9 +300,9 @@ var CPToolbarConfigurationsByIdentifier = nil;
// Store items sorted by priority. We want items to be removed first at the end of the array,
// items to be removed last at the front.
_itemsSortedByVisibilityPriority = [_items sortedArrayUsingFunction:_CPToolbarItemVisibilityPriorityCompare context:NULL];
[_toolbarView reloadToolbarItems];
}
@@ -369,10 +373,18 @@ var CPToolbarConfigurationsByIdentifier = nil;
/* @ignore */
- (id)_defaultToolbarItems
{
if (!_defaultItems)
if ([_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)])
_defaultItems = [self _itemsWithIdentifiers:[_delegate toolbarDefaultItemIdentifiers:self]];
if (!_defaultItems && [_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)])
{
_defaultItems = [];
var identifiers = [_delegate toolbarDefaultItemIdentifiers:self],
index = 0,
count = [identifiers count];
for (; index < count; ++index)
[_defaultItems addObject:[self _itemForItemIdentifier:identifiers[index] willBeInsertedIntoToolbar:NO]];
}
return _defaultItems;
}
@@ -382,35 +394,39 @@ var CPToolbarConfigurationsByIdentifier = nil;
*/
- (void)toolbarItemDidChange:(CPToolbarItem)anItem
{
if([_identifiedItems objectForKey:[anItem itemIdentifier]])
if ([_identifiedItems objectForKey:[anItem itemIdentifier]])
[_identifiedItems setObject:anItem forKey:[anItem itemIdentifier]];
for(var index = 0; index <= _items.length; index++)
var index = 0,
count = [_items count];
for (; index <= count; ++index)
{
var item = _items[index];
if([item itemIdentifier] === [anItem itemIdentifier])
if ([item itemIdentifier] === [anItem itemIdentifier])
{
_items[index] = anItem;
_itemsSortedByVisibilityPriority = [_items sortedArrayUsingFunction:_CPToolbarItemVisibilityPriorityCompare context:NULL];
[_toolbarView reloadToolbarItems];
break;
}
}
}
}
@end
var CPToolbarIdentifierKey = "CPToolbarIdentifierKey",
CPToolbarDisplayModeKey = "CPToolbarDisplayModeKey",
CPToolbarShowsBaselineSeparatorKey = "CPToolbarShowsBaselineSeparatorKey",
CPToolbarAllowsUserCustomizationKey = "CPToolbarAllowsUserCustomizationKey",
CPToolbarIsVisibleKey = "CPToolbarIsVisibleKey",
CPToolbarDelegateKey = "CPToolbarDelegateKey",
CPToolbarIdentifiedItemsKey = "CPToolbarIdentifiedItemsKey",
CPToolbarDefaultItemsKey = "CPToolbarDefaultItemsKey",
CPToolbarAllowedItemsKey = "CPToolbarAllowedItemsKey",
CPToolbarSelectableItemsKey = "CPToolbarSelectableItemsKey";
var CPToolbarIdentifierKey = @"CPToolbarIdentifierKey",
CPToolbarDisplayModeKey = @"CPToolbarDisplayModeKey",
CPToolbarShowsBaselineSeparatorKey = @"CPToolbarShowsBaselineSeparatorKey",
CPToolbarAllowsUserCustomizationKey = @"CPToolbarAllowsUserCustomizationKey",
CPToolbarIsVisibleKey = @"CPToolbarIsVisibleKey",
CPToolbarDelegateKey = @"CPToolbarDelegateKey",
CPToolbarIdentifiedItemsKey = @"CPToolbarIdentifiedItemsKey",
CPToolbarDefaultItemsKey = @"CPToolbarDefaultItemsKey",
CPToolbarAllowedItemsKey = @"CPToolbarAllowedItemsKey",
CPToolbarSelectableItemsKey = @"CPToolbarSelectableItemsKey";
@implementation CPToolbar (CPCoding)
@@ -424,38 +440,36 @@ var CPToolbarIdentifierKey = "CPToolbarIdentifierKey",
if (self)
{
_identifier = [aCoder decodeObjectForKey:CPToolbarIdentifierKey];
_displayMode = [aCoder decodeIntForKey:CPToolbarDisplayModeKey];
_showsBaselineSeparator = [aCoder decodeBoolForKey:CPToolbarShowsBaselineSeparatorKey];
_allowsUserCustomization = [aCoder decodeBoolForKey:CPToolbarAllowsUserCustomizationKey];
_isVisible = [aCoder decodeBoolForKey:CPToolbarIsVisibleKey];
_identifiedItems = [aCoder decodeObjectForKey:CPToolbarIdentifiedItemsKey];
_defaultItems = [aCoder decodeObjectForKey:CPToolbarDefaultItemsKey];
_allowedItems = [aCoder decodeObjectForKey:CPToolbarAllowedItemsKey];
_selectableItems = [aCoder decodeObjectForKey:CPToolbarSelectableItemsKey];
var identifiedItems = [_identifiedItems allValues];
[identifiedItems makeObjectsPerformSelector:@selector(_setToolbar:) withObject:self];
_identifier = [aCoder decodeObjectForKey:CPToolbarIdentifierKey];
_displayMode = [aCoder decodeIntForKey:CPToolbarDisplayModeKey];
_showsBaselineSeparator = [aCoder decodeBoolForKey:CPToolbarShowsBaselineSeparatorKey];
_allowsUserCustomization = [aCoder decodeBoolForKey:CPToolbarAllowsUserCustomizationKey];
_isVisible = [aCoder decodeBoolForKey:CPToolbarIsVisibleKey];
_identifiedItems = [aCoder decodeObjectForKey:CPToolbarIdentifiedItemsKey];
_defaultItems = [aCoder decodeObjectForKey:CPToolbarDefaultItemsKey];
_allowedItems = [aCoder decodeObjectForKey:CPToolbarAllowedItemsKey];
_selectableItems = [aCoder decodeObjectForKey:CPToolbarSelectableItemsKey];
[[_identifiedItems allValues] makeObjectsPerformSelector:@selector(_setToolbar:) withObject:self];
_items = [];
[CPToolbar _addToolbar:self forIdentifier:_identifier];
// [self setDelegate:[aCoder decodeObjectForKey:CPToolbarDelegateKey]];
/*
The delegate is actually set by reference in the "IBObjectContainer" node of the Nib and not in the "NSToolbar" node,
and therefore we cannot read it here (otherwise we'll only read NULL). The correct delegate is read later outside this class
when node "IBObjectContainer" is processed, which triggers [setDelegate:].
Because we don't know if a delegate will be set later (it is optional as if OS X 10.5), we need to call [_reloadToolbarItems] here
in order to load any toolbar items that may have been configured in the Nib. Unfortunatelly this means that if there is a delegate
specified, it will be read later and the resulting call to [setDelegate:] will cause [_reloadToolbarItems] to run again :-(
Can we make this better?
*/
// This won't come from a Cib, but can come from manual encoding.
[self setDelegate:[aCoder decodeObjectForKey:CPToolbarDelegateKey]];
// Because we don't know if a delegate will be set later (it is optional
// as of OS X 10.5), we need to call -_reloadToolbarItems here.
// In order to load any toolbar items that may have been configured in the
// Cib. Unfortunatelly this means that if there is a delegate
// specified, it will be read later and the resulting call to -setDelegate:
// will cause -_reloadToolbarItems] to run again :-(
// FIXME: Can we make this better?
[self _reloadToolbarItems];
}
return self;
}
@@ -465,18 +479,18 @@ var CPToolbarIdentifierKey = "CPToolbarIdentifierKey",
*/
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:_identifier forKey:CPToolbarIdentifierKey];
[aCoder encodeInt:_displayMode forKey:CPToolbarDisplayModeKey];
[aCoder encodeBool:_showsBaselineSeparator forKey:CPToolbarShowsBaselineSeparatorKey];
[aCoder encodeObject:_identifier forKey:CPToolbarIdentifierKey];
[aCoder encodeInt:_displayMode forKey:CPToolbarDisplayModeKey];
[aCoder encodeBool:_showsBaselineSeparator forKey:CPToolbarShowsBaselineSeparatorKey];
[aCoder encodeBool:_allowsUserCustomization forKey:CPToolbarAllowsUserCustomizationKey];
[aCoder encodeBool:_isVisible forKey:CPToolbarIsVisibleKey];
[aCoder encodeObject:_identifiedItems forKey:CPToolbarIdentifiedItemsKey];
[aCoder encodeObject:_defaultItems forKey:CPToolbarDefaultItemsKey];
[aCoder encodeObject:_allowedItems forKey:CPToolbarAllowedItemsKey];
[aCoder encodeObject:_selectableItems forKey:CPToolbarSelectableItemsKey];
[aCoder encodeConditionalObject:_delegate forKey:CPToolbarDelegateKey];
[aCoder encodeBool:_isVisible forKey:CPToolbarIsVisibleKey];
[aCoder encodeObject:_identifiedItems forKey:CPToolbarIdentifiedItemsKey];
[aCoder encodeObject:_defaultItems forKey:CPToolbarDefaultItemsKey];
[aCoder encodeObject:_allowedItems forKey:CPToolbarAllowedItemsKey];
[aCoder encodeObject:_selectableItems forKey:CPToolbarSelectableItemsKey];
[aCoder encodeConditionalObject:_delegate forKey:CPToolbarDelegateKey];
}
@end
@@ -520,7 +534,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
+ (void)initialize
{
if (self != [_CPToolbarView class])
if (self !== [_CPToolbarView class])
return;
var bundle = [CPBundle bundleForClass:self];
@@ -819,7 +833,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
_minWidth += [view minSize].width + TOOLBAR_ITEM_MARGIN;
}
[self tile];
}
@@ -882,7 +896,16 @@ var TOP_MARGIN = 5.0,
_toolbar = aToolbar;
[_toolbarItem addObserver:self forKeyPath:"enabled" options:0 context:NULL];
var keyPaths = [@"label", @"image", @"alternateImage", @"minSize", @"maxSize", @"enabled"],
index = 0,
count = [keyPaths count];
for (; index < count; ++index)
[_toolbarItem
addObserver:self
forKeyPath:keyPaths[index]
options:0
context:NULL];
}
return self;
@@ -1077,9 +1100,10 @@ var TOP_MARGIN = 5.0,
change:(CPDictionary)aChange
context:(id)aContext
{
// FIXME: Not clear if -synchronizeWindowTitleWithDocumentName is the best way to go.
if (aKeyPath === "enabled")
[self setEnabled:[anObject isEnabled]];
else
[self updateFromItem];
}
@end
+25 -143
View File
@@ -48,13 +48,13 @@ CPToolbarItemVisibilityPriorityHigh = 1000;
*/
CPToolbarItemVisibilityPriorityUser = 2000;
CPToolbarSeparatorItemIdentifier = @"CPToolbarSeparatorItemIdentifier";
CPToolbarSpaceItemIdentifier = @"CPToolbarSpaceItemIdentifier";
CPToolbarFlexibleSpaceItemIdentifier = @"CPToolbarFlexibleSpaceItemIdentifier";
CPToolbarShowColorsItemIdentifier = @"CPToolbarShowColorsItemIdentifier";
CPToolbarShowFontsItemIdentifier = @"CPToolbarShowFontsItemIdentifier";
CPToolbarCustomizeToolbarItemIdentifier = @"CPToolbarCustomizeToolbarItemIdentifier";
CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
CPToolbarSeparatorItemIdentifier = @"CPToolbarSeparatorItem";
CPToolbarSpaceItemIdentifier = @"CPToolbarSpaceItem";
CPToolbarFlexibleSpaceItemIdentifier = @"CPToolbarFlexibleSpaceItem";
CPToolbarShowColorsItemIdentifier = @"CPToolbarShowColorsItem";
CPToolbarShowFontsItemIdentifier = @"CPToolbarShowFontsItem";
CPToolbarCustomizeToolbarItemIdentifier = @"CPToolbarCustomizeToolbarItem";
CPToolbarPrintItemIdentifier = @"CPToolbarPrintItem";
/*!
@ingroup appkit
@@ -114,6 +114,7 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
_maxSize = CGSizeMakeZero();
_visibilityPriority = CPToolbarItemVisibilityPriorityStandard;
_autovalidates = YES;
}
return self;
@@ -157,9 +158,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
- (void)setLabel:(CPString)aLabel
{
_label = aLabel;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -177,9 +175,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
- (void)setPaletteLabel:(CPString)aPaletteLabel
{
_paletteLabel = aPaletteLabel;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -205,9 +200,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
[view setToolTip:aToolTip];
_toolTip = aToolTip;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -231,9 +223,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
[_view setTag:aTag];
_tag = aTag;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -259,9 +248,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
else if ([_view respondsToSelector:@selector(setTarget:)])
[_view setTarget:aTarget];
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -286,9 +272,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
else if ([_view respondsToSelector:@selector(setAction:)])
[_view setAction:anAction];
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -312,9 +295,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
[_view setEnabled:shouldBeEnabled];
_isEnabled = shouldBeEnabled;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -358,9 +338,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
[self setMaxSize:imageSize];
}
}
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -373,9 +350,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
[_view setAlternateImage:anImage];
_alternateImage = anImage;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -417,9 +391,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
_target = nil;
_action = nil;
}
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -443,9 +414,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
// Try to provide some sanity: Make maxSize >= minSize
_maxSize = CGSizeMake(MAX(_minSize.width, _maxSize.width), MAX(_minSize.height, _maxSize.height));
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
/*!
@@ -469,9 +437,6 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
// Try to provide some sanity: Make minSize <= maxSize
_minSize = CGSizeMake(MIN(_minSize.width, _maxSize.width), MIN(_minSize.height, _maxSize.height));
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
// Visibility Priority
@@ -502,9 +467,6 @@ CPToolbarItemVisibilityPriorityUser
- (void)setVisibilityPriority:(int)aVisibilityPriority
{
_visibilityPriority = aVisibilityPriority;
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
}
- (void)validate
@@ -551,7 +513,7 @@ CPToolbarItemVisibilityPriorityUser
@end
var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey",
CPToolbarItemLabelKey = @"CPToolbarItemLabelKey",
CPToolbarItemPaletteLabelKey = @"CPToolbarItemPaletteLabelKey",
CPToolbarItemToolTipKey = @"CPToolbarItemToolTipKey",
@@ -564,7 +526,8 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
CPToolbarItemViewKey = @"CPToolbarItemViewKey",
CPToolbarItemMinSizeKey = @"CPToolbarItemMinSizeKey",
CPToolbarItemMaxSizeKey = @"CPToolbarItemMaxSizeKey",
CPToolbarItemVisibilityPriorityKey = @"CPToolbarItemVisibilityPriorityKey";
CPToolbarItemVisibilityPriorityKey = @"CPToolbarItemVisibilityPriorityKey",
CPToolbarItemAutovalidatesKey = @"CPToolbarItemAutovalidatesKey";
@implementation CPToolbarItem (CPCoding)
@@ -574,7 +537,10 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
if (self)
{
_itemIdentifier = [aCoder decodeObjectForKey:CPToolbarItemIdentifierKey];
_itemIdentifier = [aCoder decodeObjectForKey:CPToolbarItemItemIdentifierKey];
_minSize = [aCoder decodeSizeForKey:CPToolbarItemMinSizeKey];
_maxSize = [aCoder decodeSizeForKey:CPToolbarItemMaxSizeKey];
[self setLabel:[aCoder decodeObjectForKey:CPToolbarItemLabelKey]];
[self setPaletteLabel:[aCoder decodeObjectForKey:CPToolbarItemPaletteLabelKey]];
@@ -591,10 +557,8 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
[self setView:[aCoder decodeObjectForKey:CPToolbarItemViewKey]];
[self setMinSize:[aCoder decodeSizeForKey:CPToolbarItemMinSizeKey]];
[self setMaxSize:[aCoder decodeSizeForKey:CPToolbarItemMaxSizeKey]];
[self setVisibilityPriority:[aCoder decodeIntForKey:CPToolbarItemVisibilityPriorityKey]];
[self setAutovalidates:[aCoder decodeBoolForKey:CPToolbarItemAutovalidatesKey]];
}
return self;
@@ -624,6 +588,7 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
[aCoder encodeSize:[self maxSize] forKey:CPToolbarItemMaxSizeKey];
[aCoder encodeObject:[self visibilityPriority] forKey:CPToolbarItemVisibilityPriorityKey];
[aCoder encodeBool:[self autovalidates] forKey:CPToolbarItemAutovalidatesKey];
}
@end
@@ -633,12 +598,12 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
- (id)copy
{
var copy = [[[self class] alloc] initWithItemIdentifier:_itemIdentifier];
if (_view)
[copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]];
[copy _setToolbar:_toolbar];
[copy setLabel:_label];
[copy setPaletteLabel:_paletteLabel];
[copy setToolTip:[self toolTip]];
@@ -646,7 +611,7 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
[copy setTag:[self tag]];
[copy setTarget:[self target]];
[copy setAction:[self action]];
[copy setEnabled:[self isEnabled]];
[copy setImage:[self image]];
@@ -654,98 +619,15 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey",
[copy setMinSize:_minSize];
[copy setMaxSize:_maxSize];
[copy setVisibilityPriority:_visibilityPriority];
[copy setVisibilityPriority:[self visibilityPriority]];
[copy setAutovalidates:[self autovalidates]];
return copy;
}
@end
var CPToolbarItemIdentifierKey = "CPToolbarItemIdentifierKey",
CPToolbarItemLabelKey = "CPToolbarItemLabelKey",
CPToolbarItemPaletteLabelKey = "CPToolbarItemPaletteLabelKey",
CPToolbarItemToolTipKey = "CPToolbarItemToolTipKey",
CPToolbarItemTagKey = "CPToolbarItemTagKey",
CPToolbarItemTargetKey = "CPToolbarItemTargetKey",
CPToolbarItemActionKey = "CPToolbarItemActionKey",
CPToolbarItemEnabledKey = "CPToolbarItemEnabledKey",
CPToolbarItemImageKey = "CPToolbarItemImageKey",
CPToolbarItemAlternateImageKey = "CPToolbarItemAlternateImageKey",
CPToolbarItemViewKey = "CPToolbarItemViewKey",
CPToolbarItemMinSizeKey = "CPToolbarItemMinSizeKey",
CPToolbarItemMaxSizeKey = "CPToolbarItemMaxSizeKey",
CPToolbarItemVisibilityPriorityKey = "CPToolbarItemVisibilityPriorityKey";
CPToolbarItemAutovalidatesKey = "CPToolbarItemAutovalidatesKey";
@implementation CPToolbarItem (CPCoding)
/*
Initializes the toolbar item by unarchiving data from <code>aCoder</code>.
@param aCoder the coder containing the archived CPToolbarItem.
*/
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super init];
if (self)
{
_itemIdentifier = [aCoder decodeObjectForKey:CPToolbarItemIdentifierKey];
_label = [aCoder decodeObjectForKey:CPToolbarItemLabelKey];
_paletteLabel = [aCoder decodeObjectForKey:CPToolbarItemPaletteLabelKey];
_toolTip = [aCoder decodeObjectForKey:CPToolbarItemToolTipKey];
_tag = [aCoder decodeIntForKey:CPToolbarItemTagKey];
_target = [aCoder decodeObjectForKey:CPToolbarItemTargetKey];
_action = [aCoder decodeObjectForKey:CPToolbarItemActionKey];
_isEnabled = [aCoder decodeBoolForKey:CPToolbarItemEnabledKey];
_view = [aCoder decodeObjectForKey:CPToolbarItemViewKey];
_minSize = [aCoder decodeSizeForKey:CPToolbarItemMinSizeKey];
_maxSize = [aCoder decodeSizeForKey:CPToolbarItemMaxSizeKey];
_visibilityPriority = [aCoder decodeIntForKey:CPToolbarItemVisibilityPriorityKey];
_autovalidates = [aCoder decodeBoolForKey:CPToolbarItemAutovalidatesKey];
if(!_minSize.height || !_minSize.width)
_minSize = CGSizeMakeZero();
if(!_maxSize.height || !_maxSize.width)
_maxSize = CGSizeMakeZero();
[self setImage: [aCoder decodeObjectForKey:CPToolbarItemImageKey]];
// [self setAlternateImage: [aCoder decodeObjectForKey:CPToolbarItemAlternateImageKey]]; // no altImage in Nib
}
return self;
}
/*
Archives this toolbar item into the provided coder.
@param aCoder the coder to which the toolbar item's instance data will be written.
*/
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:_itemIdentifier forKey:CPToolbarItemIdentifierKey];
[aCoder encodeObject:_label forKey:CPToolbarItemLabelKey];
[aCoder encodeObject:_paletteLabel forKey:CPToolbarItemPaletteLabelKey];
[aCoder encodeObject:_toolTip forKey:CPToolbarItemToolTipKey];
[aCoder encodeInt:_tag forKey:CPToolbarItemTagKey];
[aCoder encodeBool:_isEnabled forKey:CPToolbarItemEnabledKey];
[aCoder encodeObject:_view forKey:CPToolbarItemViewKey];
[aCoder encodeSize:_minSize forKey:CPToolbarItemMinSizeKey];
[aCoder encodeSize:_maxSize forKey:CPToolbarItemMaxSizeKey];
[aCoder encodeInt:_visibilityPriority forKey:CPToolbarItemVisibilityPriorityKey];
[aCoder encodeBool:_autovalidates forKey:CPToolbarItemAutovalidatesKey];
[aCoder encodeObject:_image forKey:CPToolbarItemImageKey];
// [aCoder encodeObject:_alternateImage forKey:CPToolbarItemAlternateImageKey]; // no altImage in IB
}
@end
// Standard toolbar identifiers
@implementation CPToolbarItem (Standard)
+1
View File
@@ -44,6 +44,7 @@
@import "NSResponder.j"
@import "NSScrollView.j"
@import "NSScroller.j"
@import "NSSearchField.j"
@import "NSSet.j"
@import "NSSecureTextField.j"
@import "NSSegmentedControl.j"
+41
View File
@@ -0,0 +1,41 @@
@import <AppKit/CPSearchField.j>
@import "NSTextField.j"
@implementation CPSearchField (NSCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
{
self = [super NS_initWithCoder:aCoder];
if (self)
{
}
return self;
}
@end
@implementation NSSearchField : CPSearchField
{
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self NS_initWithCoder:aCoder];
}
- (Class)classForKeyedArchiver
{
return [CPSearchField class];
}
@end
@implementation NSSearchFieldCell : NSTextFieldCell
{
}
@end
+5 -5
View File
@@ -45,7 +45,10 @@ NS_CPToolbarItemIdentifierMap =
{
var NS_itemIdentifier = [aCoder decodeObjectForKey:@"NSToolbarItemIdentifier"];
_itemIdentifier = NS_CPToolbarItemIdentifierMap[NS_itemIdentifier] || _itemIdentifier;
_itemIdentifier = NS_CPToolbarItemIdentifierMap[NS_itemIdentifier] || NS_itemIdentifier;
_minSize = [aCoder decodeSizeForKey:@"NSToolbarItemMinSize"] || CGSizeMakeZero();
_maxSize = [aCoder decodeSizeForKey:@"NSToolbarItemMaxSize"] || CGSizeMakeZero();
[self setLabel:[aCoder decodeObjectForKey:@"NSToolbarItemLabel"]];
[self setPaletteLabel:[aCoder decodeObjectForKey:@"NSToolbarItemPaletteLabel"]];
@@ -56,16 +59,13 @@ NS_CPToolbarItemIdentifierMap =
[self setAction:CPSelectorFromString([aCoder decodeObjectForKey:@"NSToolbarItemAction"])];
[self setEnabled:[aCoder decodeBoolForKey:@"NSToolbarItemEnabled"]];
[self setAutovalidates:[aCoder decodeBoolForKey:"NSToolbarItemAutovalidates"]];
[self setImage:[aCoder decodeBoolForKey:@"NSToolbarItemImage"]];
[self setView:[aCoder decodeObjectForKey:@"NSToolbarItemView"]];
_minSize = [aCoder decodeSizeForKey:@"NSToolbarItemMinSize"];
_maxSize = [aCoder decodeSizeForKey:@"NSToolbarItemMaxSize"];
[self setVisibilityPriority:[aCoder decodeIntForKey:@"NSToolbarItemVisibilityPriority"]];
[self setAutovalidates:[aCoder decodeBoolForKey:"NSToolbarItemAutovalidates"]];
}
return self;