Ignore:
Timestamp:
11/05/02 23:54:02 (21 years ago)
Author:
Nicholas Riley
Message:

Popup triangle.tiff: Needed display component of NJRFSObjectSelector.
This one appears to use transparency unlike the one I prepared for
Process Exhibits, so it should be preferred.

NSMovie-NJRExtensions: Added -isStatic to identify whether the movie
contains dynamic components. If the movie is static, it most likely
contains only an image and shouldn't be 'played' as such, otherwise
the duration will be so short that the image won't be useful.

NJRFSObjectSelector: Fixed -drawRect: to draw the drag feedback
rectangle inside the bounds of the control, not inside whatever dirty
rectangle is passed to the method (often they are the same, but not
always). Only draw the popup arrow if the control is enabled.
Properly draw the popup arrow with transparency. Display the 'make
alias' cursor as additional drag feedback.

PSMovieAlertController: Only repeat movie and auto-close after movie
finished if it contains time-based media, otherwise just display the
movie (an image) until the window is closed or alarms are cancelled.

NSImage-NJRExtensions: Include code to actually scale icons from
F-Script Anywhere, otherwise the menu ends up with 32x32 (or
potentially larger) icons if smaller variations are not provided.
There's some more code in FSA that chooses which representation to
select; this code may still not be properly handling representations,
but it works better now. A good test case is the icon for Tex-Edit
Plus documents.

NJRQTMediaPopUpButton: Added notification for movie change (needed to
update interface). Changed -_validatePreview to
-_validateWithPreview: - preview is now optional. This will be needed
when I add archiving support for the selected item; we'll need to
validate it before updating the interface, but we don't want sounds to
play. Added some #pragma mark lines to separate methods by
functionality. Call -validateWithPreview: NO in awakeFromNib (again,
this logic will become more sophisticated later). Commented some
debugging logic since I'm pretty happy with the code. Added
-canRepeat accessor and setters, notification support in the
validation method. Added drag feedback.

PSAlarmSetController: Notification support, -setSoundRepetitionCount:
to avoid flashing with repetition text field control as NSStepper is
adjusted

English.lproj/MainMenu.nib: Switched action method for the NSStepper
stuff discussed above.

AM /Users/nicholas/Documents/Development/Cocoa/Pester/Source/Popup triangle.tiff
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/NSMovie-NJRExtensions.m
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/NJRFSObjectSelector.m
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/PSMovieAlertController.m
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/NSImage-NJRExtensions.m
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/NJRQTMediaPopUpButton.h
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/.DS_Store
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/English.lproj/MainMenu.nib/objects.nib
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/English.lproj/MainMenu.nib/info.nib
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/English.lproj/MainMenu.nib/classes.nib
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/Pester.pbproj/nicholas.pbxuser
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/Pester.pbproj/project.pbxproj
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/PSAlarmSetController.h
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/PSAlarmSetController.m
M /Users/nicholas/Documents/Development/Cocoa/Pester/Source/NSMovie-NJRExtensions.h

File:
1 edited

