Mercurial > MadButterfly
annotate inkscape/firefox/content/inkscape.js @ 384:7cbb364fd273
Show the old name in the input line
Select the first object automatically.
author | wycc |
---|---|
date | Sun, 05 Apr 2009 17:00:28 +0800 |
parents | 29145d2affdb |
children | f3e6ac47752c |
rev | line source |
---|---|
288 | 1 var isInProgress=0; |
2 | |
3 var MAX_DUMP_DEPTH = 10; | |
4 var inkscape; | |
5 | |
362 | 6 |
7 function endsWith(str, s){ | |
8 var reg = new RegExp (s + "$"); | |
9 return reg.test(str); | |
10 } | |
288 | 11 |
12 function dumpObj(obj, name, indent, depth) { | |
13 if (depth > MAX_DUMP_DEPTH) { | |
14 return indent + name + ": <Maximum Depth Reached>\n"; | |
15 } | |
16 if (typeof obj == "object") { | |
17 var child = null; | |
18 var output = indent + name + "\n"; | |
19 indent += "\t"; | |
20 for (var item in obj) | |
21 { | |
22 try { | |
23 child = obj[item]; | |
24 } catch (e) { | |
25 child = "<Unable to Evaluate>"; | |
26 } | |
27 if (typeof child == "object") { | |
28 output += dumpObj(child, item, indent, depth + 1); | |
29 } else { | |
30 output += indent + item + ": " + child + "\n"; | |
31 } | |
32 } | |
33 return output; | |
34 } else { | |
35 return obj; | |
36 } | |
37 } | |
38 function dumpObjItem(obj, name, indent, depth) { | |
39 if (depth > MAX_DUMP_DEPTH) { | |
40 return indent + name + ": <Maximum Depth Reached>\n"; | |
41 } | |
42 if (typeof obj == "object") { | |
43 var child = null; | |
44 var output = indent + name + "\n"; | |
45 indent += "\t"; | |
46 for (var item in obj) | |
47 { | |
48 try { | |
49 child = obj[item]; | |
50 } catch (e) { | |
51 child = "<Unable to Evaluate>"; | |
52 } | |
53 if (typeof child == "object") { | |
54 output += dumpObjItem(child, item, indent, depth + 1); | |
55 } else { | |
56 output += indent + item + ":\n"; | |
57 } | |
58 } | |
59 return output; | |
60 } else { | |
61 return obj; | |
62 } | |
63 } | |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
64 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
65 /** |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
66 * TextEditor class |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
67 * |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
68 */ |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
69 |
362 | 70 function TextEditor(file) |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
71 { |
362 | 72 var editor = document.getElementById('inkscape'); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
73 editor.innerHTML = "<embed src="+file+" width=900 height=700 />"; |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
74 this.isInProgress = 0; |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
75 } |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
76 |
288 | 77 /** |
78 * Inkscape class | |
79 * | |
80 */ | |
81 function Inkscape(file) | |
82 { | |
83 var ink = document.getElementById('inkscape'); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
84 ink.innerHTML = "<embed src="+file+" width=900 height=700 />"; |
288 | 85 this.isInProgress = 0; |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
86 this.callback = null; |
288 | 87 |
88 setTimeout("inkscape.fetchDocument()",4000); | |
89 } | |
90 | |
91 Inkscape.prototype.gotoScene = function (n) | |
92 { | |
93 nextScene = n; | |
94 var soapBody = new SOAPObject("START"); | |
95 var sr = new SOAPRequest("START", soapBody); | |
96 SOAPClient.Proxy = "http://localhost:19192/"; | |
97 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene1(resp);},this); | |
98 this.isInProgress++; | |
99 } | |
100 Inkscape.prototype.gotoScene1 = function (resp,n) | |
101 { | |
102 var soapBody = new SOAPObject("SCENE"); | |
103 var v1 = new SOAPObject("v1"); | |
104 v1.val(nextScene); | |
105 soapBody.appendChild(v1); | |
106 var sr = new SOAPRequest("SCENE", soapBody); | |
107 SOAPClient.Proxy = "http://localhost:19192/"; | |
108 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene2(resp);},this); | |
109 } | |
110 Inkscape.prototype.gotoScene2 = function (resp) | |
111 { | |
112 var soapBody = new SOAPObject("PUBLISH"); | |
113 var sr = new SOAPRequest("PUBLISH", soapBody); | |
114 SOAPClient.Proxy = "http://localhost:19192/"; | |
115 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene3(resp);},this); | |
116 } | |
117 | |
118 Inkscape.prototype.gotoScene3 = function (resp) | |
119 { | |
120 this.isInProgress--; | |
121 } | |
122 Inkscape.prototype.publishDocument= function(resp) | |
123 { | |
124 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text); | |
125 mbsvg.renderUI(); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
126 if (this.callback) |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
127 this.callback(mbsvg); |
288 | 128 |
129 var soapBody = new SOAPObject("PUBLISH"); | |
130 var sr = new SOAPRequest("PUBLISH", soapBody); | |
131 SOAPClient.Proxy = "http://localhost:19192/"; | |
132 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this); | |
133 } | |
134 | |
135 Inkscape.prototype.refreshDocument = function(resp) | |
136 { | |
137 var soapBody = new SOAPObject("GETDOC"); | |
138 var sr = new SOAPRequest("GETDOC", soapBody); | |
139 SOAPClient.Proxy = "http://localhost:19192/"; | |
140 SOAPClient.SendRequest(sr, function(resp,arg) { arg.publishDocument(resp);},this); | |
141 } | |
142 | |
143 Inkscape.prototype.operationDone = function (res) | |
144 { | |
145 this.isInProgress--; | |
146 } | |
147 Inkscape.prototype.insertKey= function(n) | |
148 { | |
149 nextScene = n; | |
150 var soapBody = new SOAPObject("START"); | |
151 var sr = new SOAPRequest("START", soapBody); | |
152 SOAPClient.Proxy = "http://localhost:19192/"; | |
153 SOAPClient.SendRequest(sr, function (resp,arg) {arg.insertKey1(resp);},this); | |
154 this.isInProgress++; | |
155 } | |
156 Inkscape.prototype.insertKey1 = function(resp) | |
157 { | |
158 var soapBody = new SOAPObject("INSERTKEY"); | |
159 var v1 = new SOAPObject("v1"); | |
160 v1.attr('type','string'); | |
161 v1.val(currentLayer); | |
162 soapBody.appendChild(v1); | |
163 var v2 = new SOAPObject("v2"); | |
164 v2.val(nextScene); | |
165 soapBody.appendChild(v2); | |
166 var sr = new SOAPRequest("INSERTKEY", soapBody); | |
167 SOAPClient.Proxy = "http://localhost:19192/"; | |
168 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
169 } | |
170 | |
171 Inkscape.prototype.extendScene=function() | |
172 { | |
173 var soapBody = new SOAPObject("START"); | |
174 var sr = new SOAPRequest("START", soapBody); | |
175 SOAPClient.Proxy = "http://localhost:19192/"; | |
176 SOAPClient.SendRequest(sr, function (resp,arg) {arg.extendScene1(resp);},this); | |
177 this.isInProgress++; | |
178 } | |
179 | |
180 | |
181 Inkscape.prototype.extendScene1 = function(resp) | |
182 { | |
183 var soapBody = new SOAPObject("EXTENDSCENE"); | |
184 var v1 = new SOAPObject("v1"); | |
185 v1.attr('type','string'); | |
186 v1.val(currentLayer); | |
187 soapBody.appendChild(v1); | |
188 var v2 = new SOAPObject("v2"); | |
189 v2.val(currentScene); | |
190 soapBody.appendChild(v2); | |
191 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
192 SOAPClient.Proxy = "http://localhost:19192/"; | |
193 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
194 } | |
195 | |
196 | |
197 Inkscape.prototype.deleteScene=function() | |
198 { | |
199 var soapBody = new SOAPObject("START"); | |
200 var sr = new SOAPRequest("START", soapBody); | |
201 SOAPClient.Proxy = "http://localhost:19192/"; | |
202 SOAPClient.SendRequest(sr, function (resp,arg) {arg.deleteScene1(resp);},this); | |
203 this.isInProgress++; | |
204 } | |
205 | |
206 Inkscape.prototype.deleteScene1=function(resp) | |
207 { | |
208 var soapBody = new SOAPObject("DELETESCENE"); | |
209 var v1 = new SOAPObject("v1"); | |
210 v1.attr('type','string'); | |
211 v1.val(currentLayer); | |
212 soapBody.appendChild(v1); | |
213 var v2 = new SOAPObject("v2"); | |
214 v2.val(currentScene); | |
215 soapBody.appendChild(v2); | |
216 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
217 SOAPClient.Proxy = "http://localhost:19192/"; | |
218 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
219 } | |
220 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
221 Inkscape.prototype.fetchDocument = function(callback) |
288 | 222 { |
223 var soapBody = new SOAPObject("START"); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
224 this.callback = callback |
288 | 225 var sr = new SOAPRequest("START", soapBody); |
226 SOAPClient.Proxy = "http://localhost:19192/"; | |
227 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this); | |
228 this.isInProgress++; | |
229 } | |
230 | |
381 | 231 Inkscape.prototype.changeSymbolName_cb = function(callback) |
232 { | |
233 var soapBody = new SOAPObject("CHANGESYMBOL"); | |
234 var v1 = new SOAPObject("v1"); | |
235 v1.attr('type','string'); | |
236 v1.val(this.v1); | |
237 soapBody.appendChild(v1); | |
238 var v2 = new SOAPObject("v2"); | |
239 v2.val(this.v2); | |
240 soapBody.appendChild(v2); | |
241 var sr = new SOAPRequest("CHANGESYMBOL", soapBody); | |
242 SOAPClient.Proxy = "http://localhost:19192/"; | |
243 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
244 this.inProgress--; | |
245 } | |
246 | |
247 Inkscape.prototype.changeSymbolName = function(id,newname,callback) | |
248 { | |
249 var soapBody = new SOAPObject("START"); | |
250 this.callback = callback | |
251 var sr = new SOAPRequest("START", soapBody); | |
252 SOAPClient.Proxy = "http://localhost:19192/"; | |
253 this.v1 = id; | |
254 this.v2 = newname; | |
255 SOAPClient.SendRequest(sr,function(resp,arg) {arg.changeSymbolName_cb(resp);},this); | |
256 this.isInProgress++; | |
257 } | |
258 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
259 /* |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
260 * This module is used to define a symbol for the MadButterfly. This function will search for symbol which is defined in the current select object. We will list all SVG elements |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
261 * in the left side, multiple variables can be defined at one time. When any element is selected, the defined symbol will be listed in the right side. |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
262 * |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
263 */ |
288 | 264 |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
265 Inkscape.prototype.MakeSymbol=function() |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
266 { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
267 function callback(mbsvg) { |
381 | 268 inkscape.loadSymbolScreen(mbsvg); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
269 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
270 inkscape.fetchDocument(callback); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
271 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
272 |
381 | 273 |
274 Inkscape.prototype.onChangeSymbolName=function() | |
275 { | |
276 inkscape.changeSymbolName(inkscape.current_symbol, $('#newsymbolname').val()); | |
277 symboldialog.dialog('close') | |
278 } | |
279 | |
280 Inkscape.prototype.refreshSymbolPanel=function(node) | |
281 { | |
384 | 282 var reg = new RegExp('(.*)\\((.*)\\)'); |
283 var m = reg.exec(node.textContent); | |
284 var val = m[2]; | |
381 | 285 inkscape.current_symbol = node.textContent; |
384 | 286 $('#newsymbolname').val(val); |
381 | 287 } |
288 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
289 Inkscape.prototype.loadSymbolScreen=function (mbsvg) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
290 // Swap the left side to be the SVG element tree. |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
291 var i,l; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
292 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
293 symboldialog.dialog('open'); |
384 | 294 this.mbsvg = mbsvg; |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
295 l = mbsvg.selected_objects.length; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
296 var jsonobj = [] |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
297 for(i=0;i<l;i++) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
298 // Add symbol into the tree |
384 | 299 var name = mbsvg.findSymbolName(mbsvg.selected_objects[i]); |
300 var title=mbsvg.selected_objects[i]+"("+name+")"; | |
301 var obj = { attributes: {id: 'sym'+i}, data : title}; | |
302 if (i == 0) { | |
303 this.current_symbol = mbsvg.selected_objects[i]; | |
304 $('#newsymbolname').val(name); | |
305 } | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
306 jsonobj.push(obj); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
307 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
308 this.symboltree = $.tree_create(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
309 this.symboltree.init($("#symbollist"), { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
310 data: { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
311 type: "json", |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
312 json : jsonobj |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
313 }, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
314 callback : { |
384 | 315 ondblclk : function(NODE,TREE_OBJ) { inkscape.refreshSymbolPanel(NODE);} |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
316 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
317 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
318 }); |
381 | 319 var s = $('#changename'); |
320 s.click(this.onChangeSymbolName); | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
321 // Swap the right side to be the symbol editor screen. |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
322 symboldialog.show(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
323 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
324 |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
325 jQuery(document).ready(function() { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
326 symboldialog = jQuery('#symboldialog'); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
327 symboldialog.dialog({width:500, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
328 modal: true, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
329 autoOpen:false, |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
330 title:'Please select a file'}); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
331 symboldialog.hide(); |
381 | 332 symboldialog.append("<div id='symbollist'/>"); |
384 | 333 symboldialog.append("<div id='symbol'><input type='text' id='newsymbolname'> <input type='submit' value='change' id='changename'></div> "); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
334 }); |
288 | 335 |
336 function MBSVG(file) | |
337 { | |
338 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null); | |
339 xmlDoc.async=false; | |
340 xmlDoc.load(file); | |
341 MBSVG_loadFromDoc(this,xmlDoc); | |
342 | |
343 } | |
344 function MBSVGString(xml) | |
345 { | |
346 var xmlParser = new DOMParser(); | |
347 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
348 MBSVG_loadFromDoc(this,xmlDoc); | |
349 } | |
350 | |
351 | |
352 | |
353 function MBSVG_loadFromDoc(self,xmlDoc) | |
354 { | |
355 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene"); | |
356 if (scenesNode == null) { | |
357 alert('This is not a valid scene file'); | |
358 } | |
359 var len = scenesNode.length; | |
360 var i,j; | |
361 var max = 0; | |
362 var scenes = new Array(); | |
363 | |
364 // Get the length of scenes | |
365 for(i=0;i<len;i++) { | |
366 var s = scenesNode[i]; | |
367 var start = s.getAttribute("start"); | |
368 var end = s.getAttribute("end"); | |
369 var ref = s.getAttribute("ref"); | |
370 var ss = new Object(); | |
371 | |
372 if (end == null) end = start | |
373 if (max <end) max = end; | |
374 ss.node = s; | |
375 ss.start = start; | |
376 ss.end = end; | |
377 ss.ref = ref; | |
378 ss.layer = null; | |
379 scenes.push(ss); | |
380 } | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
381 if (max < 20) max = 30; |
288 | 382 // Collect all layers |
383 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes; | |
384 var layers = new Array(); | |
385 len = nodes.length; | |
386 for(i=0;i<len;i++) { | |
387 if (nodes[i].localName == 'g') { | |
388 var subnodes = nodes[i].childNodes; | |
389 for(j=0;j<subnodes.length;j++) { | |
390 if (subnodes[j].localName == 'g') { | |
391 for(var k=0;k<scenes.length;k++) { | |
392 if (scenes[k].ref == subnodes[j].getAttribute('id')) { | |
393 scenes[k].layer = nodes[i].getAttribute('id'); | |
394 break; | |
395 } | |
396 } | |
397 } | |
398 } | |
399 layers.push(nodes[i]); | |
400 } | |
401 } | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
402 var select = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","select"); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
403 len = select.length; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
404 selectobjs = []; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
405 for(i=0;i<len;i++) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
406 selectobjs.push(select[i].getAttribute('ref')); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
407 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
408 self.selected_objects = selectobjs; |
288 | 409 self.layers = layers; |
410 self.scenes = scenes; | |
411 self.maxframe = max; | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
412 self.doc = xmlDoc; |
288 | 413 } |
414 | |
415 MBSVGString.prototype=MBSVG.prototype; | |
416 MBSVG.prototype.renderUI=function() | |
417 { | |
418 var layers = this.layers; | |
419 var scenes = this.scenes; | |
420 var max = this.maxframe; | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
421 var cmd = "<table border=0>\n"; |
288 | 422 cmd = cmd + "<tr><td></td>"; |
423 for(var j=1;j<=max;j++) | |
424 cmd = cmd + "<td>"+j+"</td>"; | |
425 | |
426 for(var i=layers.length-1;i>=0;i--) { | |
427 var l = layers[i]; | |
428 var id = l.getAttribute('id'); | |
429 var label = l.getAttribute('inkscape:label'); | |
430 cmd = cmd + "<tr><td>"+label+"</td>"; | |
431 for(j=0;j<max;j++) { | |
432 var empty = 1; | |
433 var n = j +1; | |
434 var id_str = id+"#"+n | |
435 for(var k=0;k<scenes.length;k++) { | |
436 if (id != scenes[k].layer) continue; | |
437 if (n == scenes[k].start) { | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
438 cmd = cmd + "<td><img class='normal' width='16' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; |
288 | 439 empty = 0; |
440 break; | |
441 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
442 cmd = cmd + "<td><img class='normal' width='16' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; |
288 | 443 empty = 0; |
444 break; | |
445 } | |
446 } | |
447 if (empty) { | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
448 cmd = cmd + "<td><img class='normal' width='16' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>"; |
288 | 449 } |
450 | |
451 } | |
452 cmd = cmd + "</tr>\n"; | |
453 } | |
454 cmd = cmd + "</table>\n"; | |
455 var frame = document.getElementById('frame'); | |
456 frame.innerHTML=cmd; | |
457 } | |
458 | |
459 | |
384 | 460 MBSVG.prototype.findSymbolName=function(id) |
461 { | |
462 var obj = this.doc.getElementById(id); | |
463 var name = obj.getAttribute('mbname'); | |
464 return name; | |
465 | |
466 } | |
288 | 467 |
468 /** | |
469 * UI for madbuilder.html to build the scene editor | |
470 */ | |
471 | |
472 function selectCell(obj) | |
473 { | |
474 var id = obj.getAttribute('id'); | |
475 var layer,n; | |
476 var f = id.split('#'); | |
477 layer=f[0]; | |
478 n = f[1]; | |
479 var img = obj.getAttribute('src'); | |
480 var f = img.split('-'); | |
481 | |
482 if (f[0] == 'active') | |
483 return; | |
484 else { | |
485 obj.setAttribute('src', 'active-'+img); | |
486 } | |
487 | |
488 if (last_select != null) { | |
489 f = last_select.getAttribute('src').split('-'); | |
490 last_select.setAttribute('src', f[1]); | |
491 } | |
492 last_select = obj; | |
493 currentScene = n; | |
494 currentLayer = layer; | |
495 } | |
496 | |
497 | |
498 function onButtonClick(obj) | |
499 { | |
500 var id = obj.getAttribute('id'); | |
501 if (id == 'Jump') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
502 if (inkscape.isInProgress != 0) return; |
288 | 503 if (currentScene != 0) |
504 inkscape.gotoScene(currentScene); | |
505 } else if (id == 'InsertKey') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
506 if (inkscape.isInProgress != 0) return; |
288 | 507 inkscape.insertKey(currentScene); |
508 } else if (id == 'ExtendScene') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
509 if (inkscape.isInProgress != 0) return; |
288 | 510 inkscape.extendScene(currentScene); |
511 } else if (id == 'DeleteScene') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
512 if (inkscape.isInProgress != 0) return; |
288 | 513 inkscape.deleteScene(currentScene); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
514 } else if (id == 'MakeSymbol') { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
515 if (inkscape.isInProgress != 0) return; |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
516 inkscape.MakeSymbol(); |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
517 } else if (id == 'Save') { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
518 project_save(); |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
519 } else if (id == 'Test') { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
520 if (project_compile()) { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
521 project_run(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
522 } else { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
523 } |
288 | 524 } else { |
525 alert(id+' has not been implemented yet'); | |
526 } | |
527 } | |
528 | |
529 function gotoScene_cb(resObj) | |
530 { | |
531 | |
532 } | |
533 var nextScene; | |
534 var currentScene = 0; | |
535 var currentLayer = ''; | |
536 | |
357 | 537 |
538 function dump(n) | |
539 { | |
540 cmd = ""; | |
541 for(k in n) { | |
542 cmd = cmd + k+"="+n[k]+"\n"; | |
543 } | |
544 alert(cmd); | |
545 } | |
288 | 546 |
547 | |
358 | 548 |
357 | 549 |
550 | |
551 | |
358 | 552 function loadInkscapeFile() |
357 | 553 { |
554 ele = $('#mbsvg'); | |
555 file = ele.attr('value'); | |
556 inkscape = new Inkscape("file://"+file); | |
557 | |
352 | 558 file1_animation = [ |
559 { | |
560 attributes: {id:"an1-1"}, | |
561 data: "animation1" | |
562 }, | |
563 { | |
564 attributes: {id:"an1-2"}, | |
565 data: "animation2" | |
566 } | |
567 ]; | |
568 file1 = { | |
569 attributes:{id:"file1"}, | |
570 data: "scene1.mbsvg", | |
571 children: file1_animation | |
572 }; | |
573 file2 = { | |
574 attributes:{id:"file2"}, | |
575 data: "scene2.mbsvg", | |
576 }; | |
577 file3 = { | |
578 attributes:{id:"file3"}, | |
579 data: "scene3.mbsvg", | |
580 }; | |
581 | |
582 scenes = [ file1,file2,file3]; | |
583 src1 = {attributes:{id:"src1"},data:"src1.c"}; | |
584 src2 = {attributes:{id:"src1"},data:"src2.c"}; | |
585 src3 = {attributes:{id:"src1"},data:"src3.c"}; | |
586 | |
587 sources = [src1,src2,src3]; | |
588 | |
358 | 589 } |
590 | |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
591 function project_compile() |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
592 { |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
593 } |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
594 |
358 | 595 |
362 | 596 function project_showFile(node) |
597 { | |
598 var file = node.textContent; | |
599 if (endsWith(file,"mbsvg")) { | |
600 project_loadScene(node); | |
601 } else { | |
602 project_loadEditor(node); | |
603 } | |
604 | |
605 } | |
359 | 606 function project_loadScene(node) |
607 { | |
608 var file = node.textContent; | |
371 | 609 if (file.substr(0,1) == '/') |
610 inkscape = new Inkscape("file://"+file); | |
611 else | |
612 inkscape = new Inkscape("file://"+project_dir+'/'+file); | |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
613 } |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
614 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
615 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
616 function project_loadEditor(node) |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
617 { |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
618 var file = node.textContent; |
371 | 619 if (file.substr(0,1) == '/') |
620 editor = new TextEditor("file://"+file); | |
621 else | |
622 editor = new TextEditor("file://"+project_dir+'/'+file); | |
359 | 623 } |
624 | |
358 | 625 function project_parse(xml) |
626 { | |
627 | |
628 var xmlParser = new DOMParser(); | |
629 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
630 var scenesNode = xmlDoc.getElementsByTagName("scene"); | |
631 if (scenesNode == null) { | |
632 alert('This is not a valid scene file'); | |
633 } | |
634 var len = scenesNode.length; | |
635 var i,j; | |
636 var max = 0; | |
637 var scenes = new Array(); | |
638 | |
639 // Get the length of scenes | |
640 for(i=0;i<len;i++) { | |
641 var n = scenesNode[i]; | |
642 var s = new Object(); | |
643 s.attributes = new Object(); | |
644 s.attributes.id = "scene"+i; | |
645 s.state = "open"; | |
646 s.data = n.getAttribute("src"); | |
647 scenes.push(s); | |
648 } | |
649 | |
650 var nodes = xmlDoc.getElementsByTagName("source"); | |
651 var len = nodes.length; | |
652 var i,j; | |
653 var max = 0; | |
654 var sources = []; | |
655 | |
656 // Get the length of scenes | |
657 for(i=0;i<len;i++) { | |
658 var n = nodes[i]; | |
659 var s = new Object(); | |
660 s.attributes = new Object(); | |
661 s.attributes.id = "sources"+i; | |
662 s.state = "open"; | |
663 s.data = n.getAttribute("src"); | |
664 sources.push(s); | |
665 } | |
666 | |
667 var tree = $.tree_create(); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
668 project_tree = tree; |
358 | 669 tree.init($("#filelist"), { |
670 data: { | |
671 type: "json", | |
672 json : [ | |
673 { | |
674 attributes: {id: "prj"}, | |
675 state: "open", | |
676 data: "Project", | |
677 children: [ | |
678 { attributes:{id:"scenes"}, data:"scene", children: scenes}, | |
679 { attributes:{id:"sources"},data:"sources",children: sources} | |
680 ] | |
681 } | |
682 ], | |
683 }, | |
359 | 684 callback : { |
362 | 685 ondblclk : function(NODE,TREE_OBJ) { project_showFile(NODE); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);} |
359 | 686 }, |
358 | 687 ui : { |
357 | 688 context : [ |
689 { | |
690 id: "Open", | |
691 label: "Open", | |
692 icon: "open.png", | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
693 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return true;}, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
694 action: function(NODE,TREE_OBJ) { onTree_openFile(NODE,TREE_OBJ);} |
357 | 695 }, |
696 { | |
697 id: "New", | |
698 label: "New", | |
699 icon: "create.png", | |
700 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
701 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
702 }, | |
703 { | |
704 id: "Rename", | |
705 label: "Rename", | |
706 icon: "rename.png", | |
707 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
708 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
358 | 709 } |
357 | 710 ] |
358 | 711 } |
712 | |
713 }); | |
714 } | |
357 | 715 |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
716 function fileDialog_cb() |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
717 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
718 var file = $('#filedialogsrc').attr('value'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
719 filedialog.dialog('close'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
720 filedialog_cb(file,filedialog_arg); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
721 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
722 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
723 function openFileDialog(callback,arg) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
724 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
725 filedialog_cb = callback; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
726 filedialog_arg = arg; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
727 filedialog.html('Please select the scene file<br>'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
728 filedialog.append('<input type=file value="Select the scene file" id="filedialogsrc">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
729 filedialog.append('<input type=button value="Load" onclick="fileDialog_cb()">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
730 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
731 filedialog.dialog('open'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
732 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
733 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
734 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
735 function project_addScene(file,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
736 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
737 if (file == '') { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
738 return; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
739 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
740 treeobj.create(false,treeobj.selected,file); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
741 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
742 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
743 function onTree_addSceneFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
744 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
745 openFileDialog(project_addScene,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
746 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
747 |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
748 function project_addSource(file,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
749 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
750 treeobj.create(false,treeobj.selected,file); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
751 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
752 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
753 function onTree_addSourceFile(node,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
754 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
755 openFileDialog(project_addSource,treeobj); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
756 } |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
757 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
758 function onTree_openFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
759 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
760 if (node[0].id == "scenes") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
761 onTree_addSceneFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
762 } else if (node[0].id == "sources") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
763 onTree_addSourceFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
764 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
765 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
766 |
367 | 767 function system_open_read(fname) { |
768 try { | |
769 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
770 } catch (e) { | |
771 alert("Permission to read file was denied."); | |
772 } | |
773 var file = Components.classes["@mozilla.org/file/local;1"] | |
774 .createInstance(Components.interfaces.nsILocalFile); | |
775 try { | |
776 file.initWithPath( fname ); | |
777 if ( file.exists() == false ) { | |
778 alert("File does not exist"); | |
779 } | |
780 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
781 .createInstance( Components.interfaces.nsIFileInputStream ); | |
782 is.init( file,0x01, 00004, null); | |
783 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
784 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
785 sis.init( is ); | |
786 } catch(e) { | |
787 alert(fname+" does not exist"); | |
788 } | |
789 return sis; | |
790 } | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
791 |
358 | 792 function system_read(fname) { |
793 try { | |
794 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
795 } catch (e) { | |
796 alert("Permission to read file was denied."); | |
797 } | |
798 var file = Components.classes["@mozilla.org/file/local;1"] | |
799 .createInstance(Components.interfaces.nsILocalFile); | |
800 try { | |
801 file.initWithPath( fname ); | |
802 if ( file.exists() == false ) { | |
803 alert("File does not exist"); | |
804 } | |
805 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
806 .createInstance( Components.interfaces.nsIFileInputStream ); | |
807 is.init( file,0x01, 00004, null); | |
808 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
809 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
810 sis.init( is ); | |
811 var output = sis.read( sis.available() ); | |
812 sis.close(); | |
813 } catch(e) { | |
814 alert(fname+" does not exist"); | |
815 } | |
816 return output; | |
357 | 817 } |
367 | 818 function system_open_write(fname) { |
819 try { | |
820 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
821 } catch (e) { | |
822 alert("Permission to read file was denied."); | |
823 } | |
824 var file = Components.classes["@mozilla.org/file/local;1"] | |
825 .createInstance(Components.interfaces.nsILocalFile); | |
826 try { | |
827 file.initWithPath( fname ); | |
828 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"] | |
829 .createInstance( Components.interfaces.nsIFileOutputStream ); | |
830 fostream.init( file,0x02|0x8|0x20, 0666,0); | |
831 } catch(e) { | |
371 | 832 alert('can not create '+fname); |
367 | 833 } |
834 return fostream; | |
835 } | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
836 function system_write(fname,xml) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
837 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
838 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
839 } catch (e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
840 alert("Permission to read file was denied."); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
841 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
842 var file = Components.classes["@mozilla.org/file/local;1"] |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
843 .createInstance(Components.interfaces.nsILocalFile); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
844 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
845 file.initWithPath( fname ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
846 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
847 .createInstance( Components.interfaces.nsIFileOutputStream ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
848 fostream.init( file,0x02|0x8|0x20, 0666,0); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
849 fostream.write( xml,xml.length ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
850 fostream.close(); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
851 } catch(e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
852 alert(fname+" does not exist"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
853 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
854 } |
358 | 855 |
371 | 856 function system_mkdir(path) |
857 { | |
858 try { | |
859 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
860 } catch (e) { | |
861 alert("Permission to read file was denied."); | |
862 } | |
863 var file = Components.classes["@mozilla.org/file/local;1"] | |
864 .createInstance(Components.interfaces.nsILocalFile); | |
865 try { | |
866 file.initWithPath(path); | |
867 if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create | |
868 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777); | |
869 } | |
870 } catch(e) { | |
871 alert('Failed to create directopry '+path+e); | |
872 } | |
873 } | |
874 | |
875 function getPathDirectory(path) | |
876 { | |
877 var s = path.lastIndexOf('/'); | |
878 if (s == -1) | |
879 return ''; | |
880 else | |
881 return path.substr(0,s); | |
882 } | |
883 | |
358 | 884 function project_loadFile() |
885 { | |
886 prjname = $('#mbsvg').attr('value'); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
887 project_name = prjname; |
371 | 888 project_dir = getPathDirectory(prjname); |
358 | 889 var prj = system_read(prjname); |
890 project_parse(prj); | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
891 filedialog.dialog('close'); |
358 | 892 } |
893 | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
894 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
895 function project_save() |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
896 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
897 var i; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
898 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
899 var xml = "<project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
900 var scenes = $('#scenes'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
901 var sources = $('#sources'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
902 var list = project_tree.getJSON(scenes); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
903 var len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
904 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
905 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
906 xml = xml + "\t<scene src='"+list.children[i].data+"' />\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
907 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
908 list = project_tree.getJSON(sources); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
909 len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
910 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
911 xml = xml + "\t<source src='"+list.children[i].data+"' />\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
912 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
913 xml = xml + "</project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
914 system_write(project_name,xml); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
915 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
916 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
917 |
367 | 918 |
919 function onLoadProject(path) | |
920 { | |
921 project_name = path; | |
371 | 922 project_dir = getPathDirectory(project_name); |
367 | 923 var prj = system_read(project_name); |
924 project_parse(prj); | |
925 } | |
926 | |
358 | 927 var last_select = null; |
367 | 928 var wizard = new Wizard(); |
929 wizard.cb = onLoadProject; | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
930 $('#filedialog').dialog({ width:500}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
931 jQuery(document).ready(function() { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
932 filedialog = jQuery('#filedialog'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
933 filedialog.dialog({width:500, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
934 modal: true, |
367 | 935 autoOpen:false, |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
936 title:'Please select a file'}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
937 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
938 filedialog.html('Please select the project file<br>'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
939 filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
940 filedialog.append('<input type=button value="Load" onclick="project_loadFile()">'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
941 filedialog.dialog("open"); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
942 }); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
943 |
376
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
944 $('#frame').draggable(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
945 $('#btns').draggable({cursor:'crosshair'}); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
946 $('#list').tabs(); |
7d244a85dd68
Change the screen layout to make it more like an usual IDE.
wycc
parents:
371
diff
changeset
|
947 $('#display').tabs(); |