Ignore:
Timestamp:
11/05/02 03:24:08 (20 years ago)
Author:
Nicholas Riley
Message:

PSDockBounceAlert: Make it work, assuming the app doesn't get brought
forward immediately upon the alarm activation.

NJRQTMediaPopUpButton: Fixed drag and drop. Added _descriptionForDraggingInfo:
to

PSMovieAlertController: Fixed movie vertical size, looks like a bug
got enshrined in the documentation.

PSAlarmAlertController: Don't force app to front until alerts are ready.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m

    r39 r40  
    1616@interface NJRQTMediaPopUpButton (Private)
    1717- (void)_setPath:(NSString *)path;
     18- (NSMenuItem *)_itemForAlias:(BDAlias *)alias;
    1819- (BOOL)_validatePreview;
    1920@end
     
    2425// XXX don't add icons on Puma, they look like ass
    2526// XXX launch preview on a separate thread (if movies take too long to load, they inhibit the interface responsiveness)
     27
     28// Recent media layout:
     29// Most recent media are at TOP of menu (smaller item numbers, starting at [self indexOfItem: otherItem] + 1)
     30// Most recent media are at END of array (larger indices)
    2631
    2732- (NSString *)_defaultKey;
     
    6974- (void)_validateRecentMedia;
    7075{
    71     NSEnumerator *e = [recentMediaAliasData objectEnumerator];
     76    NSEnumerator *e = [recentMediaAliasData reverseObjectEnumerator];
    7277    NSData *aliasData;
    7378    NSMenuItem *item;
     
    7984    int recentItemIndex = otherIndex;
    8085    NSAssert2(recentItemCount == aliasDataCount, @"Counted %d recent menu items, %d of alias data", recentItemCount, aliasDataCount);
    81     while ( (aliasData = [e nextObject]) != nil) {
     86    while ( (aliasData = [e nextObject]) != nil) { // go BACKWARD through array while going DOWN menu
    8287        recentItemIndex++;
    8388        item = [self itemAtIndex: recentItemIndex];
    8489        itemAlias = [item representedObject];
    85         if (![itemAlias aliasDataIsEqual: aliasData])
     90        if ([itemAlias aliasDataIsEqual: aliasData])
    8691            NSLog(@"item %d %@: %@", recentItemIndex, [item title], [itemAlias fullPath]);
    8792        else
     
    124129    recentMediaAliasData = [[NSMutableArray alloc] initWithCapacity: NJRQTMediaPopUpButtonMaxRecentItems + 1];
    125130    [self _addRecentMediaFromAliasesData: [[NSUserDefaults standardUserDefaults] arrayForKey: [self _defaultKey]]];
     131    [self _validateRecentMedia];
    126132
    127133    [self registerForDraggedTypes:
     
    144150- (void)_setAlias:(BDAlias *)alias;
    145151{
    146    
    147152    BDAlias *oldAlias = [selectedAlias retain];
    148153    [previousAlias release];
     
    167172    }
    168173
    169     // [self _validateRecentMedia];
     174    [self _validateRecentMedia];
    170175    path = [alias fullPath];
    171176    sf = [[SoundFileManager sharedSoundFileManager] soundFileFromPath: path];
     
    177182        return [self itemAtIndex: [self indexOfItemWithRepresentedObject: sf]];
    178183    } else {
    179         NSEnumerator *e = [recentMediaAliasData objectEnumerator];
     184        NSEnumerator *e = [recentMediaAliasData reverseObjectEnumerator];
    180185        NSData *aliasData;
    181186        NSMenuItem *item;
    182         int recentIndex = 0;
     187        int recentIndex = 1;
    183188
    184189        while ( (aliasData = [e nextObject]) != nil) {
     
    186191            if ([alias aliasDataIsEqual: aliasData]) {
    187192                int otherIndex = [self indexOfItem: otherItem];
    188                 int menuIndex = [recentMediaAliasData count] - recentIndex + otherIndex + 1;
     193                int menuIndex = recentIndex + otherIndex;
    189194                if (menuIndex == otherIndex + 1) return [self itemAtIndex: menuIndex]; // already at top
    190195                // remove item, add (at top) later
    191                 NSLog(@"_itemForAlias removing item: count %d - idx %d + otherItemIndex %d + 1 = %d [%@]", [recentMediaAliasData count], recentIndex, otherIndex, menuIndex, [self itemAtIndex: menuIndex]);
     196                NSLog(@"_itemForAlias removing item: idx %d + otherItemIdx %d + 1 = %d [%@]", recentIndex, otherIndex, menuIndex, [self itemAtIndex: menuIndex]);
    192197                [self removeItemAtIndex: menuIndex];
    193                 [recentMediaAliasData removeObjectAtIndex: recentIndex];
     198                [recentMediaAliasData removeObjectAtIndex: [recentMediaAliasData count] - recentIndex];
    194199                break;
    195200            }
     
    267272        [[self menu] removeItem: sender];
    268273    } else if (index > otherIndex + 1) { // move "other" item to top of list
    269         int recentIndex = [recentMediaAliasData count] - index + otherIndex + 1;
     274        int recentIndex = [recentMediaAliasData count] - index + otherIndex;
    270275        NSMenuItem *item = [[self itemAtIndex: index] retain];
    271276        NSData *data = [[recentMediaAliasData objectAtIndex: recentIndex] retain];
     277        [self _validateRecentMedia];
    272278        [self removeItemAtIndex: index];
    273279        [[self menu] insertItem: item atIndex: otherIndex + 1];
     
    275281        [item release];
    276282        NSAssert(recentIndex >= 0, @"Recent media index invalid");
    277         NSLog(@"_aliasSelected removing item %d - %d + %d + 1 = %d of recentMediaAliasData", [recentMediaAliasData count], index, otherIndex, recentIndex);
     283        NSLog(@"_aliasSelected removing item %d - %d + %d = %d of recentMediaAliasData", [recentMediaAliasData count], index, otherIndex, recentIndex);
    278284        [recentMediaAliasData removeObjectAtIndex: recentIndex];
    279285        [recentMediaAliasData addObject: data];
     286        [self _validateRecentMedia];
    280287        [data release];
    281     } else NSLog(@"_aliasSelected ...already at top");
     288    } // else NSLog(@"_aliasSelected ...already at top");
    282289}
    283290
     
    324331{
    325332    NSURL *url = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
     333    NSFileManager *fm = [NSFileManager defaultManager];
     334    BOOL isDir;
    326335
    327336    if (url == nil || ![url isFileURL]) return NO;
     337
     338    if (![fm fileExistsAtPath: [url path] isDirectory: &isDir]) return NO;
     339
     340    if (isDir) return NO;
     341   
    328342    return YES;
    329343}
    330344
     345- (NSString *)_descriptionForDraggingInfo:(id <NSDraggingInfo>)sender;
     346{
     347    NSDragOperation mask = [sender draggingSourceOperationMask];
     348    NSMutableString *s = [NSMutableString stringWithFormat: @"Drag seq %d source: %@",
     349        [sender draggingSequenceNumber], [sender draggingSource]];
     350    NSPasteboard *draggingPasteboard = [sender draggingPasteboard];
     351    NSArray *types = [draggingPasteboard types];
     352    NSEnumerator *e = [types objectEnumerator];
     353    NSString *type;
     354    [s appendString: @"\nDrag operations:"];
     355    if (mask & NSDragOperationCopy) [s appendString: @" copy"];
     356    if (mask & NSDragOperationLink) [s appendString: @" link"];
     357    if (mask & NSDragOperationGeneric) [s appendString: @" generic"];
     358    if (mask & NSDragOperationPrivate) [s appendString: @" private"];
     359    if (mask & NSDragOperationMove) [s appendString: @" move"];
     360    if (mask & NSDragOperationDelete) [s appendString: @" delete"];
     361    if (mask & NSDragOperationEvery) [s appendString: @" every"];
     362    if (mask & NSDragOperationNone) [s appendString: @" none"];
     363    [s appendFormat: @"\nImage: %@ at %@", [sender draggedImage],
     364        NSStringFromPoint([sender draggedImageLocation])];
     365    [s appendFormat: @"\nDestination: %@ at %@", [sender draggingDestinationWindow],
     366        NSStringFromPoint([sender draggingLocation])];
     367    [s appendFormat: @"\nPasteboard: %@ types:", draggingPasteboard];
     368    while ( (type = [e nextObject]) != nil) {
     369        if ([type hasPrefix: @"CorePasteboardFlavorType 0x"]) {
     370            const char *osTypeHex = [[type substringFromIndex: [type rangeOfString: @"0x" options: NSBackwardsSearch].location] lossyCString];
     371            OSType osType;
     372            sscanf(osTypeHex, "%lx", &osType);
     373            [s appendFormat: @" '%4s'", &osType];
     374        } else {
     375            [s appendFormat: @" \"%@\"", type];
     376        }
     377    }
     378    return s;
     379}
     380
    331381- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
    332382{
    333383    if ([self acceptsDragFrom: sender] && [sender draggingSourceOperationMask] &
    334         NSDragOperationCopy) {
     384        (NSDragOperationCopy | NSDragOperationLink)) {
    335385        dragAccepted = YES;
    336386        [self setNeedsDisplay: YES];
    337         return NSDragOperationGeneric;
     387        // NSLog(@"draggingEntered accept:\n%@", [self _descriptionForDraggingInfo: sender]);
     388        return NSDragOperationLink;
    338389    }
    339390    return NSDragOperationNone;
     
    359410        if (url == nil) return NO;
    360411        [self _setPath: [url path]];
    361         [self _validatePreview];
     412        if ([self _validatePreview]) {
     413            [self selectItem: [self _itemForAlias: selectedAlias]];
     414        }
    362415    }
    363416    return YES;
Note: See TracChangeset for help on using the changeset viewer.