Legend:

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

    r40 r41  
    1414static const int NJRQTMediaPopUpButtonMaxRecentItems = 10;
    1515
     16NSString * const NJRQTMediaPopUpButtonMovieChangedNotification = @"NJRQTMediaPopUpButtonMovieChangedNotification";
     17
    1618@interface NJRQTMediaPopUpButton (Private)
    1719- (void)_setPath:(NSString *)path;
    1820- (NSMenuItem *)_itemForAlias:(BDAlias *)alias;
    19 - (BOOL)_validatePreview;
     21- (BOOL)_validateWithPreview:(BOOL)doPreview;
    2022@end
    2123
     
    2527// XXX don't add icons on Puma, they look like ass
    2628// 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
    2730
    2831// Recent media layout:
    2932// Most recent media are at TOP of menu (smaller item numbers, starting at [self indexOfItem: otherItem] + 1)
    3033// Most recent media are at END of array (larger indices)
     34
     35#pragma mark recently selected media tracking
    3136
    3237- (NSString *)_defaultKey;
     
    95100}
    96101
     102#pragma mark initialize-release
     103
    97104- (void)awakeFromNib;
    98105{
     
    127134    otherItem = [item retain];
    128135
     136    [self _validateWithPreview: NO];
     137
    129138    recentMediaAliasData = [[NSMutableArray alloc] initWithCapacity: NJRQTMediaPopUpButtonMaxRecentItems + 1];
    130139    [self _addRecentMediaFromAliasesData: [[NSUserDefaults standardUserDefaults] arrayForKey: [self _defaultKey]]];
    131     [self _validateRecentMedia];
     140    // [self _validateRecentMedia];
    132141
    133142    [self registerForDraggedTypes:
     
    142151    [super dealloc];
    143152}
     153
     154#pragma mark accessing
    144155
    145156- (BDAlias *)selectedAlias;
     
    172183    }
    173184
    174     [self _validateRecentMedia];
     185    // [self _validateRecentMedia];
    175186    path = [alias fullPath];
    176187    sf = [[SoundFileManager sharedSoundFileManager] soundFileFromPath: path];
    177     NSLog(@"_itemForAlias: %@", path);
     188    // NSLog(@"_itemForAlias: %@", path);
    178189
    179190    // selected a system sound?
    180191    if (sf != nil) {
    181         NSLog(@"_itemForAlias: selected system sound");
     192        // NSLog(@"_itemForAlias: selected system sound");
    182193        return [self itemAtIndex: [self indexOfItemWithRepresentedObject: sf]];
    183194    } else {
     
    194205                if (menuIndex == otherIndex + 1) return [self itemAtIndex: menuIndex]; // already at top
    195206                // 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]);
    197208                [self removeItemAtIndex: menuIndex];
    198209                [recentMediaAliasData removeObjectAtIndex: [recentMediaAliasData count] - recentIndex];
     
    209220}
    210221
     222- (BOOL)canRepeat;
     223{
     224    return movieCanRepeat;
     225}
     226
     227#pragma mark selected media validation
     228
    211229- (void)_invalidateSelection;
    212230{
    213231    [self _setAlias: previousAlias];
    214232    [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;
    218237{
    219238    [preview stop: self];
    220239    if (selectedAlias == nil) {
    221240        [preview setMovie: nil];
    222         NSBeep();
     241        movieCanRepeat = YES;
     242        if (doPreview) NSBeep();
    223243    } else {
    224244        NSMovie *movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: [selectedAlias fullPath]] byReference: YES];
     245        movieCanRepeat = ![movie isStatic];
    225246        if ([movie hasAudio])
    226247            [preview setMovie: movie];
     
    242263        [preview start: self];
    243264    }
     265    [[NSNotificationCenter defaultCenter] postNotificationName: NJRQTMediaPopUpButtonMovieChangedNotification object: self];
    244266    return YES;
    245267}
    246268
     269#pragma mark actions
     270
    247271- (IBAction)stopSoundPreview:(id)sender;
    248272{
     
    253277{
    254278    [self _setAlias: nil];
    255     [self _validatePreview];
     279    [self _validateWithPreview: YES];
    256280}
    257281
     
    259283{
    260284    [self _setPath: [(SoundFile *)[sender representedObject] path]];
    261     if (![self _validatePreview]) {
     285    if (![self _validateWithPreview: YES]) {
    262286        [[self menu] removeItem: sender];
    263287    }
     
    269293    int index = [self indexOfItem: sender], otherIndex = [self indexOfItem: otherItem];
    270294    [self _setAlias: alias];
    271     if (![self _validatePreview]) {
     295    if (![self _validateWithPreview: YES]) {
    272296        [[self menu] removeItem: sender];
    273297    } else if (index > otherIndex + 1) { // move "other" item to top of list
     
    281305        [item release];
    282306        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);
    284308        [recentMediaAliasData removeObjectAtIndex: recentIndex];
    285309        [recentMediaAliasData addObject: data];
     
    313337        NSAssert1([files count] == 1, @"%d items returned, only one expected", [files count]);
    314338        [self _setPath: [files objectAtIndex: 0]];
    315         if ([self _validatePreview]) {
     339        if ([self _validateWithPreview: YES]) {
    316340            [self selectItem: [self _itemForAlias: selectedAlias]];
    317341        }
     
    322346    }
    323347    // [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    }
    324367}
    325368
     
    410453        if (url == nil) return NO;
    411454        [self _setPath: [url path]];
    412         if ([self _validatePreview]) {
     455        if ([self _validateWithPreview: YES]) {
    413456            [self selectItem: [self _itemForAlias: selectedAlias]];
    414457        }
Note: See TracChangeset for help on using the changeset viewer.