Mercurial > MadButterfly
annotate inkscape/firefox/content/inkscape.js @ 371:3d21115297ba
Add textmenu template
author | wycc |
---|---|
date | Tue, 17 Mar 2009 08:31:04 +0800 |
parents | e21e9447f545 |
children | 7d244a85dd68 |
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; | |
371 | 475 if (file.substr(0,1) == '/') |
476 inkscape = new Inkscape("file://"+file); | |
477 else | |
478 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
|
479 } |
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 |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
482 function project_loadEditor(node) |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
483 { |
8c4456190d9a
Add text editor support to edit C source file inside the MadBuilder
wycc
parents:
359
diff
changeset
|
484 var file = node.textContent; |
371 | 485 if (file.substr(0,1) == '/') |
486 editor = new TextEditor("file://"+file); | |
487 else | |
488 editor = new TextEditor("file://"+project_dir+'/'+file); | |
359 | 489 } |
490 | |
358 | 491 function project_parse(xml) |
492 { | |
493 | |
494 var xmlParser = new DOMParser(); | |
495 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml'); | |
496 var scenesNode = xmlDoc.getElementsByTagName("scene"); | |
497 if (scenesNode == null) { | |
498 alert('This is not a valid scene file'); | |
499 } | |
500 var len = scenesNode.length; | |
501 var i,j; | |
502 var max = 0; | |
503 var scenes = new Array(); | |
504 | |
505 // Get the length of scenes | |
506 for(i=0;i<len;i++) { | |
507 var n = scenesNode[i]; | |
508 var s = new Object(); | |
509 s.attributes = new Object(); | |
510 s.attributes.id = "scene"+i; | |
511 s.state = "open"; | |
512 s.data = n.getAttribute("src"); | |
513 scenes.push(s); | |
514 } | |
515 | |
516 var nodes = xmlDoc.getElementsByTagName("source"); | |
517 var len = nodes.length; | |
518 var i,j; | |
519 var max = 0; | |
520 var sources = []; | |
521 | |
522 // Get the length of scenes | |
523 for(i=0;i<len;i++) { | |
524 var n = nodes[i]; | |
525 var s = new Object(); | |
526 s.attributes = new Object(); | |
527 s.attributes.id = "sources"+i; | |
528 s.state = "open"; | |
529 s.data = n.getAttribute("src"); | |
530 sources.push(s); | |
531 } | |
532 | |
533 var tree = $.tree_create(); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
534 project_tree = tree; |
358 | 535 tree.init($("#filelist"), { |
536 data: { | |
537 type: "json", | |
538 json : [ | |
539 { | |
540 attributes: {id: "prj"}, | |
541 state: "open", | |
542 data: "Project", | |
543 children: [ | |
544 { attributes:{id:"scenes"}, data:"scene", children: scenes}, | |
545 { attributes:{id:"sources"},data:"sources",children: sources} | |
546 ] | |
547 } | |
548 ], | |
549 }, | |
359 | 550 callback : { |
362 | 551 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 | 552 }, |
358 | 553 ui : { |
357 | 554 context : [ |
555 { | |
556 id: "Open", | |
557 label: "Open", | |
558 icon: "open.png", | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
559 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
|
560 action: function(NODE,TREE_OBJ) { onTree_openFile(NODE,TREE_OBJ);} |
357 | 561 }, |
562 { | |
563 id: "New", | |
564 label: "New", | |
565 icon: "create.png", | |
566 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
567 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
568 }, | |
569 { | |
570 id: "Rename", | |
571 label: "Rename", | |
572 icon: "rename.png", | |
573 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";}, | |
574 action: function(NODE,TREE_OBJ) { alert("open is not support yet");} | |
358 | 575 } |
357 | 576 ] |
358 | 577 } |
578 | |
579 }); | |
580 } | |
357 | 581 |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
582 function fileDialog_cb() |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
583 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
584 var file = $('#filedialogsrc').attr('value'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
585 filedialog.dialog('close'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
586 filedialog_cb(file,filedialog_arg); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
587 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
588 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
589 function openFileDialog(callback,arg) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
590 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
591 filedialog_cb = callback; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
592 filedialog_arg = arg; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
593 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
|
594 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
|
595 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
|
596 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
597 filedialog.dialog('open'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
598 } |
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 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
601 function project_addScene(file,treeobj) |
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 if (file == '') { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
604 return; |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
605 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
606 treeobj.create(false,treeobj.selected,file); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
607 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
608 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
609 function onTree_addSceneFile(node,treeobj) |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
610 { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
611 openFileDialog(project_addScene,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
612 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
613 |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
614 function project_addSource(file,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
615 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
616 treeobj.create(false,treeobj.selected,file); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
617 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
618 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
619 function onTree_addSourceFile(node,treeobj) |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
620 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
621 openFileDialog(project_addSource,treeobj); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
622 } |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
623 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
624 function onTree_openFile(node,treeobj) |
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 if (node[0].id == "scenes") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
627 onTree_addSceneFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
628 } else if (node[0].id == "sources") { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
629 onTree_addSourceFile(node,treeobj); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
630 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
631 } |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
632 |
367 | 633 function system_open_read(fname) { |
634 try { | |
635 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
636 } catch (e) { | |
637 alert("Permission to read file was denied."); | |
638 } | |
639 var file = Components.classes["@mozilla.org/file/local;1"] | |
640 .createInstance(Components.interfaces.nsILocalFile); | |
641 try { | |
642 file.initWithPath( fname ); | |
643 if ( file.exists() == false ) { | |
644 alert("File does not exist"); | |
645 } | |
646 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
647 .createInstance( Components.interfaces.nsIFileInputStream ); | |
648 is.init( file,0x01, 00004, null); | |
649 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
650 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
651 sis.init( is ); | |
652 } catch(e) { | |
653 alert(fname+" does not exist"); | |
654 } | |
655 return sis; | |
656 } | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
657 |
358 | 658 function system_read(fname) { |
659 try { | |
660 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
661 } catch (e) { | |
662 alert("Permission to read file was denied."); | |
663 } | |
664 var file = Components.classes["@mozilla.org/file/local;1"] | |
665 .createInstance(Components.interfaces.nsILocalFile); | |
666 try { | |
667 file.initWithPath( fname ); | |
668 if ( file.exists() == false ) { | |
669 alert("File does not exist"); | |
670 } | |
671 var is = Components.classes["@mozilla.org/network/file-input-stream;1"] | |
672 .createInstance( Components.interfaces.nsIFileInputStream ); | |
673 is.init( file,0x01, 00004, null); | |
674 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"] | |
675 .createInstance( Components.interfaces.nsIScriptableInputStream ); | |
676 sis.init( is ); | |
677 var output = sis.read( sis.available() ); | |
678 sis.close(); | |
679 } catch(e) { | |
680 alert(fname+" does not exist"); | |
681 } | |
682 return output; | |
357 | 683 } |
367 | 684 function system_open_write(fname) { |
685 try { | |
686 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
687 } catch (e) { | |
688 alert("Permission to read file was denied."); | |
689 } | |
690 var file = Components.classes["@mozilla.org/file/local;1"] | |
691 .createInstance(Components.interfaces.nsILocalFile); | |
692 try { | |
693 file.initWithPath( fname ); | |
694 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"] | |
695 .createInstance( Components.interfaces.nsIFileOutputStream ); | |
696 fostream.init( file,0x02|0x8|0x20, 0666,0); | |
697 } catch(e) { | |
371 | 698 alert('can not create '+fname); |
367 | 699 } |
700 return fostream; | |
701 } | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
702 function system_write(fname,xml) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
703 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
704 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
705 } catch (e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
706 alert("Permission to read file was denied."); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
707 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
708 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
|
709 .createInstance(Components.interfaces.nsILocalFile); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
710 try { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
711 file.initWithPath( fname ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
712 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
|
713 .createInstance( Components.interfaces.nsIFileOutputStream ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
714 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
|
715 fostream.write( xml,xml.length ); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
716 fostream.close(); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
717 } catch(e) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
718 alert(fname+" does not exist"); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
719 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
720 } |
358 | 721 |
371 | 722 function system_mkdir(path) |
723 { | |
724 try { | |
725 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); | |
726 } catch (e) { | |
727 alert("Permission to read file was denied."); | |
728 } | |
729 var file = Components.classes["@mozilla.org/file/local;1"] | |
730 .createInstance(Components.interfaces.nsILocalFile); | |
731 try { | |
732 file.initWithPath(path); | |
733 if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create | |
734 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777); | |
735 } | |
736 } catch(e) { | |
737 alert('Failed to create directopry '+path+e); | |
738 } | |
739 } | |
740 | |
741 function getPathDirectory(path) | |
742 { | |
743 var s = path.lastIndexOf('/'); | |
744 if (s == -1) | |
745 return ''; | |
746 else | |
747 return path.substr(0,s); | |
748 } | |
749 | |
358 | 750 function project_loadFile() |
751 { | |
752 prjname = $('#mbsvg').attr('value'); | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
753 project_name = prjname; |
371 | 754 project_dir = getPathDirectory(prjname); |
358 | 755 var prj = system_read(prjname); |
756 project_parse(prj); | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
757 filedialog.dialog('close'); |
358 | 758 } |
759 | |
365
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
760 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
761 function project_save() |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
762 { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
763 var i; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
764 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
765 var xml = "<project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
766 var scenes = $('#scenes'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
767 var sources = $('#sources'); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
768 var list = project_tree.getJSON(scenes); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
769 var len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
770 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
771 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
772 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
|
773 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
774 list = project_tree.getJSON(sources); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
775 len = list.children.length; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
776 for(i=0;i<len;i++) { |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
777 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
|
778 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
779 xml = xml + "</project>\n"; |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
780 system_write(project_name,xml); |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
781 |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
782 } |
6adb28388132
Add capability to add new scene and source into the project
wycc
parents:
364
diff
changeset
|
783 |
367 | 784 |
785 function onLoadProject(path) | |
786 { | |
787 project_name = path; | |
371 | 788 project_dir = getPathDirectory(project_name); |
367 | 789 var prj = system_read(project_name); |
790 project_parse(prj); | |
791 } | |
792 | |
358 | 793 var last_select = null; |
367 | 794 var wizard = new Wizard(); |
795 wizard.cb = onLoadProject; | |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
796 $('#filedialog').dialog({ width:500}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
797 jQuery(document).ready(function() { |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
798 filedialog = jQuery('#filedialog'); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
799 filedialog.dialog({width:500, |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
800 modal: true, |
367 | 801 autoOpen:false, |
364
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
802 title:'Please select a file'}); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
803 filedialog.show(); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
804 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
|
805 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
|
806 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
|
807 filedialog.dialog("open"); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
808 }); |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
809 |
a373b4743e63
Add file dialog to add a new scene file into the project.
wycc
parents:
362
diff
changeset
|
810 |