-
Notifications
You must be signed in to change notification settings - Fork 5
/
ApplicationController.m
55 lines (44 loc) · 1.6 KB
/
ApplicationController.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
#import "ApplicationController.h"
@implementation ApplicationController
-(void)awakeFromNib {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSDisabledDictationMenuItem"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSDisabledCharacterPaletteMenuItem"];
panel = [[FTColorPanel alloc] init];
[panel setDelegate: self];
[panel makeKeyAndOrderFront: self];
}
-(BOOL)validateMenuItem:(NSMenuItem *)item {
if ([[[item menu] title] isEqualToString: COPY_AS_MENU]) {
[item setTitle: [panel representationStringOfColorInMode:[item tag] shortVersion:NO]];
}
return YES;
}
-(IBAction)copy:(id)sender {
NSArray *contents = [NSArray arrayWithObject: [panel representationStringOfCurrentColorMode: NO]];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard writeObjects: contents];
}
-(IBAction)copyAs:(id)sender {
NSMenuItem *current = [[sender menu] itemAtIndex: [panel colorMode]];
[current setState: NSOffState];
[sender setState: NSOnState];
[panel setColorMode: (int)[sender tag]];
[self copy: nil];
}
-(IBAction)paste:(id)sender {
NSArray *classes = [NSArray arrayWithObject: [NSString class]];
NSArray *copiedStrings = [[NSPasteboard generalPasteboard] readObjectsForClasses:classes options:nil];
if (copiedStrings && [copiedStrings count] > 0) {
NSColor *color = [NSColor colorFromString: [copiedStrings objectAtIndex: 0]];
if (color) {
[panel setColor: color];
return;
}
}
NSBeep();
}
-(void)windowWillClose:(NSNotification *)aNotification {
[NSApp terminate: self];
}
@end