ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm
(Generate patch)

Comparing SheepShaver/src/MacOSX/Launcher/VMSettingsController.mm (file contents):
Revision 1.1 by asvitkine, 2009-08-02T18:34:57Z vs.
Revision 1.6 by asvitkine, 2009-08-18T03:42:11Z

# Line 25 | Line 25
25  
26   const int CDROMRefNum = -62;                    // RefNum of driver
27  
28 + #ifdef STANDALONE_PREFS
29   void prefs_init()
30   {
31   }
# Line 32 | Line 33 | void prefs_init()
33   void prefs_exit()
34   {
35   }
36 + #endif
37  
38   @implementation VMSettingsController
39  
40   + (id) sharedInstance
41   {
42 <        static VMSettingsController *_sharedInstance = nil;
43 <        if (!_sharedInstance) {
44 <                _sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init];
45 <        }
46 <        return _sharedInstance;
42 >  static VMSettingsController *_sharedInstance = nil;
43 >  if (!_sharedInstance) {
44 >    _sharedInstance = [[VMSettingsController allocWithZone:[self zone]] init];
45 >  }
46 >  return _sharedInstance;
47   }
48  
49   - (id) init
50   {
51 <  return [super initWithWindowNibName:@"VMSettingsWindow"];
51 >  self = [super initWithWindowNibName:@"VMSettingsWindow"];
52 >
53 >  cancelWasClicked = NO;
54 >
55 >  return self;
56   }
57  
58   - (int) numberOfRowsInTableView: (NSTableView *) table
# Line 131 | Line 137 | static NSString *getStringFromPrefs(cons
137    [useRawKeyCodes setIntValue: PrefsFindBool("keycodes") ];
138    [rawKeyCodes setStringValue: getStringFromPrefs("keycodefile") ];
139    [rawKeyCodes setEnabled:[useRawKeyCodes intValue]];
140 +  [browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]];
141  
142    int wheelmode = PrefsFindInt32("mousewheelmode"), wheel = 0;
143    switch (wheelmode) {
# Line 155 | Line 162 | static NSString *getStringFromPrefs(cons
162  
163   - (void) editSettingsFor: (NSString *) vmdir sender: (id) sender
164   {
165 <        chdir([vmdir fileSystemRepresentation]);
165 >  chdir([vmdir fileSystemRepresentation]);
166 >  AddPrefsDefaults();
167 >  AddPlatformPrefsDefaults();
168 >  LoadPrefs([vmdir fileSystemRepresentation]);
169 >  NSWindow *window = [self window];
170 >  [self setupGUI];
171 >  [NSApp runModalForWindow:window];
172 > }
173 >
174 > - (void) editSettingsForNewVM: (NSString *) vmdir sender: (id) sender
175 > {
176 >  chdir([vmdir fileSystemRepresentation]);
177    AddPrefsDefaults();
178    AddPlatformPrefsDefaults();
179    LoadPrefs([vmdir fileSystemRepresentation]);
180 <        NSWindow *window = [self window];
181 <        [self setupGUI];
164 <        [NSApp runModalForWindow:window];
180 >  NSWindow *window = [self window];
181 >  [NSApp runModalForWindow:window];
182   }
183  
184   static NSString *makeRelativeIfNecessary(NSString *path)
185   {
186 <        char cwd[1024], filename[1024];
187 <        int cwdlen;
188 <        strlcpy(filename, [path fileSystemRepresentation], sizeof(filename));
189 <        getcwd(cwd, sizeof(cwd));
190 <        cwdlen = strlen(cwd);
191 <        if (!strncmp(cwd, filename, cwdlen)) {
192 <                if (cwdlen >= 0 && cwd[cwdlen-1] != '/')
193 <                        cwdlen++;
194 <                return [NSString stringWithCString: filename + cwdlen];
195 <        }
196 <        return path;
186 >  char cwd[1024], filename[1024];
187 >  int cwdlen;
188 >  strlcpy(filename, [path fileSystemRepresentation], sizeof(filename));
189 >  getcwd(cwd, sizeof(cwd));
190 >  cwdlen = strlen(cwd);
191 >  if (!strncmp(cwd, filename, cwdlen)) {
192 >    if (cwdlen >= 0 && cwd[cwdlen-1] != '/')
193 >      cwdlen++;
194 >    return [NSString stringWithCString: filename + cwdlen];
195 >  }
196 >  return path;
197   }
198  
199   - (IBAction) addDisk: (id) sender
# Line 184 | Line 201 | static NSString *makeRelativeIfNecessary
201    NSOpenPanel *open = [NSOpenPanel openPanel];
202    [open setCanChooseDirectories:NO];
203    [open setAllowsMultipleSelection:NO];
204 <  [open beginSheetForDirectory: @""
204 >  [open setTreatsFilePackagesAsDirectories:YES];
205 >  [open beginSheetForDirectory: [[NSFileManager defaultManager] currentDirectoryPath]
206                            file: @"Unknown"
207                  modalForWindow: [self window]
208                   modalDelegate: self
# Line 195 | Line 213 | static NSString *makeRelativeIfNecessary
213   - (void) _addDiskEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
214   {
215    if (theReturnCode == NSOKButton) {
216 <                [diskArray addObject: makeRelativeIfNecessary([open filename])];
216 >    [diskArray addObject: makeRelativeIfNecessary([open filename])];
217      [disks reloadData];
218    }
219   }
# Line 213 | Line 231 | static NSString *makeRelativeIfNecessary
231   {
232    NSSavePanel *save = [NSSavePanel savePanel];
233    [save setAccessoryView: diskSaveSize];
234 <  [save beginSheetForDirectory: @""
234 >  [save setTreatsFilePackagesAsDirectories:YES];
235 >  [save beginSheetForDirectory: [[NSFileManager defaultManager] currentDirectoryPath]
236                            file: @"New.dsk"
237                  modalForWindow: [self window]
238                   modalDelegate: self
# Line 230 | Line 249 | static NSString *makeRelativeIfNecessary
249        snprintf(cmd, sizeof(cmd), "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", [[save filename] UTF8String], [diskSaveSizeField intValue]);
250        int ret = system(cmd);
251        if (ret == 0) {
252 <                                [diskArray addObject: makeRelativeIfNecessary([save filename])];
252 >        [diskArray addObject: makeRelativeIfNecessary([save filename])];
253          [disks reloadData];
254        }
255      }
# Line 241 | Line 260 | static NSString *makeRelativeIfNecessary
260   - (IBAction) useRawKeyCodesClicked: (id) sender
261   {
262    [rawKeyCodes setEnabled:[useRawKeyCodes intValue]];
263 +  [browseRawKeyCodesButton setEnabled:[useRawKeyCodes intValue]];
264   }
265  
266   - (IBAction) browseForROMFileClicked: (id) sender
# Line 248 | Line 268 | static NSString *makeRelativeIfNecessary
268    NSOpenPanel *open = [NSOpenPanel openPanel];
269    [open setCanChooseDirectories:NO];
270    [open setAllowsMultipleSelection:NO];
271 +  [open setTreatsFilePackagesAsDirectories:YES];
272    [open beginSheetForDirectory: @""
273                            file: [romFile stringValue]
274                  modalForWindow: [self window]
# Line 259 | Line 280 | static NSString *makeRelativeIfNecessary
280   - (void) _browseForROMFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
281   {
282    if (theReturnCode == NSOKButton) {
283 <                [romFile setStringValue: makeRelativeIfNecessary([open filename])];
284 <        }
283 >    [romFile setStringValue: makeRelativeIfNecessary([open filename])];
284 >  }
285   }
286  
287   - (IBAction) browseForUnixRootClicked: (id) sender
# Line 280 | Line 301 | static NSString *makeRelativeIfNecessary
301   - (void) _browseForUnixRootEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
302   {
303    if (theReturnCode == NSOKButton) {
304 <                [unixRoot setStringValue: makeRelativeIfNecessary([open filename])];
304 >    [unixRoot setStringValue: makeRelativeIfNecessary([open filename])];
305 >  }
306 > }
307 >
308 > - (IBAction) browseForKeyCodesFileClicked: (id) sender
309 > {
310 >  NSOpenPanel *open = [NSOpenPanel openPanel];
311 >  [open setCanChooseDirectories:NO];
312 >  [open setAllowsMultipleSelection:NO];
313 >  [open setTreatsFilePackagesAsDirectories:YES];
314 >  [open beginSheetForDirectory: @""
315 >                          file: [unixRoot stringValue]
316 >                modalForWindow: [self window]
317 >                 modalDelegate: self
318 >                didEndSelector: @selector(_browseForKeyCodesFileEnd: returnCode: contextInfo:)
319 >                   contextInfo: nil];
320 > }
321 >
322 > - (void) _browseForKeyCodesFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo
323 > {
324 >  if (theReturnCode == NSOKButton) {
325 >    [rawKeyCodes setStringValue: makeRelativeIfNecessary([open filename])];
326    }
327   }
328  
329   - (void) cancelEdit: (id) sender
330   {
331 + #ifdef STANDALONE_PREFS
332    PrefsExit();
333 <        [[self window] close];
334 <        [NSApp stopModal];
333 > #endif
334 >  [[self window] close];
335 >  [NSApp stopModal];
336 >  cancelWasClicked = YES;
337   }
338  
339   - (void) saveChanges: (id) sender
# Line 342 | Line 387 | static NSString *makeRelativeIfNecessary
387    PrefsReplaceString("serialb", [[printerPort stringValue] UTF8String]);
388    PrefsReplaceString("ether", [[ethernetInterface stringValue] UTF8String]);
389    SavePrefs();
390 + #ifdef STANDALONE_PREFS
391    PrefsExit();
392 + #endif
393  
394 <        [[self window] close];
395 <        [NSApp stopModal];
394 >  [[self window] close];
395 >  [NSApp stopModal];
396 >  cancelWasClicked = NO;
397 > }
398 >
399 > - (BOOL) cancelWasClicked
400 > {
401 >  return cancelWasClicked;
402   }
403  
404   - (void) dealloc

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines