No description or website provided.
Objective-C Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
PopoverStatusItem
.gitignore
LICENSE
PopoverStatusItem.gif
PopoverStatusItem.podspec
README.md

README.md

PopoverStatusItem

Version License Platform

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

PopoverStatusItem is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PopoverStatusItem"

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, contact@leoderbois.com

License

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