Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 184 lines (152 sloc) 4.779 kb
a327ea2 @andreyvit Imported official Platypus 4.0 sources.
authored
1 /*
2 Platypus - program for creating Mac OS X application wrappers around scripts
3 Copyright (C) 2008 Sveinbjorn Thordarson <sveinbjornt@simnet.is>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #import "Platypus.h"
22 #import "EnvController.h"
23
24 @implementation EnvController
25
26 - (id) init
27 {
28 keys = [[NSMutableArray alloc] init];
29 values = [[NSMutableArray alloc] init];
30 [keys addObject: @"APP_BUNDLER"];
31 [values addObject: PROGRAM_STAMP];
32 return self;
33 }
34
35 -(void)dealloc
36 {
37 [keys release];
38 [values release];
39 [super dealloc];
40 }
41
42 - (IBAction)add:(id)sender
43 {
44 [keys addObject: @"VARIABLE"];
45 [values addObject: @"Value"];
46 [envTableView reloadData];
47 [envTableView selectRow: [keys count]-1 byExtendingSelection: NO];
48 [self tableViewSelectionDidChange: NULL];
49 }
50
51 - (void)set: (NSDictionary *)dict;
52 {
53 [keys release];
54 [values release];
55
56 keys = [[NSMutableArray alloc] initWithArray: [dict allKeys]];
57 values = [[NSMutableArray alloc] initWithArray: [dict allValues]];
58
59 [self tableViewSelectionDidChange: NULL];
60 }
61
62 - (IBAction)apply:(id)sender
63 {
64 [window setTitle: @"Platypus"];
65 [NSApp stopModal];
66 }
67
68 - (IBAction)clear:(id)sender
69 {
70 [keys removeAllObjects];
71 [values removeAllObjects];
72 [envTableView reloadData];
73 [self tableViewSelectionDidChange: NULL];
74 }
75
76 - (IBAction)help:(id)sender
77 {
78 NSURL *fileURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"env.html" ofType:nil]];
79 [[NSWorkspace sharedWorkspace] openURL: fileURL];
80 }
81
82 - (IBAction)remove:(id)sender
83 {
84 if ([envTableView selectedRow] == -1)
85 return;
86
87 [keys removeObjectAtIndex: [envTableView selectedRow]];
88 [values removeObjectAtIndex: [envTableView selectedRow]];
89 [envTableView reloadData];
90 [self tableViewSelectionDidChange: NULL];
91 }
92
93 - (IBAction)resetDefaults:(id)sender
94 {
95 [self clear: self];
96 [keys addObject: @"APP_BUNDLER"];
97 [values addObject: PROGRAM_STAMP];
98 [envTableView reloadData];
99 [self tableViewSelectionDidChange: NULL];
100 }
101
102 - (IBAction)show:(id)sender
103 {
104 [window setTitle: @"Platypus - Environmental Variables"];
105 [envTableView reloadData];
106 [NSApp beginSheet: envWindow
107 modalForWindow: window
108 modalDelegate:nil
109 didEndSelector:nil
110 contextInfo:nil];
111 [NSApp runModalForWindow: envWindow];
112 [NSApp endSheet:envWindow];
113 [envWindow orderOut:self];
114 }
115
116
117 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
118 {
119 return([keys count]);
120 }
121
122 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
123 {
124 if ([[aTableColumn identifier] caseInsensitiveCompare: @"2"] == NSOrderedSame)//value
125 {
126 return([values objectAtIndex: rowIndex]);
127 }
128 else if ([[aTableColumn identifier] caseInsensitiveCompare: @"1"] == NSOrderedSame)//name
129 {
130 return [keys objectAtIndex: rowIndex];
131 }
132 return(@"");
133 }
134
135 - (void)tableView:(NSTableView *)aTableView setObjectValue: anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
136 {
137 if (rowIndex < 0 || rowIndex > [values count]-1)
138 return;
139
140 if ([[aTableColumn identifier] caseInsensitiveCompare: @"2"] == NSOrderedSame)//value
141 {
142 [values replaceObjectAtIndex: rowIndex withObject: anObject];
143 }
144 else if ([[aTableColumn identifier] caseInsensitiveCompare: @"1"] == NSOrderedSame)//keys
145 {
146 [keys replaceObjectAtIndex: rowIndex withObject: [anObject uppercaseString]];
147 }
148 }
149
150 - (void)tableViewSelectionDidChange:(NSNotification *)aNotification
151 {
152 int selected = [envTableView selectedRow];
153
154 if (selected != -1) //there is a selected item
155 [removeButton setEnabled: YES];
156 else
157 [removeButton setEnabled: NO];
158
159 if ([keys count] == 0)
160 [clearButton setEnabled: NO];
161 else
162 [clearButton setEnabled: YES];
163
164 if ([keys count] == 255)
165 [addButton setEnabled: NO];
166 else
167 [addButton setEnabled: YES];
168 }
169
170 - (NSMutableDictionary *)environmentDictionary
171 {
172 NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjects: values forKeys: keys];
173 return([dict retain]);
174 }
175
176 - (BOOL)validateMenuItem:(NSMenuItem*)anItem
177 {
178 if ([[anItem title] isEqualToString:@"Remove Entry"] && [envTableView selectedRow] == -1)
179 return NO;
180 return YES;
181 }
182
183 @end
Something went wrong with that request. Please try again.