Skip to content

Commit

Permalink
Add implementation of removeAllItems
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasa committed Sep 1, 2023
1 parent 3f35da7 commit 3575f0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Headers/AppKit/NSMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ APPKIT_EXPORT_CLASS
*/
- (void) removeItemAtIndex: (NSInteger)index;

#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
/** Removes all items
*/
- (void) removeAllItems;
#endif

/** Sets if a menu does autoenable.
*/
- (void) setAutoenablesItems: (BOOL)flag;
Expand Down
12 changes: 12 additions & 0 deletions Source/NSMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@ - (void) removeItemAtIndex: (NSInteger)index
[self menuChanged];
}

- (void) removeAllItems
{
NSUInteger count = [_items count];
NSUInteger index = 0;

for (index = 0; index < count; index++)
{
// always remove item 0 since the index will chane with each removal..
[self removeItemAtIndex: 0];
}
}

- (void) itemChanged: (id <NSMenuItem>)anObject
{
NSNotification *changed;
Expand Down

0 comments on commit 3575f0a

Please sign in to comment.