-
Notifications
You must be signed in to change notification settings - Fork 31
/
YLBundle.m
90 lines (74 loc) · 2.59 KB
/
YLBundle.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// YLBundle.m
// MacBlueTelnet
//
// Created by Jjgod Jiang on 8/17/08.
// Copyright 2008 Jjgod Jiang. All rights reserved.
//
#import "YLBundle.h"
@implementation YLBundle
@synthesize title;
@synthesize description;
- (id) init
{
if (self = [super init])
{
// since this is a semi-abstract class, these need to be defined in the subclasses:
title = [NSString stringWithString: @"<name undefined>"];
description = [NSString stringWithString: @"<description undefined>"];
pluginsMenu = [[[NSApp mainMenu] itemWithTitle: @"Plugins"] submenu];
}
return self;
}
- (NSImage *) icon
{
NSBundle *currBundle = [NSBundle bundleForClass: [self class]];
NSString *bundleIconName = [currBundle objectForInfoDictionaryKey: @"CFBundleIconFile"];
NSImage *iconImage = nil;
if (bundleIconName != nil)
{
NSString *iconPathStr = [currBundle pathForResource: bundleIconName
ofType: nil];
iconImage = [[[NSImage alloc] initWithContentsOfFile: iconPathStr] autorelease];
}
return iconImage;
}
- (NSMenu *) pluginMenu
{
if (! pluginsMenu)
return nil;
NSMenu *pluginMenu = [[pluginsMenu itemWithTitle: [self title]] submenu];
if (! pluginMenu)
{
NSMenuItem *pluginMenuItem = [[NSMenuItem alloc] initWithTitle: [self title]
action: nil
keyEquivalent: @""];
[pluginMenuItem setToolTip: [self description]];
[pluginsMenu addItem: pluginMenuItem];
[pluginMenuItem release];
pluginMenu = [[NSMenu alloc] initWithTitle: title];
[pluginMenuItem setSubmenu: pluginMenu];
[pluginMenu release];
}
return pluginMenu;
}
- (NSString *) localizedStringForKey: (NSString *) key
{
return [[NSBundle bundleForClass: [self class]] localizedStringForKey: key
value: @""
table: nil];
}
- (void) addMenuItem: (NSMenuItem *) item
{
[item setTarget: self];
[[self pluginMenu] addItem: item];
}
- (NSMenuItem *) addMenuItemWithTitle: (NSString *) menuTitle
action: (SEL) action
keyEquivalent: (NSString *) keyEquiv
{
return [[self pluginMenu] addItemWithTitle: menuTitle
action: action
keyEquivalent: keyEquiv];
}
@end