AppIcons are now set/cleaned correctly

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@8478 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Robert Slover 2001-01-06 16:44:39 +00:00
parent de3d438171
commit 043563d37c
2 changed files with 79 additions and 8 deletions

View file

@ -41,6 +41,7 @@
NSTextField *appClassField; NSTextField *appClassField;
NSTextField *appImageField; NSTextField *appImageField;
NSButton *setAppIconButton; NSButton *setAppIconButton;
NSButton *clearAppIconButton;
NSImageView *appIconView; NSImageView *appIconView;
NSImage *icon; NSImage *icon;
} }
@ -70,4 +71,11 @@
- (void)updateValuesFromProjectDict; - (void)updateValuesFromProjectDict;
- (void)clearAppIcon:(id)sender;
- (void)setAppIcon:(id)sender;
- (BOOL)setAppIconWithImageAtPath:(NSString *)path;
@end @end

View file

@ -79,27 +79,37 @@
appImageField =[[NSTextField alloc] initWithFrame:NSMakeRect(84,204,176,21)]; appImageField =[[NSTextField alloc] initWithFrame:NSMakeRect(84,204,176,21)];
[appImageField setAlignment: NSLeftTextAlignment]; [appImageField setAlignment: NSLeftTextAlignment];
[appImageField setBordered: YES]; [appImageField setBordered: YES];
[appImageField setEditable: YES]; [appImageField setEditable: NO];
[appImageField setBezeled: YES]; [appImageField setBezeled: YES];
[appImageField setDrawsBackground: YES]; [appImageField setDrawsBackground: YES];
[appImageField setStringValue:@""]; [appImageField setStringValue:@""];
[projectProjectInspectorView addSubview:appImageField]; [projectProjectInspectorView addSubview:appImageField];
setAppIconButton =[[NSButton alloc] initWithFrame:NSMakeRect(180,180,80,21)]; setAppIconButton =[[NSButton alloc] initWithFrame:NSMakeRect(220,180,40,21)];
[setAppIconButton setTitle:@"Set..."]; [setAppIconButton setTitle:@"Set"];
[setAppIconButton setTarget:self]; [setAppIconButton setTarget:self];
[setAppIconButton setAction:@selector(setAppIcon:)]; [setAppIconButton setAction:@selector(setAppIcon:)];
[projectProjectInspectorView addSubview:setAppIconButton]; [projectProjectInspectorView addSubview:setAppIconButton];
clearAppIconButton =[[NSButton alloc] initWithFrame:NSMakeRect(180,180,40,21)];
[clearAppIconButton setTitle:@"Clear"];
[clearAppIconButton setTarget:self];
[clearAppIconButton setAction:@selector(clearAppIcon:)];
[projectProjectInspectorView addSubview:clearAppIconButton];
_box = [[NSBox alloc] init]; _box = [[NSBox alloc] init];
[_box setFrame:frame]; [_box setFrame:frame];
[_box setTitlePosition:NSNoTitle]; [_box setTitlePosition:NSNoTitle];
//[_box setBorderType:NSNoBorder]; [_box setBorderType:NSBezelBorder];
[projectProjectInspectorView addSubview:_box]; [projectProjectInspectorView addSubview:_box];
AUTORELEASE(_box);
appIconView = [[NSImageView alloc] initWithFrame:frame]; appIconView = [[NSImageView alloc] initWithFrame:frame];
[_box addSubview:appIconView]; [_box addSubview:appIconView];
RELEASE(_box);
RELEASE(setAppIconButton);
RELEASE(clearAppIconButton);
RELEASE(appIconView);
} }
@end @end
@ -135,8 +145,6 @@
[rootCategories release]; [rootCategories release];
[appClassField release]; [appClassField release];
[appImageField release]; [appImageField release];
[setAppIconButton release];
[appIconView release];
[super dealloc]; [super dealloc];
} }
@ -163,6 +171,7 @@
NSLog([NSString stringWithFormat:@"Couldn't build the GNUmakefile %@!",makefile]); NSLog([NSString stringWithFormat:@"Couldn't build the GNUmakefile %@!",makefile]);
return NO; return NO;
} }
if (![content writeToFile:makefile atomically:YES]) { if (![content writeToFile:makefile atomically:YES]) {
NSLog([NSString stringWithFormat:@"Couldn't write the GNUmakefile %@!",makefile]); NSLog([NSString stringWithFormat:@"Couldn't write the GNUmakefile %@!",makefile]);
return NO; return NO;
@ -213,4 +222,58 @@
[appImageField setStringValue:[projectDict objectForKey:PCAppIcon]]; [appImageField setStringValue:[projectDict objectForKey:PCAppIcon]];
} }
- (void)clearAppIcon:(id)sender
{
[projectDict setObject:@"" forKey:PCAppIcon];
[appImageField setStringValue:@"No Icon!"];
[appIconView setImage:nil];
[appIconView display];
[self writeMakefile];
}
- (void)setAppIcon:(id)sender
{
int result;
NSArray *fileTypes = [NSImage imageFileTypes];
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:NO];
result = [openPanel runModalForDirectory:NSHomeDirectory()
file:nil
types:fileTypes];
if (result == NSOKButton) {
NSArray *files = [openPanel filenames];
NSString *imageFilePath = [files objectAtIndex:0];
if (![self setAppIconWithImageAtPath:imageFilePath]) {
NSRunAlertPanel(@"Error while opening file!",
@"Couldn't open %@", @"OK", nil, nil,imageFilePath);
}
}
}
- (BOOL)setAppIconWithImageAtPath:(NSString *)path
{
NSRect frame = {{0,0}, {64, 64}};
NSImage *image;
if (!(image = [[NSImage alloc] initWithContentsOfFile:path])) {
return NO;
}
[self addFile:path forKey:PCImages copy:YES];
[projectDict setObject:[path lastPathComponent] forKey:PCAppIcon];
[appImageField setStringValue:[path lastPathComponent]];
frame.size = [image size];
[appIconView setFrame:frame];
[appIconView setImage:image];
[appIconView display];
RELEASE(image);
return YES;
}
@end @end