Skip to content

Instantly share code, notes, and snippets.

@boucher
Created October 22, 2008 03:10
Show Gist options
  • Select an option

  • Save boucher/18527 to your computer and use it in GitHub Desktop.

Select an option

Save boucher/18527 to your computer and use it in GitHub Desktop.
import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[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];
toolbar = [[CPToolbar alloc] initWithIdentifier:@"EditingToolbar"];
[toolbar setDelegate:self];
[theWindow setToolbar:toolbar];
[theWindow orderFront:self];
// Uncomment the following line to turn on the standard menu bar.
//[CPMenu setMenuBarVisible:YES];
}
- (void)setQuery:(id)sender
{
alert("setQuery: stringValue: "+[sender stringValue]);
}
- (void)showQueryPanel:(id)sender
{
//Setup the panel
[self createQueryPanel];
//Bring the panel forward
[queryPanel center];
[queryPanel orderFront:self];
}
- (void)createQueryPanel
{
if ( queryPanel )
return;
//Create the query panel
queryPanel = [[CPPanel alloc] initWithContentRect:CGRectMake(0, 0, 300, 50) styleMask:CPHUDBackgroundWindowMask];
[queryPanel setFloatingPanel:YES];
//Add components to the content view
var contentView = [queryPanel contentView];
//Add the input field
var queryField = [[CPTextField alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
[queryField setEditable:true];
[queryField setBordered:true];
[queryField setBezeled:true];
[queryField setBezelStyle:CPTextFieldSquareBezel];
[queryField setTarget:self];
[queryField setAction:@selector(setQuery:)];
[contentView addSubview:queryField];
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
{
return ["FOO"];
}
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
{
return ["FOO"];
}
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar itemForItemIdentifier:(CPString)anItemIdentifier willBeInsertedIntoToolbar:(BOOL)aFlag
{
var toolbarItem = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
[toolbarItem setMinSize:CGSizeMake(240, 24)];
[toolbarItem setMaxSize:CGSizeMake(240, 24)];
inputField = [[CPTextField alloc] initWithFrame:CGRectMake(20, 0, 240, 24)];
[inputField setEditable:true];
[inputField setBordered:true];
[inputField setBezeled:true];
[inputField setBezelStyle:CPTextFieldSquareBezel];
[inputField setTarget:self];
[inputField setAction:@selector(setQuery:)];
[toolbarItem setView:inputField];
[toolbarItem setLabel:"Input brands or tags"];
return toolbarItem;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment