-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathSPButton.m
82 lines (66 loc) · 2.38 KB
/
SPButton.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
//
// SPButton.m
// tetherKit
//
// Created by Kevin Bradley on 1/18/11.
// Copyright 2011 FireCore, LLC. All rights reserved.
//
#import "SPButton.h"
#import "tetherKitAppDelegate.h"
@implementation SPButton
- (void)mouseDown:(NSEvent *)theEvent
{
//NSLog(@"mouseDown: %i", [theEvent modifierFlags]);
if ([theEvent modifierFlags] == 262401){
NSPoint locationInWindow = [theEvent locationInWindow];
[self showMenu:locationInWindow];
}
[super mouseDown:theEvent];
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
//NSLog(@"rightMouseDown: %@", theEvent);
NSPoint locationInWindow = [theEvent locationInWindow];
//NSLog(@"nsPoint: %@", NSStringFromPoint(locationInWindow));
[self showMenu:locationInWindow];
return [super rightMouseDown:theEvent];
}
- (IBAction)add:(id)sender
{
//NSLog(@"add: %@", [sender title]);
[[NSUserDefaults standardUserDefaults] setObject:[sender title] forKey:@"lastUsedBundle"];
[[NSApp delegate] bootTethered:nil];
}
- (void)showMenu:(NSPoint)thePoint
{
NSGraphicsContext *theContext = [[self window] graphicsContext];
NSUInteger windowNumber = [[self window] windowNumber];
//NSRect frame = [(NSButton *)self frame];
// NSPoint menuOrigin = [[(NSButton *)self superview] convertPoint:NSMakePoint(frame.origin.x+10, frame.origin.y+20) toView:nil];
NSEvent *event = [NSEvent mouseEventWithType:NSRightMouseDown
location:thePoint
modifierFlags:NSRightMouseDownMask // 0x100
timestamp:0
windowNumber:windowNumber
context:theContext
eventNumber:0
clickCount:1
pressure:1];
NSArray *appBundles = [tetherKitAppDelegate appSupportBundles];
//NSLog(@"appBundles: %@", appBundles);
NSEnumerator *bundleEnum = [appBundles objectEnumerator];
id currentObject = nil;
int i = 0;
NSMenu *menu = [[NSMenu alloc] init];
while (currentObject = [bundleEnum nextObject])
{
// NSLog(@"addObject: %@", currentObject);
[menu insertItemWithTitle:currentObject
action:@selector(add:)
keyEquivalent:@""
atIndex:i];
i++;
}
[NSMenu popUpContextMenu:[menu autorelease] withEvent:event forView:(NSButton *)self];
}
@end