forked from kattrali/Xcode-Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path___PACKAGENAME___.m
64 lines (52 loc) · 1.69 KB
/
___PACKAGENAME___.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// ___PACKAGENAME___.m
// ___PACKAGENAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// ___COPYRIGHT___
//
#import "___PACKAGENAME___.h"
static ___PACKAGENAME___ *sharedPlugin;
@interface ___PACKAGENAME___()
@property (nonatomic, strong) NSBundle *bundle;
@end
@implementation ___PACKAGENAME___
+ (void)pluginDidLoad:(NSBundle *)plugin
{
static id sharedPlugin = nil;
static dispatch_once_t onceToken;
NSString *currentApplicationName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"];
if ([currentApplicationName isEqual:@"Xcode"]) {
dispatch_once(&onceToken, ^{
sharedPlugin = [[self alloc] initWithBundle:plugin];
});
}
}
- (id)initWithBundle:(NSBundle *)plugin {
{
if (self = [super init]) {
// reference to plugin's bundle, for resource acccess
self.bundle = plugin;
// Create menu items, initialize UI, etc.
// Sample Menu Item:
NSMenuItem *menuItem = [[NSApp mainMenu] itemWithTitle:@"File"];
if (menuItem) {
[[menuItem submenu] addItem:[NSMenuItem separatorItem]];
NSMenuItem *actionMenuItem = [[NSMenuItem alloc] initWithTitle:@"Do Action" action:@selector(doMenuAction) keyEquivalent:@""];
[actionMenuItem setTarget:self];
[[menuItem submenu] addItem:actionMenuItem];
}
}
return self;
}
// Sample Action, for menu item:
- (void)doMenuAction
{
NSAlert *alert = [NSAlert alertWithMessageText:@"Hello, World" defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:@""];
[alert runModal];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end