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

/Frameworks/AppKit/browser.platform/CPDocument.j

http://github.com/polymar/polish
Unknown | 325 lines | 325 code | 0 blank | 0 comment | 0 complexity | ba29944fa9a5c4ca782b792ebd05f20e MD5 | raw file
  1I;21;Foundation/CPString.jI;20;Foundation/CPArray.ji;13;CPResponder.ji;20;CPWindowController.jc;12379;
  2CPSaveOperation=0;
  3CPSaveAsOperation=1;
  4CPSaveToOperation=2;
  5CPAutosaveOperation=3;
  6CPChangeDone=0;
  7CPChangeUndone=1;
  8CPChangeCleared=2;
  9CPChangeReadOtherContents=3;
 10CPChangeAutosaved=4;
 11CPDocumentWillSaveNotification="CPDocumentWillSaveNotification";
 12CPDocumentDidSaveNotification="CPDocumentDidSaveNotification";
 13CPDocumentDidFailToSaveNotification="CPDocumentDidFailToSaveNotification";
 14var _1=0;
 15var _2=objj_allocateClassPair(CPResponder,"CPDocument"),_3=_2.isa;
 16class_addIvars(_2,[new objj_ivar("_fileURL"),new objj_ivar("_fileType"),new objj_ivar("_windowControllers"),new objj_ivar("_untitledDocumentIndex"),new objj_ivar("_hasUndoManager"),new objj_ivar("_undoManager"),new objj_ivar("_changeCount"),new objj_ivar("_readConnection"),new objj_ivar("_writeRequest")]);
 17objj_registerClassPair(_2);
 18objj_addClassForBundle(_2,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 19class_addMethods(_2,[new objj_method(sel_getUid("init"),function(_4,_5){
 20with(_4){
 21_4=objj_msgSendSuper({receiver:_4,super_class:objj_getClass("CPResponder")},"init");
 22if(_4){
 23_windowControllers=[];
 24_hasUndoManager=YES;
 25_changeCount=0;
 26objj_msgSend(_4,"setNextResponder:",CPApp);
 27}
 28return _4;
 29}
 30}),new objj_method(sel_getUid("initWithType:error:"),function(_6,_7,_8,_9){
 31with(_6){
 32_6=objj_msgSend(_6,"init");
 33if(_6){
 34objj_msgSend(_6,"setFileType:",_8);
 35}
 36return _6;
 37}
 38}),new objj_method(sel_getUid("initWithContentsOfURL:ofType:delegate:didReadSelector:contextInfo:"),function(_a,_b,_c,_d,_e,_f,_10){
 39with(_a){
 40_a=objj_msgSend(_a,"init");
 41if(_a){
 42objj_msgSend(_a,"readFromURL:ofType:delegate:didReadSelector:contextInfo:",_c,_d,_e,_f,_10);
 43objj_msgSend(_a,"setFileURL:",_c);
 44objj_msgSend(_a,"setFileType:",_d);
 45}
 46return _a;
 47}
 48}),new objj_method(sel_getUid("initForURL:withContentsOfURL:ofType:delegate:didReadSelector:contextInfo:"),function(_11,_12,_13,_14,_15,_16,_17,_18){
 49with(_11){
 50_11=objj_msgSend(_11,"init");
 51if(_11){
 52objj_msgSend(_11,"readFromURL:ofType:delegate:didReadSelector:contextInfo:",_14,_15,_16,_17,_18);
 53objj_msgSend(_11,"setFileURL:",_13);
 54objj_msgSend(_11,"setFileType:",_15);
 55}
 56return _11;
 57}
 58}),new objj_method(sel_getUid("dataOfType:error:"),function(_19,_1a,_1b,_1c){
 59with(_19){
 60objj_msgSend(CPException,"raise:reason:",CPUnsupportedMethodException,"dataOfType:error: must be overridden by the document subclass.");
 61}
 62}),new objj_method(sel_getUid("readFromData:ofType:error:"),function(_1d,_1e,_1f,_20,_21){
 63with(_1d){
 64objj_msgSend(CPException,"raise:reason:",CPUnsupportedMethodException,"readFromData:ofType: must be overridden by the document subclass.");
 65}
 66}),new objj_method(sel_getUid("makeWindowControllers"),function(_22,_23){
 67with(_22){
 68var _24=objj_msgSend(objj_msgSend(CPWindowController,"alloc"),"initWithWindowCibName:",nil);
 69objj_msgSend(_22,"addWindowController:",_24);
 70}
 71}),new objj_method(sel_getUid("windowControllers"),function(_25,_26){
 72with(_25){
 73return _windowControllers;
 74}
 75}),new objj_method(sel_getUid("addWindowController:"),function(_27,_28,_29){
 76with(_27){
 77objj_msgSend(_windowControllers,"addObject:",_29);
 78if(objj_msgSend(_29,"document")!=_27){
 79objj_msgSend(_29,"setNextResponder:",_27);
 80objj_msgSend(_29,"setDocument:",_27);
 81}
 82}
 83}),new objj_method(sel_getUid("showWindows"),function(_2a,_2b){
 84with(_2a){
 85objj_msgSend(_windowControllers,"makeObjectsPerformSelector:withObject:",sel_getUid("showWindow:"),_2a);
 86}
 87}),new objj_method(sel_getUid("displayName"),function(_2c,_2d){
 88with(_2c){
 89if(_fileURL){
 90return objj_msgSend(_fileURL,"lastPathComponent");
 91}
 92if(!_untitledDocumentIndex){
 93_untitledDocumentIndex=++_1;
 94}
 95if(_untitledDocumentIndex==1){
 96return "Untitled";
 97}
 98return "Untitled "+_untitledDocumentIndex;
 99}
100}),new objj_method(sel_getUid("windowCibName"),function(_2e,_2f){
101with(_2e){
102return nil;
103}
104}),new objj_method(sel_getUid("windowControllerDidLoadNib:"),function(_30,_31,_32){
105with(_30){
106}
107}),new objj_method(sel_getUid("windowControllerWillLoadNib:"),function(_33,_34,_35){
108with(_33){
109}
110}),new objj_method(sel_getUid("readFromURL:ofType:delegate:didReadSelector:contextInfo:"),function(_36,_37,_38,_39,_3a,_3b,_3c){
111with(_36){
112objj_msgSend(_readConnection,"cancel");
113_readConnection=objj_msgSend(CPURLConnection,"connectionWithRequest:delegate:",objj_msgSend(CPURLRequest,"requestWithURL:",_38),_36);
114_readConnection.session=_3d(_39,_3a,_3b,_3c);
115}
116}),new objj_method(sel_getUid("fileURL"),function(_3e,_3f){
117with(_3e){
118return _fileURL;
119}
120}),new objj_method(sel_getUid("setFileURL:"),function(_40,_41,_42){
121with(_40){
122if(_fileURL==_42){
123return;
124}
125_fileURL=_42;
126objj_msgSend(_windowControllers,"makeObjectsPerformSelector:",sel_getUid("synchronizeWindowTitleWithDocumentName"));
127}
128}),new objj_method(sel_getUid("saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:"),function(_43,_44,_45,_46,_47,_48,_49,_4a){
129with(_43){
130var _4b=objj_msgSend(_43,"dataOfType:error:",objj_msgSend(_43,"fileType"),nil),_4c=_changeCount;
131_writeRequest=objj_msgSend(CPURLRequest,"requestWithURL:",_45);
132objj_msgSend(_writeRequest,"setHTTPMethod:","POST");
133objj_msgSend(_writeRequest,"setHTTPBody:",objj_msgSend(_4b,"string"));
134objj_msgSend(_writeRequest,"setValue:forHTTPHeaderField:","close","Connection");
135if(_47==CPSaveOperation){
136objj_msgSend(_writeRequest,"setValue:forHTTPHeaderField:","true","x-cappuccino-overwrite");
137}
138if(_47!=CPSaveToOperation){
139objj_msgSend(_43,"updateChangeCount:",CPChangeCleared);
140}
141var _4d=objj_msgSend(CPURLConnection,"connectionWithRequest:delegate:",_writeRequest,_43);
142_4d.session=_4e(_45,_47,_4c,_48,_49,_4a,_4d);
143}
144}),new objj_method(sel_getUid("connection:didReceiveResponse:"),function(_4f,_50,_51,_52){
145with(_4f){
146if(!objj_msgSend(_52,"isKindOfClass:",objj_msgSend(CPHTTPURLResponse,"class"))){
147return;
148}
149var _53=objj_msgSend(_52,"statusCode");
150if(_53===200){
151return;
152}
153var _54=_51.session;
154if(_51==_readConnection){
155objj_msgSend(_51,"cancel");
156alert("There was an error retrieving the document.");
157objj_msgSend(_54.delegate,_54.didReadSelector,_4f,NO,_54.contextInfo);
158}else{
159if(_53==409){
160objj_msgSend(_51,"cancel");
161if(confirm("There already exists a file with that name, would you like to overwrite it?")){
162objj_msgSend(_writeRequest,"setValue:forHTTPHeaderField:","true","x-cappuccino-overwrite");
163objj_msgSend(_51,"start");
164}else{
165if(_54.saveOperation!=CPSaveToOperation){
166_changeCount+=_54.changeCount;
167objj_msgSend(_windowControllers,"makeObjectsPerformSelector:withObject:",sel_getUid("setDocumentEdited:"),objj_msgSend(_4f,"isDocumentEdited"));
168}
169_writeRequest=nil;
170objj_msgSend(_54.delegate,_54.didSaveSelector,_4f,NO,_54.contextInfo);
171}
172}
173}
174}
175}),new objj_method(sel_getUid("connection:didReceiveData:"),function(_55,_56,_57,_58){
176with(_55){
177var _59=_57.session;
178if(_57==_readConnection){
179objj_msgSend(_55,"readFromData:ofType:error:",objj_msgSend(CPData,"dataWithString:",_58),_59.fileType,nil);
180objj_msgSend(_59.delegate,_59.didReadSelector,_55,YES,_59.contextInfo);
181}else{
182if(_59.saveOperation!=CPSaveToOperation){
183objj_msgSend(_55,"setFileURL:",_59.absoluteURL);
184}
185_writeRequest=nil;
186objj_msgSend(_59.delegate,_59.didSaveSelector,_55,YES,_59.contextInfo);
187}
188}
189}),new objj_method(sel_getUid("connection:didFailWithError:"),function(_5a,_5b,_5c,_5d){
190with(_5a){
191var _5e=_5c.session;
192if(_readConnection==_5c){
193objj_msgSend(_5e.delegate,_5e.didReadSelector,_5a,NO,_5e.contextInfo);
194}else{
195if(_5e.saveOperation!=CPSaveToOperation){
196_changeCount+=_5e.changeCount;
197objj_msgSend(_windowControllers,"makeObjectsPerformSelector:withObject:",sel_getUid("setDocumentEdited:"),objj_msgSend(_5a,"isDocumentEdited"));
198}
199_writeRequest=nil;
200alert("There was an error saving the document.");
201objj_msgSend(_5e.delegate,_5e.didSaveSelector,_5a,NO,_5e.contextInfo);
202}
203}
204}),new objj_method(sel_getUid("connectionDidFinishLoading:"),function(_5f,_60,_61){
205with(_5f){
206if(_readConnection==_61){
207_readConnection=nil;
208}
209}
210}),new objj_method(sel_getUid("isDocumentEdited"),function(_62,_63){
211with(_62){
212return _changeCount!=0;
213}
214}),new objj_method(sel_getUid("updateChangeCount:"),function(_64,_65,_66){
215with(_64){
216if(_66==CPChangeDone){
217++_changeCount;
218}else{
219if(_66==CPChangeUndone){
220--_changeCount;
221}else{
222if(_66==CPChangeCleared){
223_changeCount=0;
224}
225}
226}
227objj_msgSend(_windowControllers,"makeObjectsPerformSelector:withObject:",sel_getUid("setDocumentEdited:"),objj_msgSend(_64,"isDocumentEdited"));
228}
229}),new objj_method(sel_getUid("setFileType:"),function(_67,_68,_69){
230with(_67){
231_fileType=_69;
232}
233}),new objj_method(sel_getUid("fileType"),function(_6a,_6b){
234with(_6a){
235return _fileType;
236}
237}),new objj_method(sel_getUid("hasUndoManager"),function(_6c,_6d){
238with(_6c){
239return _hasUndoManager;
240}
241}),new objj_method(sel_getUid("setHasUndoManager:"),function(_6e,_6f,_70){
242with(_6e){
243if(_hasUndoManager==_70){
244return;
245}
246_hasUndoManager=_70;
247if(!_hasUndoManager){
248objj_msgSend(_6e,"setUndoManager:",nil);
249}
250}
251}),new objj_method(sel_getUid("_undoManagerWillCloseGroup:"),function(_71,_72,_73){
252with(_71){
253var _74=objj_msgSend(_73,"object");
254if(objj_msgSend(_74,"isUndoing")||objj_msgSend(_74,"isRedoing")){
255return;
256}
257objj_msgSend(_71,"updateChangeCount:",CPChangeDone);
258}
259}),new objj_method(sel_getUid("_undoManagerDidUndoChange:"),function(_75,_76,_77){
260with(_75){
261objj_msgSend(_75,"updateChangeCount:",CPChangeUndone);
262}
263}),new objj_method(sel_getUid("_undoManagerDidRedoChange:"),function(_78,_79,_7a){
264with(_78){
265objj_msgSend(_78,"updateChangeCount:",CPChangeDone);
266}
267}),new objj_method(sel_getUid("setUndoManager:"),function(_7b,_7c,_7d){
268with(_7b){
269var _7e=objj_msgSend(CPNotificationCenter,"defaultCenter");
270if(_undoManager){
271objj_msgSend(_7e,"removeObserver:name:object:",_7b,CPUndoManagerDidUndoChangeNotification,_undoManager);
272objj_msgSend(_7e,"removeObserver:name:object:",_7b,CPUndoManagerDidRedoChangeNotification,_undoManager);
273objj_msgSend(_7e,"removeObserver:name:object:",_7b,CPUndoManagerWillCloseUndoGroupNotification,_undoManager);
274}
275_undoManager=_7d;
276if(_undoManager){
277objj_msgSend(_7e,"addObserver:selector:name:object:",_7b,sel_getUid("_undoManagerDidUndoChange:"),CPUndoManagerDidUndoChangeNotification,_undoManager);
278objj_msgSend(_7e,"addObserver:selector:name:object:",_7b,sel_getUid("_undoManagerDidRedoChange:"),CPUndoManagerDidRedoChangeNotification,_undoManager);
279objj_msgSend(_7e,"addObserver:selector:name:object:",_7b,sel_getUid("_undoManagerWillCloseGroup:"),CPUndoManagerWillCloseUndoGroupNotification,_undoManager);
280}
281}
282}),new objj_method(sel_getUid("undoManager"),function(_7f,_80){
283with(_7f){
284if(_hasUndoManager&&!_undoManager){
285objj_msgSend(_7f,"setUndoManager:",objj_msgSend(objj_msgSend(CPUndoManager,"alloc"),"init"));
286}
287return _undoManager;
288}
289}),new objj_method(sel_getUid("windowWillReturnUndoManager:"),function(_81,_82,_83){
290with(_81){
291return objj_msgSend(_81,"undoManager");
292}
293}),new objj_method(sel_getUid("saveDocument:"),function(_84,_85,_86){
294with(_84){
295if(_fileURL){
296objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPDocumentWillSaveNotification,_84);
297objj_msgSend(_84,"saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:",_fileURL,objj_msgSend(_84,"fileType"),CPSaveOperation,_84,sel_getUid("document:didSave:contextInfo:"),NULL);
298}else{
299objj_msgSend(_84,"saveDocumentAs:",_84);
300}
301}
302}),new objj_method(sel_getUid("saveDocumentAs:"),function(_87,_88,_89){
303with(_87){
304_documentName=window.prompt("Document Name:");
305if(!_documentName){
306return;
307}
308objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPDocumentWillSaveNotification,_87);
309objj_msgSend(_87,"saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:",objj_msgSend(_87,"proposedFileURL"),objj_msgSend(_87,"fileType"),CPSaveAsOperation,_87,sel_getUid("document:didSave:contextInfo:"),NULL);
310}
311}),new objj_method(sel_getUid("document:didSave:contextInfo:"),function(_8a,_8b,_8c,_8d,_8e){
312with(_8a){
313if(_8d){
314objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPDocumentDidSaveNotification,_8a);
315}else{
316objj_msgSend(objj_msgSend(CPNotificationCenter,"defaultCenter"),"postNotificationName:object:",CPDocumentDidFailToSaveNotification,_8a);
317}
318}
319})]);
320var _3d=function(_8f,_90,_91,_92){
321return {fileType:_8f,delegate:_90,didReadSelector:_91,contextInfo:_92};
322};
323var _4e=function(_93,_94,_95,_96,_97,_98,_99){
324return {absoluteURL:_93,saveOperation:_94,changeCount:_95,delegate:_96,didSaveSelector:_97,contextInfo:_98,connection:_99};
325};