Mercurial > MadButterfly
annotate inkscape/firefox/content/inkscape.js @ 365:6adb28388132
Add capability to add new scene and source into the project
Add Save button to save the project.
author | wycc |
---|---|
date | Sat, 14 Mar 2009 16:42:37 +0800 |
parents | a373b4743e63 |
children | e21e9447f545 |
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'); |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
73 editor.innerHTML = "<embed src="+file+" width=700 height=700 />"; |
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'); | |
352 | 84 ink.innerHTML = "<embed src="+file+" width=700 height=700 />"; |
288 | 85 this.isInProgress = 0; |
86 | |
87 setTimeout("inkscape.fetchDocument()",4000); | |
88 } | |
89 | |
90 Inkscape.prototype.gotoScene = function (n) | |
91 { | |
92 nextScene = n; | |
93 var soapBody = new SOAPObject("START"); | |
94 var sr = new SOAPRequest("START", soapBody); | |
95 SOAPClient.Proxy = "http://localhost:19192/"; | |
96 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene1(resp);},this); | |
97 this.isInProgress++; | |
98 } | |
99 Inkscape.prototype.gotoScene1 = function (resp,n) | |
100 { | |
101 var soapBody = new SOAPObject("SCENE"); | |
102 var v1 = new SOAPObject("v1"); | |
103 v1.val(nextScene); | |
104 soapBody.appendChild(v1); | |
105 var sr = new SOAPRequest("SCENE", soapBody); | |
106 SOAPClient.Proxy = "http://localhost:19192/"; | |
107 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene2(resp);},this); | |
108 } | |
109 Inkscape.prototype.gotoScene2 = function (resp) | |
110 { | |
111 var soapBody = new SOAPObject("PUBLISH"); | |
112 var sr = new SOAPRequest("PUBLISH", soapBody); | |
113 SOAPClient.Proxy = "http://localhost:19192/"; | |
114 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene3(resp);},this); | |
115 } | |
116 | |
117 Inkscape.prototype.gotoScene3 = function (resp) | |
118 { | |
119 this.isInProgress--; | |
120 } | |
121 Inkscape.prototype.publishDocument= function(resp) | |
122 { | |
123 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text); | |
124 mbsvg.renderUI(); | |
125 | |
126 var soapBody = new SOAPObject("PUBLISH"); | |
127 var sr = new SOAPRequest("PUBLISH", soapBody); | |
128 SOAPClient.Proxy = "http://localhost:19192/"; | |
129 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this); | |
130 } | |
131 | |
132 Inkscape.prototype.refreshDocument = function(resp) | |
133 { | |
134 var soapBody = new SOAPObject("GETDOC"); | |
135 var sr = new SOAPRequest("GETDOC", soapBody); | |
136 SOAPClient.Proxy = "http://localhost:19192/"; | |
137 SOAPClient.SendRequest(sr, function(resp,arg) { arg.publishDocument(resp);},this); | |
138 } | |
139 | |
140 Inkscape.prototype.operationDone = function (res) | |
141 { | |
142 this.isInProgress--; | |
143 } | |
144 Inkscape.prototype.insertKey= function(n) | |
145 { | |
146 nextScene = n; | |
147 var soapBody = new SOAPObject("START"); | |
148 var sr = new SOAPRequest("START", soapBody); | |
149 SOAPClient.Proxy = "http://localhost:19192/"; | |
150 SOAPClient.SendRequest(sr, function (resp,arg) {arg.insertKey1(resp);},this); | |
151 this.isInProgress++; | |
152 } | |
153 Inkscape.prototype.insertKey1 = function(resp) | |
154 { | |
155 var soapBody = new SOAPObject("INSERTKEY"); | |
156 var v1 = new SOAPObject("v1"); | |
157 v1.attr('type','string'); | |
158 v1.val(currentLayer); | |
159 soapBody.appendChild(v1); | |
160 var v2 = new SOAPObject("v2"); | |
161 v2.val(nextScene); | |
162 soapBody.appendChild(v2); | |
163 var sr = new SOAPRequest("INSERTKEY", soapBody); | |
164 SOAPClient.Proxy = "http://localhost:19192/"; | |
165 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
166 } | |
167 | |
168 Inkscape.prototype.extendScene=function() | |
169 { | |
170 var soapBody = new SOAPObject("START"); | |
171 var sr = new SOAPRequest("START", soapBody); | |
172 SOAPClient.Proxy = "http://localhost:19192/"; | |
173 SOAPClient.SendRequest(sr, function (resp,arg) {arg.extendScene1(resp);},this); | |
174 this.isInProgress++; | |
175 } | |
176 | |
177 | |
178 Inkscape.prototype.extendScene1 = function(resp) | |
179 { | |
180 var soapBody = new SOAPObject("EXTENDSCENE"); | |
181 var v1 = new SOAPObject("v1"); | |
182 v1.attr('type','string'); | |
183 v1.val(currentLayer); | |
184 soapBody.appendChild(v1); | |
185 var v2 = new SOAPObject("v2"); | |
186 v2.val(currentScene); | |
187 soapBody.appendChild(v2); | |
188 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
189 SOAPClient.Proxy = "http://localhost:19192/"; | |
190 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
191 } | |
192 | |
193 | |
194 Inkscape.prototype.deleteScene=function() | |
195 { | |
196 var soapBody = new SOAPObject("START"); | |
197 var sr = new SOAPRequest("START", soapBody); | |
198 SOAPClient.Proxy = "http://localhost:19192/"; | |
199 SOAPClient.SendRequest(sr, function (resp,arg) {arg.deleteScene1(resp);},this); | |
200 this.isInProgress++; | |
201 } | |
202 | |
203 Inkscape.prototype.deleteScene1=function(resp) | |
204 { | |
205 var soapBody = new SOAPObject("DELETESCENE"); | |
206 var v1 = new SOAPObject("v1"); | |
207 v1.attr('type','string'); | |
208 v1.val(currentLayer); | |
209 soapBody.appendChild(v1); | |
210 var v2 = new SOAPObject("v2"); | |
211 v2.val(currentScene); | |
212 soapBody.appendChild(v2); | |
213 var sr = new SOAPRequest("EXTENDSCENE", soapBody); | |
214 SOAPClient.Proxy = "http://localhost:19192/"; | |
215 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); | |
216 } | |
217 | |
218 Inkscape.prototype.fetchDocument = function() | |
219 { | |
220 var soapBody = new SOAPObject("START"); | |
221 var sr = new SOAPRequest("START", soapBody); | |
222 SOAPClient.Proxy = "http://localhost:19192/"; | |
223 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this); | |
224 this.isInProgress++; | |
225 } | |
226 | |
227 | |
228 | |
229 function MBSVG(file) | |
230 { | |
231 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null); | |
232 xmlDoc.async=false; | |
233 xmlDoc.load(file); | |
234 MBSVG_loadFromDoc(this,xmlDoc); | |
235 | |
236 } | |
237 function MBSVGString(xml) | |
238 { | |
239 var xmlParser = new DOMParser(); | |
240 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
241 MBSVG_loadFromDoc(this,xmlDoc); | |
242 } | |
243 | |
244 | |
245 | |
246 function MBSVG_loadFromDoc(self,xmlDoc) | |
247 { | |
248 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene"); | |
249 if (scenesNode == null) { | |
250 alert('This is not a valid scene file'); | |
251 } | |
252 var len = scenesNode.length; | |
253 var i,j; | |
254 var max = 0; | |
255 var scenes = new Array(); | |
256 | |
257 // Get the length of scenes | |
258 for(i=0;i<len;i++) { | |
259 var s = scenesNode[i]; | |
260 var start = s.getAttribute("start"); | |
261 var end = s.getAttribute("end"); | |
262 var ref = s.getAttribute("ref"); | |
263 var ss = new Object(); | |
264 | |
265 if (end == null) end = start | |
266 if (max <end) max = end; | |
267 ss.node = s; | |
268 ss.start = start; | |
269 ss.end = end; | |
270 ss.ref = ref; | |
271 ss.layer = null; | |
272 scenes.push(ss); | |
273 } | |
274 if (max < 20) max = 20; | |
275 // Collect all layers | |
276 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes; | |
277 var layers = new Array(); | |
278 len = nodes.length; | |
279 for(i=0;i<len;i++) { | |
280 if (nodes[i].localName == 'g') { | |
281 var subnodes = nodes[i].childNodes; | |
282 for(j=0;j<subnodes.length;j++) { | |
283 if (subnodes[j].localName == 'g') { | |
284 for(var k=0;k<scenes.length;k++) { | |
285 if (scenes[k].ref == subnodes[j].getAttribute('id')) { | |
286 scenes[k].layer = nodes[i].getAttribute('id'); | |
287 break; | |
288 } | |
289 } | |
290 } | |
291 } | |
292 layers.push(nodes[i]); | |
293 } | |
294 } | |
295 self.layers = layers; | |
296 self.scenes = scenes; | |
297 self.maxframe = max; | |
298 } | |
299 | |
300 MBSVGString.prototype=MBSVG.prototype; | |
301 MBSVG.prototype.renderUI=function() | |
302 { | |
303 var layers = this.layers; | |
304 var scenes = this.scenes; | |
305 var max = this.maxframe; | |
306 var cmd = "<table border=1>\n"; | |
307 cmd = cmd + "<tr><td></td>"; | |
308 for(var j=1;j<=max;j++) | |
309 cmd = cmd + "<td>"+j+"</td>"; | |
310 | |
311 for(var i=layers.length-1;i>=0;i--) { | |
312 var l = layers[i]; | |
313 var id = l.getAttribute('id'); | |
314 var label = l.getAttribute('inkscape:label'); | |
315 cmd = cmd + "<tr><td>"+label+"</td>"; | |
316 for(j=0;j<max;j++) { | |
317 var empty = 1; | |
318 var n = j +1; | |
319 var id_str = id+"#"+n | |
320 for(var k=0;k<scenes.length;k++) { | |
321 if (id != scenes[k].layer) continue; | |
322 if (n == scenes[k].start) { | |
323 cmd = cmd + "<td><img class='normal' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; | |
324 empty = 0; | |
325 break; | |
326 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { | |
327 cmd = cmd + "<td><img class='normal' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; | |
328 empty = 0; | |
329 break; | |
330 } | |
331 } | |
332 if (empty) { | |
333 cmd = cmd + "<td><img class='normal' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>"; | |
334 } | |
335 | |
336 } | |
337 cmd = cmd + "</tr>\n"; | |
338 } | |
339 cmd = cmd + "</table>\n"; | |
340 var frame = document.getElementById('frame'); | |
341 frame.innerHTML=cmd; | |
342 } | |
343 | |
344 | |
345 | |
346 /** | |
347 * UI for madbuilder.html to build the scene editor | |
348 */ | |
349 | |
350 function selectCell(obj) | |
351 { | |
352 var id = obj.getAttribute('id'); | |
353 var layer,n; | |
354 var f = id.split('#'); | |
355 layer=f[0]; | |
356 n = f[1]; | |
357 var img = obj.getAttribute('src'); | |
358 var f = img.split('-'); | |
359 | |
360 if (f[0] == 'active') | |
361 return; | |
362 else { | |
363 obj.setAttribute('src', 'active-'+img); | |
364 } | |
365 | |
366 if (last_select != null) { | |
367 f = last_select.getAttribute('src').split('-'); | |
368 last_select.setAttribute('src', f[1]); | |
369 } | |
370 last_select = obj; | |
371 currentScene = n; | |
372 currentLayer = layer; | |
373 } | |
374 | |
375 | |
376 function onButtonClick(obj) | |
377 { | |
378 var id = obj.getAttribute('id'); | |
379 if (id == 'Jump') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
380 if (inkscape.isInProgress != 0) return; |
288 | 381 if (currentScene != 0) |
382 inkscape.gotoScene(currentScene); | |
383 } else if (id == 'InsertKey') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
384 if (inkscape.isInProgress != 0) return; |
288 | 385 inkscape.insertKey(currentScene); |
386 } else if (id == 'ExtendScene') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
387 if (inkscape.isInProgress != 0) return; |
288 | 388 inkscape.extendScene(currentScene); |
389 } else if (id == 'DeleteScene') { | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
390 if (inkscape.isInProgress != 0) return; |
288 | 391 inkscape.deleteScene(currentScene); |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
392 } else if (id == 'Save') { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
393 project_save(); |
288 | 394 } else { |
395 alert(id+' has not been implemented yet'); | |
396 } | |
397 } | |
398 | |
399 function gotoScene_cb(resObj) | |
400 { | |
401 | |
402 } | |
403 var nextScene; | |
404 var currentScene = 0; | |
405 var currentLayer = ''; | |
406 | |
357 | 407 |
408 function dump(n) | |
409 { | |
410 cmd = ""; | |
411 for(k in n) { | |
412 cmd = cmd + k+"="+n[k]+"\n"; | |
413 } | |
414 alert(cmd); | |
415 } | |
288 | 416 |
417 | |
358 | 418 |
357 | 419 |
420 | |
421 | |
358 | 422 function loadInkscapeFile() |
357 | 423 { |
424 ele = $('#mbsvg'); | |
425 file = ele.attr('value'); | |
426 inkscape = new Inkscape("file://"+file); | |
427 | |
352 | 428 file1_animation = [ |
429 { | |
430 attributes: {id:"an1-1"}, | |
431 data: "animation1" | |
432 }, | |
433 { | |
434 attributes: {id:"an1-2"}, | |
435 data: "animation2" | |
436 } | |
437 ]; | |
438 file1 = { | |
439 attributes:{id:"file1"}, | |
440 data: "scene1.mbsvg", | |
441 children: file1_animation | |
442 }; | |
443 file2 = { | |
444 attributes:{id:"file2"}, | |
445 data: "scene2.mbsvg", | |
446 }; | |
447 file3 = { | |
448 attributes:{id:"file3"}, | |
449 data: "scene3.mbsvg", | |
450 }; | |
451 | |
452 scenes = [ file1,file2,file3]; | |
453 src1 = {attributes:{id:"src1"},data:"src1.c"}; | |
454 src2 = {attributes:{id:"src1"},data:"src2.c"}; | |
455 src3 = {attributes:{id:"src1"},data:"src3.c"}; | |
456 | |
457 sources = [src1,src2,src3]; | |
458 | |
358 | 459 } |
460 | |
461 | |
362 | 462 function project_showFile(node) |
463 { | |
464 var file = node.textContent; | |
465 if (endsWith(file,"mbsvg")) { | |
466 project_loadScene(node); | |
467 } else { | |
468 project_loadEditor(node); | |
469 } | |
470 | |
471 } | |
359 | 472 function project_loadScene(node) |
473 { | |
474 var file = node.textContent; | |
475 inkscape = new Inkscape("file://"+file); | |
361
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
476 } |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
477 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
478 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
479 function project_loadEditor(node) |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
480 { |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
481 var file = node.textContent; |
362 | 482 editor = new TextEditor("file://"+file); |
359 | 483 } |
484 | |
358 | 485 function project_parse(xml) |
486 { | |
487 | |
488 var xmlParser = new DOMParser(); | |
489 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
490 var scenesNode = xmlDoc.getElementsByTagName("scene"); | |
491 if (scenesNode == null) { | |
492 alert('This is not a valid scene file'); | |
493 } | |
494 var len = scenesNode.length; | |
495 var i,j; | |
496 var max = 0; | |
497 var scenes = new Array(); | |
498 | |
499 // Get the length of scenes | |
500 for(i=0;i<len;i++) { | |
501 var n = scenesNode[i]; | |
502 var s = new Object(); | |
503 s.attributes = new Object(); | |
504 s.attributes.id = "scene"+i; | |
505 s.state = "open"; | |
506 s.data = n.getAttribute("src"); | |
507 scenes.push(s); | |
508 } | |
509 | |
510 var nodes = xmlDoc.getElementsByTagName("source"); | |
511 var len = nodes.length; | |
512 var i,j; | |
513 var max = 0; | |
514 var sources = []; | |
515 | |
516 // Get the length of scenes | |
517 for(i=0;i<len;i++) { | |
518 var n = nodes[i]; | |
519 var s = new Object(); | |
520 s.attributes = new Object(); | |
521 s.attributes.id = "sources"+i; | |
522 s.state = "open"; | |
523 s.data = n.getAttribute("src"); | |
524 sources.push(s); | |
525 } | |
526 | |
527 var tree = $.tree_create(); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
528 project_tree = tree; |
358 | 529 tree.init($("#filelist"), { |
530 data: { | |
531 type: "json", | |
532 json : [ | |
533 { | |
534 attributes: {id: "prj"}, | |
535 state: "open", | |
536 data: "Project", | |
537 children: [ | |
538 { attributes:{id:"scenes"}, data:"scene", children: scenes}, | |
539 { attributes:{id:"sources"},data:"sources",children: sources} | |
540 ] | |
541 } | |
542 ], | |
543 }, | |
359 | 544 callback : { |
362 | 545 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 | 546 }, |
358 | 547 ui : { |
357 | 548 context : [ |
549 { | |
550 id: "Open", | |
551 label: "Open", | |
552 icon: "open.png", | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
553 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
|
554 action: function(NODE,TREE_OBJ) { onTree_openFile(NODE,TREE_OBJ);} |
357 | 555 }, |
556 { | |
557 id: "New", | |
558 label: "New", | |
559 icon: "create.png", | |
560 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
561 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
562 }, | |
563 { | |
564 id: "Rename", | |
565 label: "Rename", | |
566 icon: "rename.png", | |
567 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
568 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
358 | 569 } |
357 | 570 ] |
358 | 571 } |
572 | |
573 }); | |
574 } | |
357 | 575 |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
576 function fileDialog_cb() |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
577 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
578 var file = $('#filedialogsrc').attr('value'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
579 filedialog.dialog('close'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
580 filedialog_cb(file,filedialog_arg); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
581 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
582 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
583 function openFileDialog(callback,arg) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
584 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
585 filedialog_cb = callback; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
586 filedialog_arg = arg; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
587 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
|
588 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
|
589 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
|
590 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
591 filedialog.dialog('open'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
592 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
593 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
594 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
595 function project_addScene(file,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
596 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
597 if (file == '') { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
598 return; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
599 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
600 treeobj.create(false,treeobj.selected,file); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
601 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
602 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
603 function onTree_addSceneFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
604 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
605 openFileDialog(project_addScene,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
606 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
607 |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
608 function project_addSource(file,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
609 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
610 treeobj.create(false,treeobj.selected,file); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
611 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
612 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
613 function onTree_addSourceFile(node,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
614 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
615 openFileDialog(project_addSource,treeobj); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
616 } |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
617 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
618 function onTree_openFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
619 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
620 if (node[0].id == "scenes") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
621 onTree_addSceneFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
622 } else if (node[0].id == "sources") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
623 onTree_addSourceFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
624 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
625 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
626 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
627 |
358 | 628 function system_read(fname) { |
629 try { | |
630 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
631 } catch (e) { | |
632 alert("Permission to read file was denied."); | |
633 } | |
634 var file = Components.classes["@mozilla.org/file/local;1"] | |
635 .createInstance(Components.interfaces.nsILocalFile); | |
636 try { | |
637 file.initWithPath( fname ); | |
638 if ( file.exists() == false ) { | |
639 alert("File does not exist"); | |
640 } | |
641 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
642 .createInstance( Components.interfaces.nsIFileInputStream ); | |
643 is.init( file,0x01, 00004, null); | |
644 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
645 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
646 sis.init( is ); | |
647 var output = sis.read( sis.available() ); | |
648 sis.close(); | |
649 } catch(e) { | |
650 alert(fname+" does not exist"); | |
651 } | |
652 return output; | |
357 | 653 } |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
654 function system_write(fname,xml) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
655 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
656 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
657 } catch (e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
658 alert("Permission to read file was denied."); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
659 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
660 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
|
661 .createInstance(Components.interfaces.nsILocalFile); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
662 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
663 file.initWithPath( fname ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
664 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
|
665 .createInstance( Components.interfaces.nsIFileOutputStream ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
666 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
|
667 fostream.write( xml,xml.length ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
668 fostream.close(); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
669 } catch(e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
670 alert(fname+" does not exist"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
671 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
672 } |
358 | 673 |
674 function project_loadFile() | |
675 { | |
676 prjname = $('#mbsvg').attr('value'); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
677 project_name = prjname; |
358 | 678 var prj = system_read(prjname); |
679 project_parse(prj); | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
680 filedialog.dialog('close'); |
358 | 681 } |
682 | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
683 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
684 function project_save() |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
685 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
686 var i; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
687 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
688 var xml = "<project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
689 var scenes = $('#scenes'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
690 var sources = $('#sources'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
691 var list = project_tree.getJSON(scenes); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
692 var len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
693 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
694 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
695 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
|
696 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
697 list = project_tree.getJSON(sources); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
698 len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
699 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
700 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
|
701 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
702 xml = xml + "</project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
703 system_write(project_name,xml); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
704 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
705 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
706 |
358 | 707 var last_select = null; |
708 | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
709 $('#filedialog').dialog({ width:500}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
710 jQuery(document).ready(function() { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
711 filedialog = jQuery('#filedialog'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
712 filedialog.dialog({width:500, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
713 modal: true, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
714 autopen:false, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
715 title:'Please select a file'}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
716 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
717 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
|
718 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
|
719 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
|
720 filedialog.dialog("open"); |
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 |