PageRenderTime 22ms CodeModel.GetById 4ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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