comparison inkscape/firefox/content/inkscape.js @ 376:7d244a85dd68

Change the screen layout to make it more like an usual IDE.
author wycc
date Sat, 04 Apr 2009 06:12:10 +0800
parents 3d21115297ba
children 29145d2affdb
comparison
equal deleted inserted replaced
371:3d21115297ba 376:7d244a85dd68
68 */ 68 */
69 69
70 function TextEditor(file) 70 function TextEditor(file)
71 { 71 {
72 var editor = document.getElementById('inkscape'); 72 var editor = document.getElementById('inkscape');
73 editor.innerHTML = "<embed src="+file+" width=700 height=700 />"; 73 editor.innerHTML = "<embed src="+file+" width=900 height=700 />";
74 this.isInProgress = 0; 74 this.isInProgress = 0;
75 } 75 }
76 76
77 /** 77 /**
78 * Inkscape class 78 * Inkscape class
79 * 79 *
80 */ 80 */
81 function Inkscape(file) 81 function Inkscape(file)
82 { 82 {
83 var ink = document.getElementById('inkscape'); 83 var ink = document.getElementById('inkscape');
84 ink.innerHTML = "<embed src="+file+" width=700 height=700 />"; 84 ink.innerHTML = "<embed src="+file+" width=900 height=700 />";
85 this.isInProgress = 0; 85 this.isInProgress = 0;
86 this.callback = null;
86 87
87 setTimeout("inkscape.fetchDocument()",4000); 88 setTimeout("inkscape.fetchDocument()",4000);
88 } 89 }
89 90
90 Inkscape.prototype.gotoScene = function (n) 91 Inkscape.prototype.gotoScene = function (n)
120 } 121 }
121 Inkscape.prototype.publishDocument= function(resp) 122 Inkscape.prototype.publishDocument= function(resp)
122 { 123 {
123 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text); 124 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text);
124 mbsvg.renderUI(); 125 mbsvg.renderUI();
126 if (this.callback)
127 this.callback(mbsvg);
125 128
126 var soapBody = new SOAPObject("PUBLISH"); 129 var soapBody = new SOAPObject("PUBLISH");
127 var sr = new SOAPRequest("PUBLISH", soapBody); 130 var sr = new SOAPRequest("PUBLISH", soapBody);
128 SOAPClient.Proxy = "http://localhost:19192/"; 131 SOAPClient.Proxy = "http://localhost:19192/";
129 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this); 132 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this);
213 var sr = new SOAPRequest("EXTENDSCENE", soapBody); 216 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
214 SOAPClient.Proxy = "http://localhost:19192/"; 217 SOAPClient.Proxy = "http://localhost:19192/";
215 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this); 218 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
216 } 219 }
217 220
218 Inkscape.prototype.fetchDocument = function() 221 Inkscape.prototype.fetchDocument = function(callback)
219 { 222 {
220 var soapBody = new SOAPObject("START"); 223 var soapBody = new SOAPObject("START");
224 this.callback = callback
221 var sr = new SOAPRequest("START", soapBody); 225 var sr = new SOAPRequest("START", soapBody);
222 SOAPClient.Proxy = "http://localhost:19192/"; 226 SOAPClient.Proxy = "http://localhost:19192/";
223 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this); 227 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this);
224 this.isInProgress++; 228 this.isInProgress++;
225 } 229 }
226 230
227 231 /*
232 * 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
233 * 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.
234 *
235 */
236
237 Inkscape.prototype.MakeSymbol=function()
238 {
239 function callback(mbsvg) {
240 this.loadSymbolScreen(mbsvg);
241 }
242 inkscape.fetchDocument(callback);
243 }
244
245 Inkscape.prototype.loadSymbolScreen=function (mbsvg) {
246 // Swap the left side to be the SVG element tree.
247 var i,l;
248
249 symboldialog.dialog('open');
250 l = mbsvg.selected_objects.length;
251 var jsonobj = []
252 for(i=0;i<l;i++) {
253 // Add symbol into the tree
254 var obj = { attributes: {id: 'sym'+i}, data : mbsvg.selected_objects[i]};
255 jsonobj.push(obj);
256 }
257 this.symboltree = $.tree_create();
258 this.symboltree.init($("#symbollist"), {
259 data: {
260 type: "json",
261 json : jsonobj
262 },
263 callback : {
264 ondblclk : function(NODE,TREE_OBJ) { this.refreshSymbolPanel(TREE_OBJ); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);}
265 }
266
267 });
268 // Swap the right side to be the symbol editor screen.
269 symboldialog.show();
270 }
271
272 jQuery(document).ready(function() {
273 symboldialog = jQuery('#symboldialog');
274 symboldialog.dialog({width:500,
275 modal: true,
276 autoOpen:false,
277 title:'Please select a file'});
278 symboldialog.hide();
279 symboldialog.append("<div id='symbollist'>");
280 symboldialog.append("<div id='symbol'>");
281 });
228 282
229 function MBSVG(file) 283 function MBSVG(file)
230 { 284 {
231 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null); 285 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null);
232 xmlDoc.async=false; 286 xmlDoc.async=false;
269 ss.end = end; 323 ss.end = end;
270 ss.ref = ref; 324 ss.ref = ref;
271 ss.layer = null; 325 ss.layer = null;
272 scenes.push(ss); 326 scenes.push(ss);
273 } 327 }
274 if (max < 20) max = 20; 328 if (max < 20) max = 30;
275 // Collect all layers 329 // Collect all layers
276 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes; 330 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes;
277 var layers = new Array(); 331 var layers = new Array();
278 len = nodes.length; 332 len = nodes.length;
279 for(i=0;i<len;i++) { 333 for(i=0;i<len;i++) {
290 } 344 }
291 } 345 }
292 layers.push(nodes[i]); 346 layers.push(nodes[i]);
293 } 347 }
294 } 348 }
349 var select = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","select");
350 len = select.length;
351 selectobjs = [];
352 for(i=0;i<len;i++) {
353 selectobjs.push(select[i].getAttribute('ref'));
354 }
355 self.selected_objects = selectobjs;
295 self.layers = layers; 356 self.layers = layers;
296 self.scenes = scenes; 357 self.scenes = scenes;
297 self.maxframe = max; 358 self.maxframe = max;
359 self.doc = xmlDoc;
298 } 360 }
299 361
300 MBSVGString.prototype=MBSVG.prototype; 362 MBSVGString.prototype=MBSVG.prototype;
301 MBSVG.prototype.renderUI=function() 363 MBSVG.prototype.renderUI=function()
302 { 364 {
303 var layers = this.layers; 365 var layers = this.layers;
304 var scenes = this.scenes; 366 var scenes = this.scenes;
305 var max = this.maxframe; 367 var max = this.maxframe;
306 var cmd = "<table border=1>\n"; 368 var cmd = "<table border=0>\n";
307 cmd = cmd + "<tr><td></td>"; 369 cmd = cmd + "<tr><td></td>";
308 for(var j=1;j<=max;j++) 370 for(var j=1;j<=max;j++)
309 cmd = cmd + "<td>"+j+"</td>"; 371 cmd = cmd + "<td>"+j+"</td>";
310 372
311 for(var i=layers.length-1;i>=0;i--) { 373 for(var i=layers.length-1;i>=0;i--) {
318 var n = j +1; 380 var n = j +1;
319 var id_str = id+"#"+n 381 var id_str = id+"#"+n
320 for(var k=0;k<scenes.length;k++) { 382 for(var k=0;k<scenes.length;k++) {
321 if (id != scenes[k].layer) continue; 383 if (id != scenes[k].layer) continue;
322 if (n == scenes[k].start) { 384 if (n == scenes[k].start) {
323 cmd = cmd + "<td><img class='normal' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>"; 385 cmd = cmd + "<td><img class='normal' width='16' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
324 empty = 0; 386 empty = 0;
325 break; 387 break;
326 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) { 388 } 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>"; 389 cmd = cmd + "<td><img class='normal' width='16' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
328 empty = 0; 390 empty = 0;
329 break; 391 break;
330 } 392 }
331 } 393 }
332 if (empty) { 394 if (empty) {
333 cmd = cmd + "<td><img class='normal' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>"; 395 cmd = cmd + "<td><img class='normal' width='16' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>";
334 } 396 }
335 397
336 } 398 }
337 cmd = cmd + "</tr>\n"; 399 cmd = cmd + "</tr>\n";
338 } 400 }
387 if (inkscape.isInProgress != 0) return; 449 if (inkscape.isInProgress != 0) return;
388 inkscape.extendScene(currentScene); 450 inkscape.extendScene(currentScene);
389 } else if (id == 'DeleteScene') { 451 } else if (id == 'DeleteScene') {
390 if (inkscape.isInProgress != 0) return; 452 if (inkscape.isInProgress != 0) return;
391 inkscape.deleteScene(currentScene); 453 inkscape.deleteScene(currentScene);
454 } else if (id == 'MakeSymbol') {
455 if (inkscape.isInProgress != 0) return;
456 inkscape.MakeSymbol();
392 } else if (id == 'Save') { 457 } else if (id == 'Save') {
393 project_save(); 458 project_save();
459 } else if (id == 'Test') {
460 if (project_compile()) {
461 project_run();
462 } else {
463 }
394 } else { 464 } else {
395 alert(id+' has not been implemented yet'); 465 alert(id+' has not been implemented yet');
396 } 466 }
397 } 467 }
398 468
454 src2 = {attributes:{id:"src1"},data:"src2.c"}; 524 src2 = {attributes:{id:"src1"},data:"src2.c"};
455 src3 = {attributes:{id:"src1"},data:"src3.c"}; 525 src3 = {attributes:{id:"src1"},data:"src3.c"};
456 526
457 sources = [src1,src2,src3]; 527 sources = [src1,src2,src3];
458 528
529 }
530
531 function project_compile()
532 {
459 } 533 }
460 534
461 535
462 function project_showFile(node) 536 function project_showFile(node)
463 { 537 {
805 filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">'); 879 filedialog.append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
806 filedialog.append('<input type=button value="Load" onclick="project_loadFile()">'); 880 filedialog.append('<input type=button value="Load" onclick="project_loadFile()">');
807 filedialog.dialog("open"); 881 filedialog.dialog("open");
808 }); 882 });
809 883
810 884 $('#frame').draggable();
885 $('#btns').draggable({cursor:'crosshair'});
886 $('#list').tabs();
887 $('#display').tabs();