Skip to content

Instantly share code, notes, and snippets.

@cappuccino
Created March 16, 2009 01:21
Show Gist options
  • Save cappuccino/79627 to your computer and use it in GitHub Desktop.
Save cappuccino/79627 to your computer and use it in GitHub Desktop.
/*
* AppController.j
*
* Created by __Me__ on __Date__.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*/
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPToolbar toolbar;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
toolbar = [[CPToolbar alloc] initWithIdentifier:"HierarchicalTicketsViewToolbar"];
[toolbar setDelegate:self];
[theWindow setToolbar:toolbar];
[label setStringValue:@"Hello World!"];
[label setFont:[CPFont boldSystemFontOfSize:24.0]];
[label sizeToFit];
[label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[label setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([label frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([label frame])) / 2.0)];
[contentView addSubview:label];
[theWindow orderFront:self];
//Uncomment the following line to turn on the standard menu bar.
[CPMenu setMenuBarVisible:YES];
[CPMenu setMenuBarTitle:@"Title"];
[CPMenu setMenuBarAttributes:
[CPDictionary dictionaryWithObjects:
[ [CPColor whiteColor], [CPColor blueColor], [CPColor greenColor] ]
forKeys:
[@"CPMenuBarBackgroundColor", @"CPMenuBarTextColor", @"CPMenuBarTitleColor"]
]
];
}
// CPToolbar delegates ---------------------------------
- (CPArray) toolbarAllowedItemIdentifiers:(CPToolbar)toolbar
{
CPLog.info("toolbarAllowedItemIdentifiers");
return [CPArray arrayWithObjects:"MyButton"];
}
- (CPArray) toolbarDefaultItemIdentifiers:(CPToolbar)toolbar
{
CPLog.info("toolbarDefaultItemIdentifiers");
return [CPArray arrayWithObjects:"MyButton"];
}
- (CPToolbarItem) toolbar:(CPToolbar)toolbar itemForItemIdentifier:(CPString)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
CPLog.info("Called toolbar");
if (["MyButton" isEqual:itemIdentifier])
{
var item = [[CPToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
[item setLabel:@"My Button"];
[item setMinSize:CPMakeSize(50, 32)];
[item setMaxSize:CPMakeSize(170, 32)];
//[item setToolTip:@"tooltip for my button."]; // TODO: doesn't seem to work
var button = [[CPPopUpButton alloc] initWithFrame:CPMakeRect(0, 0, 170, 20)];
//var button = [[CPButton alloc] initWithFrame:CPMakeRect(0, 0, 170, 20)];
[button setBezelStyle:CPTexturedRoundedBezelStyle];
[button setTitle:@"Something..."];
[item setView:button];
CPLog.info("Finished toolbar returning item");
return item;
}
CPLog.info("Finished toolbar returning nil");
return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment