forked from genki/terminalcopyonselect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTCOSPreferences.m
43 lines (36 loc) · 1.13 KB
/
TCOSPreferences.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
#import "TCOSPreferences.h"
@implementation TCOSPreferences
+(TCOSPreferences*)sharedInstance
{
static TCOSPreferences* pref = nil;
if (pref == nil) {
pref = [[TCOSPreferences alloc] init];
}
return pref;
}
-(id)init
{
self = [super init];
[NSBundle loadNibNamed:@"TCOSPreferences.nib" owner:self];
return self;
}
-(void)awakeFromNib
{
BOOL copyOnSelect = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_KEY];
BOOL pasteOnRightClick = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_RIGHTCLICK_KEY];
NSMenu* applicationMenu = [[[[NSApplication sharedApplication] mainMenu] itemAtIndex: 0] submenu];
copyOnSelectMenuItem.state = copyOnSelect;
pasteOnRightClickMenuItem.state = pasteOnRightClick;
for(NSMenuItem* menuItem in [terminalMenuAdditions itemArray]){
[terminalMenuAdditions removeItem:menuItem];
[applicationMenu insertItem:menuItem atIndex:3];
}
}
-(IBAction)
toggle:(NSMenuItem *)sender
{
sender.state = 1 - sender.state;
NSString* key = sender.tag == 0 ? USER_DEFAULTS_KEY : USER_DEFAULTS_RIGHTCLICK_KEY;
[[NSUserDefaults standardUserDefaults] setBool:sender.state forKey:key];
}
@end