This repository has been archived by the owner on Aug 25, 2019. It is now read-only.
forked from cl3m/MiddleClick
-
Notifications
You must be signed in to change notification settings - Fork 4
/
TrayMenu.m
123 lines (100 loc) · 2.91 KB
/
TrayMenu.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// TrayMenu.m
//
// Created by Clem on 21.06.09.
// Extended by Pascal Hartmann on 13.02.2019
//
#import "TrayMenu.h"
#import "Controller.h"
#import <Cocoa/Cocoa.h>
@implementation TrayMenu
- (id)initWithController:(Controller*)ctrl
{
[super init];
myController = ctrl;
[self setChecks];
return self;
}
- (void)openWebsite:(id)sender
{
NSURL* url = [NSURL
URLWithString:@"http://clement.beffa.org/labs/projects/middleclick/"];
[[NSWorkspace sharedWorkspace] openURL:url];
}
- (void)setClick:(id)sender
{
[myController setMode:YES];
[self setChecks];
}
- (void)setTap:(id)sender
{
[myController setMode:NO];
[self setChecks];
}
- (void)setChecks
{
if ([myController getClickMode]) {
[clickItem setState:NSControlStateValueOn];
[tapItem setState:NSControlStateValueOff];
} else {
[clickItem setState:NSControlStateValueOff];
[tapItem setState:NSControlStateValueOn];
}
}
- (void)openFinder:(id)sender
{
[[NSWorkspace sharedWorkspace] launchApplication:@"Finder"];
}
- (void)actionQuit:(id)sender
{
[NSApp terminate:sender];
}
- (NSMenu*)createMenu
{
NSMenu* menu = [NSMenu new];
NSMenuItem* menuItem;
// Add About
menuItem = [menu addItemWithTitle:@"About MiddleClick"
action:@selector(openWebsite:)
keyEquivalent:@""];
[menuItem setTarget:self];
[menu addItem:[NSMenuItem separatorItem]];
clickItem = [menu addItemWithTitle:@"3 Finger Click"
action:@selector(setClick:)
keyEquivalent:@""];
[clickItem setTarget:self];
tapItem = [menu addItemWithTitle:@"3 Finger Tap"
action:@selector(setTap:)
keyEquivalent:@""];
[tapItem setTarget:self];
[self setChecks];
// Add Separator
[menu addItem:[NSMenuItem separatorItem]];
// Add Quit Action
menuItem = [menu addItemWithTitle:@"Quit"
action:@selector(actionQuit:)
keyEquivalent:@""];
[menuItem setTarget:self];
return menu;
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
NSMenu* menu = [self createMenu];
// Check if Darkmode menubar is supported and enable templating of the icon in
// that case.
NSImage* icon = [NSApp applicationIconImage];
[icon setSize:CGSizeMake(19, 19)];
BOOL oldBusted = (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9);
if (!oldBusted) {
// 10.10 or higher, so setTemplate: is safe
[icon setTemplate:YES];
}
_statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSSquareStatusItemLength] retain];
_statusItem.highlightMode = YES;
_statusItem.menu = menu;
_statusItem.button.toolTip = @"MiddleClick";
_statusItem.button.image = icon;
[menu release];
}
@end