Commits

Anonymous committed 1ced318 Merge

Merged changes from master.

  • Participants
  • Parent commits cc6d7c6, fb8a46e

Comments (0)

Files changed (4)

File FileTree/FileTreeController.m

 	}
 }
 
+-(BOOL)validateMenuItem:(NSMenuItem*)menuItem
+{
+	SEL action = [menuItem action];
+
+	if ([outlineView numberOfSelectedRows] == 0)
+		return NO;
+
+	if (action == @selector(setAsRoot:))
+	{
+		BOOL isDir;
+		NSInteger row = [outlineView selectedRow];
+
+		if ([outlineView numberOfSelectedRows] > 1)
+			return NO;
+
+		// Only let directories be Set as Root
+		[[NSFileManager defaultManager] fileExistsAtPath:[[[outlineView itemAtRow:row] URL] path] isDirectory:&isDir];
+		return isDir;
+	}
+
+	return YES;
+}
 @end

File FileTree/FileTreeOutlineView.m

 
 - (void)awakeFromNib
 {
-	[[self menu] setAutoenablesItems:NO];
 	[self setDoubleAction:@selector(addToPlaylist:)];
 	[self setTarget:[self delegate]];
 }
 {
 	//Find which row is under the cursor
 	[[self window] makeFirstResponder:self];
-	BOOL isDir;
 	NSPoint   menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
 	NSInteger iRow = [self rowAtPoint:menuPoint];
 	NSMenu* contextMenu = [self menu];
 		[self selectRow:iRow byExtendingSelection:NO];
 	}
 
-	if ([self numberOfSelectedRows] > 0)
-	{
-		[[contextMenu itemWithTag:1] setEnabled:YES];	// Add to Playlist
-		[[contextMenu itemWithTag:2] setEnabled:YES];	// Set as Playlist
-		[[contextMenu itemWithTag:3] setEnabled:YES];	// Show in Finder
-		
-		// Only let directories be Set as Root
-		[[NSFileManager defaultManager] fileExistsAtPath:[[[self itemAtRow:iRow] URL] path] isDirectory:&isDir];
-		[[contextMenu itemWithTag:4] setEnabled:(isDir? YES : NO)];
-	}
-	else
-	{
-		//No rows are selected, so the menu should be displayed with all items disabled
-		int i;
-		for (i=0;i<[contextMenu numberOfItems];i++) {
-			[[contextMenu itemAtIndex:i] setEnabled:NO];
-		}
-	}
-	 
 	return contextMenu;
 }
 

File Plugins/TagLib/TagLibMetadataReader.h

 
 }
 
++ (BOOL)isCoverFile:(NSString *)fileName;
++ (NSArray *)coverNames;
+
 @end

File Plugins/TagLib/TagLibMetadataReader.m

 			}
 		}
 
+		if (nil == image) {
+			// Try to load image from external file
+
+			// If we find an appropriately-named image in this directory, it will
+			// be tagged with the first image cache tag. Subsequent directory entries
+			// may have a different tag, but an image search would result in the same
+			// artwork.
+			
+			static NSString *lastImagePath = nil;
+			static NSString *lastCacheTag = nil;
+						
+			NSString *path = [[url path] stringByDeletingLastPathComponent];
+
+			if ([path isEqualToString:lastImagePath]) {
+				// Use whatever image may have been stored with the initial tag for the path
+				// (might be nil but no point scanning again)
+				
+				image = [NSImage imageNamed:lastCacheTag];
+			} else {
+				// Book-keeping...
+				
+				if (nil != lastImagePath)
+					[lastImagePath release];
+				
+				lastImagePath = [path retain];
+
+				if (nil != lastCacheTag)
+					[lastCacheTag release];
+				
+				lastCacheTag = [imageCacheTag retain];
+				
+				// Gather list of candidate image files
+				
+				NSArray *fileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
+				NSArray *imageFileNames = [fileNames pathsMatchingExtensions:[NSImage imageFileTypes]];
+				
+				NSEnumerator *imageEnumerator = [imageFileNames objectEnumerator];
+				NSString *fileName;
+				
+				while (fileName = [imageEnumerator nextObject]) {
+					if ([TagLibMetadataReader isCoverFile:fileName]) {
+						image = [[[NSImage alloc] initByReferencingFile:[path stringByAppendingPathComponent:fileName]] autorelease];
+						[image setName:imageCacheTag];
+						break;
+					}
+				}
+			}
+		}
+		
 		if (nil != image) {
 			[dict setObject:image forKey:@"albumArt"];
 		}
 	return [dict autorelease];
 }
 
++ (BOOL)isCoverFile:(NSString *)fileName
+{
+	NSEnumerator *coverEnumerator = [[TagLibMetadataReader coverNames] objectEnumerator];
+	NSString *coverFileName;
+	
+	while (coverFileName = [coverEnumerator nextObject]) {
+		if ([[[[fileName lastPathComponent] stringByDeletingPathExtension] lowercaseString] hasSuffix:coverFileName]) {
+			return true;
+		}
+	}
+	return false;
+			
+}
+
++ (NSArray *)coverNames
+{
+	return [NSArray arrayWithObjects:@"cover", @"folder", @"album", @"front", nil];
+}
+
 + (NSArray *)fileTypes
 {
 	//May be a way to get a list of supported formats