More support for toolbar items and nib2cib. Added support for CPToolbarShowColorsItem.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2010-01-13 22:39:15 -08:00
1 parent e25a227e4d
commit c36f975bbf
15 files changed
+459 -67

No files matched your search

+80 -25
View File
@@ -19,7 +19,7 @@
* 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 <Foundation/CPBundle.j>
@import <Foundation/CPNotificationCenter.j>
@import <Foundation/CPObject.j>
@@ -38,17 +38,32 @@ CPImageLoadStatusReadError = 6;
CPImageDidLoadNotification = @"CPImageDidLoadNotification";
// Image Names
CPImageNameColorPanel = @"CPImageNameColorPanel";
CPImageNameColorPanelHighlighted = @"CPImageNameColorPanelHighlighted";
var imagesForNames = { },
AppKitImageForNames = { };
AppKitImageForNames[CPImageNameColorPanel] = CGSizeMake(26.0, 29.0);
AppKitImageForNames[CPImageNameColorPanelHighlighted] = CGSizeMake(26.0, 29.0);
function CPImageInBundle(aFilename, aSize, aBundle)
{
if (!aBundle)
aBundle = [CPBundle mainBundle];
if (aSize)
return [[CPImage alloc] initWithContentsOfFile:[aBundle pathForResource:aFilename] size:aSize];
return [[CPImage alloc] initWithContentsOfFile:[aBundle pathForResource:aFilename]];
}
function CPAppKitImage(aFilename, aSize)
{
return CPImageInBundle(aFilename, aSize, [CPBundle bundleForClass:[CPView class]]);
}
/*!
@ingroup appkit
@class CPImage
@@ -74,10 +89,11 @@ function CPImageInBundle(aFilename, aSize, aBundle)
{
CGSize _size;
CPString _filename;
CPString _name;
id _delegate;
unsigned _loadStatus;
Image _image;
}
@@ -97,14 +113,14 @@ function CPImageInBundle(aFilename, aSize, aBundle)
- (id)initByReferencingFile:(CPString)aFilename size:(CGSize)aSize
{
self = [super init];
if (self)
{
_size = CPSizeCreateCopy(aSize);
_filename = aFilename;
_loadStatus = CPImageLoadStatusInitialized;
}
return self;
}
@@ -117,10 +133,10 @@ function CPImageInBundle(aFilename, aSize, aBundle)
- (id)initWithContentsOfFile:(CPString)aFilename size:(CGSize)aSize
{
self = [self initByReferencingFile:aFilename size:aSize];
if (self)
[self load];
return self;
}
@@ -133,10 +149,10 @@ function CPImageInBundle(aFilename, aSize, aBundle)
- (id)initWithContentsOfFile:(CPString)aFilename
{
self = [self initByReferencingFile:aFilename size:CGSizeMake(-1, -1)];
if (self)
[self load];
return self;
}
@@ -165,6 +181,45 @@ function CPImageInBundle(aFilename, aSize, aBundle)
return _size;
}
+ (id)imageNamed:(CPString)aName
{
var image = imagesForNames[aName];
if (image)
return image;
var imageOrSize = AppKitImageForNames[aName];
if (!imageOrSize.isa)
{
imageOrSize = CPAppKitImage("CPImage/" + aName + ".png", imageOrSize);
[imageOrSize setName:aName];
AppKitImageForNames[aName] = imageOrSize;
}
return imageOrSize;
}
- (void)setName:(CPString)aName
{
if (_name === aName)
return;
if (imagesForNames[aName] === self)
imagesForNames[aName] = nil;
_name = aName;
imagesForNames[aName] = self;
}
- (CPString)name
{
return _name;
}
/*!
Sets the receiver's delegate.
@param the delegate
@@ -200,7 +255,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
{
if (_loadStatus == CPImageLoadStatusLoading || _loadStatus == CPImageLoadStatusCompleted)
return;
_loadStatus = CPImageLoadStatusLoading;
_image = new Image();
@@ -219,7 +274,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
}
[self _derefFromImage];
}
_image.onerror = function ()
{
if (isSynchronous)
@@ -231,7 +286,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
}
[self _derefFromImage];
}
_image.onabort = function ()
{
if (isSynchronous)
@@ -243,7 +298,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
}
[self _derefFromImage];
}
_image.src = _filename;
// onload and friends may fire after this point but BEFORE the end of the run loop,
@@ -281,7 +336,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
[[CPNotificationCenter defaultCenter]
postNotificationName:CPImageDidLoadNotification
object:self];
if ([_delegate respondsToSelector:@selector(imageDidLoad:)])
[_delegate imageDidLoad:self];
}
@@ -290,7 +345,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
- (void)_imageDidError
{
_loadStatus = CPImageLoadStatusReadError;
if ([_delegate respondsToSelector:@selector(imageDidError:)])
[_delegate imageDidError:self];
}
@@ -299,7 +354,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
- (void)_imageDidAbort
{
_loadStatus = CPImageLoadStatusCancelled;
if ([_delegate respondsToSelector:@selector(imageDidAbort:)])
[_delegate imageDidAbort:self];
}
@@ -339,7 +394,7 @@ function CPImageInBundle(aFilename, aSize, aBundle)
- (id)initWithImageSlices:(CPArray)imageSlices isVertical:(BOOL)isVertical
{
self = [super init];
if (self)
{
_imageSlices = imageSlices;
@@ -384,13 +439,13 @@ var CPThreePartImageImageSlicesKey = @"CPThreePartImageImageSlicesKey",
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super init];
if (self)
{
_imageSlices = [aCoder decodeObjectForKey:CPThreePartImageImageSlicesKey];
_isVertical = [aCoder decodeBoolForKey:CPThreePartImageIsVerticalKey];
}
return self;
}
@@ -411,10 +466,10 @@ var CPThreePartImageImageSlicesKey = @"CPThreePartImageImageSlicesKey",
- (id)initWithImageSlices:(CPArray)imageSlices
{
self = [super init];
if (self)
_imageSlices = imageSlices;
return self;
}
@@ -447,10 +502,10 @@ var CPNinePartImageImageSlicesKey = @"CPNinePartImageImageSlicesKey";
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super init];
if (self)
_imageSlices = [aCoder decodeObjectForKey:CPNinePartImageImageSlicesKey];
return self;
}
+4 -6
View File
@@ -267,17 +267,16 @@ var CPToolbarConfigurationsByIdentifier = nil;
_itemIdentifiers = [_itemIdentifiers arrayByAddingObjectsFromArray:itemIdentifiersFromDelegate];
}
var count = [_itemIdentifiers count];
var index = 0,
count = [_itemIdentifiers count];
_items = [];
var index = 0;
for (; index < count; ++index)
{
var identifier = _itemIdentifiers[index],
item = [CPToolbarItem _standardItemWithItemIdentifier:identifier];
// May come from a Cib.
if (!item)
item = [_identifiedItems objectForKey:identifier];
@@ -610,7 +609,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
minWidth = _minWidth,
// FIXME: This should be a CPSet.
invisibleItemsSortedByPriority = [];
_visibleItems = items;
// We only have hidden items if our actual width is smaller than our
@@ -802,7 +801,6 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
}
else
[_additionalItemsButton removeFromSuperview];
}
- (void)reloadToolbarItems
+14 -27
View File
@@ -320,15 +320,10 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItem";
_image = anImage;
if (!_image)
{
if(_toolbar)
[_toolbar toolbarItemDidChange:self];
return;
}
if (_minSize.width == 0 && _minSize.height == 0 &&
_maxSize.width == 0 && _maxSize.height == 0)
if (_minSize.width === 0 && _minSize.height === 0 &&
_maxSize.width === 0 && _maxSize.height === 0)
{
var imageSize = [_image size];
@@ -552,8 +547,8 @@ var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey",
[self setEnabled:[aCoder decodeBoolForKey:CPToolbarItemEnabledKey]];
[self setImage:[aCoder decodeBoolForKey:CPToolbarItemImageKey]];
[self setAlternateImage:[aCoder decodeBoolForKey:CPToolbarItemAlternateImageKey]];
[self setImage:[aCoder decodeObjectForKey:CPToolbarItemImageKey]];
[self setAlternateImage:[aCoder decodeObjectForKey:CPToolbarItemAlternateImageKey]];
[self setView:[aCoder decodeObjectForKey:CPToolbarItemViewKey]];
@@ -635,26 +630,12 @@ var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey",
/* @ignore */
+ (CPToolbarItem)_standardItemWithItemIdentifier:(CPString)anItemIdentifier
{
var item = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
switch (anItemIdentifier)
{
case CPToolbarSeparatorItemIdentifier: [item setMinSize:CGSizeMake(2.0, 0.0)];
[item setMaxSize:CGSizeMake(2.0, 100000.0)];
return item;
case CPToolbarSpaceItemIdentifier: [item setMinSize:CGSizeMake(32.0, 32.0)];
[item setMaxSize:CGSizeMake(32.0, 32.0)];
return item;
case CPToolbarFlexibleSpaceItemIdentifier: [item setMinSize:CGSizeMake(32.0, 32.0)];
[item setMaxSize:CGSizeMake(10000.0, 32.0)];
return item;
case CPToolbarShowColorsItemIdentifier: return nil;
case CPToolbarSeparatorItemIdentifier: return [_CPToolbarSeparatorItem new];
case CPToolbarSpaceItemIdentifier: return [_CPToolbarSpaceItem new];
case CPToolbarFlexibleSpaceItemIdentifier: return [_CPToolbarFlexibleSpaceItem new];
case CPToolbarShowColorsItemIdentifier: return [_CPToolbarShowColorsItem new];
case CPToolbarShowFontsItemIdentifier: return nil;
case CPToolbarCustomizeToolbarItemIdentifier: return nil;
case CPToolbarPrintItemIdentifier: return nil;
@@ -664,3 +645,9 @@ var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey",
}
@end
@import "_CPToolbarFlexibleSpaceItem.j"
@import "_CPToolbarShowColorsItem.j"
@import "_CPToolbarSeparatorItem.j"
@import "_CPToolbarSpaceItem.j"
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

+52
View File
@@ -0,0 +1,52 @@
/*
* _CPToolbarFlexibleSpaceItem.j
* AppKit
*
* 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 "CPToolbarItem.j"
@implementation _CPToolbarFlexibleSpaceItem : CPToolbarItem
{
}
- (id)initWithItemIdentifier:(CPString)anIgnoredIdentifier
{
self = [super initWithItemIdentifier:CPToolbarFlexibleSpaceItemIdentifier];
if (self)
{
[self setMinSize:CGSizeMake(32.0, 32.0)];
[self setMaxSize:CGSizeMake(10000.0, 32.0)];
}
return self;
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self init];
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
}
@end
+52
View File
@@ -0,0 +1,52 @@
/*
* _CPToolbarSeparatorItem.j
* AppKit
*
* 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 "CPToolbarItem.j"
@implementation _CPToolbarSeparatorItem : CPToolbarItem
{
}
- (id)initWithItemIdentifier:(CPString)anIgnoredIdentifier
{
self = [super initWithItemIdentifier:CPToolbarSeparatorItemIdentifier];
if (self)
{
[self setMinSize:CGSizeMake(2.0, 0.0)];
[self setMaxSize:CGSizeMake(2.0, 100000.0)];
}
return self;
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self init];
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
}
@end
+61
View File
@@ -0,0 +1,61 @@
/*
* _CPToolbarShowColorsItem.j
* AppKit
*
* 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 "CPToolbarItem.j"
@implementation _CPToolbarShowColorsItem : CPToolbarItem
{
}
- (id)initWithItemIdentifier:(CPString)anIgnoredIdentifier
{
self = [super initWithItemIdentifier:CPToolbarShowColorsItemIdentifier];
if (self)
{
[self setMinSize:CGSizeMake(32.0, 32.0)];
[self setMaxSize:CGSizeMake(32.0, 32.0)];
[self setLabel:@"Colors"];
[self setPaletteLabel:@"Show Colors"];
[self setTarget:CPApp];
[self setAction:@selector(orderFrontColorPanel:)];
[self setImage:[CPImage imageNamed:CPImageNameColorPanel]];
[self setAlternateImage:[CPImage imageNamed:CPImageNameColorPanelHighlighted]];
[self setToolTip:@"Show the Colors panel."];
}
return self;
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self init];
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
}
@end
+52
View File
@@ -0,0 +1,52 @@
/*
* _CPToolbarSpaceItem.j
* AppKit
*
* 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 "CPToolbarItem.j"
@implementation _CPToolbarSpaceItem : CPToolbarItem
{
}
- (id)initWithItemIdentifier:(CPString)anIgnoredIdentifier
{
self = [super initWithItemIdentifier:CPToolbarSpaceItemIdentifier];
if (self)
{
[self setMinSize:CGSizeMake(32.0, 32.0)];
[self setMaxSize:CGSizeMake(32.0, 32.0)];
}
return self;
}
- (id)initWithCoder:(CPCoder)aCoder
{
return [self init];
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
}
@end
+4
View File
@@ -56,7 +56,11 @@
@import "NSTabViewItem.j"
@import "NSTextField.j"
@import "NSToolbar.j"
@import "NSToolbarFlexibleSpaceItem.j"
@import "NSToolbarItem.j"
@import "NSToolbarShowColorsItem.j"
@import "NSToolbarSeparatorItem.j"
@import "NSToolbarSpaceItem.j"
@import "NSView.j"
@import "NSViewController.j"
@import "NSWindowTemplate.j"
@@ -0,0 +1,35 @@
/*
* NSToolbarFlexibleSpaceItem.j
* AppKit
*
* 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 <AppKit/_CPToolbarFlexibleSpaceItem.j>
@implementation NSToolbarFlexibleSpaceItem : _CPToolbarFlexibleSpaceItem
{
}
- (Class)classForKeyedArchiver
{
return [_CPToolbarFlexibleSpaceItem class];
}
@end
-9
View File
@@ -87,12 +87,3 @@ NS_CPToolbarItemIdentifierMap =
}
@end
@implementation NSToolbarSpaceItem : NSToolbarItem
@end
@implementation NSToolbarFlexibleSpaceItem : NSToolbarItem
@end
@implementation NSToolbarSeparatorItem : NSToolbarItem
@end
+35
View File
@@ -0,0 +1,35 @@
/*
* NSToolbarSeparatorItem.j
* AppKit
*
* 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 <AppKit/_CPToolbarSeparatorItem.j>
@implementation NSToolbarSeparatorItem : _CPToolbarSeparatorItem
{
}
- (Class)classForKeyedArchiver
{
return [_CPToolbarSeparatorItem class];
}
@end
+35
View File
@@ -0,0 +1,35 @@
/*
* NSToolbarShowColorsItem.j
* AppKit
*
* 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 <AppKit/_CPToolbarShowColorsItem.j>
@implementation NSToolbarShowColorsItem : _CPToolbarShowColorsItem
{
}
- (Class)classForKeyedArchiver
{
return [_CPToolbarShowColorsItem class];
}
@end
+35
View File
@@ -0,0 +1,35 @@
/*
* NSToolbarSpaceItem.j
* AppKit
*
* 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 <AppKit/_CPToolbarSpaceItem.j>
@implementation NSToolbarSpaceItem : _CPToolbarSpaceItem
{
}
- (Class)classForKeyedArchiver
{
return [_CPToolbarSpaceItem class];
}
@end