forked from mvexel/MilkMaid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MilkMaidAppDelegate.m
90 lines (71 loc) · 2.49 KB
/
MilkMaidAppDelegate.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
//
// SimpleRTMAppDelegate.m
// SimpleRTM
//
// Created by Gregamel on 1/27/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "MilkMaidAppDelegate.h"
#import "MilkMaidWindowController.h"
@implementation MilkMaidAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
windowsVisible = YES;
[self registerDefaultSettings];
[self updateMenuIcon];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"dockicon"]) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
windowControllers = [[NSMutableArray alloc] init];
[self openNewWindow:nil];
}
-(void)registerDefaultSettings {
[[NSUserDefaults standardUserDefaults] registerDefaults:
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:1],
@"menuicon",
[NSNumber numberWithInt:1],
@"dockicon",
[NSNumber numberWithInt:1],
@"tagsInDropDown",
nil]];
}
-(void)updateMenuIcon {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"menuicon"] && !statusItem) {
NSStatusBar *statusBar = [NSStatusBar systemStatusBar];
statusItem = [[statusBar statusItemWithLength:NSVariableStatusItemLength] retain];
NSImage *statusIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon_menu" ofType:@"png"]];
[statusItem setImage:statusIcon];
[statusItem setToolTip:@"MilkMaid"];
[statusItem setHighlightMode:YES];
[statusItem setAction:@selector(toggleWindows)];
[statusItem setTarget:self];
} else if (statusItem) {
[statusItem release];
}
}
-(void)toggleWindows {
for (MilkMaidWindowController *wc in windowControllers) {
if (windowsVisible) {
[wc.window orderOut:self];
} else {
[wc.window orderFrontRegardless];
}
}
windowsVisible = !windowsVisible;
}
-(void)openNewWindow:(id)sender {
MilkMaidWindowController *windowController = [[MilkMaidWindowController alloc] initWithWindowNibName:@"MilkMaid"];
NSWindow *window = windowController.window;
if ([windowControllers count] == 0) {
[windowController setLoadLastList:YES];
}
[windowControllers addObject:windowController];
[[NSApplication sharedApplication] addWindowsItem:window title:window.title filename:NO];
[windowController showWindow:self];
}
-(void)showPreferences:(id)sender {
PreferencesWindowController* prefsWindowController = [[PreferencesWindowController alloc] initWithWindowNibName:@"Preferences"];
[prefsWindowController showWindow:self];
}
@end