/*
 * AppController.j
 * Tutorial-Drawing-part2
 *
 * Created by Philippe Laval on 2009/04/21.
 * Copyright 2009 Philippe Laval. All rights reserved.
 */

@import <Foundation/CPObject.j>


@import "PLGraphicView.j"
@import "PLDocument.j"
@import "PLToolPaletteController.j"

@implementation AppController : CPObject
{
}

- (id)init {
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
    var contentView = [theWindow contentView];
    var bounds = [contentView bounds];

    var button = [[CPButton alloc] initWithFrame:CGRectMake(10, 10, 200, 24)];
    [button setTitle:@"Create Document"];
    [button setAction:@selector(createDocument:)];
    [button setTarget:self];
    [button setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [contentView addSubview:button];

	// debugger;
    button = [[CPButton alloc] initWithFrame:CGRectMake(10, 40, 200, 24)];
    [button setTitle:@"Show Tools"];
    [button setAction:@selector(showToolsWindow:)];
    [button setTarget:self];
    [button setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [contentView addSubview:button];

    button = [[CPButton alloc] initWithFrame:CGRectMake(10, 70, 200, 24)];
    [button setTitle:@"Hide Tools"];
    [button setAction:@selector(hideToolsWindow:)];
    [button setTarget:self];
    [button setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [contentView addSubview:button];

	[theWindow makeKeyAndOrderFront:self];
    
    // Uncomment the following line to turn on the standard menu bar.
    //[CPMenu setMenuBarVisible:YES];
}


-(IBAction)showToolsWindow:(id)sender
{
    var sharedToolPaletteController = [PLToolPaletteController sharedToolPaletteController];
    [sharedToolPaletteController showWindow:sender];
}

-(IBAction)hideToolsWindow:(id)sender
{
    var sharedToolPaletteController = [PLToolPaletteController sharedToolPaletteController];
    [[sharedToolPaletteController window] orderOut:sender];
}

-(IBAction)createDocument:(id)sender
{
	var sharedDocumentController = [CPDocumentController sharedDocumentController];
	
	var documents = [sharedDocumentController documents];
	var defaultType = [sharedDocumentController defaultType];
	
	[sharedDocumentController newDocument:self];
	// [sharedDocumentController openUntitledDocumentOfType:@"MyBundle" display:YES];
}

@end
