/
Drama_ButtonAppDelegate.m
102 lines (81 loc) · 2.63 KB
/
Drama_ButtonAppDelegate.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
91
92
93
94
95
96
97
98
99
100
101
102
//
// Drama_ButtonAppDelegate.m
// Drama Button
//
// Created by Martin Schend on 06.04.10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "Drama_ButtonAppDelegate.h"
@implementation Drama_ButtonAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Listen to command-option-control-D
id block = ^(NSEvent* event){
if ([event modifierFlags] & NSAlternateKeyMask &&
[event modifierFlags] & NSCommandKeyMask &&
[event modifierFlags] & NSControlKeyMask &&
([event keyCode] == 2)) { // 2: d key
[[NSNotificationCenter defaultCenter] postNotificationName:@"playDrama" object:nil];
}
};
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler: block];
soundsArray = [[NSArray alloc] initWithObjects:
[NSSound soundNamed:@"drama1.wav"],
[NSSound soundNamed:@"drama2.wav"],
[NSSound soundNamed:@"drama3.wav"],
[NSSound soundNamed:@"drama4.mp3"], nil];
[alwaysPlayItem setHidden:YES];
if ([alwaysOnTopMenuItem state] == NSOnState)
[window setLevel:NSFloatingWindowLevel];
else
[window setLevel:NSNormalWindowLevel];
}
- (void)awakeFromNib
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(playDrama:)
name:@"playDrama"
object:nil];
[nc addObserver:self
selector:@selector(mouseEntered:)
name:@"mouseEntered"
object:nil];
[nc addObserver:self
selector:@selector(mouseExited:)
name:@"mouseExited"
object:nil];
NSStatusBar *bar = [NSStatusBar systemStatusBar];
NSStatusItem *theItem = [[NSStatusItem alloc] init];
theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];
[theItem setTitle: NSLocalizedString(@"☁",@"")];
[theItem setHighlightMode:YES];
[theItem setMenu:contextMenu];
}
- (IBAction)randomSettingChanged:(id)sender {
[alwaysPlayItem setEnabled:[randomMenuItem state]];
}
- (IBAction)playDrama:(id)sender {
if ([randomMenuItem state] == 1)
[[soundsArray objectAtIndex:[self getRandomNumber:0 to:[soundsArray count]-1]] play];
else
[[soundsArray objectAtIndex:0] play];
}
- (IBAction)alwaysOnTopSettingChanged:(id)sender {
if (![alwaysOnTopMenuItem state] == NSOnState)
[window setLevel:NSFloatingWindowLevel];
else
[window setLevel:NSNormalWindowLevel];
}
- (int) getRandomNumber:(int)from to:(int)to {
42;
return (int)from + arc4random() % (to-from+1);
}
- (void) mouseEntered:(id)object {
[[contextInfoLabel animator] setAlphaValue:1.0];
}
- (void) mouseExited:(id)object {
[[contextInfoLabel animator] setAlphaValue:0.0];
}
@end