-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMessageManager.m
More file actions
executable file
·139 lines (111 loc) · 3.92 KB
/
MessageManager.m
File metadata and controls
executable file
·139 lines (111 loc) · 3.92 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*!
@source MessageManager.m
@project Pusher
@author Alexander Maksimenko
@copyright Copyright (c) 2009 Ripdev. All rights reserved.
*/
#import "FloatingMessage.h"
#import "MessageManager.h"
@implementation MessageManager
-(id) init
{
self = [super init];
_floatingMessage = nil;
_floatingMessageTimer = nil;
return self;
}
-(void) dealloc
{
[super dealloc];
}
-(void) showBubble:(NSAttributedString*) text onSide:(MAWindowPosition) side ofView:(NSView*) view withTimeout:(int) seconds andDismissMode:(DismissMode) dismissMode
{
NSDisableScreenUpdates();
[self stopFloatingMessage];
_floatingMessage = [[FloatingMessage alloc] initWithText:text ofKind:BubbleMessage onSide:side ofView:view withDismissMode:dismissMode];
[_floatingMessage run];
if(seconds > 0)
[self startFloatingMessageTimer:seconds];
NSEnableScreenUpdates();
[self runFloatingMessageLoop];
}
-(void) showMessage:(NSAttributedString*) text ofKind:(MessageKind) kind withTimeout:(int) seconds buttons:(NSArray*) buttons
{
NSDisableScreenUpdates();
[self stopFloatingMessage];
_floatingMessage = [[FloatingMessage alloc] initWithText:text ofKind:kind onWindow:[[InstanceManager mainController] window] buttons:buttons];
[_floatingMessage run];
if(seconds > 0)
[self startFloatingMessageTimer:seconds];
NSEnableScreenUpdates();
[self runFloatingMessageLoop];
}
-(void) stopFloatingMessage
{
if(_floatingMessage != nil)
{
[_floatingMessageTimer invalidate];
_floatingMessageTimer = nil;
[_floatingMessage stop];
[_floatingMessage release];
_floatingMessage = nil;
}
}
-(void) startFloatingMessageTimer:(int) seconds
{
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:[MessageManager instanceMethodSignatureForSelector:@selector(stopFloatingMessage)]];
[invocation setSelector:@selector(stopFloatingMessage)];
[invocation setTarget:self];
_floatingMessageTimer = [NSTimer scheduledTimerWithTimeInterval:seconds invocation:invocation repeats:NO];
}
-(void) runFloatingMessageLoop
{
NSDate* distantPast = [NSDate distantPast];
NSEvent* event;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@try
{
while([_floatingMessage isRunning])
{
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:distantPast inMode:NSDefaultRunLoopMode dequeue:YES];
if(event != nil)
{
if([event type] == NSLeftMouseDown)
{
switch([_floatingMessage dismissMode])
{
case dmNone:
if([event window] != [_floatingMessage window])
NSBeep();
break;
case dmAnyClick:
[self stopFloatingMessage];
[NSApp sendEvent:event];
break;
case dmInnerClick:
if([event window] == [_floatingMessage window])
[self stopFloatingMessage];
else
NSBeep();
break;
case dmOuterClick:
if([event window] != [_floatingMessage window])
[self stopFloatingMessage];
break;
}
}
if([event window] == [_floatingMessage window] || [event type] == NSAppKitDefined || [event type] == NSSystemDefined)
[NSApp sendEvent:event];
}
}
}
@catch (NSException *ex)
{
Log(@"%@ %@", [ex name], [ex reason]);
}
@finally
{
[pool release];
}
}
@end