Added an instance method to NSMenu that will remove all of the items in
authorJoseph Spiros <joseph.spiros@ithinksw.com>
Tue, 26 Oct 2004 23:40:29 +0000 (23:40 +0000)
committerJoseph Spiros <joseph.spiros@ithinksw.com>
Tue, 26 Oct 2004 23:40:29 +0000 (23:40 +0000)
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.

ITCategory-NSMenu.h
ITCategory-NSMenu.m
ITCategory-NSView.h
ITCategory-NSView.m

index 6a41379..2a4870e 100755 (executable)
@@ -4,10 +4,9 @@
  *    Category which extends NSMenu
  *
  *  Original Author : Joseph Spiros <joseph.spiros@ithinksw.com>
- *   Responsibility : Matthew Judy <mjudy@ithinksw.com>
  *   Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
  *
- *  Copyright (c) 2002 - 2003 iThink Software.
+ *  Copyright (c) 2002 - 2004 iThink Software.
  *  All Rights Reserved
  *
  */
@@ -23,5 +22,6 @@
 - (void)indentItem:(id <NSMenuItem>)item toLevel:(int)indentLevel;
 - (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel;
 - (MenuRef)menuRef;
+- (void)removeAllItems;
 
 @end
index 78470cc..80501bf 100755 (executable)
@@ -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
index de8beff..3f0c047 100755 (executable)
@@ -4,10 +4,9 @@
  *    Category which extends NSView
  *
  *  Original Author : Joseph Spiros <joseph.spiros@ithinksw.com>
- *   Responsibility : Matthew Judy <mjudy@ithinksw.com>
  *   Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
  *
- *  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
index b2c8c0c..8c6ed90 100755 (executable)
@@ -7,4 +7,10 @@
     [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
 }
 
+- (void)removeSubview:(NSView *)subview {
+       if ([subview superview] == self) {
+               [subview removeFromSuperview];
+       }
+}
+
 @end