Changeset 41 for trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
- Timestamp:
- 11/05/02 23:54:02 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
r40 r41 14 14 static const int NJRQTMediaPopUpButtonMaxRecentItems = 10; 15 15 16 NSString * const NJRQTMediaPopUpButtonMovieChangedNotification = @"NJRQTMediaPopUpButtonMovieChangedNotification"; 17 16 18 @interface NJRQTMediaPopUpButton (Private) 17 19 - (void)_setPath:(NSString *)path; 18 20 - (NSMenuItem *)_itemForAlias:(BDAlias *)alias; 19 - (BOOL)_validate Preview;21 - (BOOL)_validateWithPreview:(BOOL)doPreview; 20 22 @end 21 23 … … 25 27 // XXX don't add icons on Puma, they look like ass 26 28 // XXX launch preview on a separate thread (if movies take too long to load, they inhibit the interface responsiveness) 29 // XXX when dropping invalid JPEG file on button, it dies 27 30 28 31 // Recent media layout: 29 32 // Most recent media are at TOP of menu (smaller item numbers, starting at [self indexOfItem: otherItem] + 1) 30 33 // Most recent media are at END of array (larger indices) 34 35 #pragma mark recently selected media tracking 31 36 32 37 - (NSString *)_defaultKey; … … 95 100 } 96 101 102 #pragma mark initialize-release 103 97 104 - (void)awakeFromNib; 98 105 { … … 127 134 otherItem = [item retain]; 128 135 136 [self _validateWithPreview: NO]; 137 129 138 recentMediaAliasData = [[NSMutableArray alloc] initWithCapacity: NJRQTMediaPopUpButtonMaxRecentItems + 1]; 130 139 [self _addRecentMediaFromAliasesData: [[NSUserDefaults standardUserDefaults] arrayForKey: [self _defaultKey]]]; 131 [self _validateRecentMedia];140 // [self _validateRecentMedia]; 132 141 133 142 [self registerForDraggedTypes: … … 142 151 [super dealloc]; 143 152 } 153 154 #pragma mark accessing 144 155 145 156 - (BDAlias *)selectedAlias; … … 172 183 } 173 184 174 [self _validateRecentMedia];185 // [self _validateRecentMedia]; 175 186 path = [alias fullPath]; 176 187 sf = [[SoundFileManager sharedSoundFileManager] soundFileFromPath: path]; 177 NSLog(@"_itemForAlias: %@", path);188 // NSLog(@"_itemForAlias: %@", path); 178 189 179 190 // selected a system sound? 180 191 if (sf != nil) { 181 NSLog(@"_itemForAlias: selected system sound");192 // NSLog(@"_itemForAlias: selected system sound"); 182 193 return [self itemAtIndex: [self indexOfItemWithRepresentedObject: sf]]; 183 194 } else { … … 194 205 if (menuIndex == otherIndex + 1) return [self itemAtIndex: menuIndex]; // already at top 195 206 // remove item, add (at top) later 196 NSLog(@"_itemForAlias removing item: idx %d + otherItemIdx %d + 1 = %d [%@]", recentIndex, otherIndex, menuIndex, [self itemAtIndex: menuIndex]);207 // NSLog(@"_itemForAlias removing item: idx %d + otherItemIdx %d + 1 = %d [%@]", recentIndex, otherIndex, menuIndex, [self itemAtIndex: menuIndex]); 197 208 [self removeItemAtIndex: menuIndex]; 198 209 [recentMediaAliasData removeObjectAtIndex: [recentMediaAliasData count] - recentIndex]; … … 209 220 } 210 221 222 - (BOOL)canRepeat; 223 { 224 return movieCanRepeat; 225 } 226 227 #pragma mark selected media validation 228 211 229 - (void)_invalidateSelection; 212 230 { 213 231 [self _setAlias: previousAlias]; 214 232 [self selectItem: [self _itemForAlias: [self selectedAlias]]]; 215 } 216 217 - (BOOL)_validatePreview; 233 [[NSNotificationCenter defaultCenter] postNotificationName: NJRQTMediaPopUpButtonMovieChangedNotification object: self]; 234 } 235 236 - (BOOL)_validateWithPreview:(BOOL)doPreview; 218 237 { 219 238 [preview stop: self]; 220 239 if (selectedAlias == nil) { 221 240 [preview setMovie: nil]; 222 NSBeep(); 241 movieCanRepeat = YES; 242 if (doPreview) NSBeep(); 223 243 } else { 224 244 NSMovie *movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: [selectedAlias fullPath]] byReference: YES]; 245 movieCanRepeat = ![movie isStatic]; 225 246 if ([movie hasAudio]) 226 247 [preview setMovie: movie]; … … 242 263 [preview start: self]; 243 264 } 265 [[NSNotificationCenter defaultCenter] postNotificationName: NJRQTMediaPopUpButtonMovieChangedNotification object: self]; 244 266 return YES; 245 267 } 246 268 269 #pragma mark actions 270 247 271 - (IBAction)stopSoundPreview:(id)sender; 248 272 { … … 253 277 { 254 278 [self _setAlias: nil]; 255 [self _validate Preview];279 [self _validateWithPreview: YES]; 256 280 } 257 281 … … 259 283 { 260 284 [self _setPath: [(SoundFile *)[sender representedObject] path]]; 261 if (![self _validate Preview]) {285 if (![self _validateWithPreview: YES]) { 262 286 [[self menu] removeItem: sender]; 263 287 } … … 269 293 int index = [self indexOfItem: sender], otherIndex = [self indexOfItem: otherItem]; 270 294 [self _setAlias: alias]; 271 if (![self _validate Preview]) {295 if (![self _validateWithPreview: YES]) { 272 296 [[self menu] removeItem: sender]; 273 297 } else if (index > otherIndex + 1) { // move "other" item to top of list … … 281 305 [item release]; 282 306 NSAssert(recentIndex >= 0, @"Recent media index invalid"); 283 NSLog(@"_aliasSelected removing item %d - %d + %d = %d of recentMediaAliasData", [recentMediaAliasData count], index, otherIndex, recentIndex);307 // NSLog(@"_aliasSelected removing item %d - %d + %d = %d of recentMediaAliasData", [recentMediaAliasData count], index, otherIndex, recentIndex); 284 308 [recentMediaAliasData removeObjectAtIndex: recentIndex]; 285 309 [recentMediaAliasData addObject: data]; … … 313 337 NSAssert1([files count] == 1, @"%d items returned, only one expected", [files count]); 314 338 [self _setPath: [files objectAtIndex: 0]]; 315 if ([self _validate Preview]) {339 if ([self _validateWithPreview: YES]) { 316 340 [self selectItem: [self _itemForAlias: selectedAlias]]; 317 341 } … … 322 346 } 323 347 // [self _validateRecentMedia]; 348 } 349 350 #pragma mark drag feedback 351 352 - (void)drawRect:(NSRect)rect; 353 { 354 if (dragAccepted) { 355 NSWindow *window = [self window]; 356 NSRect boundsRect = [self bounds]; 357 BOOL isFirstResponder = ([window firstResponder] == self); 358 // focus ring and drag feedback interfere with one another 359 if (isFirstResponder) [window makeFirstResponder: window]; 360 [super drawRect: rect]; 361 [[NSColor selectedControlColor] set]; 362 NSFrameRectWithWidthUsingOperation(NSInsetRect(boundsRect, 2, 2), 3, NSCompositeSourceIn); 363 if (isFirstResponder) [window makeFirstResponder: self]; 364 } else { 365 [super drawRect: rect]; 366 } 324 367 } 325 368 … … 410 453 if (url == nil) return NO; 411 454 [self _setPath: [url path]]; 412 if ([self _validate Preview]) {455 if ([self _validateWithPreview: YES]) { 413 456 [self selectItem: [self _itemForAlias: selectedAlias]]; 414 457 }
Note:
See TracChangeset
for help on using the changeset viewer.