annotate inkscape/firefox/content/inkscape.js @ 361:8c4456190d9a

Add text editor support to edit C source file inside the MadBuilder
author wycc
date Wed, 11 Mar 2009 08:51:11 +0800
parents b4bd4819091c
children 83cae12cf428
rev   line source
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
1 var isInProgress=0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
2
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
3 var MAX_DUMP_DEPTH = 10;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
4 var inkscape;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
5
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
6
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
7
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
8 function dumpObj(obj, name, indent, depth) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
9 if (depth > MAX_DUMP_DEPTH) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
10 return indent + name + ": <Maximum Depth Reached>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
11 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
12 if (typeof obj == "object") {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
13 var child = null;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
14 var output = indent + name + "\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
15 indent += "\t";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
16 for (var item in obj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
17 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
18 try {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
19 child = obj[item];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
20 } catch (e) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
21 child = "<Unable to Evaluate>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
22 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
23 if (typeof child == "object") {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
24 output += dumpObj(child, item, indent, depth + 1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
25 } else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
26 output += indent + item + ": " + child + "\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
27 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
28 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
29 return output;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
30 } else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
31 return obj;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
32 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
33 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
34 function dumpObjItem(obj, name, indent, depth) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
35 if (depth > MAX_DUMP_DEPTH) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
36 return indent + name + ": <Maximum Depth Reached>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
37 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
38 if (typeof obj == "object") {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
39 var child = null;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
40 var output = indent + name + "\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
41 indent += "\t";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
42 for (var item in obj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
43 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
44 try {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
45 child = obj[item];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
46 } catch (e) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
47 child = "<Unable to Evaluate>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
48 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
49 if (typeof child == "object") {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
50 output += dumpObjItem(child, item, indent, depth + 1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
51 } else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
52 output += indent + item + ":\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
53 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
54 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
55 return output;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
56 } else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
57 return obj;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
58 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
59 }
361
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
60
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
61 /**
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
62 * TextEditor class
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
63 *
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 function Inkscape(file)
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 var editor = document.getElementById('editor');
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
69 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
70 this.isInProgress = 0;
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
71 }
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
72
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
73 /**
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
74 * Inkscape class
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
75 *
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
76 */
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
77 function Inkscape(file)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
78 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
79 var ink = document.getElementById('inkscape');
352
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
80 ink.innerHTML = "<embed src="+file+" width=700 height=700 />";
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
81 this.isInProgress = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
82
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
83 setTimeout("inkscape.fetchDocument()",4000);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
84 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
86 Inkscape.prototype.gotoScene = function (n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
87 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
88 nextScene = n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
89 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
90 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
91 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
92 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
93 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
94 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
95 Inkscape.prototype.gotoScene1 = function (resp,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
96 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 var soapBody = new SOAPObject("SCENE");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99 v1.val(nextScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
100 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
101 var sr = new SOAPRequest("SCENE", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
102 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
103 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene2(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
105 Inkscape.prototype.gotoScene2 = function (resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
106 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
107 var soapBody = new SOAPObject("PUBLISH");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
108 var sr = new SOAPRequest("PUBLISH", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene3(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
112
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
113 Inkscape.prototype.gotoScene3 = function (resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
114 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
115 this.isInProgress--;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
116 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
117 Inkscape.prototype.publishDocument= function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
118 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
119 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
120 mbsvg.renderUI();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
121
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
122 var soapBody = new SOAPObject("PUBLISH");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
123 var sr = new SOAPRequest("PUBLISH", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
124 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
125 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
126 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
127
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
128 Inkscape.prototype.refreshDocument = function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
129 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
130 var soapBody = new SOAPObject("GETDOC");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
131 var sr = new SOAPRequest("GETDOC", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
132 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
133 SOAPClient.SendRequest(sr, function(resp,arg) { arg.publishDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
134 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
135
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
136 Inkscape.prototype.operationDone = function (res)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
137 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
138 this.isInProgress--;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
139 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
140 Inkscape.prototype.insertKey= function(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
141 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
142 nextScene = n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
143 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
144 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
145 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
146 SOAPClient.SendRequest(sr, function (resp,arg) {arg.insertKey1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
147 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
148 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
149 Inkscape.prototype.insertKey1 = function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
150 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
151 var soapBody = new SOAPObject("INSERTKEY");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
152 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
153 v1.attr('type','string');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
154 v1.val(currentLayer);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
155 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
156 var v2 = new SOAPObject("v2");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
157 v2.val(nextScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
158 soapBody.appendChild(v2);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
159 var sr = new SOAPRequest("INSERTKEY", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
160 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
161 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
162 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
163
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
164 Inkscape.prototype.extendScene=function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
165 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
166 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
167 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
168 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
169 SOAPClient.SendRequest(sr, function (resp,arg) {arg.extendScene1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
170 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
171 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
172
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
173
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
174 Inkscape.prototype.extendScene1 = function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
175 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
176 var soapBody = new SOAPObject("EXTENDSCENE");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
177 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
178 v1.attr('type','string');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
179 v1.val(currentLayer);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
180 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
181 var v2 = new SOAPObject("v2");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
182 v2.val(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
183 soapBody.appendChild(v2);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
184 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
185 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
186 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
187 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
188
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
189
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
190 Inkscape.prototype.deleteScene=function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
191 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
192 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
193 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
194 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
195 SOAPClient.SendRequest(sr, function (resp,arg) {arg.deleteScene1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
196 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
197 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
198
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
199 Inkscape.prototype.deleteScene1=function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
200 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
201 var soapBody = new SOAPObject("DELETESCENE");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
202 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
203 v1.attr('type','string');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
204 v1.val(currentLayer);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
205 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
206 var v2 = new SOAPObject("v2");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
207 v2.val(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
208 soapBody.appendChild(v2);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
209 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
210 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
211 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
212 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
213
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
214 Inkscape.prototype.fetchDocument = function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
215 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
216 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
217 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
218 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
219 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
220 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
221 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
222
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
223
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
224
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
225 function MBSVG(file)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
226 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
227 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
228 xmlDoc.async=false;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
229 xmlDoc.load(file);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
230 MBSVG_loadFromDoc(this,xmlDoc);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
231
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
232 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
233 function MBSVGString(xml)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
234 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
235 var xmlParser = new DOMParser();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
236 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
237 MBSVG_loadFromDoc(this,xmlDoc);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
238 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
239
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
240
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
241
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
242 function MBSVG_loadFromDoc(self,xmlDoc)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
243 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
244 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
245 if (scenesNode == null) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
246 alert('This is not a valid scene file');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
247 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
248 var len = scenesNode.length;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
249 var i,j;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
250 var max = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
251 var scenes = new Array();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
252
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
253 // Get the length of scenes
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
254 for(i=0;i<len;i++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
255 var s = scenesNode[i];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
256 var start = s.getAttribute("start");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
257 var end = s.getAttribute("end");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
258 var ref = s.getAttribute("ref");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
259 var ss = new Object();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
260
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
261 if (end == null) end = start
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
262 if (max <end) max = end;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
263 ss.node = s;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
264 ss.start = start;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
265 ss.end = end;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
266 ss.ref = ref;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
267 ss.layer = null;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
268 scenes.push(ss);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
269 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
270 if (max < 20) max = 20;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
271 // Collect all layers
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
272 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
273 var layers = new Array();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
274 len = nodes.length;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
275 for(i=0;i<len;i++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
276 if (nodes[i].localName == 'g') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
277 var subnodes = nodes[i].childNodes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
278 for(j=0;j<subnodes.length;j++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
279 if (subnodes[j].localName == 'g') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
280 for(var k=0;k<scenes.length;k++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
281 if (scenes[k].ref == subnodes[j].getAttribute('id')) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
282 scenes[k].layer = nodes[i].getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
283 break;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
284 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
285 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
286 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
287 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
288 layers.push(nodes[i]);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
289 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
290 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
291 self.layers = layers;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
292 self.scenes = scenes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
293 self.maxframe = max;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
294 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
295
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
296 MBSVGString.prototype=MBSVG.prototype;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
297 MBSVG.prototype.renderUI=function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
298 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
299 var layers = this.layers;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
300 var scenes = this.scenes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
301 var max = this.maxframe;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
302 var cmd = "<table border=1>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
303 cmd = cmd + "<tr><td></td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
304 for(var j=1;j<=max;j++)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
305 cmd = cmd + "<td>"+j+"</td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
306
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
307 for(var i=layers.length-1;i>=0;i--) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
308 var l = layers[i];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
309 var id = l.getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
310 var label = l.getAttribute('inkscape:label');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
311 cmd = cmd + "<tr><td>"+label+"</td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
312 for(j=0;j<max;j++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
313 var empty = 1;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
314 var n = j +1;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
315 var id_str = id+"#"+n
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
316 for(var k=0;k<scenes.length;k++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
317 if (id != scenes[k].layer) continue;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
318 if (n == scenes[k].start) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
319 cmd = cmd + "<td><img class='normal' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
320 empty = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
321 break;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
322 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
323 cmd = cmd + "<td><img class='normal' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
324 empty = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
325 break;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
326 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
327 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
328 if (empty) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
329 cmd = cmd + "<td><img class='normal' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
330 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
331
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
332 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
333 cmd = cmd + "</tr>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
334 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
335 cmd = cmd + "</table>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
336 var frame = document.getElementById('frame');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
337 frame.innerHTML=cmd;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
338 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
339
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
340
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
341
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
342 /**
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
343 * UI for madbuilder.html to build the scene editor
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
344 */
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
345
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
346 function selectCell(obj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
347 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
348 var id = obj.getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
349 var layer,n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
350 var f = id.split('#');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
351 layer=f[0];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
352 n = f[1];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
353 var img = obj.getAttribute('src');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
354 var f = img.split('-');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
355
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
356 if (f[0] == 'active')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
357 return;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
358 else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
359 obj.setAttribute('src', 'active-'+img);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
360 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
361
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
362 if (last_select != null) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
363 f = last_select.getAttribute('src').split('-');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
364 last_select.setAttribute('src', f[1]);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
365 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
366 last_select = obj;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
367 currentScene = n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
368 currentLayer = layer;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
369 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
370
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
371
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
372 function onButtonClick(obj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
373 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
374 if (inkscape.isInProgress != 0) return;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
375 var id = obj.getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
376 if (id == 'Jump') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
377 if (currentScene != 0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
378 inkscape.gotoScene(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
379 } else if (id == 'InsertKey') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
380 inkscape.insertKey(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
381 } else if (id == 'ExtendScene') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
382 inkscape.extendScene(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
383 } else if (id == 'DeleteScene') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
384 inkscape.deleteScene(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
385 } else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
386 alert(id+' has not been implemented yet');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
387 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
388 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
389
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
390 function gotoScene_cb(resObj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
391 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
392
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
393 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
394 var nextScene;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
395 var currentScene = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
396 var currentLayer = '';
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
397
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
398
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
399 function dump(n)
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
400 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
401 cmd = "";
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
402 for(k in n) {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
403 cmd = cmd + k+"="+n[k]+"\n";
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
404 }
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
405 alert(cmd);
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
406 }
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
407
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
408
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
409
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
410
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
411
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
412
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
413 function loadInkscapeFile()
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
414 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
415 ele = $('#mbsvg');
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
416 file = ele.attr('value');
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
417 inkscape = new Inkscape("file://"+file);
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
418
352
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
419 file1_animation = [
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
420 {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
421 attributes: {id:"an1-1"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
422 data: "animation1"
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
423 },
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
424 {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
425 attributes: {id:"an1-2"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
426 data: "animation2"
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
427 }
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
428 ];
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
429 file1 = {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
430 attributes:{id:"file1"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
431 data: "scene1.mbsvg",
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
432 children: file1_animation
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
433 };
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
434 file2 = {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
435 attributes:{id:"file2"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
436 data: "scene2.mbsvg",
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
437 };
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
438 file3 = {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
439 attributes:{id:"file3"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
440 data: "scene3.mbsvg",
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
441 };
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
442
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
443 scenes = [ file1,file2,file3];
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
444 src1 = {attributes:{id:"src1"},data:"src1.c"};
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
445 src2 = {attributes:{id:"src1"},data:"src2.c"};
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
446 src3 = {attributes:{id:"src1"},data:"src3.c"};
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
447
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
448 sources = [src1,src2,src3];
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
449
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
450 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
451
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
452
359
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
453 function project_loadScene(node)
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
454 {
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
455 var file = node.textContent;
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
456 inkscape = new Inkscape("file://"+file);
361
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
457 $('#inkscape').show('slow');
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
458 $('#editor').hide('slow');
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
459 }
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
460
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
461
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
462 function project_loadEditor(node)
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
463 {
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
464 var file = node.textContent;
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
465 editor = new TextEditor(file);
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
466 $('#inkscape').hide('slow');
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
467 $('#editor').show('slow');
359
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
468 }
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
469
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
470 function project_parse(xml)
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
471 {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
472
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
473 var xmlParser = new DOMParser();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
474 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml');
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
475 var scenesNode = xmlDoc.getElementsByTagName("scene");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
476 if (scenesNode == null) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
477 alert('This is not a valid scene file');
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
478 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
479 var len = scenesNode.length;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
480 var i,j;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
481 var max = 0;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
482 var scenes = new Array();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
483
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
484 // Get the length of scenes
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
485 for(i=0;i<len;i++) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
486 var n = scenesNode[i];
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
487 var s = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
488 s.attributes = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
489 s.attributes.id = "scene"+i;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
490 s.state = "open";
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
491 s.data = n.getAttribute("src");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
492 scenes.push(s);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
493 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
494
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
495 var nodes = xmlDoc.getElementsByTagName("source");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
496 var len = nodes.length;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
497 var i,j;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
498 var max = 0;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
499 var sources = [];
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
500
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
501 // Get the length of scenes
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
502 for(i=0;i<len;i++) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
503 var n = nodes[i];
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
504 var s = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
505 s.attributes = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
506 s.attributes.id = "sources"+i;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
507 s.state = "open";
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
508 s.data = n.getAttribute("src");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
509 sources.push(s);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
510 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
511
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
512 var tree = $.tree_create();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
513 tree.init($("#filelist"), {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
514 data: {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
515 type: "json",
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
516 json : [
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
517 {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
518 attributes: {id: "prj"},
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
519 state: "open",
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
520 data: "Project",
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
521 children: [
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
522 { attributes:{id:"scenes"}, data:"scene", children: scenes},
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
523 { attributes:{id:"sources"},data:"sources",children: sources}
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
524 ]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
525 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
526 ],
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
527 },
359
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
528 callback : {
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
529 ondblclk : function(NODE,TREE_OBJ) { project_loadScene(NODE); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);}
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
530 },
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
531 ui : {
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
532 context : [
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
533 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
534 id: "Open",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
535 label: "Open",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
536 icon: "open.png",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
537 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";},
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
538 action: function(NODE,TREE_OBJ) { openFile(TREE_OBJ);}
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
539 },
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
540 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
541 id: "New",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
542 label: "New",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
543 icon: "create.png",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
544 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";},
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
545 action: function(NODE,TREE_OBJ) { alert("open is not support yet");}
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
546 },
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
547 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
548 id: "Rename",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
549 label: "Rename",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
550 icon: "rename.png",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
551 visible: function(NODE,TREE_OBJ) { if(NODE.length != 1) return false; return NODE[0].id == "prj";},
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
552 action: function(NODE,TREE_OBJ) { alert("open is not support yet");}
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
553 }
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
554 ]
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
555 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
556
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
557 });
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
558 }
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
559
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
560 function system_read(fname) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
561 try {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
562 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
563 } catch (e) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
564 alert("Permission to read file was denied.");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
565 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
566 var file = Components.classes["@mozilla.org/file/local;1"]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
567 .createInstance(Components.interfaces.nsILocalFile);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
568 try {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
569 file.initWithPath( fname );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
570 if ( file.exists() == false ) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
571 alert("File does not exist");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
572 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
573 var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
574 .createInstance( Components.interfaces.nsIFileInputStream );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
575 is.init( file,0x01, 00004, null);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
576 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
577 .createInstance( Components.interfaces.nsIScriptableInputStream );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
578 sis.init( is );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
579 var output = sis.read( sis.available() );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
580 sis.close();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
581 } catch(e) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
582 alert(fname+" does not exist");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
583 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
584 return output;
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
585 }
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
586
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
587 function project_loadFile()
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
588 {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
589 prjname = $('#mbsvg').attr('value');
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
590 var prj = system_read(prjname);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
591 project_parse(prj);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
592 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
593
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
594 var last_select = null;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
595
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
596 $('#inkscape').html('Please select the project file<br>');
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
597 $('#inkscape').append('<input type=file value="Select the project file" id="mbsvg" accept="image/png">');
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
598 $('#inkscape').append('<input type=button value="Load" onclick="project_loadFile()">');