From: Joseph Spiros Date: Tue, 26 Oct 2004 23:40:29 +0000 (+0000) Subject: Added an instance method to NSMenu that will remove all of the items in X-Git-Tag: v1.0~11 X-Git-Url: http://git.ithinksw.org/ITKit.git/commitdiff_plain/a8daf8ac0972b8b5b582a97b50889fec447f45a4 Added an instance method to NSMenu that will remove all of the items in the reciever. Also added an instance method to NSView that allows for subview removal from the superview's point of view, including a check that is often rewritten whenever needed. This should save a few lines of code whenever this aspect is required. --- diff --git a/ITCategory-NSMenu.h b/ITCategory-NSMenu.h index 6a41379..2a4870e 100755 --- a/ITCategory-NSMenu.h +++ b/ITCategory-NSMenu.h @@ -4,10 +4,9 @@ * Category which extends NSMenu * * Original Author : Joseph Spiros - * Responsibility : Matthew Judy * Responsibility : Joseph Spiros * - * Copyright (c) 2002 - 2003 iThink Software. + * Copyright (c) 2002 - 2004 iThink Software. * All Rights Reserved * */ @@ -23,5 +22,6 @@ - (void)indentItem:(id )item toLevel:(int)indentLevel; - (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel; - (MenuRef)menuRef; +- (void)removeAllItems; @end diff --git a/ITCategory-NSMenu.m b/ITCategory-NSMenu.m index 78470cc..80501bf 100755 --- a/ITCategory-NSMenu.m +++ b/ITCategory-NSMenu.m @@ -1,11 +1,3 @@ -// -// ITCategory-NSMenu.m -// ITKit -// -// Created by Joseph Spiros on Sat Sep 27 2003. -// Copyright (c) 2003 __MyCompanyName__. All rights reserved. -// - #import "ITCategory-NSMenu.h" @interface NSMenu (HACKHACKHACKHACK) @@ -55,4 +47,14 @@ extern MenuRef _NSGetCarbonMenu( NSMenu *menu); return carbonMenu; } +- (void)removeAllItems { + int numOfItems = [self numberOfItems]; + int i = numOfItems; + + while (i != 0) { + [self removeItemAtIndex:(i-1)]; + i--; + } +} + @end diff --git a/ITCategory-NSView.h b/ITCategory-NSView.h index de8beff..3f0c047 100755 --- a/ITCategory-NSView.h +++ b/ITCategory-NSView.h @@ -4,10 +4,9 @@ * Category which extends NSView * * Original Author : Joseph Spiros - * Responsibility : Matthew Judy * Responsibility : Joseph Spiros * - * Copyright (c) 2002 - 2003 iThink Software. + * Copyright (c) 2002 - 2004 iThink Software. * All Rights Reserved * */ @@ -19,5 +18,6 @@ @interface NSView (ITCategory) - (void)removeAllSubviews; +- (void)removeSubview:(NSView *)subview; @end diff --git a/ITCategory-NSView.m b/ITCategory-NSView.m index b2c8c0c..8c6ed90 100755 --- a/ITCategory-NSView.m +++ b/ITCategory-NSView.m @@ -7,4 +7,10 @@ [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; } +- (void)removeSubview:(NSView *)subview { + if ([subview superview] == self) { + [subview removeFromSuperview]; + } +} + @end