i'm trying to make my iconsForFiles a smaller size than the default. how is it possible to change the size of the iconForFile(s) using setSize:NSMakeSize(16, 16), or any other way?
also, to check to see if the Desktop directory is empty or not, i've added an array with directoryContentsAtPath, and an if statement counting the array, but it doesn't seem to work.
here's my code:
also, to check to see if the Desktop directory is empty or not, i've added an array with directoryContentsAtPath, and an if statement counting the array, but it doesn't seem to work.
here's my code:
Code:
- (void)awakeFromNib
{
NSMenu *desktopMenu = [[NSMenu alloc] initWithTitle:@""];
NSMenuItem *desktopItem = [[NSMenuItem alloc] initWithTitle:@"Desktop Files" action:nil keyEquivalent:@""];
[desktopItem setSubmenu:desktopMenu];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *desktopDirectory = [@"~/Desktop" stringByExpandingTildeInPath];
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:desktopDirectory];
NSString *fileOrFolder;
NSArray *theFolderContents = [fileManager directoryContentsAtPath:desktopDirectory];
if ([theFolderContents count] == 0)
{
NSLog(@"no files");
NSMenuItem *noFilesItem = [[NSMenuItem alloc] initWithTitle:@"No Files - Empty Directory" action:nil keyEquivalent:@""];
[desktopMenu addItem:noFilesItem];
[noFilesItem release];
}
else
{
while ((fileOrFolder = [directoryEnumerator nextObject]))
{
//ignore invisible files
if ([fileOrFolder hasPrefix:@"."])
{
continue;
}
[directoryEnumerator skipDescendents];
NSMenuItem *desktopItems = [[NSMenuItem alloc] initWithTitle:fileOrFolder action:@selector(launchFileOrFolder:) keyEquivalent:@""];
[desktopItems setTarget:self];
[desktopItems setRepresentedObject:[desktopDirectory stringByAppendingPathComponent:fileOrFolder]];
[desktopItems setImage:[[NSWorkspace sharedWorkspace] iconForFile:[desktopDirectory stringByAppendingPathComponent:fileOrFolder]]];
[desktopMenu addItem:desktopItems];
[desktopItems release];
}
}
[theMenu insertItem:desktopItem atIndex:1];
[desktopMenu release];
[desktopItem release];
}
- (void)launchFileOrFolder:(id)sender
{
NSString *filePath = [sender representedObject];
[[NSWorkspace sharedWorkspace] openFile:filePath];
}
- (void)dealloc
{
[super dealloc];
}