Paste number 61795: example Objective-J

Paste number 61795: example Objective-J
Pasted by: frogor
5 months, 3 weeks ago
#macosx | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
import <AppKit/CPPanel.j>
import "AuthorizedConnection.j"

var SharedSavePanel = nil;

@implementation SavePanel : CPPanel
{
    CPProgressIndicator _progressIndicator;
    CPURLConnection     _connection;
}


+ (id)sharedSavePanel
{
    if (!SharedSavePanel)
        SharedSavePanel = [[SavePanel alloc] init];
    
    return SharedSavePanel;
}


- (id)init
{
    self = [super initWithContentRect:CGRectMake(0.0, 0.0, 300.0, 200.0) styleMask:CPHUDBackgroundWindowMask | CPTitledWindowMask];
    
    if (self)
    {
        [self setTitle:@"Saving..."];
        [self setLevel:CPModalPanelWindowLevel];
        
        var contentView = [self contentView],
            bounds = [contentView bounds];
        
        _progressIndicator = [[CPProgressIndicator alloc] initWithFrame:CGRectMakeZero()];
        
        [_progressIndicator setStyle:CPProgressIndicatorSpinningStyle];
        [_progressIndicator setControlSize:CPRegularControlSize];
        [_progressIndicator sizeToFit];
        
        [_progressIndicator setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
        
        var size = [_progressIndicator frame].size;
        
        [_progressIndicator setFrameOrigin:CGPointMake((CGRectGetWidth(bounds) - size.width) / 2.0, (CGRectGetHeight(bounds) - size.height) / 2.0)];
        
        [contentView addSubview:_progressIndicator];
    
}

    
    return self;
}


- (void)saveData:(CPData)aData toURL:(CPString)aURL withName:(CPString)aName slideCount:(unsigned)slideCount
{
    [CPApp runModalForWindow:self];
    
    var request = [CPURLRequest requestWithURL:BASE_URL + @"save.php"],
        parameters = "documentName=" + encodeURIComponent(aName) + "&numSlides=" + slideCount + "\n" + aData.string;
    
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:parameters];
    
    [request setValue:@"close" forHTTPHeaderField:@"Connection"];

    _connection = [AuthorizedConnection connectionWithRequest:request delegate:self];
}


- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
{
}


- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError
{
    [self connectionDidFinishLoading:aConnection];
}


- (void)connectionDidFinishLoading:(CPURLConnection)aConnection
{
    if (aConnection == _connection)
        _connection = nil;
        
    [CPApp stopModal];
    [self close];
}


@end

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.