annotate inkscape/firefox/content/inkscape.js @ 365:6adb28388132

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