/Frameworks/Foundation/objj.platform/CPUndoManager.j

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 396 lines · 396 code · 0 blank · 0 comment · 0 complexity · b233875de91377fef80356a0fff3aa24 MD5 · raw file

  1. i;10;CPObject.ji;14;CPInvocation.jc;13713;
  2. var _1=0,_2=1,_3=2;
  3. CPUndoManagerCheckpointNotification="CPUndoManagerCheckpointNotification";
  4. CPUndoManagerDidOpenUndoGroupNotification="CPUndoManagerDidOpenUndoGroupNotification";
  5. CPUndoManagerDidRedoChangeNotification="CPUndoManagerDidRedoChangeNotification";
  6. CPUndoManagerDidUndoChangeNotification="CPUndoManagerDidUndoChangeNotification";
  7. CPUndoManagerWillCloseUndoGroupNotification="CPUndoManagerWillCloseUndoGroupNotification";
  8. CPUndoManagerWillRedoChangeNotification="CPUndoManagerWillRedoChangeNotification";
  9. CPUndoManagerWillUndoChangeNotification="CPUndoManagerWillUndoChangeNotification";
  10. CPUndoCloseGroupingRunLoopOrdering=350000;
  11. var _4=[],_5=5;
  12. var _6=objj_allocateClassPair(CPObject,"_CPUndoGrouping"),_7=_6.isa;
  13. class_addIvars(_6,[new objj_ivar("_parent"),new objj_ivar("_invocations")]);
  14. objj_registerClassPair(_6);
  15. objj_addClassForBundle(_6,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  16. class_addMethods(_6,[new objj_method(sel_getUid("initWithParent:"),function(_8,_9,_a){
  17. with(_8){
  18. _8=objj_msgSendSuper({receiver:_8,super_class:objj_getClass("CPObject")},"init");
  19. if(_8){
  20. _parent=_a;
  21. _invocations=[];
  22. }
  23. return _8;
  24. }
  25. }),new objj_method(sel_getUid("parent"),function(_b,_c){
  26. with(_b){
  27. return _parent;
  28. }
  29. }),new objj_method(sel_getUid("addInvocation:"),function(_d,_e,_f){
  30. with(_d){
  31. _invocations.push(_f);
  32. }
  33. }),new objj_method(sel_getUid("addInvocationsFromArray:"),function(_10,_11,_12){
  34. with(_10){
  35. objj_msgSend(_invocations,"addObjectsFromArray:",_12);
  36. }
  37. }),new objj_method(sel_getUid("removeInvocationsWithTarget:"),function(_13,_14,_15){
  38. with(_13){
  39. var _16=_invocations.length;
  40. while(_16--){
  41. if(objj_msgSend(_invocations[_16],"target")==_15){
  42. _invocations.splice(_16,1);
  43. }
  44. }
  45. }
  46. }),new objj_method(sel_getUid("invocations"),function(_17,_18){
  47. with(_17){
  48. return _invocations;
  49. }
  50. }),new objj_method(sel_getUid("invoke"),function(_19,_1a){
  51. with(_19){
  52. var _1b=_invocations.length;
  53. while(_1b--){
  54. objj_msgSend(_invocations[_1b],"invoke");
  55. }
  56. }
  57. })]);
  58. class_addMethods(_7,[new objj_method(sel_getUid("_poolUndoGrouping:"),function(_1c,_1d,_1e){
  59. with(_1c){
  60. if(!_1e||_4.length>=_5){
  61. return;
  62. }
  63. _4.push(_1e);
  64. }
  65. }),new objj_method(sel_getUid("undoGroupingWithParent:"),function(_1f,_20,_21){
  66. with(_1f){
  67. if(_4.length){
  68. var _22=_4.pop();
  69. _22._parent=_21;
  70. if(_22._invocations.length){
  71. _22._invocations=[];
  72. }
  73. return _22;
  74. }
  75. return objj_msgSend(objj_msgSend(_1f,"alloc"),"initWithParent:",_21);
  76. }
  77. })]);
  78. var _23="_CPUndoGroupingParentKey",_24="_CPUndoGroupingInvocationsKey";
  79. var _6=objj_getClass("_CPUndoGrouping");
  80. if(!_6){
  81. objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"_CPUndoGrouping\""));
  82. }
  83. var _7=_6.isa;
  84. class_addMethods(_6,[new objj_method(sel_getUid("initWithCoder:"),function(_25,_26,_27){
  85. with(_25){
  86. _25=objj_msgSendSuper({receiver:_25,super_class:objj_getClass("CPObject")},"init");
  87. if(_25){
  88. _parent=objj_msgSend(_27,"decodeObjectForKey:",_23);
  89. _invocations=objj_msgSend(_27,"decodeObjectForKey:",_24);
  90. }
  91. return _25;
  92. }
  93. }),new objj_method(sel_getUid("encodeWithCoder:"),function(_28,_29,_2a){
  94. with(_28){
  95. objj_msgSend(_2a,"encodeObject:forKey:",_parent,_23);
  96. objj_msgSend(_2a,"encodeObject:forKey:",_invocations,_24);
  97. }
  98. })]);
  99. var _6=objj_allocateClassPair(CPObject,"CPUndoManager"),_7=_6.isa;
  100. class_addIvars(_6,[new objj_ivar("_redoStack"),new objj_ivar("_undoStack"),new objj_ivar("_groupsByEvent"),new objj_ivar("_disableCount"),new objj_ivar("_levelsOfUndo"),new objj_ivar("_currentGrouping"),new objj_ivar("_state"),new objj_ivar("_actionName"),new objj_ivar("_preparedTarget"),new objj_ivar("_runLoopModes"),new objj_ivar("_registeredWithRunLoop")]);
  101. objj_registerClassPair(_6);
  102. objj_addClassForBundle(_6,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  103. class_addMethods(_6,[new objj_method(sel_getUid("init"),function(_2b,_2c){
  104. with(_2b){
  105. _2b=objj_msgSendSuper({receiver:_2b,super_class:objj_getClass("CPObject")},"init");
  106. if(_2b){
  107. _redoStack=[];
  108. _undoStack=[];
  109. _state=_1;
  110. objj_msgSend(_2b,"setRunLoopModes:",[CPDefaultRunLoopMode]);
  111. objj_msgSend(_2b,"setGroupsByEvent:",YES);
  112. _performRegistered=NO;
  113. }
  114. return _2b;
  115. }
  116. }),new objj_method(sel_getUid("registerUndoWithTarget:selector:object:"),function(_2d,_2e,_2f,_30,_31){
  117. with(_2d){
  118. if(!_currentGrouping){
  119. objj_msgSend(CPException,"raise:reason:",CPInternalInconsistencyException,"No undo group is currently open");
  120. }
  121. if(_disableCount>0){
  122. return;
  123. }
  124. var _32=objj_msgSend(CPInvocation,"invocationWithMethodSignature:",nil);
  125. objj_msgSend(_32,"setTarget:",_2f);
  126. objj_msgSend(_32,"setSelector:",_30);
  127. objj_msgSend(_32,"setArgument:atIndex:",_31,2);
  128. objj_msgSend(_currentGrouping,"addInvocation:",_32);
  129. if(_state==_1){
  130. objj_msgSend(_redoStack,"removeAllObjects");
  131. }
  132. }
  133. }),new objj_method(sel_getUid("prepareWithInvocationTarget:"),function(_33,_34,_35){
  134. with(_33){
  135. _preparedTarget=_35;
  136. return _33;
  137. }
  138. }),new objj_method(sel_getUid("methodSignatureForSelector:"),function(_36,_37,_38){
  139. with(_36){
  140. if(objj_msgSend(_preparedTarget,"respondsToSelector:",_38)){
  141. return 1;
  142. }
  143. return nil;
  144. }
  145. }),new objj_method(sel_getUid("forwardInvocation:"),function(_39,_3a,_3b){
  146. with(_39){
  147. if(_disableCount>0){
  148. return;
  149. }
  150. objj_msgSend(_3b,"setTarget:",_preparedTarget);
  151. objj_msgSend(_currentGrouping,"addInvocation:",_3b);
  152. if(_state==_1){
  153. objj_msgSend(_redoStack,"removeAllObjects");
  154. }
  155. _preparedTarget=nil;
  156. }
  157. }),new objj_method(sel_getUid("canRedo"),function(_3c,_3d){
  158. with(_3c){
  159. return _redoStack.length>0;
  160. }
  161. }),new objj_method(sel_getUid("canUndo"),function(_3e,_3f){
  162. with(_3e){
  163. if(_undoStack.length>0){
  164. return YES;
  165. }
  166. return objj_msgSend(_currentGrouping,"actions").length>0;
  167. }
  168. }),new objj_method(sel_getUid("undo"),function(_40,_41){
  169. with(_40){
  170. if(objj_msgSend(_40,"groupingLevel")==1){
  171. objj_msgSend(_40,"endUndoGrouping");
  172. }
  173. objj_msgSend(_40,"undoNestedGroup");
  174. }
  175. }),new objj_method(sel_getUid("undoNestedGroup"),function(_42,_43){
  176. with(_42){
  177. if(_undoStack.length==0){
  178. return;
  179. }
  180. var _44=objj_msgSend(CPNotificationCenter,"defaultCenter");
  181. objj_msgSend(_44,"postNotificationName:object:",CPUndoManagerWillUndoChangeNotification,_42);
  182. var _45=_undoStack.pop();
  183. _state=_2;
  184. objj_msgSend(_42,"beginUndoGrouping");
  185. objj_msgSend(_45,"invoke");
  186. objj_msgSend(_42,"endUndoGrouping");
  187. objj_msgSend(_CPUndoGrouping,"_poolUndoGrouping:",_45);
  188. _state=_1;
  189. objj_msgSend(_44,"postNotificationName:object:",CPUndoManagerDidUndoChangeNotification,_42);
  190. }
  191. }),new objj_method(sel_getUid("redo"),function(_46,_47){
  192. with(_46){
  193. if(_redoStack.length==0){
  194. return;
  195. }
  196. var _48=objj_msgSend(CPNotificationCenter,"defaultCenter");
  197. objj_msgSend(_48,"postNotificationName:object:",CPUndoManagerWillRedoChangeNotification,_46);
  198. var _49=_currentGrouping,_4a=_redoStack.pop();
  199. _currentGrouping=nil;
  200. _state=_3;
  201. objj_msgSend(_46,"beginUndoGrouping");
  202. objj_msgSend(_4a,"invoke");
  203. objj_msgSend(_46,"endUndoGrouping");
  204. objj_msgSend(_CPUndoGrouping,"_poolUndoGrouping:",_4a);
  205. _currentGrouping=_49;
  206. _state=_1;
  207. objj_msgSend(_48,"postNotificationName:object:",CPUndoManagerDidRedoChangeNotification,_46);
  208. }
  209. }),new objj_method(sel_getUid("beginUndoGrouping"),function(_4b,_4c){
  210. with(_4b){
  211. _currentGrouping=objj_msgSend(_CPUndoGrouping,"undoGroupingWithParent:",_currentGrouping);
  212. }
  213. }),new objj_method(sel_getUid("endUndoGrouping"),function(_4d,_4e){
  214. with(_4d){
  215. if(!_currentGrouping){
  216. objj_msgSend(CPException,"raise:reason:",CPInternalInconsistencyException,"endUndoGrouping. No undo group is currently open.");
  217. }
  218. var _4f=objj_msgSend(_currentGrouping,"parent");
  219. if(!_4f&&objj_msgSend(_currentGrouping,"invocations").length>0){
  220. objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPUndoManagerWillCloseUndoGroupNotification,_4d);
  221. var _50=_state==_2?_redoStack:_undoStack;
  222. _50.push(_currentGrouping);
  223. if(_levelsOfUndo>0&&_50.length>_levelsOfUndo){
  224. _50.splice(0,1);
  225. }
  226. }else{
  227. objj_msgSend(_4f,"addInvocationsFromArray:",objj_msgSend(_currentGrouping,"invocations"));
  228. objj_msgSend(_CPUndoGrouping,"_poolUndoGrouping:",_currentGrouping);
  229. }
  230. _currentGrouping=_4f;
  231. }
  232. }),new objj_method(sel_getUid("enableUndoRegistration"),function(_51,_52){
  233. with(_51){
  234. if(_disableCount<=0){
  235. objj_msgSend(CPException,"raise:reason:",CPInternalInconsistencyException,"enableUndoRegistration. There are no disable messages in effect right now.");
  236. }
  237. _disableCount--;
  238. }
  239. }),new objj_method(sel_getUid("groupsByEvent"),function(_53,_54){
  240. with(_53){
  241. return _groupsByEvent;
  242. }
  243. }),new objj_method(sel_getUid("setGroupsByEvent:"),function(_55,_56,_57){
  244. with(_55){
  245. if(_groupsByEvent==_57){
  246. return;
  247. }
  248. _groupsByEvent=_57;
  249. if(_groupsByEvent){
  250. objj_msgSend(_55,"_registerWithRunLoop");
  251. if(!_currentGrouping){
  252. objj_msgSend(_55,"beginUndoGrouping");
  253. }
  254. }else{
  255. objj_msgSend(_55,"_unregisterWithRunLoop");
  256. }
  257. }
  258. }),new objj_method(sel_getUid("groupingLevel"),function(_58,_59){
  259. with(_58){
  260. var _5a=_currentGrouping,_5b=_currentGrouping!=nil;
  261. while(_5a=objj_msgSend(_5a,"parent")){
  262. ++_5b;
  263. }
  264. return _5b;
  265. }
  266. }),new objj_method(sel_getUid("disableUndoRegistration"),function(_5c,_5d){
  267. with(_5c){
  268. ++_disableCount;
  269. }
  270. }),new objj_method(sel_getUid("isUndoRegistrationEnabled"),function(_5e,_5f){
  271. with(_5e){
  272. return _disableCount==0;
  273. }
  274. }),new objj_method(sel_getUid("isUndoing"),function(_60,_61){
  275. with(_60){
  276. return _state==_2;
  277. }
  278. }),new objj_method(sel_getUid("isRedoing"),function(_62,_63){
  279. with(_62){
  280. return _state==_3;
  281. }
  282. }),new objj_method(sel_getUid("removeAllActions"),function(_64,_65){
  283. with(_64){
  284. _redoStack=[];
  285. _undoStack=[];
  286. _disableCount=0;
  287. }
  288. }),new objj_method(sel_getUid("removeAllActionsWithTarget:"),function(_66,_67,_68){
  289. with(_66){
  290. objj_msgSend(_currentGrouping,"removeInvocationsWithTarget:",_68);
  291. var _69=_redoStack.length;
  292. while(_69--){
  293. var _6a=_redoStack[_69];
  294. objj_msgSend(_6a,"removeInvocationsWithTarget:",_68);
  295. if(!objj_msgSend(_6a,"invocations").length){
  296. _redoStack.splice(_69,1);
  297. }
  298. }
  299. _69=_undoStack.length;
  300. while(_69--){
  301. var _6a=_undoStack[_69];
  302. objj_msgSend(_6a,"removeInvocationsWithTarget:",_68);
  303. if(!objj_msgSend(_6a,"invocations").length){
  304. _undoStack.splice(_69,1);
  305. }
  306. }
  307. }
  308. }),new objj_method(sel_getUid("setActionName:"),function(_6b,_6c,_6d){
  309. with(_6b){
  310. _actionName=_6d;
  311. }
  312. }),new objj_method(sel_getUid("redoActionName"),function(_6e,_6f){
  313. with(_6e){
  314. return objj_msgSend(_6e,"canRedo")?_actionName:nil;
  315. }
  316. }),new objj_method(sel_getUid("undoActionName"),function(_70,_71){
  317. with(_70){
  318. return objj_msgSend(_70,"canUndo")?_actionName:nil;
  319. }
  320. }),new objj_method(sel_getUid("runLoopModes"),function(_72,_73){
  321. with(_72){
  322. return _runLoopModes;
  323. }
  324. }),new objj_method(sel_getUid("setRunLoopModes:"),function(_74,_75,_76){
  325. with(_74){
  326. _runLoopModes=_76;
  327. objj_msgSend(_74,"_unregisterWithRunLoop");
  328. if(_groupsByEvent){
  329. objj_msgSend(_74,"_registerWithRunLoop");
  330. }
  331. }
  332. }),new objj_method(sel_getUid("beginUndoGroupingForEvent"),function(_77,_78){
  333. with(_77){
  334. if(!_groupsByEvent){
  335. return;
  336. }
  337. if(_currentGrouping!=nil){
  338. objj_msgSend(_77,"endUndoGrouping");
  339. }
  340. objj_msgSend(_77,"beginUndoGrouping");
  341. objj_msgSend(objj_msgSend(CPRunLoop,"currentRunLoop"),"performSelector:target:argument:order:modes:",sel_getUid("beginUndoGroupingForEvent"),_77,nil,CPUndoCloseGroupingRunLoopOrdering,_runLoopModes);
  342. }
  343. }),new objj_method(sel_getUid("_registerWithRunLoop"),function(_79,_7a){
  344. with(_79){
  345. if(_registeredWithRunLoop){
  346. return;
  347. }
  348. _registeredWithRunLoop=YES;
  349. objj_msgSend(objj_msgSend(CPRunLoop,"currentRunLoop"),"performSelector:target:argument:order:modes:",sel_getUid("beginUndoGroupingForEvent"),_79,nil,CPUndoCloseGroupingRunLoopOrdering,_runLoopModes);
  350. }
  351. }),new objj_method(sel_getUid("_unregisterWithRunLoop"),function(_7b,_7c){
  352. with(_7b){
  353. if(!_registeredWithRunLoop){
  354. return;
  355. }
  356. _registeredWithRunLoop=NO;
  357. objj_msgSend(objj_msgSend(CPRunLoop,"currentRunLoop"),"cancelPerformSelector:target:argument:",sel_getUid("beginUndoGroupingForEvent"),_7b,nil);
  358. }
  359. })]);
  360. var _7d="CPUndoManagerRedoStackKey",_7e="CPUndoManagerUndoStackKey";
  361. CPUndoManagerLevelsOfUndoKey="CPUndoManagerLevelsOfUndoKey";
  362. CPUndoManagerActionNameKey="CPUndoManagerActionNameKey";
  363. CPUndoManagerCurrentGroupingKey="CPUndoManagerCurrentGroupingKey";
  364. CPUndoManagerRunLoopModesKey="CPUndoManagerRunLoopModesKey";
  365. CPUndoManagerGroupsByEventKey="CPUndoManagerGroupsByEventKey";
  366. var _6=objj_getClass("CPUndoManager");
  367. if(!_6){
  368. objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPUndoManager\""));
  369. }
  370. var _7=_6.isa;
  371. class_addMethods(_6,[new objj_method(sel_getUid("initWithCoder:"),function(_7f,_80,_81){
  372. with(_7f){
  373. _7f=objj_msgSendSuper({receiver:_7f,super_class:objj_getClass("CPObject")},"init");
  374. if(_7f){
  375. _redoStack=objj_msgSend(_81,"decodeObjectForKey:",_7d);
  376. _undoStack=objj_msgSend(_81,"decodeObjectForKey:",_7e);
  377. _levelsOfUndo=objj_msgSend(_81,"decodeObjectForKey:",CPUndoManagerLevelsOfUndoKey);
  378. _actionName=objj_msgSend(_81,"decodeObjectForKey:",CPUndoManagerActionNameKey);
  379. _currentGrouping=objj_msgSend(_81,"decodeObjectForKey:",CPUndoManagerCurrentGroupingKey);
  380. _state=_1;
  381. objj_msgSend(_7f,"setRunLoopModes:",objj_msgSend(_81,"decodeObjectForKey:",CPUndoManagerRunLoopModesKey));
  382. objj_msgSend(_7f,"setGroupsByEvent:",objj_msgSend(_81,"decodeBoolForKey:",CPUndoManagerGroupsByEventKey));
  383. }
  384. return _7f;
  385. }
  386. }),new objj_method(sel_getUid("encodeWithCoder:"),function(_82,_83,_84){
  387. with(_82){
  388. objj_msgSend(_84,"encodeObject:forKey:",_redoStack,_7d);
  389. objj_msgSend(_84,"encodeObject:forKey:",_undoStack,_7e);
  390. objj_msgSend(_84,"encodeInt:forKey:",_levelsOfUndo,CPUndoManagerLevelsOfUndoKey);
  391. objj_msgSend(_84,"encodeObject:forKey:",_actionName,CPUndoManagerActionNameKey);
  392. objj_msgSend(_84,"encodeObject:forKey:",_currentGrouping,CPUndoManagerCurrentGroupingKey);
  393. objj_msgSend(_84,"encodeObject:forKey:",_runLoopModes,CPUndoManagerRunLoopModesKey);
  394. objj_msgSend(_84,"encodeBool:forKey:",_groupsByEvent,CPUndoManagerGroupsByEventKey);
  395. }
  396. })]);