37 |
|
|
38 |
|
+ (id) sharedInstance |
39 |
|
{ |
40 |
< |
static VMSettingsController *_sharedInstance = nil; |
41 |
< |
if (!_sharedInstance) { |
42 |
< |
_sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init]; |
43 |
< |
} |
44 |
< |
return _sharedInstance; |
40 |
> |
static VMSettingsController *_sharedInstance = nil; |
41 |
> |
if (!_sharedInstance) { |
42 |
> |
_sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init]; |
43 |
> |
} |
44 |
> |
return _sharedInstance; |
45 |
|
} |
46 |
|
|
47 |
|
- (id) init |
48 |
|
{ |
49 |
|
self = [super initWithWindowNibName:@"VMSettingsWindow"]; |
50 |
|
|
51 |
< |
cancelWasClicked = NO; |
51 |
> |
cancelWasClicked = NO; |
52 |
|
|
53 |
< |
return self; |
53 |
> |
return self; |
54 |
|
} |
55 |
|
|
56 |
|
- (int) numberOfRowsInTableView: (NSTableView *) table |
135 |
|
[useRawKeyCodes setIntValue: PrefsFindBool("keycodes") ]; |
136 |
|
[rawKeyCodes setStringValue: getStringFromPrefs("keycodefile") ]; |
137 |
|
[rawKeyCodes setEnabled:[useRawKeyCodes intValue]]; |
138 |
+ |
[browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]]; |
139 |
|
|
140 |
|
int wheelmode = PrefsFindInt32("mousewheelmode"), wheel = 0; |
141 |
|
switch (wheelmode) { |
160 |
|
|
161 |
|
- (void) editSettingsFor: (NSString *) vmdir sender: (id) sender |
162 |
|
{ |
163 |
< |
chdir([vmdir fileSystemRepresentation]); |
163 |
> |
chdir([vmdir fileSystemRepresentation]); |
164 |
|
AddPrefsDefaults(); |
165 |
|
AddPlatformPrefsDefaults(); |
166 |
|
LoadPrefs([vmdir fileSystemRepresentation]); |
167 |
< |
NSWindow *window = [self window]; |
168 |
< |
[self setupGUI]; |
169 |
< |
[NSApp runModalForWindow:window]; |
167 |
> |
NSWindow *window = [self window]; |
168 |
> |
[self setupGUI]; |
169 |
> |
[NSApp runModalForWindow:window]; |
170 |
|
} |
171 |
|
|
172 |
|
static NSString *makeRelativeIfNecessary(NSString *path) |
173 |
|
{ |
174 |
< |
char cwd[1024], filename[1024]; |
175 |
< |
int cwdlen; |
176 |
< |
strlcpy(filename, [path fileSystemRepresentation], sizeof(filename)); |
177 |
< |
getcwd(cwd, sizeof(cwd)); |
178 |
< |
cwdlen = strlen(cwd); |
179 |
< |
if (!strncmp(cwd, filename, cwdlen)) { |
180 |
< |
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
181 |
< |
cwdlen++; |
182 |
< |
return [NSString stringWithCString: filename + cwdlen]; |
183 |
< |
} |
184 |
< |
return path; |
174 |
> |
char cwd[1024], filename[1024]; |
175 |
> |
int cwdlen; |
176 |
> |
strlcpy(filename, [path fileSystemRepresentation], sizeof(filename)); |
177 |
> |
getcwd(cwd, sizeof(cwd)); |
178 |
> |
cwdlen = strlen(cwd); |
179 |
> |
if (!strncmp(cwd, filename, cwdlen)) { |
180 |
> |
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
181 |
> |
cwdlen++; |
182 |
> |
return [NSString stringWithCString: filename + cwdlen]; |
183 |
> |
} |
184 |
> |
return path; |
185 |
|
} |
186 |
|
|
187 |
|
- (IBAction) addDisk: (id) sender |
189 |
|
NSOpenPanel *open = [NSOpenPanel openPanel]; |
190 |
|
[open setCanChooseDirectories:NO]; |
191 |
|
[open setAllowsMultipleSelection:NO]; |
192 |
< |
[open beginSheetForDirectory: @"" |
192 |
> |
[open setTreatsFilePackagesAsDirectories:YES]; |
193 |
> |
[open beginSheetForDirectory: [[NSFileManager defaultManager] currentDirectoryPath] |
194 |
|
file: @"Unknown" |
195 |
|
modalForWindow: [self window] |
196 |
|
modalDelegate: self |
201 |
|
- (void) _addDiskEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
202 |
|
{ |
203 |
|
if (theReturnCode == NSOKButton) { |
204 |
< |
[diskArray addObject: makeRelativeIfNecessary([open filename])]; |
204 |
> |
[diskArray addObject: makeRelativeIfNecessary([open filename])]; |
205 |
|
[disks reloadData]; |
206 |
|
} |
207 |
|
} |
219 |
|
{ |
220 |
|
NSSavePanel *save = [NSSavePanel savePanel]; |
221 |
|
[save setAccessoryView: diskSaveSize]; |
222 |
< |
[save beginSheetForDirectory: @"" |
222 |
> |
[save setTreatsFilePackagesAsDirectories:YES]; |
223 |
> |
[save beginSheetForDirectory: [[NSFileManager defaultManager] currentDirectoryPath] |
224 |
|
file: @"New.dsk" |
225 |
|
modalForWindow: [self window] |
226 |
|
modalDelegate: self |
237 |
|
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", [[save filename] UTF8String], [diskSaveSizeField intValue]); |
238 |
|
int ret = system(cmd); |
239 |
|
if (ret == 0) { |
240 |
< |
[diskArray addObject: makeRelativeIfNecessary([save filename])]; |
240 |
> |
[diskArray addObject: makeRelativeIfNecessary([save filename])]; |
241 |
|
[disks reloadData]; |
242 |
|
} |
243 |
|
} |
248 |
|
- (IBAction) useRawKeyCodesClicked: (id) sender |
249 |
|
{ |
250 |
|
[rawKeyCodes setEnabled:[useRawKeyCodes intValue]]; |
251 |
+ |
[browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]]; |
252 |
|
} |
253 |
|
|
254 |
|
- (IBAction) browseForROMFileClicked: (id) sender |
256 |
|
NSOpenPanel *open = [NSOpenPanel openPanel]; |
257 |
|
[open setCanChooseDirectories:NO]; |
258 |
|
[open setAllowsMultipleSelection:NO]; |
259 |
+ |
[open setTreatsFilePackagesAsDirectories:YES]; |
260 |
|
[open beginSheetForDirectory: @"" |
261 |
|
file: [romFile stringValue] |
262 |
|
modalForWindow: [self window] |
268 |
|
- (void) _browseForROMFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
269 |
|
{ |
270 |
|
if (theReturnCode == NSOKButton) { |
271 |
< |
[romFile setStringValue: makeRelativeIfNecessary([open filename])]; |
272 |
< |
} |
271 |
> |
[romFile setStringValue: makeRelativeIfNecessary([open filename])]; |
272 |
> |
} |
273 |
|
} |
274 |
|
|
275 |
|
- (IBAction) browseForUnixRootClicked: (id) sender |
289 |
|
- (void) _browseForUnixRootEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
290 |
|
{ |
291 |
|
if (theReturnCode == NSOKButton) { |
292 |
< |
[unixRoot setStringValue: makeRelativeIfNecessary([open filename])]; |
292 |
> |
[unixRoot setStringValue: makeRelativeIfNecessary([open filename])]; |
293 |
> |
} |
294 |
> |
} |
295 |
> |
|
296 |
> |
- (IBAction) browseForKeyCodesFileClicked: (id) sender |
297 |
> |
{ |
298 |
> |
NSOpenPanel *open = [NSOpenPanel openPanel]; |
299 |
> |
[open setCanChooseDirectories:NO]; |
300 |
> |
[open setAllowsMultipleSelection:NO]; |
301 |
> |
[open setTreatsFilePackagesAsDirectories:YES]; |
302 |
> |
[open beginSheetForDirectory: @"" |
303 |
> |
file: [unixRoot stringValue] |
304 |
> |
modalForWindow: [self window] |
305 |
> |
modalDelegate: self |
306 |
> |
didEndSelector: @selector(_browseForKeyCodesFileEnd: returnCode: contextInfo:) |
307 |
> |
contextInfo: nil]; |
308 |
> |
} |
309 |
> |
|
310 |
> |
- (void) _browseForKeyCodesFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
311 |
> |
{ |
312 |
> |
if (theReturnCode == NSOKButton) { |
313 |
> |
[rawKeyCodes setStringValue: makeRelativeIfNecessary([open filename])]; |
314 |
|
} |
315 |
|
} |
316 |
|
|
317 |
|
- (void) cancelEdit: (id) sender |
318 |
|
{ |
319 |
|
PrefsExit(); |
320 |
< |
[[self window] close]; |
321 |
< |
[NSApp stopModal]; |
322 |
< |
cancelWasClicked = YES; |
320 |
> |
[[self window] close]; |
321 |
> |
[NSApp stopModal]; |
322 |
> |
cancelWasClicked = YES; |
323 |
|
} |
324 |
|
|
325 |
|
- (void) saveChanges: (id) sender |
375 |
|
SavePrefs(); |
376 |
|
PrefsExit(); |
377 |
|
|
378 |
< |
[[self window] close]; |
379 |
< |
[NSApp stopModal]; |
380 |
< |
cancelWasClicked = NO; |
378 |
> |
[[self window] close]; |
379 |
> |
[NSApp stopModal]; |
380 |
> |
cancelWasClicked = NO; |
381 |
|
} |
382 |
|
|
383 |
|
- (BOOL) cancelWasClicked |