Skip to content

Commit

Permalink
Fix for toolbar item's target set to null.
Browse files Browse the repository at this point in the history
[cappuccino#115 state:resolved]

Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed Oct 27, 2008
1 parent f7dd436 commit 745df35
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 25 deletions.
3 changes: 2 additions & 1 deletion AppKit/CPToolbar.j
Expand Up @@ -430,6 +430,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)

// Determine all the items that have flexible width.
// Also determine the height of the toolbar.
// NOTE: height is height without top margin, and bottom margin/label.
var index = _visibleItems.length,
height = 0.0;

Expand Down Expand Up @@ -511,7 +512,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)

itemWidth = MAX([self minWidthForItem:item], viewWidth),

viewHeight = MAX([item minSize].height, MIN([item maxSize].height, height));
viewHeight = CGRectGetHeight(viewFrame);

// itemWidth != viewWidth. itemWidth is MAX(size of view, size of label). If the label is larger,
// *center* the view, don't resize it.
Expand Down
106 changes: 82 additions & 24 deletions AppKit/CPToolbarItem.j
Expand Up @@ -77,7 +77,9 @@ var _CPToolbarSeparatorItemView = nil;
BOOL _isEnabled;
CPImage _image;
CPImage _alternateImage;

CPView _view;

CGSize _minSize;
CGSize _maxSize;

Expand All @@ -98,6 +100,9 @@ var _CPToolbarSeparatorItemView = nil;
{
_itemIdentifier = anItemIdentifier;

_tag = 0;
_isEnabled = YES;

_minSize = CGSizeMakeZero();
_maxSize = CGSizeMakeZero();

Expand Down Expand Up @@ -165,6 +170,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (CPString)toolTip
{
if ([_view respondsToSelector:@selector(toolTip)])
return [_view toolTip];

return _toolTip;
}

Expand All @@ -174,6 +182,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setToolTip:(CPString)aToolTip
{
if ([_view respondsToSelector:@selector(setToolTip:)])
[view setToolTip:aToolTip];

_toolTip = aToolTip;
}

Expand All @@ -182,6 +193,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (int)tag
{
if ([_view respondsToSelector:@selector(tag)])
return [_view tag];

return _tag;
}

Expand All @@ -191,6 +205,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setTag:(int)aTag
{
if ([_view respondsToSelector:@selector(setTag:)])
[_view setTag:aTag];

_tag = aTag;
}

Expand All @@ -199,6 +216,9 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (id)target
{
if (_view)
return [_view respondsToSelector:@selector(target)] ? [_view target] : nil;

return _target;
}

Expand All @@ -209,14 +229,21 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setTarget:(id)aTarget
{
_target = aTarget;
if (!_view)
_target = aTarget;

else if ([_view respondsToSelector:@selector(setTarget:)])
[_view setTarget:aTarget];
}

/*!
Returns the action that is triggered when the user clicks this item.
*/
- (SEL)action
{
if (_view)
return [_view respondsToSelector:@selector(action)] ? [_view action] : nil;

return _action;
}

Expand All @@ -226,31 +253,44 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setAction:(SEL)anAction
{
_action = anAction;
if (!_view)
_action = anAction;

else if ([_view respondsToSelector:@selector(setAction:)])
[_view setAction:anAction];
}

/*!
Returns <code>YES</code> if the item is enabled.
*/
- (BOOL)isEnabled
{
if ([_view respondsToSelector:@selector(isEnabled)])
return [_view isEnabled];

return _isEnabled;
}

/*!
Sets whether the item is enabled.
@param aFlag <code>YES</code> enables the item
*/
- (void)setEnabled:(BOOL)aFlag
- (void)setEnabled:(BOOL)shouldBeEnabled
{
_isEnabled = aFlag;
if ([_view respondsToSelector:@selector(setEnabled:)])
[_view setEnabled:shouldBeEnabled];

_isEnabled = shouldBeEnabled;
}

/*!
Returns the item's image
*/
- (CPImage)image
{
if ([_view respondsToSelector:@selector(image)])
return [_view image];

return _image;
}

Expand All @@ -260,22 +300,24 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setImage:(CPImage)anImage
{
if ([_view respondsToSelector:@selector(setImage:)])
[_view setImage:anImage];

_image = anImage;

// FIXME: We can't keep assuming this.
[_view setImage:anImage];

if (!_image)
return;

var imageSize = [_image size];

if (_minSize.width == 0 && _minSize.height == 0 &&
_maxSize.width == 0 && _maxSize.height == 0 &&
(imageSize.width > 0 || imageSize.height > 0))
_maxSize.width == 0 && _maxSize.height == 0)
{
[self setMinSize:imageSize];
[self setMaxSize:imageSize];
var imageSize = [_image size];

if (imageSize.width > 0 || imageSize.height > 0)
{
[self setMinSize:imageSize];
[self setMaxSize:imageSize];
}
}
}

Expand All @@ -285,17 +327,20 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setAlternateImage:(CPImage)anImage
{
_alternateImage = anImage;
if ([_view respondsToSelector:@selector(setAlternateImage:)])
[_view setAlternateImage:anImage];

// FIXME: We can't keep assuming this.
[_view setAlternateImage:anImage];
_alternateImage = anImage;
}

/*!
Returns the alternate image. This image is displayed on the item when the user is clicking it.
*/
- (CPImage)alternateImage
{
if ([_view respondsToSelector:@selector(alternateIamge)])
return [_view alternateImage];

return _alternateImage;
}

Expand All @@ -313,7 +358,20 @@ var _CPToolbarSeparatorItemView = nil;
*/
- (void)setView:(CPView)aView
{
if (_view == aView)
return;

_view = aView;

if (_view)
{
// Tags get forwarded.
if (_tag !== 0 && [_view respondsToSelector:@selector(setTag:)])
[_view setTag:_tag];

_target = nil;
_action = nil;
}
}

/*!
Expand Down Expand Up @@ -394,21 +452,21 @@ CPToolbarItemVisibilityPriorityUser
{
var copy = [[[self class] alloc] initWithItemIdentifier:_itemIdentifier];

if (_view)
[copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]];

[copy setLabel:_label];
[copy setPaletteLabel:_paletteLabel];
[copy setToolTip:_toolTip];
[copy setToolTip:[self toolTip]];

[copy setTag:_tag];
[copy setTarget:_target];
[copy setAction:_action];
[copy setTag:[self tag]];
[copy setTarget:[self target]];
[copy setAction:[self action]];

[copy setEnabled:_isEnabled];
[copy setEnabled:[self isEnabled]];
[copy setImage:_image];
[copy setAlternateImage:_alternateImage];

if (_view)
[copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]];

[copy setMinSize:_minSize];
[copy setMaxSize:_maxSize];

Expand Down

0 comments on commit 745df35

Please sign in to comment.