diff foosdk/sdk/foobar2000/helpers-mac/NSMenu+ppaddons.m @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/foosdk/sdk/foobar2000/helpers-mac/NSMenu+ppaddons.m	Mon Jan 05 02:15:46 2026 -0500
@@ -0,0 +1,39 @@
+#import "NSMenu+ppaddons.h"
+
+@implementation NSMenu (ppaddons)
+
+- (NSMenuItem*) pp_addItemWithTitle: (NSString*) title action: (SEL) action target: (id) target {
+    NSMenuItem * item = [[NSMenuItem alloc] initWithTitle: title action: action keyEquivalent: @""];
+    item.target = target;
+    [self addItem: item];
+    return item;
+}
+
+- (void) pp_addSeparator {
+    [self addItem: [NSMenuItem separatorItem]];
+}
+
+- (NSMenuItem*) pp_addSubMenu: (NSMenu*) menu withTitle: (NSString*) title {
+    NSMenuItem * item = [[NSMenuItem alloc] init];
+    item.title = title;
+    item.submenu = menu;
+    [self addItem: item];
+    return item;
+}
+
+- (void)pp_popUpForView:(NSView *)view {
+    BOOL pullsDown = YES;
+    NSMenu *popMenu = [self copy];
+    NSRect frame = [view frame];
+    frame.origin.x = 0.0;
+    frame.origin.y = 0.0;
+    
+    if (pullsDown) [popMenu insertItemWithTitle:@"" action:NULL keyEquivalent:@"" atIndex:0];
+    
+    NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:pullsDown];
+    [popUpButtonCell setMenu:popMenu];
+    if (!pullsDown) [popUpButtonCell selectItem:nil];
+    [popUpButtonCell performClickWithFrame:frame inView:view];
+}
+
+@end