forked from themartorana/MultiFirefox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.m
More file actions
162 lines (129 loc) · 5.14 KB
/
MainWindow.m
File metadata and controls
162 lines (129 loc) · 5.14 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// MainWindow.m
// MultiFirefox
//
// Created by David Martorana on 4/7/08.
// Copyright 2008. All rights reserved.
//
#import "MainWindow.h"
#import "MFF.h"
@implementation MainWindowController
// Determines if profile list should refresh on window focus
BOOL shouldReloadProfiles = NO;
#pragma mark Standard Methods
-(void) PopulateVersionValues {
NSArray *versionsArray = [[MFF versionsList] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
[mVersionsController removeObjects:[mVersionsController arrangedObjects]];
[mVersionsController addObjects:versionsArray];
[mVersionsController setSelectionIndex:0];
}
-(void) PopulateProfileValues {
NSArray *profilesArray = [[MFF profilesList] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
[mProfilesController removeObjects:[mProfilesController arrangedObjects]];
[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];
[mVersionsTable setDelegate:self];
[mVersionsTable setDoubleAction:@selector(LaunchFirefox:)];
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
{
NSBeginAlertSheet(@"You need to create a profile!",
@"OK",
nil,
nil,
[self window],
self,
@selector(noProfilesOKClick:returnCode:contextInfo:),
NULL,
NULL,
@"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."
);
}
-(IBAction)LaunchFirefox:(id)sender {
NSString *profileName = (NSString *)[[mProfilesController selectedObjects] objectAtIndex:0];
NSString *versionName = [self GetSelectedVersion];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:profileName forKey:@"lastProfile"];
[defaults setObject:versionName forKey:@"lastVersion"];
[defaults synchronize];
NSLog(@"Version: %@ / Profile: %@", versionName, profileName);
[MFF launchFirefox:versionName withProfile:profileName];
}
-(IBAction)ShowProfileManager:(id)sender {
shouldReloadProfiles = YES;
[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;
}
- (void) SelectProfileForVersion:(NSString *)version {
// Strip any directory paths
version = [version lastPathComponent];
BOOL versionIsPlain = [[version lowercaseString] isEqualToString:@"firefox"];
// Find the first profile whose name starts with the version name
NSArray *profiles = [mProfilesController arrangedObjects];
for (NSString *profile in profiles) {
if (
(versionIsPlain && [profile isEqualToString:@"default"]) ||
[profile hasPrefix:version]
) {
[mProfilesController setSelectedObjects:[NSArray arrayWithObject:profile]];
break;
}
}
}
#pragma mark NSTableView Delegates
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
[self SelectProfileForVersion:[self GetSelectedVersion]];
}
#pragma mark Window Delegates
- (void)windowWillClose:(NSNotification *)notification {
[NSApp terminate:self];
}
- (void)windowDidBecomeMain:(NSNotification *)notification {
if (shouldReloadProfiles) {
NSArray *oldValues = [mProfilesController selectedObjects];
[self PopulateProfileValues];
[mProfilesController setSelectedObjects:oldValues];
shouldReloadProfiles = NO;
}
}
-(void)noProfilesOKClick:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo{
[self ShowProfileManager:nil];
}
#pragma mark Application Delegates
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[self window] center];
[[self window] makeKeyAndOrderFront:self];
}
@end