PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/AppKit/browser.platform/CPAlert.j

http://github.com/polymar/polish
Unknown | 133 lines | 133 code | 0 blank | 0 comment | 0 complexity | 42c9b21dc531eeb29bd0179c941c82a1 MD5 | raw file
  1I;21;Foundation/CPObject.jI;21;Foundation/CPString.jI;22;AppKit/CPApplication.jI;17;AppKit/CPButton.jI;16;AppKit/CPColor.jI;15;AppKit/CPFont.jI;16;AppKit/CPImage.jI;20;AppKit/CPImageView.jI;16;AppKit/CPPanel.jI;20;AppKit/CPTextField.jc;5572;
  2CPWarningAlertStyle=0;
  3CPInformationalAlertStyle=1;
  4CPCriticalAlertStyle=2;
  5var _1,_2,_3;
  6var _4=objj_allocateClassPair(CPObject,"CPAlert"),_5=_4.isa;
  7class_addIvars(_4,[new objj_ivar("_alertPanel"),new objj_ivar("_messageLabel"),new objj_ivar("_alertImageView"),new objj_ivar("_alertStyle"),new objj_ivar("_windowTitle"),new objj_ivar("_windowStyle"),new objj_ivar("_buttonCount"),new objj_ivar("_buttons"),new objj_ivar("_delegate")]);
  8objj_registerClassPair(_4);
  9objj_addClassForBundle(_4,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 10class_addMethods(_4,[new objj_method(sel_getUid("init"),function(_6,_7){
 11with(_6){
 12_6=objj_msgSendSuper({receiver:_6,super_class:objj_getClass("CPObject")},"init");
 13if(_6){
 14_buttonCount=0;
 15_buttons=objj_msgSend(CPArray,"array");
 16_alertStyle=CPWarningAlertStyle;
 17_messageLabel=objj_msgSend(objj_msgSend(CPTextField,"alloc"),"initWithFrame:",CGRectMake(57,10,220,80));
 18objj_msgSend(_messageLabel,"setFont:",objj_msgSend(CPFont,"systemFontOfSize:",12));
 19objj_msgSend(_messageLabel,"setLineBreakMode:",CPLineBreakByWordWrapping);
 20objj_msgSend(_messageLabel,"setAlignment:",CPJustifiedTextAlignment);
 21_alertImageView=objj_msgSend(objj_msgSend(CPImageView,"alloc"),"initWithFrame:",CGRectMake(15,12,32,32));
 22objj_msgSend(_6,"setWindowStyle:",nil);
 23}
 24return _6;
 25}
 26}),new objj_method(sel_getUid("setWindowStyle:"),function(_8,_9,_a){
 27with(_8){
 28_windowStyle=_a;
 29_alertPanel=objj_msgSend(objj_msgSend(CPPanel,"alloc"),"initWithContentRect:styleMask:",CGRectMake(0,0,300,130),_a?_a|CPTitledWindowMask:CPTitledWindowMask);
 30objj_msgSend(_alertPanel,"setFloatingPanel:",YES);
 31objj_msgSend(_alertPanel,"center");
 32objj_msgSend(_messageLabel,"setTextColor:",(_a==CPHUDBackgroundWindowMask)?objj_msgSend(CPColor,"whiteColor"):objj_msgSend(CPColor,"blackColor"));
 33var _b=objj_msgSend(_buttons,"count");
 34for(var i=0;i<_b;i++){
 35var _d=_buttons[i];
 36objj_msgSend(_d,"setFrameSize:",CGSizeMake(objj_msgSend(_d,"frame").size.width,(_a==CPHUDBackgroundWindowMask)?20:24));
 37objj_msgSend(_d,"setBezelStyle:",(_a==CPHUDBackgroundWindowMask)?CPHUDBezelStyle:CPRoundedBezelStyle);
 38objj_msgSend(objj_msgSend(_alertPanel,"contentView"),"addSubview:",_d);
 39}
 40objj_msgSend(objj_msgSend(_alertPanel,"contentView"),"addSubview:",_messageLabel);
 41objj_msgSend(objj_msgSend(_alertPanel,"contentView"),"addSubview:",_alertImageView);
 42}
 43}),new objj_method(sel_getUid("setTitle:"),function(_e,_f,_10){
 44with(_e){
 45_windowTitle=_10;
 46}
 47}),new objj_method(sel_getUid("title"),function(_11,_12){
 48with(_11){
 49return _windowTitle;
 50}
 51}),new objj_method(sel_getUid("windowStyle"),function(_13,_14){
 52with(_13){
 53return _windowStyle;
 54}
 55}),new objj_method(sel_getUid("setDelegate:"),function(_15,_16,_17){
 56with(_15){
 57_delegate=_17;
 58}
 59}),new objj_method(sel_getUid("delegate"),function(_18,_19){
 60with(_18){
 61return _delegate;
 62}
 63}),new objj_method(sel_getUid("setAlertStyle:"),function(_1a,_1b,_1c){
 64with(_1a){
 65_alertStyle=_1c;
 66}
 67}),new objj_method(sel_getUid("alertStyle"),function(_1d,_1e){
 68with(_1d){
 69return _alertStyle;
 70}
 71}),new objj_method(sel_getUid("setMessageText:"),function(_1f,_20,_21){
 72with(_1f){
 73objj_msgSend(_messageLabel,"setStringValue:",_21);
 74}
 75}),new objj_method(sel_getUid("messageText"),function(_22,_23){
 76with(_22){
 77return objj_msgSend(_messageLabel,"stringValue");
 78}
 79}),new objj_method(sel_getUid("addButtonWithTitle:"),function(_24,_25,_26){
 80with(_24){
 81var _27=objj_msgSend(objj_msgSend(CPButton,"alloc"),"initWithFrame:",CGRectMake(200-(_buttonCount*90),98,80,(_windowStyle==CPHUDBackgroundWindowMask)?20:24));
 82objj_msgSend(_27,"setTitle:",_26);
 83objj_msgSend(_27,"setTarget:",_24);
 84objj_msgSend(_27,"setTag:",_buttonCount);
 85objj_msgSend(_27,"setAction:",sel_getUid("_notifyDelegate:"));
 86objj_msgSend(_27,"setBezelStyle:",(_windowStyle==CPHUDBackgroundWindowMask)?CPHUDBezelStyle:CPRoundRectBezelStyle);
 87objj_msgSend(objj_msgSend(_alertPanel,"contentView"),"addSubview:",_27);
 88if(_buttonCount==0){
 89objj_msgSend(_alertPanel,"setDefaultButton:",_27);
 90}
 91_buttonCount++;
 92objj_msgSend(_buttons,"addObject:",_27);
 93}
 94}),new objj_method(sel_getUid("runModal"),function(_28,_29){
 95with(_28){
 96var _2a;
 97switch(_alertStyle){
 98case CPWarningAlertStyle:
 99objj_msgSend(_alertImageView,"setImage:",_1);
100_2a="Warning";
101break;
102case CPInformationalAlertStyle:
103objj_msgSend(_alertImageView,"setImage:",_2);
104_2a="Information";
105break;
106case CPCriticalAlertStyle:
107objj_msgSend(_alertImageView,"setImage:",_3);
108_2a="Error";
109break;
110}
111objj_msgSend(_alertPanel,"setTitle:",_windowTitle?_windowTitle:_2a);
112objj_msgSend(CPApp,"runModalForWindow:",_alertPanel);
113}
114}),new objj_method(sel_getUid("_notifyDelegate:"),function(_2b,_2c,_2d){
115with(_2b){
116if(_delegate&&objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("alertDidEnd:returnCode:"))){
117objj_msgSend(_delegate,"alertDidEnd:returnCode:",_2b,objj_msgSend(_2d,"tag"));
118}
119objj_msgSend(CPApp,"abortModal");
120objj_msgSend(_alertPanel,"close");
121}
122})]);
123class_addMethods(_5,[new objj_method(sel_getUid("initialize"),function(_2e,_2f){
124with(_2e){
125if(_2e!=CPAlert){
126return;
127}
128var _30=objj_msgSend(CPBundle,"bundleForClass:",objj_msgSend(_2e,"class"));
129_1=objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(_30,"pathForResource:","CPAlert/dialog-warning.png"),CGSizeMake(32,32));
130_2=objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(_30,"pathForResource:","CPAlert/dialog-information.png"),CGSizeMake(32,32));
131_3=objj_msgSend(objj_msgSend(CPImage,"alloc"),"initWithContentsOfFile:size:",objj_msgSend(_30,"pathForResource:","CPAlert/dialog-error.png"),CGSizeMake(32,32));
132}
133})]);