annotate inkscape/firefox/content/inkscape.js @ 384:7cbb364fd273

Show the old name in the input line Select the first object automatically.
author wycc
date Sun, 05 Apr 2009 17:00:28 +0800
parents 29145d2affdb
children f3e6ac47752c
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');
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
73 editor.innerHTML = "<embed src="+file+" width=900 height=700 />";
361
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');
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
84 ink.innerHTML = "<embed src="+file+" width=900 height=700 />";
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85 this.isInProgress = 0;
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
86 this.callback = null;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
87
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
88 setTimeout("inkscape.fetchDocument()",4000);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
89 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
90
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
91 Inkscape.prototype.gotoScene = function (n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
92 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
93 nextScene = n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
94 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
95 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
96 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
100 Inkscape.prototype.gotoScene1 = function (resp,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
101 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
102 var soapBody = new SOAPObject("SCENE");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
103 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 v1.val(nextScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
105 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
106 var sr = new SOAPRequest("SCENE", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
107 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
108 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene2(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 Inkscape.prototype.gotoScene2 = function (resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
112 var soapBody = new SOAPObject("PUBLISH");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
113 var sr = new SOAPRequest("PUBLISH", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
114 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
115 SOAPClient.SendRequest(sr, function (resp,arg) {arg.gotoScene3(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
116 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
117
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
118 Inkscape.prototype.gotoScene3 = function (resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
119 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
120 this.isInProgress--;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
121 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
122 Inkscape.prototype.publishDocument= function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
123 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
124 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
125 mbsvg.renderUI();
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
126 if (this.callback)
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
127 this.callback(mbsvg);
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
128
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
129 var soapBody = new SOAPObject("PUBLISH");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
130 var sr = new SOAPRequest("PUBLISH", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
131 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
132 SOAPClient.SendRequest(sr, function(resp,arg) {arg.operationDone(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
133 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
134
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
135 Inkscape.prototype.refreshDocument = function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
136 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
137 var soapBody = new SOAPObject("GETDOC");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
138 var sr = new SOAPRequest("GETDOC", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
139 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
140 SOAPClient.SendRequest(sr, function(resp,arg) { arg.publishDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
141 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
142
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
143 Inkscape.prototype.operationDone = function (res)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
144 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
145 this.isInProgress--;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
146 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
147 Inkscape.prototype.insertKey= function(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
148 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
149 nextScene = n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
150 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
151 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
152 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
153 SOAPClient.SendRequest(sr, function (resp,arg) {arg.insertKey1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
154 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
155 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
156 Inkscape.prototype.insertKey1 = function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
157 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
158 var soapBody = new SOAPObject("INSERTKEY");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
159 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
160 v1.attr('type','string');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
161 v1.val(currentLayer);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
162 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
163 var v2 = new SOAPObject("v2");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
164 v2.val(nextScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
165 soapBody.appendChild(v2);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
166 var sr = new SOAPRequest("INSERTKEY", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
167 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
168 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
169 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
170
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
171 Inkscape.prototype.extendScene=function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
172 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
173 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
174 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
175 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
176 SOAPClient.SendRequest(sr, function (resp,arg) {arg.extendScene1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
177 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
178 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
179
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
180
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
181 Inkscape.prototype.extendScene1 = function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
182 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
183 var soapBody = new SOAPObject("EXTENDSCENE");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
184 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
185 v1.attr('type','string');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
186 v1.val(currentLayer);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
187 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
188 var v2 = new SOAPObject("v2");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
189 v2.val(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
190 soapBody.appendChild(v2);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
191 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
192 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
193 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
194 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
195
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
196
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
197 Inkscape.prototype.deleteScene=function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
198 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
199 var soapBody = new SOAPObject("START");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
200 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
201 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
202 SOAPClient.SendRequest(sr, function (resp,arg) {arg.deleteScene1(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
203 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
204 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
205
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
206 Inkscape.prototype.deleteScene1=function(resp)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
207 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
208 var soapBody = new SOAPObject("DELETESCENE");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
209 var v1 = new SOAPObject("v1");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
210 v1.attr('type','string');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
211 v1.val(currentLayer);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
212 soapBody.appendChild(v1);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
213 var v2 = new SOAPObject("v2");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
214 v2.val(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
215 soapBody.appendChild(v2);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
216 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
217 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
218 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
219 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
220
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
221 Inkscape.prototype.fetchDocument = function(callback)
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
222 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
223 var soapBody = new SOAPObject("START");
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
224 this.callback = callback
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
225 var sr = new SOAPRequest("START", soapBody);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
226 SOAPClient.Proxy = "http://localhost:19192/";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
227 SOAPClient.SendRequest(sr,function(resp,arg) {arg.refreshDocument(resp);},this);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
228 this.isInProgress++;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
229 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
230
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
231 Inkscape.prototype.changeSymbolName_cb = function(callback)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
232 {
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
233 var soapBody = new SOAPObject("CHANGESYMBOL");
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
234 var v1 = new SOAPObject("v1");
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
235 v1.attr('type','string');
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
236 v1.val(this.v1);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
237 soapBody.appendChild(v1);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
238 var v2 = new SOAPObject("v2");
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
239 v2.val(this.v2);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
240 soapBody.appendChild(v2);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
241 var sr = new SOAPRequest("CHANGESYMBOL", soapBody);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
242 SOAPClient.Proxy = "http://localhost:19192/";
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
243 SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
244 this.inProgress--;
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
245 }
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
246
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
247 Inkscape.prototype.changeSymbolName = function(id,newname,callback)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
248 {
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
249 var soapBody = new SOAPObject("START");
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
250 this.callback = callback
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
251 var sr = new SOAPRequest("START", soapBody);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
252 SOAPClient.Proxy = "http://localhost:19192/";
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
253 this.v1 = id;
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
254 this.v2 = newname;
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
255 SOAPClient.SendRequest(sr,function(resp,arg) {arg.changeSymbolName_cb(resp);},this);
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
256 this.isInProgress++;
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
257 }
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
258
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
259 /*
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
260 * This module is used to define a symbol for the MadButterfly. This function will search for symbol which is defined in the current select object. We will list all SVG elements
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
261 * in the left side, multiple variables can be defined at one time. When any element is selected, the defined symbol will be listed in the right side.
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
262 *
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
263 */
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
264
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
265 Inkscape.prototype.MakeSymbol=function()
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
266 {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
267 function callback(mbsvg) {
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
268 inkscape.loadSymbolScreen(mbsvg);
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
269 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
270 inkscape.fetchDocument(callback);
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
271 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
272
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
273
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
274 Inkscape.prototype.onChangeSymbolName=function()
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
275 {
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
276 inkscape.changeSymbolName(inkscape.current_symbol, $('#newsymbolname').val());
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
277 symboldialog.dialog('close')
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
278 }
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
279
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
280 Inkscape.prototype.refreshSymbolPanel=function(node)
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
281 {
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
282 var reg = new RegExp('(.*)\\((.*)\\)');
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
283 var m = reg.exec(node.textContent);
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
284 var val = m[2];
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
285 inkscape.current_symbol = node.textContent;
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
286 $('#newsymbolname').val(val);
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
287 }
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
288
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
289 Inkscape.prototype.loadSymbolScreen=function (mbsvg) {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
290 // Swap the left side to be the SVG element tree.
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
291 var i,l;
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
292
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
293 symboldialog.dialog('open');
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
294 this.mbsvg = mbsvg;
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
295 l = mbsvg.selected_objects.length;
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
296 var jsonobj = []
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
297 for(i=0;i<l;i++) {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
298 // Add symbol into the tree
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
299 var name = mbsvg.findSymbolName(mbsvg.selected_objects[i]);
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
300 var title=mbsvg.selected_objects[i]+"("+name+")";
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
301 var obj = { attributes: {id: 'sym'+i}, data : title};
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
302 if (i == 0) {
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
303 this.current_symbol = mbsvg.selected_objects[i];
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
304 $('#newsymbolname').val(name);
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
305 }
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
306 jsonobj.push(obj);
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
307 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
308 this.symboltree = $.tree_create();
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
309 this.symboltree.init($("#symbollist"), {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
310 data: {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
311 type: "json",
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
312 json : jsonobj
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
313 },
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
314 callback : {
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
315 ondblclk : function(NODE,TREE_OBJ) { inkscape.refreshSymbolPanel(NODE);}
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
316 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
317
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
318 });
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
319 var s = $('#changename');
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
320 s.click(this.onChangeSymbolName);
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
321 // Swap the right side to be the symbol editor screen.
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
322 symboldialog.show();
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
323 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
324
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
325 jQuery(document).ready(function() {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
326 symboldialog = jQuery('#symboldialog');
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
327 symboldialog.dialog({width:500,
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
328 modal: true,
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
329 autoOpen:false,
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
330 title:'Please select a file'});
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
331 symboldialog.hide();
381
29145d2affdb Add function to change the name of the symbol
wycc
parents: 376
diff changeset
332 symboldialog.append("<div id='symbollist'/>");
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
333 symboldialog.append("<div id='symbol'><input type='text' id='newsymbolname'> <input type='submit' value='change' id='changename'></div> ");
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
334 });
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
335
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
336 function MBSVG(file)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
337 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
338 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
339 xmlDoc.async=false;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
340 xmlDoc.load(file);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
341 MBSVG_loadFromDoc(this,xmlDoc);
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 function MBSVGString(xml)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
345 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
346 var xmlParser = new DOMParser();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
347 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
348 MBSVG_loadFromDoc(this,xmlDoc);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
349 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
350
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
351
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
352
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
353 function MBSVG_loadFromDoc(self,xmlDoc)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
354 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
355 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
356 if (scenesNode == null) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
357 alert('This is not a valid scene file');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
358 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
359 var len = scenesNode.length;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
360 var i,j;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
361 var max = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
362 var scenes = new Array();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
363
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
364 // Get the length of scenes
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
365 for(i=0;i<len;i++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
366 var s = scenesNode[i];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
367 var start = s.getAttribute("start");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
368 var end = s.getAttribute("end");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
369 var ref = s.getAttribute("ref");
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
370 var ss = new Object();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
371
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
372 if (end == null) end = start
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
373 if (max <end) max = end;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
374 ss.node = s;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
375 ss.start = start;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
376 ss.end = end;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
377 ss.ref = ref;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
378 ss.layer = null;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
379 scenes.push(ss);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
380 }
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
381 if (max < 20) max = 30;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
382 // Collect all layers
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
383 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
384 var layers = new Array();
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
385 len = nodes.length;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
386 for(i=0;i<len;i++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
387 if (nodes[i].localName == 'g') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
388 var subnodes = nodes[i].childNodes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
389 for(j=0;j<subnodes.length;j++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
390 if (subnodes[j].localName == 'g') {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
391 for(var k=0;k<scenes.length;k++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
392 if (scenes[k].ref == subnodes[j].getAttribute('id')) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
393 scenes[k].layer = nodes[i].getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
394 break;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
395 }
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 layers.push(nodes[i]);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
400 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
401 }
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
402 var select = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","select");
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
403 len = select.length;
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
404 selectobjs = [];
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
405 for(i=0;i<len;i++) {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
406 selectobjs.push(select[i].getAttribute('ref'));
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
407 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
408 self.selected_objects = selectobjs;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
409 self.layers = layers;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
410 self.scenes = scenes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
411 self.maxframe = max;
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
412 self.doc = xmlDoc;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
413 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
414
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
415 MBSVGString.prototype=MBSVG.prototype;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
416 MBSVG.prototype.renderUI=function()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
417 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
418 var layers = this.layers;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
419 var scenes = this.scenes;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
420 var max = this.maxframe;
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
421 var cmd = "<table border=0>\n";
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
422 cmd = cmd + "<tr><td></td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
423 for(var j=1;j<=max;j++)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
424 cmd = cmd + "<td>"+j+"</td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
425
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
426 for(var i=layers.length-1;i>=0;i--) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
427 var l = layers[i];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
428 var id = l.getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
429 var label = l.getAttribute('inkscape:label');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
430 cmd = cmd + "<tr><td>"+label+"</td>";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
431 for(j=0;j<max;j++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
432 var empty = 1;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
433 var n = j +1;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
434 var id_str = id+"#"+n
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
435 for(var k=0;k<scenes.length;k++) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
436 if (id != scenes[k].layer) continue;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
437 if (n == scenes[k].start) {
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
438 cmd = cmd + "<td><img class='normal' width='16' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
439 empty = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
440 break;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
441 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) {
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
442 cmd = cmd + "<td><img class='normal' width='16' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
443 empty = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
444 break;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
445 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
446 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
447 if (empty) {
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
448 cmd = cmd + "<td><img class='normal' width='16' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>";
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
449 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
450
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
451 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
452 cmd = cmd + "</tr>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
453 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
454 cmd = cmd + "</table>\n";
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
455 var frame = document.getElementById('frame');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
456 frame.innerHTML=cmd;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
457 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
458
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
459
384
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
460 MBSVG.prototype.findSymbolName=function(id)
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
461 {
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
462 var obj = this.doc.getElementById(id);
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
463 var name = obj.getAttribute('mbname');
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
464 return name;
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
465
7cbb364fd273 Show the old name in the input line
wycc
parents: 381
diff changeset
466 }
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
467
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
468 /**
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
469 * UI for madbuilder.html to build the scene editor
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
470 */
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
471
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
472 function selectCell(obj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
473 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
474 var id = obj.getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
475 var layer,n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
476 var f = id.split('#');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
477 layer=f[0];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
478 n = f[1];
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
479 var img = obj.getAttribute('src');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
480 var f = img.split('-');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
481
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
482 if (f[0] == 'active')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
483 return;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
484 else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
485 obj.setAttribute('src', 'active-'+img);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
486 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
487
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
488 if (last_select != null) {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
489 f = last_select.getAttribute('src').split('-');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
490 last_select.setAttribute('src', f[1]);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
491 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
492 last_select = obj;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
493 currentScene = n;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
494 currentLayer = layer;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
495 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
496
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
497
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
498 function onButtonClick(obj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
499 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
500 var id = obj.getAttribute('id');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
501 if (id == 'Jump') {
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
502 if (inkscape.isInProgress != 0) return;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
503 if (currentScene != 0)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
504 inkscape.gotoScene(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
505 } else if (id == 'InsertKey') {
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
506 if (inkscape.isInProgress != 0) return;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
507 inkscape.insertKey(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
508 } else if (id == 'ExtendScene') {
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
509 if (inkscape.isInProgress != 0) return;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
510 inkscape.extendScene(currentScene);
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
511 } else if (id == 'DeleteScene') {
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
512 if (inkscape.isInProgress != 0) return;
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
513 inkscape.deleteScene(currentScene);
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
514 } else if (id == 'MakeSymbol') {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
515 if (inkscape.isInProgress != 0) return;
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
516 inkscape.MakeSymbol();
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
517 } else if (id == 'Save') {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
518 project_save();
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
519 } else if (id == 'Test') {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
520 if (project_compile()) {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
521 project_run();
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
522 } else {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
523 }
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
524 } else {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
525 alert(id+' has not been implemented yet');
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
526 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
527 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
528
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
529 function gotoScene_cb(resObj)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
530 {
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
531
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
532 }
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
533 var nextScene;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
534 var currentScene = 0;
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
535 var currentLayer = '';
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
536
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
537
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
538 function dump(n)
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
539 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
540 cmd = "";
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
541 for(k in n) {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
542 cmd = cmd + k+"="+n[k]+"\n";
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
543 }
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
544 alert(cmd);
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
545 }
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
546
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
547
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
548
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
549
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
550
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
551
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
552 function loadInkscapeFile()
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
553 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
554 ele = $('#mbsvg');
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
555 file = ele.attr('value');
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
556 inkscape = new Inkscape("file://"+file);
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
557
352
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
558 file1_animation = [
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
559 {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
560 attributes: {id:"an1-1"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
561 data: "animation1"
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
562 },
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
563 {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
564 attributes: {id:"an1-2"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
565 data: "animation2"
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
566 }
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
567 ];
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
568 file1 = {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
569 attributes:{id:"file1"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
570 data: "scene1.mbsvg",
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
571 children: file1_animation
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
572 };
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
573 file2 = {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
574 attributes:{id:"file2"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
575 data: "scene2.mbsvg",
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
576 };
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
577 file3 = {
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
578 attributes:{id:"file3"},
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
579 data: "scene3.mbsvg",
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
580 };
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
581
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
582 scenes = [ file1,file2,file3];
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
583 src1 = {attributes:{id:"src1"},data:"src1.c"};
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
584 src2 = {attributes:{id:"src1"},data:"src2.c"};
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
585 src3 = {attributes:{id:"src1"},data:"src3.c"};
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
586
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
587 sources = [src1,src2,src3];
4350aa369149 Use jQuery UI components.
wycc
parents: 339
diff changeset
588
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
589 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
590
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
591 function project_compile()
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
592 {
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
593 }
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
594
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
595
362
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
596 function project_showFile(node)
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
597 {
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
598 var file = node.textContent;
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
599 if (endsWith(file,"mbsvg")) {
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
600 project_loadScene(node);
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
601 } else {
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
602 project_loadEditor(node);
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
603 }
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
604
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
605 }
359
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
606 function project_loadScene(node)
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
607 {
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
608 var file = node.textContent;
371
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
609 if (file.substr(0,1) == '/')
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
610 inkscape = new Inkscape("file://"+file);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
611 else
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
612 inkscape = new Inkscape("file://"+project_dir+'/'+file);
361
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
613 }
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
614
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
615
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
616 function project_loadEditor(node)
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
617 {
8c4456190d9a Add text editor support to edit C source file inside the MadBuilder
wycc
parents: 359
diff changeset
618 var file = node.textContent;
371
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
619 if (file.substr(0,1) == '/')
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
620 editor = new TextEditor("file://"+file);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
621 else
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
622 editor = new TextEditor("file://"+project_dir+'/'+file);
359
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
623 }
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
624
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
625 function project_parse(xml)
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
626 {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
627
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
628 var xmlParser = new DOMParser();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
629 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml');
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
630 var scenesNode = xmlDoc.getElementsByTagName("scene");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
631 if (scenesNode == null) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
632 alert('This is not a valid scene file');
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 len = scenesNode.length;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
635 var i,j;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
636 var max = 0;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
637 var scenes = new Array();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
638
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
639 // Get the length of scenes
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
640 for(i=0;i<len;i++) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
641 var n = scenesNode[i];
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
642 var s = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
643 s.attributes = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
644 s.attributes.id = "scene"+i;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
645 s.state = "open";
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
646 s.data = n.getAttribute("src");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
647 scenes.push(s);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
648 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
649
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
650 var nodes = xmlDoc.getElementsByTagName("source");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
651 var len = nodes.length;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
652 var i,j;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
653 var max = 0;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
654 var sources = [];
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
655
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
656 // Get the length of scenes
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
657 for(i=0;i<len;i++) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
658 var n = nodes[i];
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
659 var s = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
660 s.attributes = new Object();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
661 s.attributes.id = "sources"+i;
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
662 s.state = "open";
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
663 s.data = n.getAttribute("src");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
664 sources.push(s);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
665 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
666
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
667 var tree = $.tree_create();
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
668 project_tree = tree;
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
669 tree.init($("#filelist"), {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
670 data: {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
671 type: "json",
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
672 json : [
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
673 {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
674 attributes: {id: "prj"},
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
675 state: "open",
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
676 data: "Project",
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
677 children: [
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
678 { attributes:{id:"scenes"}, data:"scene", children: scenes},
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
679 { attributes:{id:"sources"},data:"sources",children: sources}
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
680 ]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
681 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
682 ],
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
683 },
359
b4bd4819091c Load mbsvg file when it is double clicked
wycc
parents: 358
diff changeset
684 callback : {
362
83cae12cf428 Load scene and source in different way.
wycc
parents: 361
diff changeset
685 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
686 },
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
687 ui : {
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
688 context : [
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
689 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
690 id: "Open",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
691 label: "Open",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
692 icon: "open.png",
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
693 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
694 action: function(NODE,TREE_OBJ) { onTree_openFile(NODE,TREE_OBJ);}
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
695 },
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
696 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
697 id: "New",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
698 label: "New",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
699 icon: "create.png",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
700 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
701 action: function(NODE,TREE_OBJ) { alert("open is not support yet");}
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
702 },
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
703 {
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
704 id: "Rename",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
705 label: "Rename",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
706 icon: "rename.png",
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
707 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
708 action: function(NODE,TREE_OBJ) { alert("open is not support yet");}
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
709 }
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
710 ]
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
711 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
712
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
713 });
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
714 }
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
715
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
716 function fileDialog_cb()
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
717 {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
718 var file = $('#filedialogsrc').attr('value');
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
719 filedialog.dialog('close');
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
720 filedialog_cb(file,filedialog_arg);
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 function openFileDialog(callback,arg)
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
724 {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
725 filedialog_cb = callback;
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
726 filedialog_arg = arg;
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
727 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
728 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
729 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
730 filedialog.show();
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
731 filedialog.dialog('open');
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
732 }
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
733
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
734
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
735 function project_addScene(file,treeobj)
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
736 {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
737 if (file == '') {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
738 return;
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
739 }
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
740 treeobj.create(false,treeobj.selected,file);
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
741 }
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
742
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
743 function onTree_addSceneFile(node,treeobj)
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
744 {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
745 openFileDialog(project_addScene,treeobj);
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
746 }
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
747
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
748 function project_addSource(file,treeobj)
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
749 {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
750 treeobj.create(false,treeobj.selected,file);
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
751 }
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
752
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
753 function onTree_addSourceFile(node,treeobj)
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
754 {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
755 openFileDialog(project_addSource,treeobj);
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
756 }
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
757
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
758 function onTree_openFile(node,treeobj)
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
759 {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
760 if (node[0].id == "scenes") {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
761 onTree_addSceneFile(node,treeobj);
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
762 } else if (node[0].id == "sources") {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
763 onTree_addSourceFile(node,treeobj);
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
764 }
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
765 }
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
766
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
767 function system_open_read(fname) {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
768 try {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
769 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
770 } catch (e) {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
771 alert("Permission to read file was denied.");
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
772 }
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
773 var file = Components.classes["@mozilla.org/file/local;1"]
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
774 .createInstance(Components.interfaces.nsILocalFile);
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
775 try {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
776 file.initWithPath( fname );
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
777 if ( file.exists() == false ) {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
778 alert("File does not exist");
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
779 }
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
780 var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
781 .createInstance( Components.interfaces.nsIFileInputStream );
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
782 is.init( file,0x01, 00004, null);
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
783 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
784 .createInstance( Components.interfaces.nsIScriptableInputStream );
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
785 sis.init( is );
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
786 } catch(e) {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
787 alert(fname+" does not exist");
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
788 }
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
789 return sis;
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
790 }
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
791
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
792 function system_read(fname) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
793 try {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
794 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
795 } catch (e) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
796 alert("Permission to read file was denied.");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
797 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
798 var file = Components.classes["@mozilla.org/file/local;1"]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
799 .createInstance(Components.interfaces.nsILocalFile);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
800 try {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
801 file.initWithPath( fname );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
802 if ( file.exists() == false ) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
803 alert("File does not exist");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
804 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
805 var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
806 .createInstance( Components.interfaces.nsIFileInputStream );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
807 is.init( file,0x01, 00004, null);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
808 var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
809 .createInstance( Components.interfaces.nsIScriptableInputStream );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
810 sis.init( is );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
811 var output = sis.read( sis.available() );
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
812 sis.close();
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
813 } catch(e) {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
814 alert(fname+" does not exist");
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
815 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
816 return output;
357
6fd8da22a5ef Implement scene file load function.
wycc
parents: 352
diff changeset
817 }
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
818 function system_open_write(fname) {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
819 try {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
820 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
821 } catch (e) {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
822 alert("Permission to read file was denied.");
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
823 }
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
824 var file = Components.classes["@mozilla.org/file/local;1"]
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
825 .createInstance(Components.interfaces.nsILocalFile);
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
826 try {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
827 file.initWithPath( fname );
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
828 var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"]
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
829 .createInstance( Components.interfaces.nsIFileOutputStream );
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
830 fostream.init( file,0x02|0x8|0x20, 0666,0);
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
831 } catch(e) {
371
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
832 alert('can not create '+fname);
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
833 }
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
834 return fostream;
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
835 }
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
836 function system_write(fname,xml) {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
837 try {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
838 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
839 } catch (e) {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
840 alert("Permission to read file was denied.");
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
841 }
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
842 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
843 .createInstance(Components.interfaces.nsILocalFile);
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
844 try {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
845 file.initWithPath( fname );
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
846 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
847 .createInstance( Components.interfaces.nsIFileOutputStream );
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
848 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
849 fostream.write( xml,xml.length );
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
850 fostream.close();
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
851 } catch(e) {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
852 alert(fname+" does not exist");
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
853 }
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
854 }
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
855
371
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
856 function system_mkdir(path)
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
857 {
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
858 try {
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
859 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
860 } catch (e) {
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
861 alert("Permission to read file was denied.");
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
862 }
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
863 var file = Components.classes["@mozilla.org/file/local;1"]
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
864 .createInstance(Components.interfaces.nsILocalFile);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
865 try {
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
866 file.initWithPath(path);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
867 if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
868 file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
869 }
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
870 } catch(e) {
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
871 alert('Failed to create directopry '+path+e);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
872 }
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
873 }
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
874
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
875 function getPathDirectory(path)
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
876 {
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
877 var s = path.lastIndexOf('/');
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
878 if (s == -1)
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
879 return '';
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
880 else
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
881 return path.substr(0,s);
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
882 }
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
883
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
884 function project_loadFile()
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
885 {
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
886 prjname = $('#mbsvg').attr('value');
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
887 project_name = prjname;
371
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
888 project_dir = getPathDirectory(prjname);
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
889 var prj = system_read(prjname);
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
890 project_parse(prj);
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
891 filedialog.dialog('close');
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
892 }
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
893
365
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
894
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
895 function project_save()
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
896 {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
897 var i;
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
898
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
899 var xml = "<project>\n";
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
900 var scenes = $('#scenes');
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
901 var sources = $('#sources');
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
902 var list = project_tree.getJSON(scenes);
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
903 var len = list.children.length;
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
904
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
905 for(i=0;i<len;i++) {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
906 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
907 }
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
908 list = project_tree.getJSON(sources);
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
909 len = list.children.length;
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
910 for(i=0;i<len;i++) {
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
911 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
912 }
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
913 xml = xml + "</project>\n";
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
914 system_write(project_name,xml);
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
915
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
916 }
6adb28388132 Add capability to add new scene and source into the project
wycc
parents: 364
diff changeset
917
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
918
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
919 function onLoadProject(path)
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
920 {
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
921 project_name = path;
371
3d21115297ba Add textmenu template
wycc
parents: 367
diff changeset
922 project_dir = getPathDirectory(project_name);
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
923 var prj = system_read(project_name);
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
924 project_parse(prj);
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
925 }
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
926
358
50d33c3987ba Add loader for project file.
wycc
parents: 357
diff changeset
927 var last_select = null;
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
928 var wizard = new Wizard();
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
929 wizard.cb = onLoadProject;
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
930 $('#filedialog').dialog({ width:500});
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
931 jQuery(document).ready(function() {
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
932 filedialog = jQuery('#filedialog');
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
933 filedialog.dialog({width:500,
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
934 modal: true,
367
e21e9447f545 Add wizard. We still need to add the template files.
wycc
parents: 365
diff changeset
935 autoOpen:false,
364
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
936 title:'Please select a file'});
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
937 filedialog.show();
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
938 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
939 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
940 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
941 filedialog.dialog("open");
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
942 });
a373b4743e63 Add file dialog to add a new scene file into the project.
wycc
parents: 362
diff changeset
943
376
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
944 $('#frame').draggable();
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
945 $('#btns').draggable({cursor:'crosshair'});
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
946 $('#list').tabs();
7d244a85dd68 Change the screen layout to make it more like an usual IDE.
wycc
parents: 371
diff changeset
947 $('#display').tabs();