From 351c1be33154d12b55e658cfb8f3101858fba63c Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 8 May 2011 18:29:46 +0000 Subject: Allow IWAD files to be double-clicked in the finder to set the IWAD configuration. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2334 --- pkg/osx/AppController.m | 8 ++++++++ pkg/osx/IWADController.h | 1 + pkg/osx/IWADController.m | 39 +++++++++++++++++++++++++++++++++++++++ pkg/osx/LauncherManager.h | 1 + pkg/osx/LauncherManager.m | 5 +++++ 5 files changed, 54 insertions(+) diff --git a/pkg/osx/AppController.m b/pkg/osx/AppController.m index a26a7c9e..ba8dae9b 100644 --- a/pkg/osx/AppController.m +++ b/pkg/osx/AppController.m @@ -83,6 +83,14 @@ { NSString *extension; + // This may be an IWAD. If so, add it to the IWAD configuration; + // don't add it like a PWAD. + + if ([self->launcherManager addIWADPath: fileName]) + { + return YES; + } + // If this is the first file added, clear out the existing // command line. This allows us to select multiple files // in the finder and open them all together (for TCs, etc). diff --git a/pkg/osx/IWADController.h b/pkg/osx/IWADController.h index 90f44667..7464af9f 100644 --- a/pkg/osx/IWADController.h +++ b/pkg/osx/IWADController.h @@ -47,6 +47,7 @@ - (void) saveConfig; - (char *) doomWadPath; - (void) setEnvironment; +- (BOOL) addIWADPath: (NSString *) path; @end diff --git a/pkg/osx/IWADController.m b/pkg/osx/IWADController.m index 3c596850..0c55b3f5 100644 --- a/pkg/osx/IWADController.m +++ b/pkg/osx/IWADController.m @@ -343,5 +343,44 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = //free(env); } +// Examine a path to a WAD and determine whether it is an IWAD file. +// If so, it is added to the IWAD configuration, and true is returned. + +- (BOOL) addIWADPath: (NSString *) path +{ + IWADLocation *iwadList[NUM_IWAD_TYPES]; + NSArray *pathComponents; + NSString *filename; + unsigned int i; + + [self getIWADList: iwadList]; + + // Find an IWAD file that matches the filename in the path that we + // have been given. + + pathComponents = [path pathComponents]; + filename = [pathComponents objectAtIndex: [pathComponents count] - 1]; + + for (i = 0; i < NUM_IWAD_TYPES; ++i) + { + if ([filename caseInsensitiveCompare: IWADFilenames[i]] == 0) + { + // Configure this IWAD. + + [iwadList[i] setLocation: path]; + + // Rebuild dropdown list and select the new IWAD. + + [self setDropdownList]; + [self->iwadSelector selectItemWithTitle:IWADLabels[i]]; + return YES; + } + } + + // No IWAD found with this name. + + return NO; +} + @end diff --git a/pkg/osx/LauncherManager.h b/pkg/osx/LauncherManager.h index 712bc093..1c8a5187 100644 --- a/pkg/osx/LauncherManager.h +++ b/pkg/osx/LauncherManager.h @@ -41,6 +41,7 @@ - (void) runSetup: (id)sender; - (void) awakeFromNib; - (void) clearCommandLine; +- (BOOL) addIWADPath: (NSString *) path; - (void) addFileToCommandLine: (NSString *) fileName forArgument: (NSString *) args; - (void) openTerminal: (id) sender; diff --git a/pkg/osx/LauncherManager.m b/pkg/osx/LauncherManager.m index df1ad18e..937c0d98 100644 --- a/pkg/osx/LauncherManager.m +++ b/pkg/osx/LauncherManager.m @@ -358,5 +358,10 @@ static NSString *AppendQuotedFilename(NSString *str, NSString *fileName) [self setConfig]; } +- (BOOL) addIWADPath: (NSString *) path +{ + return [self->iwadController addIWADPath: path]; +} + @end -- cgit v1.2.3