Giter VIP home page Giter VIP logo

ccnstatusitem's Introduction

Flattr this git repo Travis Status

Overview

CCNStatusItem is a subclass of NSObject to act as a custom NSStatusItem. Running on Yosemite it has full support for the class NSStatusBarButton which is provided by NSStatusItem via the button property.

Features:

  • Yosemite's dark menu mode will be automatically handled
  • Proximity drag detection
  • Support for Drag&Drop
  • Custom Views as StatusItems
  • Support for switching the StatusItem on/off (in case you're using both the StatusItem and a Dock Icon)

It supports a customizable statusItemWindow that will manage any NSViewController instance for presenting the content.

This screenshot presents the current example application:

CCNStatusItem Example Application

Integration

You can add CCNStatusItem by using CocoaPods. Just add this line to your Podfile:

pod 'CCNStatusItem'

Usage

After it's integrated into your project you are just a few lines of code away from your (maybe) first NSStatusItem with a custom view and a beautiful looking popover window. A good place to add these lines of code is your AppDelegate:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
   ...
    [[CCNStatusItem sharedInstance] presentStatusItemWithImage:[NSImage imageNamed:@"statusbar-icon"]
                                         contentViewController:[ContentViewController viewController]];
   ...
}

That's all! You will have some options to change the design of this statusItem popover window using CCNStatusItemWindowConfiguration. In the example above internally CCNStatusItem uses [CCNStatusItemWindowConfiguration defaultConfiguration] to set a default design and behavior of the status bar popover window. The next example will show you how to change this design and behaviour:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    ...
    
    // configure the status item
    CCNStatusItem *sharedItem = [CCNStatusItem sharedInstance];
    sharedItem.windowConfiguration.presentationTransition = CCNPresentationTransitionSlideAndFade;
    sharedItem.proximityDragDetectionHandler = ^(CCNStatusItem *item, NSPoint eventLocation, CCNStatusItemProximityDragStatus dragStatus) {
        switch (dragStatus) {
            case CCNProximityDragStatusEntered:
                [item showStatusItemWindow];
                break;

            case CCNProximityDragStatusExited:
                [item dismissStatusItemWindow];
                break;
        }
    };
    [sharedItem presentStatusItemWithImage:[NSImage imageNamed:@"statusbar-icon"]
                     contentViewController:[ContentViewController viewController]];
    ...
}

Some Side Notes

The statusItem popover's frame size will be determined automatically by calling preferedContentSize on the contentViewController. So you shouldn't forget to set it to a reasonable value. Using XIB's for building the content a good way to do so is returning:

- (CGSize)preferredContentSize {
    return self.view.frame.size;
}

Requirements

CCNStatusItem has been written using ARC and "modern" Objective-C 2. It supports OS X 10.10 Yosemite and above.

Contribution

The code is provided as-is, and it is far off being complete or free of bugs. If you like this component feel free to support it. Make changes related to your needs, extend it or just use it in your own project. Pull-Requests and Feedbacks are very welcome. Just contact me at [[email protected]](mailto:[email protected]?Subject=[CCNStatusItem] Your component on Github) or send me a ping on Twitter @TheCocoaNaut.

Documentation

The complete documentation you will find on CocoaDocs.

License

This software is published under the MIT License.

Software that uses CCNStatusItem

  • Review Times - A small Mac tool that shows you the calculated average of the review times for both the Mac App Store and the iOS App Store
  • SalesX - SalesX is the simplest way to reach your iTC sales reports

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.