-
Notifications
You must be signed in to change notification settings - Fork 8
/
StatusItemAppDelegate.m
121 lines (106 loc) · 4.41 KB
/
StatusItemAppDelegate.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
//
// StatusItemAppDelegate.m
// StatusItem
//
// Created by Joshua Garnham on 07/03/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "StatusItemAppDelegate.h"
@implementation StatusItemAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
menuController = [[[JGMenuWindowController alloc] initWithWindowNibName:@"JGMenuWindow"] retain];
[menuController setHeaderView:customView];
[menuController setMenuDelegate:self];
[menuController setStatusItemTitle:@"Search"];
// [menuController setStatusItemImage:[NSImage imageNamed:@"img.png"]];
/* NSMutableArray *items = [[NSMutableArray alloc] init];
for (int i = 0; i < 6; i++) {
if (i==3)
[items addObject:[JGMenuItem seperatorItem]];
JGMenuItem *menuItem = [[JGMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Result %i", i] target:self action:@selector(itemSelected)];
if (i==2) {
JGMenuItem *title = [[JGMenuItem alloc] initWithTitle:@"You can't select me." target:nil action:NULL];
[title setEnabled:NO];
[items addObject:title];
}
if (i==3) {
[menuItem setImage:[NSImage imageNamed:@"img.png"]];
JGMenuWindowController *subController = [[JGMenuWindowController alloc] initWithWindowNibName:@"JGMenuWindow"];
[subController setIsStatusItem:NO];
JGMenuItem *subItem = [[JGMenuItem alloc] initWithTitle:@"i'm a lone sub item :(" target:self action:NULL];
[subController setMenuItems:[NSArray arrayWithObject:subItem]];
[menuItem setSubmenu:subController];
}
[items addObject:menuItem];
}
[menuController setMenuItems:items]; */
}
#pragma mark Showing and Hiding Table
- (void)showTableView {
NSMutableArray *items = [[NSMutableArray alloc] init];
for (int i = 0; i < 6; i++) {
if (i==3)
[items addObject:[JGMenuItem seperatorItem]];
JGMenuItem *menuItem = [[JGMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Result %i", i] target:self action:@selector(itemSelected)];
if (i==2) {
JGMenuItem *title = [[JGMenuItem alloc] initWithTitle:@"You can't select me." target:nil action:NULL];
[title setEnabled:NO];
[items addObject:title];
}
if (i==3) {
[menuItem setImage:[NSImage imageNamed:@"img.png"]];
JGMenuWindowController *subController = [[JGMenuWindowController alloc] initWithWindowNibName:@"JGMenuWindow"];
[subController setIsStatusItem:NO];
JGMenuItem *subItem = [[JGMenuItem alloc] initWithTitle:@"i'm a lone sub item :(" target:self action:NULL];
[subController setMenuItems:[NSArray arrayWithObject:subItem]];
[menuItem setSubmenu:subController];
}
[items addObject:menuItem];
}
[menuController setMenuItems:items];
[menuController highlightMenuItemAtIndex:0];
}
- (void)hideTableView {
[menuController setMenuItems:nil];
}
- (void)itemSelected {
JGMenuWindowController *subController = [[JGMenuWindowController alloc] initWithWindowNibName:@"JGMenuWindow"];
[subController setIsStatusItem:NO];
NSMutableArray *items = [[NSMutableArray alloc] init];
for (int i = 0; i < 6; i++) {
if (i==3)
[items addObject:[JGMenuItem seperatorItem]];
JGMenuItem *menuItem = [[JGMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Result %i", i] target:self action:NULL];
if (i==4) {
JGMenuWindowController *subController = [[JGMenuWindowController alloc] initWithWindowNibName:@"JGMenuWindow"];
[subController setIsStatusItem:NO];
JGMenuItem *subItem = [[JGMenuItem alloc] initWithTitle:@"i'm another lone sub item" target:self action:NULL];
[subController setMenuItems:[NSArray arrayWithObject:subItem]];
[menuItem setSubmenu:subController];
}
[items addObject:menuItem];
}
[subController setProMode:YES];
[subController setMenuItems:items];
[subController popUpContextMenuAtPoint:NSMakePoint(500, 500)];
}
#pragma mark JGMenuWindowDelegate
- (void)menuWillOpen {
[searchField becomeFirstResponder]; // Even though it will happen automatically, just to be on the safe side…
}
#pragma mark NSControlTextEditingDelegate
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor {
if (![searchField.stringValue isEqualToString:@""] && [searchField.stringValue length] <= 1) {
[self showTableView];
}
return YES;
}
- (void)controlTextDidChange:(NSNotification *)obj {
if (![searchField.stringValue isEqualToString:@""] && [searchField.stringValue length] <= 1) {
[self showTableView];
} else if ([searchField.stringValue isEqualToString:@""]) {
[self hideTableView];
}
}
@end