forked from themartorana/MultiFirefox
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainWindow.m
126 lines (99 loc) · 3.94 KB
/
MainWindow.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
124
125
126
//
// MainWindow.m
// MultiFirefox
//
// Created by David Martorana on 4/7/08.
// Copyright 2008. All rights reserved.
//
#import "MainWindow.h"
#import "MFF.h"
@implementation MainWindowController
// Set the value
BOOL alreadyChecked = NO;
#pragma mark Standard Methods
-(void) PopulateVersionValues{
NSArray *versionsArray = [[MFF versionsList] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
[mVersionsController addObjects:versionsArray];
[mVersionsController setSelectionIndex:0];
}
-(void) PopulateProfileValues{
NSArray *profilesArray = [[MFF profilesList] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
[mProfilesController addObjects:profilesArray];
[mProfilesController setSelectionIndex:0];
}
#pragma mark Event Handlers
- (void) awakeFromNib
{
// Check to be sure there are multiple profiles
if (![MFF multipleProfilesExist]){
[self performSelector:@selector(showNotEnoughProfilesThingy)
withObject:nil
afterDelay:1.0];
}
[self PopulateProfileValues];
[self PopulateVersionValues];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* lastVersion = [defaults objectForKey:@"lastVersion"];
NSString* lastProfile = [defaults objectForKey:@"lastProfile"];
if (lastVersion) {
[mVersionsController setSelectedObjects:[NSArray arrayWithObject:lastVersion]];
}
if (lastProfile) {
[mProfilesController setSelectedObjects:[NSArray arrayWithObject:lastProfile]];
}
}
- (void) showNotEnoughProfilesThingy
{
NSString *msg = @"You only have one profile set up for Firefox. In order to run multiple versions of Firefox side by side, you must have multiple profiles defined.\n\nClick OK to open the profile manager. Once you've set up a seperate multiple profiles, please relaunch MultiFirefox.";
NSBeginAlertSheet(@"You need to create a profile!",
@"OK",
nil,
nil,
[self window],
self,
@selector(noProfilesOKClick:returnCode:contextInfo:),
NULL,
NULL,
msg);
}
-(IBAction)LaunchFirefox:(id)sender {
NSString *profileName = (NSString *)[[mProfilesController selectedObjects] objectAtIndex:0];
//NSString *versionName = (NSString *)[[mVersionsController selectedObject] self];
NSString *versionName = [self GetSelectedVersion];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:profileName forKey:@"lastProfile"];
[defaults setObject:versionName forKey:@"lastVersion"];
[defaults synchronize];
NSLog(@"%@", [profileName stringByAppendingString:versionName]);
[MFF launchFirefox:versionName withProfile:profileName];
}
-(IBAction)ShowProfileManager:(id)sender {
[MFF openFirefoxProfilesWindow:[self GetSelectedVersion]];
}
-(IBAction)CreateApplication:(id)sender {
NSString *profileName = (NSString *)[[mProfilesController selectedObjects] objectAtIndex:0];
NSString *versionName = [self GetSelectedVersion];
[MFF createApplicationWithVersion:versionName andProfile:profileName];
}
#pragma mark Common Functions
- (NSString *)GetSelectedVersion
{
NSString *versionName = (NSString *)[[mVersionsController selectedObjects] objectAtIndex:0];
return versionName;
}
#pragma mark Window Delegates
- (BOOL)windowWillClose:(NSNotification *)notification {
[NSApp terminate:self];
return NO;
}
-(void)noProfilesOKClick:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo{
[MFF openFirefoxProfilesWindow:[self GetSelectedVersion]];
[NSApp terminate:self];
}
#pragma mark Application Delegates
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[self window] center];
[[self window] makeKeyAndOrderFront:self];
}
@end