Added an instance method to NSMenu that will remove all of the items in
[ITKit.git] / ITCategory-NSMenu.m
index 4e94be0..80501bf 100755 (executable)
@@ -1,52 +1,60 @@
-//
-//  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)
 - (id)_menuImpl;
 @end
 
+extern void _NSGetMenuItemForCommandKeyEvent (NSMenu *menu, void *chicken, void *taco, void *food); 
 extern MenuRef _NSGetCarbonMenu( NSMenu *menu);
 
 @implementation NSMenu (ITCategory)
 
-- (void)indentItem:(NSMenuItem *)item {
-    [self indentItem:item toLevel:2];
+- (void)indentItem:(id <NSMenuItem>)item {
+    [self indentItem:item toLevel:1];
 }
 
 - (void)indentItemAtIndex:(int)index {
-    [self indentItemAtIndex:index toLevel:2];
+    [self indentItemAtIndex:index toLevel:1];
 }
 
-- (void)indentItem:(NSMenuItem *)item toLevel:(int)indentLevel {
+- (void)indentItem:(id <NSMenuItem>)item toLevel:(int)indentLevel {
     [self indentItemAtIndex:[self indexOfItem:item] toLevel:indentLevel];
 }
 
 - (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel {
-    MenuRef carbonMenu = [self menuRef];
-    
-    if (carbonMenu) {
-        SetMenuItemIndent(carbonMenu, index, indentLevel);
+    if ([[self itemAtIndex:index] respondsToSelector:@selector(setIndentationLevel:)]) {
+        (void)[[self itemAtIndex:index] setIndentationLevel:indentLevel];
+    } else {
+        MenuRef carbonMenu = [self menuRef];
+        if (carbonMenu) {
+            SetMenuItemIndent(carbonMenu, index + 1, indentLevel);
+        }
     }
 }
 
 - (MenuRef)menuRef {
     MenuRef carbonMenu;
+    int w00t, m00f;
     
     if( [self respondsToSelector:@selector(_menuImpl)] ) {
-        [self _menuImpl];
+        (void)[self _menuImpl];
     } else {
         return nil;
     }
     
+    _NSGetMenuItemForCommandKeyEvent(self, NULL, &w00t, &m00f); 
     carbonMenu = _NSGetCarbonMenu(self);
     return carbonMenu;
 }
 
+- (void)removeAllItems {
+       int numOfItems = [self numberOfItems];
+       int i = numOfItems;
+       
+       while (i != 0) {
+               [self removeItemAtIndex:(i-1)];
+               i--;
+       }
+}
+
 @end