From 1c89968b69346b464f88a900b619ea76b329d928 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 12 Jan 2010 19:02:43 -0800 Subject: [PATCH 1/6] nib2cib support for the new CPToolbar/CPToolbarItem, also improved classes to pick up item property changes (i.e, setLabel:, setAction:, etc.) after the toolbar has been initialized Conflicts: Tools/nib2cib/NSAppKit.j Tools/nib2cib/NSToolbarItem.j --- AppKit/CPToolbar.j | 69 ++++++++-- AppKit/CPToolbarItem.j | 152 ++++++++++++++++++++- Tools/nib2cib/NSAppKit.j | 5 +- Tools/nib2cib/NSToolbarFlexibleSpaceItem.j | 41 ++++++ Tools/nib2cib/NSToolbarItem.j | 28 ++-- Tools/nib2cib/NSToolbarSeparatorItem.j | 41 ++++++ Tools/nib2cib/NSToolbarSpaceItem.j | 41 ++++++ 7 files changed, 348 insertions(+), 29 deletions(-) create mode 100644 Tools/nib2cib/NSToolbarFlexibleSpaceItem.j create mode 100644 Tools/nib2cib/NSToolbarSeparatorItem.j create mode 100644 Tools/nib2cib/NSToolbarSpaceItem.j diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index 04024632e..fe60da738 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -252,16 +252,19 @@ var CPToolbarConfigurationsByIdentifier = nil; /* @ignore */ - (void)_reloadToolbarItems { - if (!_delegate) - return; + // 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). - var count = [_itemIdentifiers count]; - - if (!count) - { - _itemIdentifiers = [[_delegate toolbarDefaultItemIdentifiers:self] mutableCopy]; - count = [_itemIdentifiers count]; - } + // _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]; _items = []; @@ -273,6 +276,9 @@ var CPToolbarConfigurationsByIdentifier = nil; item = [CPToolbarItem _standardItemWithItemIdentifier:identifier]; if (!item) + item = [_identifiedItems objectForKey:identifier]; // may have been loaded from Nib + + if (!item && _delegate) item = [_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES]; item = [item copy]; @@ -280,6 +286,8 @@ var CPToolbarConfigurationsByIdentifier = nil; if (item == nil) [CPException raise:CPInvalidArgumentException reason:sprintf(@"_delegate %s returned nil toolbar item returned for identifier %s", _delegate, identifier)]; + + item._toolbar = self; [_items addObject:item]; } @@ -359,7 +367,7 @@ var CPToolbarConfigurationsByIdentifier = nil; } /* @ignore */ --(id)_defaultToolbarItems +- (id)_defaultToolbarItems { if (!_defaultItems) if ([_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)]) @@ -368,6 +376,28 @@ var CPToolbarConfigurationsByIdentifier = nil; return _defaultItems; } +/*! + Notifies the toolbar that an item has been changed. This will cause the toolbar to reload its items. + @param anItem the item that has been changed +*/ +- (void)toolbarItemDidChange:(CPToolbarItem)anItem +{ + if([_identifiedItems objectForKey:[anItem itemIdentifier]]) + [_identifiedItems setObject:anItem forKey:[anItem itemIdentifier]]; + + for(var index = 0; index <= _items.length; index++) + { + var item = _items[index]; + if([item itemIdentifier] === [anItem itemIdentifier]) + { + _items[index] = anItem; + _itemsSortedByVisibilityPriority = [_items sortedArrayUsingFunction:_CPToolbarItemVisibilityPriorityCompare context:NULL]; + [_toolbarView reloadToolbarItems]; + break; + } + } +} + @end @@ -405,10 +435,25 @@ var CPToolbarIdentifierKey = "CPToolbarIdentifierKey", _allowedItems = [aCoder decodeObjectForKey:CPToolbarAllowedItemsKey]; _selectableItems = [aCoder decodeObjectForKey:CPToolbarSelectableItemsKey]; + var identifiedItems = [_identifiedItems allValues]; + [identifiedItems makeObjectsPerformSelector:@selector(_setToolbar:) withObject:self]; + _items = []; [CPToolbar _addToolbar:self forIdentifier:_identifier]; - - [self setDelegate:[aCoder decodeObjectForKey:CPToolbarDelegateKey]]; + +// [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? + */ + [self _reloadToolbarItems]; } return self; diff --git a/AppKit/CPToolbarItem.j b/AppKit/CPToolbarItem.j index 2cdd5528c..5562ef784 100644 --- a/AppKit/CPToolbarItem.j +++ b/AppKit/CPToolbarItem.j @@ -65,9 +65,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; @implementation CPToolbarItem : CPObject { CPString _itemIdentifier; - + CPToolbar _toolbar; - + CPString _label; CPString _paletteLabel; CPString _toolTip; @@ -77,12 +77,12 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; BOOL _isEnabled; CPImage _image; CPImage _alternateImage; - + CPView _view; - + CGSize _minSize; CGSize _maxSize; - + int _visibilityPriority; BOOL _autovalidates; @@ -136,6 +136,12 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; return _toolbar; } +/* @ignore */ +- (void)_setToolbar:(CPToolbar)aToolbar +{ + _toolbar = aToolbar; +} + /*! Returns the item's label */ @@ -151,6 +157,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; - (void)setLabel:(CPString)aLabel { _label = aLabel; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -168,6 +177,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; - (void)setPaletteLabel:(CPString)aPaletteLabel { _paletteLabel = aPaletteLabel; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -193,6 +205,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; [view setToolTip:aToolTip]; _toolTip = aToolTip; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -216,6 +231,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; [_view setTag:aTag]; _tag = aTag; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -241,6 +259,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; else if ([_view respondsToSelector:@selector(setTarget:)]) [_view setTarget:aTarget]; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -265,6 +286,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; else if ([_view respondsToSelector:@selector(setAction:)]) [_view setAction:anAction]; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -288,6 +312,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; [_view setEnabled:shouldBeEnabled]; _isEnabled = shouldBeEnabled; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -313,7 +340,12 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; _image = anImage; if (!_image) + { + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; + return; + } if (_minSize.width == 0 && _minSize.height == 0 && _maxSize.width == 0 && _maxSize.height == 0) @@ -326,6 +358,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; [self setMaxSize:imageSize]; } } + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -338,6 +373,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; [_view setAlternateImage:anImage]; _alternateImage = anImage; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -379,6 +417,9 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; _target = nil; _action = nil; } + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } /*! @@ -395,10 +436,16 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; */ - (void)setMinSize:(CGSize)aMinSize { + if(!aMinSize.height || !aMinSize.width) + return; + _minSize = CGSizeMakeCopy(aMinSize); // 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]; } /*! @@ -415,10 +462,16 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier"; */ - (void)setMaxSize:(CGSize)aMaxSize { + if(!aMaxSize.height || !aMaxSize.width) + return; + _maxSize = CGSizeMakeCopy(aMaxSize); // 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 @@ -449,6 +502,9 @@ CPToolbarItemVisibilityPriorityUser - (void)setVisibilityPriority:(int)aVisibilityPriority { _visibilityPriority = aVisibilityPriority; + + if(_toolbar) + [_toolbar toolbarItemDidChange:self]; } - (void)validate @@ -581,6 +637,8 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey", if (_view) [copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]]; + [copy _setToolbar:_toolbar]; + [copy setLabel:_label]; [copy setPaletteLabel:_paletteLabel]; [copy setToolTip:[self toolTip]]; @@ -604,6 +662,90 @@ var CPToolbarItemIdentifierKey = @"CPToolbarItemIdentifierKey", @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 aCoder. + @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) diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index b6c4cda04..311d5a349 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -1,4 +1,4 @@ -/* + /* * NSAppKit.j * nib2cib * @@ -56,6 +56,9 @@ @import "NSTextField.j" @import "NSToolbar.j" @import "NSToolbarItem.j" +@import "NSToolbarFlexibleSpaceItem.j" +@import "NSToolbarSeparatorItem.j" +@import "NSToolbarSpaceItem.j" @import "NSView.j" @import "NSViewController.j" @import "NSWindowTemplate.j" diff --git a/Tools/nib2cib/NSToolbarFlexibleSpaceItem.j b/Tools/nib2cib/NSToolbarFlexibleSpaceItem.j new file mode 100644 index 000000000..d48775e72 --- /dev/null +++ b/Tools/nib2cib/NSToolbarFlexibleSpaceItem.j @@ -0,0 +1,41 @@ +/* + * NSToolbarFlexibleSpaceItem.j + * nib2cib + * + * Created by Dimitris Tsitses. + * Copyright 2010, Blueberry Associates LLC. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + + + +@implementation NSToolbarFlexibleSpaceItem : CPToolbarItem +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPToolbarItem class]; +} + +@end diff --git a/Tools/nib2cib/NSToolbarItem.j b/Tools/nib2cib/NSToolbarItem.j index 1fc82af08..d6c0e7b69 100644 --- a/Tools/nib2cib/NSToolbarItem.j +++ b/Tools/nib2cib/NSToolbarItem.j @@ -2,8 +2,9 @@ * NSToolbarItem.j * nib2cib * - * Created by Francisco Tolmasky. + * Created by Francisco Tolmasky and Dimitris Tsitses. * Copyright 2010, 280 North, Inc. + * Copyright 2010, Blueberry Associates LLC. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -23,6 +24,17 @@ @import +NS_CPToolbarItemIdentifierMap = +{ + @"NSToolbarSeparatorItem" : CPToolbarSeparatorItemIdentifier, + @"NSToolbarSpaceItem" : CPToolbarSpaceItemIdentifier, + @"NSToolbarFlexibleSpaceItem" : CPToolbarFlexibleSpaceItemIdentifier, + @"NSToolbarShowColorsItem" : CPToolbarShowColorsItemIdentifier, + @"NSToolbarShowFontsItem" : CPToolbarShowFontsItemIdentifier, + @"NSToolbarCustomizeToolbarItem" : CPToolbarCustomizeToolbarItemIdentifier, + @"NSToolbarPrintItem" : CPToolbarPrintItemIdentifier +}; + @implementation CPToolbarItem (NSCoding) - (id)NS_initWithCoder:(CPCoder)aCoder @@ -31,7 +43,9 @@ if (self) { - _itemIdentifier = [aCoder decodeObjectForKey:@"NSToolbarItemIdentifier"]; + var NS_itemIdentifier = [aCoder decodeObjectForKey:@"NSToolbarItemIdentifier"]; + + _itemIdentifier = NS_CPToolbarItemIdentifierMap[NS_itemIdentifier] || _itemIdentifier; [self setLabel:[aCoder decodeObjectForKey:@"NSToolbarItemLabel"]]; [self setPaletteLabel:[aCoder decodeObjectForKey:@"NSToolbarItemPaletteLabel"]]; @@ -42,6 +56,7 @@ [self setAction:CPSelectorFromString([aCoder decodeObjectForKey:@"NSToolbarItemAction"])]; [self setEnabled:[aCoder decodeBoolForKey:@"NSToolbarItemEnabled"]]; + [self setAutovalidates:[aCoder decodeBoolForKey:"NSToolbarItemAutovalidates"]]; [self setImage:[aCoder decodeBoolForKey:@"NSToolbarItemImage"]]; @@ -73,12 +88,3 @@ } @end - -@implementation NSToolbarSpaceItem : NSToolbarItem -@end - -@implementation NSToolbarFlexibleSpaceItem : NSToolbarItem -@end - -@implementation NSToolbarSeparatorItem : NSToolbarItem -@end diff --git a/Tools/nib2cib/NSToolbarSeparatorItem.j b/Tools/nib2cib/NSToolbarSeparatorItem.j new file mode 100644 index 000000000..9d1b68ee6 --- /dev/null +++ b/Tools/nib2cib/NSToolbarSeparatorItem.j @@ -0,0 +1,41 @@ +/* + * NSToolbarSeparatorItem.j + * nib2cib + * + * Created by Dimitris Tsitses. + * Copyright 2010, Blueberry Associates LLC. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + + + +@implementation NSToolbarSeparatorItem : CPToolbarItem +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPToolbarItem class]; +} + +@end diff --git a/Tools/nib2cib/NSToolbarSpaceItem.j b/Tools/nib2cib/NSToolbarSpaceItem.j new file mode 100644 index 000000000..6e0fcdc19 --- /dev/null +++ b/Tools/nib2cib/NSToolbarSpaceItem.j @@ -0,0 +1,41 @@ +/* + * NSToolbarSpaceItem.j + * nib2cib + * + * Created by Dimitris Tsitses. + * Copyright 2010, Blueberry Associates LLC. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + + + +@implementation NSToolbarSpaceItem : CPToolbarItem +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPToolbarItem class]; +} + +@end From 03eed5f4f9ace56587b7595a7f76a564c7bc2c63 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 12 Jan 2010 19:05:22 -0800 Subject: [PATCH 2/6] Got rid of unecessary code/files. Reviewed by me. --- Tools/nib2cib/NSAppKit.j | 3 -- Tools/nib2cib/NSToolbarFlexibleSpaceItem.j | 41 ---------------------- Tools/nib2cib/NSToolbarItem.j | 9 +++++ Tools/nib2cib/NSToolbarSeparatorItem.j | 41 ---------------------- Tools/nib2cib/NSToolbarSpaceItem.j | 41 ---------------------- 5 files changed, 9 insertions(+), 126 deletions(-) delete mode 100644 Tools/nib2cib/NSToolbarFlexibleSpaceItem.j delete mode 100644 Tools/nib2cib/NSToolbarSeparatorItem.j delete mode 100644 Tools/nib2cib/NSToolbarSpaceItem.j diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index 311d5a349..d1e102e28 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -56,9 +56,6 @@ @import "NSTextField.j" @import "NSToolbar.j" @import "NSToolbarItem.j" -@import "NSToolbarFlexibleSpaceItem.j" -@import "NSToolbarSeparatorItem.j" -@import "NSToolbarSpaceItem.j" @import "NSView.j" @import "NSViewController.j" @import "NSWindowTemplate.j" diff --git a/Tools/nib2cib/NSToolbarFlexibleSpaceItem.j b/Tools/nib2cib/NSToolbarFlexibleSpaceItem.j deleted file mode 100644 index d48775e72..000000000 --- a/Tools/nib2cib/NSToolbarFlexibleSpaceItem.j +++ /dev/null @@ -1,41 +0,0 @@ -/* - * NSToolbarFlexibleSpaceItem.j - * nib2cib - * - * Created by Dimitris Tsitses. - * Copyright 2010, Blueberry Associates LLC. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -@import - - - -@implementation NSToolbarFlexibleSpaceItem : CPToolbarItem -{ -} - -- (id)initWithCoder:(CPCoder)aCoder -{ - return [self NS_initWithCoder:aCoder]; -} - -- (Class)classForKeyedArchiver -{ - return [CPToolbarItem class]; -} - -@end diff --git a/Tools/nib2cib/NSToolbarItem.j b/Tools/nib2cib/NSToolbarItem.j index d6c0e7b69..4914862db 100644 --- a/Tools/nib2cib/NSToolbarItem.j +++ b/Tools/nib2cib/NSToolbarItem.j @@ -88,3 +88,12 @@ NS_CPToolbarItemIdentifierMap = } @end + +@implementation NSToolbarSpaceItem : NSToolbarItem +@end + +@implementation NSToolbarFlexibleSpaceItem : NSToolbarItem +@end + +@implementation NSToolbarSeparatorItem : NSToolbarItem +@end diff --git a/Tools/nib2cib/NSToolbarSeparatorItem.j b/Tools/nib2cib/NSToolbarSeparatorItem.j deleted file mode 100644 index 9d1b68ee6..000000000 --- a/Tools/nib2cib/NSToolbarSeparatorItem.j +++ /dev/null @@ -1,41 +0,0 @@ -/* - * NSToolbarSeparatorItem.j - * nib2cib - * - * Created by Dimitris Tsitses. - * Copyright 2010, Blueberry Associates LLC. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -@import - - - -@implementation NSToolbarSeparatorItem : CPToolbarItem -{ -} - -- (id)initWithCoder:(CPCoder)aCoder -{ - return [self NS_initWithCoder:aCoder]; -} - -- (Class)classForKeyedArchiver -{ - return [CPToolbarItem class]; -} - -@end diff --git a/Tools/nib2cib/NSToolbarSpaceItem.j b/Tools/nib2cib/NSToolbarSpaceItem.j deleted file mode 100644 index 6e0fcdc19..000000000 --- a/Tools/nib2cib/NSToolbarSpaceItem.j +++ /dev/null @@ -1,41 +0,0 @@ -/* - * NSToolbarSpaceItem.j - * nib2cib - * - * Created by Dimitris Tsitses. - * Copyright 2010, Blueberry Associates LLC. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -@import - - - -@implementation NSToolbarSpaceItem : CPToolbarItem -{ -} - -- (id)initWithCoder:(CPCoder)aCoder -{ - return [self NS_initWithCoder:aCoder]; -} - -- (Class)classForKeyedArchiver -{ - return [CPToolbarItem class]; -} - -@end From 24b495ca43c482fd52ee235e959afc252f4702d0 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 12 Jan 2010 22:52:34 -0800 Subject: [PATCH 3/6] Temporary fix for CPTableView being broken. Reviewed by me. --- AppKit/CPTableView.j | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 3408769ad..7f02b307b 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -182,10 +182,10 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; SEL _doubleAction; unsigned _columnAutoResizingStyle; - BOOL _verticalMotionCanDrag; +// BOOL _verticalMotionCanDrag; unsigned _destinationDragStyle; BOOL _isSelectingSession; - CPIndexSet _draggedRowIndexes; +// CPIndexSet _draggedRowIndexes; _dropOperationDrawingView _dropOperationFeedbackView; CPDragOperation _dragOperationDefaultMask; int _retargetedDropRow; @@ -241,9 +241,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; _selectedColumnIndexes = [CPIndexSet indexSet]; _selectedRowIndexes = [CPIndexSet indexSet]; - - _draggedRowIndexes = [CPIndexSet indexSet]; - _verticalMotionCanDrag = YES; +window.setTimeout(function(){ + self._draggedRowIndexes = [CPIndexSet indexSet]; + self._verticalMotionCanDrag = YES;}, 0); _destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular; _dropOperationFeedbackView = [[_dropOperationDrawingView alloc] initWithFrame:_CGRectMakeZero()]; [self addSubview:_dropOperationFeedbackView]; From e76ee3c96eaf6a0cf41369fc7c166acc64a32ce5 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 12 Jan 2010 22:54:35 -0800 Subject: [PATCH 4/6] A few more changes for CPToolbar nib2cib support and added beginnings of search field support. Reviewed by me. --- AppKit/CPToolbar.j | 186 +++++++++++++++++++--------------- AppKit/CPToolbarItem.j | 168 +++++------------------------- Tools/nib2cib/NSAppKit.j | 1 + Tools/nib2cib/NSSearchField.j | 41 ++++++++ Tools/nib2cib/NSToolbarItem.j | 10 +- 5 files changed, 177 insertions(+), 229 deletions(-) create mode 100644 Tools/nib2cib/NSSearchField.j diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index fe60da738..0917ce948 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -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 diff --git a/AppKit/CPToolbarItem.j b/AppKit/CPToolbarItem.j index 5562ef784..54e93c6b0 100644 --- a/AppKit/CPToolbarItem.j +++ b/AppKit/CPToolbarItem.j @@ -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 aCoder. - @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) diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index d1e102e28..e6258e6e2 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -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" diff --git a/Tools/nib2cib/NSSearchField.j b/Tools/nib2cib/NSSearchField.j new file mode 100644 index 000000000..22cec52f1 --- /dev/null +++ b/Tools/nib2cib/NSSearchField.j @@ -0,0 +1,41 @@ + + +@import +@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 diff --git a/Tools/nib2cib/NSToolbarItem.j b/Tools/nib2cib/NSToolbarItem.j index 4914862db..76ab09665 100644 --- a/Tools/nib2cib/NSToolbarItem.j +++ b/Tools/nib2cib/NSToolbarItem.j @@ -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; From 81d784b5dcae9875ab6cd670848fa36c8e780f4d Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 12 Jan 2010 22:55:58 -0800 Subject: [PATCH 5/6] Added missing license. Reviewed by me. --- Tools/nib2cib/NSSearchField.j | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Tools/nib2cib/NSSearchField.j b/Tools/nib2cib/NSSearchField.j index 22cec52f1..7ac04ac46 100644 --- a/Tools/nib2cib/NSSearchField.j +++ b/Tools/nib2cib/NSSearchField.j @@ -1,4 +1,24 @@ - +/* + * NSSearchField.j + * nib2cib + * + * Created by Francisco Tolmasky. + * Copyright 2010, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ @import @import "NSTextField.j" From 5ddfef7eb77a0fcbb56a149296c5b39b7fdc0ea6 Mon Sep 17 00:00:00 2001 From: Paul Baumgart Date: Wed, 13 Jan 2010 00:45:40 -0800 Subject: [PATCH 6/6] Convert relative paths to absolute when specifying an install_directory for narwhal. --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 7a19b51a2..df2c06bb9 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -106,7 +106,7 @@ if [ "$install_narwhal" ]; then echo "To use the default location, \"$install_directory\", just hit enter/return, or enter another path:" read input if [ "$input" ]; then - install_directory="$input" + install_directory="`cd \`dirname $input\`; pwd`/`basename $input`" fi if [ "$git_clone" ]; then