Public feed #599192

Something

public text v1 · immutable
Raw Edit
·published 2007-07-02 01:50 UTC
rendered paste body
+ (NSOpenPanel *)panelToOpenUTIs:(NSString *)firstArg, ... {
	va_list argList;
	NSString *uti = firstArg;
	NSOpenPanel *newOpenPanel = [NSOpenPanel openPanel];
	NSArray *types = [NSArray array];
	va_start(argList, firstArg);
	do {

		NSDictionary *utiDict = (id)UTTypeCopyDeclaration((CFStringRef)uti);
		id exts = [[utiDict
			objectForKey:(id)kUTTypeTagSpecificationKey]
			objectForKey:(id)kUTTagClassFilenameExtension];
		if (exts) {
			if ([exts isKindOfClass: [NSArray class]]) {
				types = [types arrayByAddingObjectsFromArray:exts];
			} else {
				types = [types arrayByAddingObject:exts];
			}
		}
		id osTypes = [[utiDict
			objectForKey:(id)kUTTypeTagSpecificationKey]
			objectForKey:(id)kUTTagClassOSType];
		if (osTypes) {
			if ([osTypes isKindOfClass: [NSArray class]]) {
				types = [types arrayByAddingObjectsFromArray:osTypes];
			} else {
				types = [types arrayByAddingObject:osTypes];
			}
		}
	} while (uti = va_arg(argList, NSString*));
	va_end(argList);
	[newOpenPanel setAllowedFileTypes:types];
	return newOpenPanel;
}

- (id)init {
	self = [super init];
	workspace = [NSWorkspace sharedWorkspace];
	appOpenPanel = [DMGDJController panelToOpenUTIs:
		@"com.apple.application-bundle",
		@"com.apple.application-file",
		nil];
	[appOpenPanel setAllowsMultipleSelection:YES];
	imgOpenPanel = [DMGDJController panelToOpenUTIs:
		@"public.iso-image",
		@"com.apple.disk-image",
		@"com.apple.disk-image-udif",
		@"com.apple.disk-image-ndif",
		@"com.apple.disk-image-smi",
		@"com.apple.disk-image-sparse",
		@"com.apple.disk-image-cdr",
		@"com.roxio.disk-image-toast",
		nil];
	[imgOpenPanel setAllowsMultipleSelection:YES];
	return self;
}

- (IBAction)addApp:(id)sender {
	[appOpenPanel
		beginSheetForDirectory:nil
		file:nil
		modalForWindow:prefsWindow
		modalDelegate:self
		didEndSelector:@selector(addingApp: returnCode: contextInfo:)
		contextInfo:NULL];
	[self syncMounts];
}