/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

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