Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created February 17, 2009 00:46
Show Gist options
  • Save nickjs/65500 to your computer and use it in GitHub Desktop.
Save nickjs/65500 to your computer and use it in GitHub Desktop.
@import "NodePanel.j"
@implementation AppController : CPObject
{
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var node = {
'name': @"Click Me"
}
[[NodePanel sharedPanel] beginWithNode:node modalDelegate:self didEndSelector:@selector(nodePanel:didEndWithReturnCode:)];
}
- (void)nodePanel:(NodePanel)aPanel didEndWithReturnCode:(id)returnCode
{
}
@end
@import <AppKit/CPPanel.j>
var SharedPanel = nil;
@implementation NodePanel : CPPanel
{
PKObject _node;
id _modalDelegate;
SEL _didEndSelector;
InfoTextField _name;
}
+ (id)sharedPanel
{
if(!SharedPanel)
SharedPanel = [[NodePanel alloc] init];
return SharedPanel;
}
- (id)init
{
self = [super initWithContentRect:CGRectMake(0.0, 0.0, 500.0, 300.0) styleMask:CPHUDBackgroundWindowMask | CPTitledWindowMask];
if(self)
{
[self setLevel:CPModalPanelWindowLevel];
// [self setMovableByWindowBackground:NO]; // Uncommenting this will cause the view events to work.
var contentView = [self contentView],
bounds = [contentView bounds];
_name = [[InfoTextField alloc] initWithFrame:CGRectMake(230.0, 15.0, CGRectGetWidth(bounds) - 240.0, 40.0)];
[_name setAlignment:CPCenterTextAlignment];
[_name setFont:[CPFont boldSystemFontOfSize:26.0]];
[_name setTarget:self];
[_name setAction:@selector(openEnd:)]; // should get called but won't
[contentView addSubview:_name];
var button = [[CPButton alloc] initWithFrame:CGRectMake(300.0, 100.0, 100.0, 20.0)];
[button setTitle:@"Something"];
[button setTarget:self];
[button setAction:@selector(itWorksIfYouGetAnError:)]
[contentView addSubview:button];
}
return self;
}
- (void)beginWithNode:(CPObject)anObject modalDelegate:(id)aDelegate didEndSelector:(SEL)aSelector
{
_node = anObject;
_modalDelegate = aDelegate;
_didEndSelector = aSelector;
// [self setTitle:Strings.connectWith + @" " + [_node name]];
[self setTitle:_node.name] // For testcase only
// var flag = [_node canView];
var flag = YES; // For testcase only
// [_name setStringValue:[_node name]];
[_name setStringValue:_node.name]; //Testcase only
[_name setEnabled:flag];
[CPApp runModalForWindow:self];
[self orderFront:self];
}
- (void)ok:(id)sender
{
[CPApp stopModal];
[self performClose:sender];
objj_msgSend(_modalDelegate, _didEndSelector, self, CPOKButton);
}
- (void)cancel:(id)sender
{
[CPApp stopModal];
[self performClose:sender];
objj_msgSend(_modalDelegate, _didEndSelector, self, CPCancelButton);
}
- (void)openNode:(id)sender
{
[self cancel:sender];
console.log('this should be called by clicking on the title view');
// [PageController prepareWindow];
// if([_node class] == Document)
// [[CPApp delegate] openDocumentWithContentsOfURL:BASE_URL + @"documents/" + [_node identifier] display:YES error:nil];
}
@end
var TextShadow = [CPShadow shadowWithOffset:CGSizeMake(0.0, 0.0) blurRadius:5.0 color:[CPColor colorWithHexString:@"333333"]];
@implementation InfoTextField : CPTextField
{
BOOL _enabled;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self)
{
[self setEnabled:YES];
[self setTextShadow:TextShadow];
}
return self;
}
- (void)setEnabled:(BOOL)aFlag
{
_enabled = aFlag;
[self redraw];
}
- (void)redraw
{
if(_enabled)
[self setTextColor:[CPColor whiteColor]];
else
[self setTextColor:[CPColor lightGrayColor]];
if(_enabled && _target && _action)
{
_DOMTextElement.className = @"hoverable";
_DOMTextElement.style.cursor = @"pointer";
}
else
{
_DOMTextElement.className = @"";
_DOMTextElement.style.cursor = @"default";
}
}
- (void)mouseUp:(CPEvent)anEvent
{
if(_enabled && _target && _action)
objj_msgSend([self target], [self action], self);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment