Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TomLiu/5097211 to your computer and use it in GitHub Desktop.
Save TomLiu/5097211 to your computer and use it in GitHub Desktop.
//
// NSSharingServicePicker+ESSSharingServicePickerMenu.h
//
// Created by Matthias Gansrigler on 22.11.12.
// Copyright (c) 2012 Eternal Storms Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface NSSharingServicePicker (ESSSharingServicePickerMenu)
+ (NSMenu *)menuForSharingItems:(NSArray *)items
withTarget:(id)target
selector:(SEL)aSel
serviceDelegate:(id <NSSharingServiceDelegate>)del;
@end
//
// NSSharingServicePicker+ESSSharingServicePickerMenu.m
//
// Created by Matthias Gansrigler on 22.11.12.
// Copyright (c) 2012 Eternal Storms Software. All rights reserved.
//
#import "NSSharingServicePicker+ESSSharingServicePickerMenu.h"
@implementation NSSharingServicePicker (ESSSharingServicePickerMenu)
+ (NSMenu *)menuForSharingItems:(NSArray *)items
withTarget:(id)target
selector:(SEL)aSel
serviceDelegate:(id <NSSharingServiceDelegate>)del
{
NSArray *sharingServices = [NSSharingService sharingServicesForItems:items];
if (sharingServices.count == 0)
return nil;
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"MountainLionSharingMenu"];
// rebuild the menu
for (NSSharingService *currentService in sharingServices)
{
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:currentService.title action:aSel keyEquivalent:@""];
item.image = currentService.image;
item.representedObject = currentService;
currentService.delegate = del;
item.target = target;
[menu addItem:item];
}
return menu;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment