PopoverStatusItem 0.4.0

PopoverStatusItem 0.4.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2015

Maintained by Léo Derbois.


Downloads

Total20
Week0
Month0

Installs

Apps10
powered by Segment

GitHub

Stars1
Watchers2
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files2
LOCLines of Code 245


Demo

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

OS X 10.7 Minimum. ARC.

Installation

How to use

PopoverStatusItemDelegate protocol

PopoverStatusItemDelegate protocol provide to the object NSViewcontroller to display and menubar NSImage.

- (NSViewController *)popoverStatusItem:(PopoverStatusItem *)popOverStatusItem wantsViewControllerForAction:(PopoverStatusItemAction)action {

    /******************
     * return a IBoutlet of NSViewController in NIB
     * associate with a NSView in NIB Too
     ********************/

    NSViewController *controller = nil;
    switch (action) {
        case FirstPopoverAction:
            return self.firstController;
            break;

        case SecondPopoverAction:
            return self.secondController;
            break;

        case CommandPopoverAction:
            return self.cmdController;
            break;

        default:
            break;
    }
    return controller;
}
- (NSImage *)popoverStatusItemwantsImage:(PopoverStatusItem *)popOverStatusItem {
    DDLogInfo(@"NOT Use PopoverStatusItemDragDropDelegate protocol");

    static NSImage *normalImage  = nil;
    static NSImage *hilightImage = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        normalImage = [NSImage imageNamed:@"black"];
        hilightImage = [NSImage imageNamed:@"white"];
    });
    if (popOverStatusItem.isActive) {
        return hilightImage;
    }
    return normalImage;
}

PopoverStatusItemDragDropDelegate protocol

In addition to PopoverStatusItemDelegate you can support a Drag and Drop protocol for you menubar item. This protocol permit to update image in function of PopoverStatusItemDragDropStatus (accept, refuse...) and validate entries.

// replace the standard method.
- (NSImage *)popoverStatusItem:(PopoverStatusItem *)popOverStatusItem wantsImageForDragDropStatus:(PopoverStatusItemDragDropStatus)status {
    DDLogInfo(@"Use PopoverStatusItemDragDropDelegate protocol");
    static NSImage *blackImage  = nil;
    static NSImage *whiteImage  = nil;
    static NSImage *redImage    = nil;
    static NSImage *greenImage  = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        blackImage = [NSImage imageNamed:@"black"];
        whiteImage = [NSImage imageNamed:@"white"];
        redImage = [NSImage imageNamed:@"red"];
        greenImage = [NSImage imageNamed:@"green"];
    });
    NSImage *image = blackImage;

    if (status == DragDropInvalidType) {
        image = redImage;
    } else if (status == DragDropValidType) {
        image = greenImage;
    } else if (popOverStatusItem.isActive) {
        image = whiteImage;
    }

    return image;
}


- (BOOL)popoverStatusItem:(PopoverStatusItem *)popOverStatusItem isValidTypeOFfiles:(NSArray *)files {
    NSString *file = [files objectAtIndex:0];

    CFStringRef fileExtension = (__bridge CFStringRef)[file pathExtension];
    CFStringRef fileUTI       = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);

    if (UTTypeConformsTo(fileUTI, kUTTypeAudio)) {
        return YES;
    }
    return NO;
}


- (void)popoverStatusItem:(PopoverStatusItem *)popOverStatusItem provideFiles:(NSArray *)files {
        NSLog(@"validate files : %@", files);
}

Author

Léo Derbois, [email protected]

License

PopoverStatusItem is available under the MIT license. See the LICENSE file for more info.