Latest 0.4.0
Homepage https://github.com/leoderbois/PopoverStatusItem
License MIT
Platforms osx 10.8, requires ARC
Authors

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, [email protected]

License

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

Latest podspec

{
    "name": "PopoverStatusItem",
    "version": "0.4.0",
    "summary": "A class which permit to manage a NSPopover located on the NSMenubar and manage drag and drop operation if necessary.",
    "homepage": "https://github.com/leoderbois/PopoverStatusItem",
    "license": "MIT",
    "authors": {
        "Lu00e9o Derbois": "[email protected]"
    },
    "source": {
        "git": "https://github.com/leoderbois/PopoverStatusItem.git",
        "tag": "0.4.0"
    },
    "social_media_url": "https://twitter.com/leoderbois",
    "platforms": {
        "osx": "10.8"
    },
    "requires_arc": true,
    "source_files": "PopoverStatusItem"
}

Pin It on Pinterest

Share This