diff --git a/ChangeLog b/ChangeLog index 5596020..aa2832c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-17 Richard frith-Macdonald + + Clean up document type keys in ...info.plist + Implement support for help document. + 2008-12-16 Richard frith-Macdonald Attempt to get NSRole set correctly in document type info. diff --git a/Modules/Projects/Application/PCAppProject+Inspector.h b/Modules/Projects/Application/PCAppProject+Inspector.h index 73fc8dd..696a58b 100644 --- a/Modules/Projects/Application/PCAppProject+Inspector.h +++ b/Modules/Projects/Application/PCAppProject+Inspector.h @@ -43,6 +43,8 @@ - (void)clearFile:(id)sender; - (void)setAppIcon:(id)sender; - (void)clearAppIcon:(id)sender; +- (void)setHelpFile:(id)sender; +- (void)clearHelpFile:(id)sender; - (BOOL)setAppIconWithImageAtPath:(NSString *)path; - (void)setMainNib:(id)sender; - (BOOL)setMainNibWithFileAtPath:(NSString *)path; diff --git a/Modules/Projects/Application/PCAppProject+Inspector.m b/Modules/Projects/Application/PCAppProject+Inspector.m index 38f92ab..67be696 100644 --- a/Modules/Projects/Application/PCAppProject+Inspector.m +++ b/Modules/Projects/Application/PCAppProject+Inspector.m @@ -31,6 +31,39 @@ // ---------------------------------------------------------------------------- NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; +static void +setOrRemove(NSMutableDictionary *m, id v, NSString *k) +{ + if ([v isKindOfClass: [NSString class]]) + { + v = [v stringByTrimmingSpaces]; + if ([v length] == 0) + v = nil; + } + else if ([v isKindOfClass: [NSArray class]]) + { + if ([v count] == 0) + v = nil; + } + if (v == nil) + [m removeObjectForKey: k]; + else + [m setObject: v forKey: k]; +} + +static id +cleanup(NSMutableDictionary *m, NSString *k) +{ + id v; + + setOrRemove(m, [m objectForKey: k], k); + v = [m objectForKey: k]; + if (v == nil) + v = @""; + return v; +} + + @implementation PCAppTextField - (BOOL)becomeFirstResponder @@ -51,7 +84,7 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; [docBasedAppButton setRefusesFirstResponder:YES]; [docBasedAppButton setState: - ([[projectDict objectForKey:PCDocumentBasedApp] + ([[projectDict objectForKey: PCDocumentBasedApp] isEqualToString: @"YES"]) ? NSOnState : NSOffState]; } @@ -62,30 +95,30 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; - (void)createProjectAttributes { // TFs Buttons - [setFieldButton setRefusesFirstResponder:YES]; - [clearFieldButton setRefusesFirstResponder:YES]; + [setFieldButton setRefusesFirstResponder: YES]; + [clearFieldButton setRefusesFirstResponder: YES]; // Document types buttons - [addDocTypeButton setRefusesFirstResponder:YES]; - [removeDocTypeButton setRefusesFirstResponder:YES]; - [docBasedAppButton setRefusesFirstResponder:YES]; + [addDocTypeButton setRefusesFirstResponder: YES]; + [removeDocTypeButton setRefusesFirstResponder: YES]; + [docBasedAppButton setRefusesFirstResponder: YES]; - [self setDocBasedApp:docBasedAppButton]; + [self setDocBasedApp: docBasedAppButton]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(tfGetFocus:) - name:PCITextFieldGetFocus - object:nil]; + [[NSNotificationCenter defaultCenter] addObserver: self + selector: @selector(tfGetFocus:) + name: PCITextFieldGetFocus + object: nil]; [projectAttributesView retain]; - [self updateInspectorValues:nil]; + [self updateInspectorValues: nil]; } - (NSView *)projectAttributesView { if (!projectAttributesView) { - if ([NSBundle loadNibNamed:@"Inspector" owner:self] == NO) + if ([NSBundle loadNibNamed: @"Inspector" owner: self] == NO) { NSLog(@"PCAppProject: error loading Inspector NIB!"); return nil; @@ -100,35 +133,35 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; // --- Actions // ---------------------------------------------------------------------------- -- (void)setAppType:(id)sender +- (void)setAppType: (id)sender { NSString *appType = [appTypeField stringValue]; - NSMutableArray *libs = [[projectDict objectForKey:PCLibraries] mutableCopy]; + NSMutableArray *libs = [[projectDict objectForKey: PCLibraries] mutableCopy]; - if ([appType isEqualToString:@"Renaissance"]) + if ([appType isEqualToString: @"Renaissance"]) { - [libs addObject:@"Renaissance"]; + [libs addObject: @"Renaissance"]; } else { - [libs removeObject:@"Renaissance"]; + [libs removeObject: @"Renaissance"]; } - [self setProjectDictObject:libs forKey:PCLibraries notify:YES]; + [self setProjectDictObject: libs forKey: PCLibraries notify: YES]; RELEASE(libs); - [self setProjectDictObject:appType forKey:PCAppType notify:YES]; + [self setProjectDictObject: appType forKey: PCAppType notify: YES]; } -- (void)setAppClass:(id)sender +- (void)setAppClass: (id)sender { - [self setProjectDictObject:[appClassField stringValue] - forKey:PCPrincipalClass - notify:YES]; + [self setProjectDictObject: [appClassField stringValue] + forKey: PCPrincipalClass + notify: YES]; } -- (void)setIconViewImage:(NSImage *)image +- (void)setIconViewImage: (NSImage *)image { - [iconView setImage:nil]; + [iconView setImage: nil]; [iconView display]; if (image == nil) @@ -136,11 +169,11 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; return; } - [iconView setImage:image]; + [iconView setImage: image]; [iconView display]; } -- (void)setFile:(id)sender +- (void)setFile: (id)sender { if (!activeTextField) { @@ -149,18 +182,19 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; if (activeTextField == appImageField) { - [self setAppIcon:self]; + [self setAppIcon: self]; } else if (activeTextField == helpFileField) { + [self setHelpFile: self]; } else if (activeTextField == mainNIBField) { - [self setMainNib:self]; + [self setMainNib: self]; } } -- (void)clearFile:(id)sender +- (void)clearFile: (id)sender { if (!activeTextField) { @@ -169,40 +203,41 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; if (activeTextField == appImageField) { - [self clearAppIcon:self]; + [self clearAppIcon: self]; } else if (activeTextField == helpFileField) { + [self clearHelpFile: self]; } else if (activeTextField == mainNIBField) { - [self clearMainNib:self]; + [self clearMainNib: self]; } - [self setIconViewImage:nil]; + [self setIconViewImage: nil]; } // Application Icon -- (void)setAppIcon:(id)sender +- (void)setAppIcon: (id)sender { int result; NSArray *fileTypes = [NSImage imageFileTypes]; NSOpenPanel *openPanel = [NSOpenPanel openPanel]; NSString *dir = nil; - [openPanel setAllowsMultipleSelection:NO]; - [openPanel setTitle:@"Set Application Icon"]; + [openPanel setAllowsMultipleSelection: NO]; + [openPanel setTitle: @"Set Application Icon"]; dir = [[NSUserDefaults standardUserDefaults] - objectForKey:@"LastOpenDirectory"]; - result = [openPanel runModalForDirectory:dir - file:nil - types:fileTypes]; + objectForKey: @"LastOpenDirectory"]; + result = [openPanel runModalForDirectory: dir + file: nil + types: fileTypes]; if (result == NSOKButton) { - NSString *imageFilePath = [[openPanel filenames] objectAtIndex:0]; + NSString *imageFilePath = [[openPanel filenames] objectAtIndex: 0]; - if (![self setAppIconWithImageAtPath:imageFilePath]) + if (![self setAppIconWithImageAtPath: imageFilePath]) { NSRunAlertPanel(@"Error while opening file!", @"Couldn't open %@", @"OK", nil, nil,imageFilePath); @@ -210,69 +245,106 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; } } -- (void)clearAppIcon:(id)sender +- (void)setHelpFile: (id)sender { - [appImageField setStringValue:@""]; - [infoDict setObject:@"" forKey:@"NSIcon"]; - [infoDict setObject:@"" forKey:@"ApplicationIcon"]; + int result; + NSArray *fileTypes = [NSArray arrayWithObject: @"rtfd"]; + NSOpenPanel *openPanel = [NSOpenPanel openPanel]; + NSString *dir = nil; + + [openPanel setAllowsMultipleSelection: NO]; + [openPanel setTitle: @"Set Help File"]; - [self setProjectDictObject:@"" forKey:PCAppIcon notify:YES]; + dir = [[NSUserDefaults standardUserDefaults] + objectForKey: @"LastOpenDirectory"]; + result = [openPanel runModalForDirectory: dir + file: nil + types: fileTypes]; + + if (result == NSOKButton) + { + NSString *path = [[openPanel filenames] objectAtIndex: 0]; + NSString *file = [path lastPathComponent]; + + [helpFileField setStringValue: file]; + + [self addAndCopyFiles: [NSArray arrayWithObject: path] + forKey: PCDocuFiles]; + + [infoDict setObject: file forKey: @"GSHelpContentsFile"]; + [self setProjectDictObject: file forKey: PCHelpFile notify: YES]; + } } -- (BOOL)setAppIconWithImageAtPath:(NSString *)path +- (void)clearAppIcon: (id)sender +{ + [appImageField setStringValue: @""]; + [infoDict setObject: @"" forKey: @"NSIcon"]; + [infoDict setObject: @"" forKey: @"ApplicationIcon"]; + + [self setProjectDictObject: @"" forKey: PCAppIcon notify: YES]; +} + +- (void)clearHelpFile: (id)sender +{ + [infoDict removeObjectForKey: @"GSHelpContentsFile"]; + [self setProjectDictObject: @"" forKey: PCHelpFile notify: YES]; +} + +- (BOOL)setAppIconWithImageAtPath: (NSString *)path { NSImage *image = nil; NSString *imageName = nil; - if (!(image = [[NSImage alloc] initWithContentsOfFile:path])) + if (!(image = [[NSImage alloc] initWithContentsOfFile: path])) { return NO; } imageName = [path lastPathComponent]; - [appImageField setStringValue:imageName]; + [appImageField setStringValue: imageName]; - [self setIconViewImage:image]; + [self setIconViewImage: image]; - [self addAndCopyFiles:[NSArray arrayWithObject:path] forKey:PCImages]; + [self addAndCopyFiles: [NSArray arrayWithObject: path] forKey: PCImages]; - [infoDict setObject:imageName forKey:@"NSIcon"]; - [infoDict setObject:imageName forKey:@"ApplicationIcon"]; + [infoDict setObject: imageName forKey: @"NSIcon"]; + [infoDict setObject: imageName forKey: @"ApplicationIcon"]; - [self setProjectDictObject:imageName forKey:PCAppIcon notify:YES]; + [self setProjectDictObject: imageName forKey: PCAppIcon notify: YES]; return YES; } // Main Interface File -- (void)setMainNib:(id)sender +- (void)setMainNib: (id)sender { int result; NSOpenPanel *openPanel = [NSOpenPanel openPanel]; NSString *dir = nil; NSArray *types = nil; - [openPanel setAllowsMultipleSelection:NO]; - [openPanel setTitle:@"Set Main Interface File"]; - if ([[projectDict objectForKey:PCAppType] isEqualToString:@"GORM"]) + [openPanel setAllowsMultipleSelection: NO]; + [openPanel setTitle: @"Set Main Interface File"]; + if ([[projectDict objectForKey: PCAppType] isEqualToString: @"GORM"]) { - types = [NSArray arrayWithObject:@"gorm"]; + types = [NSArray arrayWithObject: @"gorm"]; } else { - types = [NSArray arrayWithObject:@"gsmarkup"]; + types = [NSArray arrayWithObject: @"gsmarkup"]; } dir = [[NSUserDefaults standardUserDefaults] - objectForKey:@"LastOpenDirectory"]; - result = [openPanel runModalForDirectory:dir file:nil types:types]; + objectForKey: @"LastOpenDirectory"]; + result = [openPanel runModalForDirectory: dir file: nil types: types]; if (result == NSOKButton) { - NSString *file = [[openPanel filenames] objectAtIndex:0]; + NSString *file = [[openPanel filenames] objectAtIndex: 0]; - if (![self setMainNibWithFileAtPath:file]) + if (![self setMainNibWithFileAtPath: file]) { NSRunAlertPanel(@"Error while opening file!", @"Couldn't open %@", @"OK", nil, nil,file); @@ -280,231 +352,222 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; } } -- (BOOL)setMainNibWithFileAtPath:(NSString *)path +- (BOOL)setMainNibWithFileAtPath: (NSString *)path { NSString *nibName = [path lastPathComponent]; - [self setIconViewImage:[[NSWorkspace sharedWorkspace] iconForFile:path]]; + [self setIconViewImage: [[NSWorkspace sharedWorkspace] iconForFile: path]]; - [self addAndCopyFiles:[NSArray arrayWithObject:path] forKey:PCInterfaces]; - [infoDict setObject:nibName forKey:@"NSMainNibFile"]; + [self addAndCopyFiles: [NSArray arrayWithObject: path] forKey: PCInterfaces]; + [infoDict setObject: nibName forKey: @"NSMainNibFile"]; - [self setProjectDictObject:nibName forKey:PCMainInterfaceFile notify:YES]; + [self setProjectDictObject: nibName forKey: PCMainInterfaceFile notify: YES]; - [mainNIBField setStringValue:nibName]; + [mainNIBField setStringValue: nibName]; return YES; } -- (void)clearMainNib:(id)sender +- (void)clearMainNib: (id)sender { - [mainNIBField setStringValue:@""]; - [infoDict setObject:@"" forKey:@"NSMainNibFile"]; + [mainNIBField setStringValue: @""]; + [infoDict setObject: @"" forKey: @"NSMainNibFile"]; - [self setProjectDictObject:@"" forKey:PCMainInterfaceFile notify:YES]; + [self setProjectDictObject: @"" forKey: PCMainInterfaceFile notify: YES]; } // Document Types -- (void)showDocTypesPanel:(id)sender +- (void)showDocTypesPanel: (id)sender { - [docTypesPanel makeKeyAndOrderFront:nil]; + [docTypesPanel makeKeyAndOrderFront: nil]; } -- (void)setDocBasedApp:(id)sender +- (void)setDocBasedApp: (id)sender { - NSString *docBased = [projectDict objectForKey:PCDocumentBasedApp]; + NSString *docBased = [projectDict objectForKey: PCDocumentBasedApp]; if ([docBasedAppButton state] == NSOnState) { - [docTypeLabel setTextColor:[NSColor blackColor]]; - [docTypeField setBackgroundColor:[NSColor whiteColor]]; - [docTypeField setTextColor:[NSColor blackColor]]; - [docTypeField setEditable:YES]; + [docTypeLabel setTextColor: [NSColor blackColor]]; + [docTypeField setBackgroundColor: [NSColor whiteColor]]; + [docTypeField setTextColor: [NSColor blackColor]]; + [docTypeField setEditable: YES]; - [docNameLabel setTextColor:[NSColor blackColor]]; - [docNameField setBackgroundColor:[NSColor whiteColor]]; - [docNameField setTextColor:[NSColor blackColor]]; - [docNameField setEditable:YES]; + [docNameLabel setTextColor: [NSColor blackColor]]; + [docNameField setBackgroundColor: [NSColor whiteColor]]; + [docNameField setTextColor: [NSColor blackColor]]; + [docNameField setEditable: YES]; - [docRoleLabel setTextColor:[NSColor blackColor]]; - [docRoleField setBackgroundColor:[NSColor whiteColor]]; - [docRoleField setTextColor:[NSColor blackColor]]; - [docRoleField setEditable:YES]; + [docRoleLabel setTextColor: [NSColor blackColor]]; + [docRoleField setBackgroundColor: [NSColor whiteColor]]; + [docRoleField setTextColor: [NSColor blackColor]]; + [docRoleField setEditable: YES]; - [docClassLabel setTextColor:[NSColor blackColor]]; - [docClassField setBackgroundColor:[NSColor whiteColor]]; - [docClassField setTextColor:[NSColor blackColor]]; - [docClassField setEditable:YES]; + [docClassLabel setTextColor: [NSColor blackColor]]; + [docClassField setBackgroundColor: [NSColor whiteColor]]; + [docClassField setTextColor: [NSColor blackColor]]; + [docClassField setEditable: YES]; - [nameColumn setIdentifier:@"NSHumanReadableName"]; - [[nameColumn headerCell] setStringValue:@"Name"]; - [docTypesList addTableColumn:roleColumn]; - [docTypesList addTableColumn:classColumn]; + [nameColumn setIdentifier: @"NSHumanReadableName"]; + [[nameColumn headerCell] setStringValue: @"Name"]; + [docTypesList addTableColumn: roleColumn]; + [docTypesList addTableColumn: classColumn]; RELEASE(roleColumn); RELEASE(classColumn); - if (![docBased isEqualToString:@"YES"]) + if (![docBased isEqualToString: @"YES"]) { - [self setProjectDictObject:@"YES" - forKey:PCDocumentBasedApp - notify:YES]; + [self setProjectDictObject: @"YES" + forKey: PCDocumentBasedApp + notify: YES]; } } else { - [docTypeLabel setTextColor:[NSColor darkGrayColor]]; - [docTypeField setBackgroundColor:[NSColor lightGrayColor]]; - [docTypeField setTextColor:[NSColor darkGrayColor]]; - [docTypeField setEditable:NO]; + [docTypeLabel setTextColor: [NSColor darkGrayColor]]; + [docTypeField setBackgroundColor: [NSColor lightGrayColor]]; + [docTypeField setTextColor: [NSColor darkGrayColor]]; + [docTypeField setEditable: NO]; - [docNameLabel setTextColor:[NSColor darkGrayColor]]; - [docNameField setBackgroundColor:[NSColor lightGrayColor]]; - [docNameField setTextColor:[NSColor darkGrayColor]]; - [docNameField setEditable:NO]; + [docNameLabel setTextColor: [NSColor darkGrayColor]]; + [docNameField setBackgroundColor: [NSColor lightGrayColor]]; + [docNameField setTextColor: [NSColor darkGrayColor]]; + [docNameField setEditable: NO]; - [docRoleLabel setTextColor:[NSColor darkGrayColor]]; - [docRoleField setBackgroundColor:[NSColor lightGrayColor]]; - [docRoleField setTextColor:[NSColor darkGrayColor]]; - [docRoleField setEditable:NO]; + [docRoleLabel setTextColor: [NSColor darkGrayColor]]; + [docRoleField setBackgroundColor: [NSColor lightGrayColor]]; + [docRoleField setTextColor: [NSColor darkGrayColor]]; + [docRoleField setEditable: NO]; - [docClassLabel setTextColor:[NSColor darkGrayColor]]; - [docClassField setBackgroundColor:[NSColor lightGrayColor]]; - [docClassField setTextColor:[NSColor darkGrayColor]]; - [docClassField setEditable:NO]; + [docClassLabel setTextColor: [NSColor darkGrayColor]]; + [docClassField setBackgroundColor: [NSColor lightGrayColor]]; + [docClassField setTextColor: [NSColor darkGrayColor]]; + [docClassField setEditable: NO]; // Columns // [docTypesList removeTableColumn:nameColumn]; - [nameColumn setIdentifier:@"NSIcon"]; - [[nameColumn headerCell] setStringValue:@"Icon"]; + [nameColumn setIdentifier: @"NSIcon"]; + [[nameColumn headerCell] setStringValue: @"Icon"]; RETAIN(roleColumn); RETAIN(classColumn); - [docTypesList removeTableColumn:roleColumn]; - [docTypesList removeTableColumn:classColumn]; + [docTypesList removeTableColumn: roleColumn]; + [docTypesList removeTableColumn: classColumn]; - if (![docBased isEqualToString:@"NO"]) + if (![docBased isEqualToString: @"NO"]) { - [self setProjectDictObject:@"NO" - forKey:PCDocumentBasedApp - notify:YES]; + [self setProjectDictObject: @"NO" + forKey: PCDocumentBasedApp + notify: YES]; } } } -- (void)addDocType:(id)sender +- (void)addDocType: (id)sender { int row; - NSMutableDictionary *entry = [NSMutableDictionary dictionaryWithCapacity:6]; + NSMutableDictionary *entry = [NSMutableDictionary dictionaryWithCapacity: 6]; int selectedRow = [docTypesList selectedRow]; - NSString *s; - [entry setObject:[docTypeField stringValue] forKey:@"NSName"]; - [entry setObject:[docNameField stringValue] forKey:@"NSHumanReadableName"]; - [entry setObject:[[docExtensionsField stringValue] componentsSeparatedByString:@","] forKey:@"NSUnixExtensions"]; - [entry setObject:[docIconField stringValue] forKey:@"NSIcon"]; - s = [[docRoleField stringValue] stringByTrimmingSpaces]; - if ([s length] == 0) - [entry removeObjectForKey: @"NSRole"]; - else - [entry setObject: s forKey:@"NSRole"]; - [entry setObject:[docClassField stringValue] forKey:@"NSDocumentClass"]; + setOrRemove(entry, [docTypeField stringValue], @"NSName"); + setOrRemove(entry, [docNameField stringValue], @"NSHumanReadableName"); + setOrRemove(entry, [[docExtensionsField stringValue] componentsSeparatedByString: @","], @"NSUnixExtensions"); + setOrRemove(entry, [docIconField stringValue], @"NSIcon"); + setOrRemove(entry, [docRoleField stringValue], @"NSRole"); + setOrRemove(entry, [docClassField stringValue], @"NSDocumentClass"); if (selectedRow >= 0 && [docTypesItems count] > 0) { - [docTypesItems insertObject:entry atIndex:selectedRow + 1]; + [docTypesItems insertObject: entry atIndex: selectedRow + 1]; row = selectedRow + 1; } else { - [docTypesItems addObject:entry]; + [docTypesItems addObject: entry]; row = [docTypesItems count] - 1; } [docTypesList reloadData]; - [docTypesList selectRow:row byExtendingSelection:NO]; + [docTypesList selectRow: row byExtendingSelection: NO]; - [self fillFieldsForRow:row]; + [self fillFieldsForRow: row]; - [self setProjectDictObject:docTypesItems - forKey:PCDocumentTypes - notify:YES]; + [self setProjectDictObject: docTypesItems + forKey: PCDocumentTypes + notify: YES]; } -- (void)removeDocType:(id)sender +- (void)removeDocType: (id)sender { int selectedRow = [docTypesList selectedRow]; if (selectedRow >= 0) { - [docTypesItems removeObjectAtIndex:selectedRow]; + [docTypesItems removeObjectAtIndex: selectedRow]; [docTypesList reloadData]; } if (([docTypesList selectedRow] < 0) && ([docTypesItems count] > 0)) { - [docTypesList selectRow:[docTypesItems count]-1 byExtendingSelection:NO]; - [self fillFieldsForRow:[docTypesItems count]-1]; + [docTypesList selectRow: [docTypesItems count]-1 + byExtendingSelection: NO]; + [self fillFieldsForRow: [docTypesItems count]-1]; } - [self setProjectDictObject:docTypesItems - forKey:PCDocumentTypes - notify:YES]; + [self setProjectDictObject: docTypesItems + forKey: PCDocumentTypes + notify: YES]; } -- (void)docFieldSet:(id)sender +- (void)docFieldSet: (id)sender { NSMutableDictionary *object = nil; NSLog(@"docFieldSet"); if (sender != docTypeField && sender != docNameField - && sender != docIconField && sender != docExtensionsField - && sender != docRoleField && sender != docClassField) + && sender != docIconField && sender != docExtensionsField + && sender != docRoleField && sender != docClassField) { return; } if ([docTypesItems count] <= 0) { - [self addDocType:addDocTypeButton]; + [self addDocType: addDocTypeButton]; } - object = [[docTypesItems objectAtIndex:[docTypesList selectedRow]] + object = [[docTypesItems objectAtIndex: [docTypesList selectedRow]] mutableCopy]; if (sender == docTypeField) { - [object setObject:[sender stringValue] forKey:@"NSName"]; + setOrRemove(object, [sender stringValue], @"NSName"); } else if (sender == docNameField) { - [object setObject:[sender stringValue] forKey:@"NSHumanReadableName"]; + setOrRemove(object, [sender stringValue], @"NSHumanReadableName"); } else if (sender == docIconField) { - [object setObject:[sender stringValue] forKey:@"NSIcon"]; + setOrRemove(object, [sender stringValue], @"NSIcon"); } else if (sender == docExtensionsField) { - [object - setObject:[[sender stringValue] componentsSeparatedByString:@","] - forKey:@"NSUnixExtensions"]; + setOrRemove(object, + [[sender stringValue] componentsSeparatedByString: @","], + @"NSUnixExtensions"); } else if (sender == docRoleField) { - NSString *s = [[sender stringValue] stringByTrimmingSpaces]; - - if ([s length] == 0) - [object removeObjectForKey: @"NSRole"]; - else - [object setObject: s forKey:@"NSRole"]; + setOrRemove(object, [sender stringValue], @"NSRole"); } else if (sender == docClassField) { - [object setObject:[sender stringValue] forKey:@"NSDocumentClass"]; + setOrRemove(object, [sender stringValue], @"NSDocumentClass"); } - [docTypesItems replaceObjectAtIndex:[docTypesList selectedRow] - withObject:object]; + [docTypesItems replaceObjectAtIndex: [docTypesList selectedRow] + withObject: object]; [docTypesList reloadData]; [object release]; } @@ -513,39 +576,39 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; // --- Document Types browser // ---------------------------------------------------------------------------- -- (int)numberOfRowsInTableView:(NSTableView *)aTableView +- (int)numberOfRowsInTableView: (NSTableView *)aTableView { return [docTypesItems count]; } -- (id) tableView:(NSTableView *)aTableView - objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (id) tableView: (NSTableView *)aTableView + objectValueForTableColumn: (NSTableColumn *)aTableColumn + row: (int)rowIndex { NSDictionary *object = nil; if (docTypesItems != nil || [docTypesItems count] > 0) { - object = [docTypesItems objectAtIndex:rowIndex]; + object = [docTypesItems objectAtIndex: rowIndex]; if (aTableColumn == extensionsColumn) { - return [[object objectForKey:@"NSUnixExtensions"] - componentsJoinedByString:@","]; + return [[object objectForKey: @"NSUnixExtensions"] + componentsJoinedByString: @","]; } else { - return [object objectForKey:[aTableColumn identifier]]; + return [object objectForKey: [aTableColumn identifier]]; } } return nil; } -- (void)tableView:(NSTableView *)aTableView - setObjectValue:anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (void)tableView: (NSTableView *)aTableView + setObjectValue: anObject + forTableColumn: (NSTableColumn *)aTableColumn + row: (int)rowIndex { NSMutableDictionary *type = nil; @@ -554,84 +617,80 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; return; } - type = [docTypesItems objectAtIndex:rowIndex]; - if ([[aTableColumn identifier] isEqualToString:@"NSUnixExtensions"]) + type = [docTypesItems objectAtIndex: rowIndex]; + if ([[aTableColumn identifier] isEqualToString: @"NSUnixExtensions"]) { - [type removeObjectForKey:@"Extension"]; - [type setObject:anObject forKey:@"Extension"]; + setOrRemove(type, anObject, @"Extension"); } - else if ([[aTableColumn identifier] isEqualToString:@"NSIcon"]) + else if ([[aTableColumn identifier] isEqualToString: @"NSIcon"]) { - [type removeObjectForKey:@"Icon"]; - [type setObject:anObject forKey:@"Icon"]; + setOrRemove(type, anObject, @"Icon"); } - [self setProjectDictObject:docTypesItems - forKey:PCDocumentTypes - notify:YES]; + [self setProjectDictObject: docTypesItems + forKey: PCDocumentTypes + notify: YES]; } -- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex +- (BOOL)tableView: (NSTableView *)aTableView shouldSelectRow: (int)rowIndex { - [self fillFieldsForRow:rowIndex]; + [self fillFieldsForRow: rowIndex]; return YES; } -- (void)fillFieldsForRow:(int)rowIndex +- (void)fillFieldsForRow: (int)rowIndex { - NSDictionary *type = nil; - NSString *s; + NSMutableDictionary *type = nil; int itemCount = [docTypesItems count]; if (itemCount <= 0 || rowIndex > itemCount || rowIndex < 0) { - [docTypeField setStringValue:@""]; - [docNameField setStringValue:@""]; - [docIconField setStringValue:@""]; - [docExtensionsField setStringValue:@""]; + [docTypeField setStringValue: @""]; + [docNameField setStringValue: @""]; + [docIconField setStringValue: @""]; + [docExtensionsField setStringValue: @""]; [docRoleField setStringValue: @""]; - [docClassField setStringValue:@""]; + [docClassField setStringValue: @""]; return; } - type = [docTypesItems objectAtIndex:rowIndex]; + type = [docTypesItems objectAtIndex: rowIndex]; - [docTypeField setStringValue:[type objectForKey:@"NSName"]]; - [docNameField setStringValue:[type objectForKey:@"NSHumanReadableName"]]; - [docIconField setStringValue:[type objectForKey:@"NSIcon"]]; + [docTypeField setStringValue: cleanup(type, @"NSName")]; + [docNameField setStringValue: cleanup(type, @"NSHumanReadableName")]; + [docIconField setStringValue: cleanup(type, @"NSIcon")]; - [docExtensionsField setStringValue:@""]; - if ([[type objectForKey:@"NSUnixExtensions"] count] > 0) + [docExtensionsField setStringValue: @""]; + if ([[type objectForKey: @"NSUnixExtensions"] count] > 0) { [docExtensionsField setStringValue: - [[type objectForKey:@"NSUnixExtensions"] - componentsJoinedByString:@","]]; + [[type objectForKey: @"NSUnixExtensions"] + componentsJoinedByString: @","]]; } - s = [type objectForKey:@"NSRole"]; - if ([s length] > 0) - [docRoleField setStringValue: s]; - [docClassField setStringValue:[type objectForKey:@"NSDocumentClass"]]; + [docRoleField setStringValue: cleanup(type, @"NSRole")]; + [docClassField setStringValue: cleanup(type, @"NSDocumentClass")]; } // ---------------------------------------------------------------------------- // --- Notifications // ---------------------------------------------------------------------------- -- (void)updateInspectorValues:(NSNotification *)aNotif +- (void)updateInspectorValues: (NSNotification *)aNotif { // NSLog (@"PCAppProject: updateInspectorValues"); // Project Attributes view - [appTypeField selectItemWithTitle:[projectDict objectForKey:PCAppType]]; - [appClassField setStringValue:[projectDict objectForKey:PCPrincipalClass]]; + [appTypeField selectItemWithTitle: [projectDict objectForKey: PCAppType]]; + [appClassField setStringValue: [projectDict objectForKey: PCPrincipalClass]]; - [appImageField setStringValue:[projectDict objectForKey:PCAppIcon]]; - [helpFileField setStringValue:[projectDict objectForKey:PCHelpFile]]; - [mainNIBField setStringValue:[projectDict objectForKey:PCMainInterfaceFile]]; + [appImageField setStringValue: [projectDict objectForKey: PCAppIcon]]; + [helpFileField setStringValue: [projectDict objectForKey: PCHelpFile]]; + [mainNIBField setStringValue: + [projectDict objectForKey: PCMainInterfaceFile]]; - docTypesItems = [projectDict objectForKey:PCDocumentTypes]; + docTypesItems = [projectDict objectForKey: PCDocumentTypes]; [docTypesList reloadData]; } @@ -642,7 +701,7 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; // with resignFirstResponder: method overriding. Here we're using // controlTextDidEndEditing (NSTextField's delegate method) to achieve this. -- (void)tfGetFocus:(NSNotification *)aNotif +- (void)tfGetFocus: (NSNotification *)aNotif { id anObject = [aNotif object]; NSString *file = nil; @@ -650,8 +709,8 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; if (anObject != appImageField - && anObject != helpFileField - && anObject != mainNIBField) + && anObject != helpFileField + && anObject != mainNIBField) { // NSLog(@"tfGetFocus: not that textfield"); return; @@ -661,12 +720,12 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; { file = [appImageField stringValue]; - if (![file isEqualToString:@""]) + if (![file isEqualToString: @""]) { - path = [self dirForCategoryKey:PCImages]; - path = [path stringByAppendingPathComponent:file]; - [self setIconViewImage:[[NSImage alloc] - initWithContentsOfFile:path]]; + path = [self dirForCategoryKey: PCImages]; + path = [path stringByAppendingPathComponent: file]; + [self setIconViewImage: [[NSImage alloc] + initWithContentsOfFile: path]]; } activeTextField = appImageField; } @@ -678,41 +737,41 @@ NSString *PCITextFieldGetFocus = @"PCITextFieldGetFocusNotification"; { file = [mainNIBField stringValue]; - if (![file isEqualToString:@""]) + if (![file isEqualToString: @""]) { - path = [projectPath stringByAppendingPathComponent:file]; - [self setIconViewImage:[[NSWorkspace sharedWorkspace] - iconForFile:path]]; + path = [projectPath stringByAppendingPathComponent: file]; + [self setIconViewImage: [[NSWorkspace sharedWorkspace] + iconForFile: path]]; } activeTextField = mainNIBField; } - [setFieldButton setEnabled:YES]; - [clearFieldButton setEnabled:YES]; + [setFieldButton setEnabled: YES]; + [clearFieldButton setEnabled: YES]; } -- (void)controlTextDidEndEditing:(NSNotification *)aNotification +- (void)controlTextDidEndEditing: (NSNotification *)aNotification { NSControl *anObject = [aNotification object]; id target = [anObject target]; SEL action = [anObject action]; if (anObject == appImageField - || anObject == helpFileField - || anObject == mainNIBField) + || anObject == helpFileField + || anObject == mainNIBField) { activeTextField = nil; - [self setIconViewImage:nil]; + [self setIconViewImage: nil]; - [setFieldButton setEnabled:NO]; - [clearFieldButton setEnabled:NO]; + [setFieldButton setEnabled: NO]; + [clearFieldButton setEnabled: NO]; return; } - if ([target respondsToSelector:action]) + if ([target respondsToSelector: action]) { - [target performSelector:action withObject:anObject]; + [target performSelector: action withObject: anObject]; } }