Skip to content

Commit

Permalink
Add removeAllItems method
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasa committed Sep 1, 2023
1 parent 983bc7d commit 7cdf35f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
-decodeObjectForXib:forClassName:withID: to decode toolTip using
alternative format described in the issue.

2023-08-29 Gregory Casamento <greg.casamento@gmail.com>

* Headers/AppKit/NSMenu.h (-removeAllItems): Add method declaration.
* Source/NSMenu.m (-removeAllItems): Add implementation to remove
all menu items in the reciever.

2023-08-13 Fred Kiefer <FredKiefer@gmx.de>

* Source/NSSwitch.m (-drawRect:): Correct drawing as suggested by
Expand Down
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 7cdf35f

Please sign in to comment.