File: properties-window.e

package info (click to toggle)
entity 1.0.1-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,604 kB
  • ctags: 5,394
  • sloc: ansic: 64,242; sh: 7,377; makefile: 776; perl: 319
file content (463 lines) | stat: -rw-r--r-- 11,985 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

<!-- This is the actual properties window -->
<window name="properties" width="279" height="304"
 title="Stembuilder: Node Properties" border="3" dialog="true">
  <notebook expand="true">
    <notepage title="Common">
      <valign name="common_properties" spacing="5" border="5">
        <halign>
          <label text="name:" xalign="100" width="80"/>
          <entry name="properties_name" onenter="properties_name_changed"/>
        </halign>
      </valign>
    </notepage>
    <notepage title="All">
      <valign name="all_properties" border="5" spacing="5">
        <halign>
          <label text="Supported:" width="80" xalign="100"/>
          <dropdown name="supported" onselect="properties_dropdown_selected" onopen="properties_supported_attribs_reload"/>
        </halign>
        <halign>
          <label text="Currently Set:" width="80" xalign="100"/>
          <dropdown name="set" onselect="properties_dropdown_selected" onopen="properties_set_attribs_reload"/>
        </halign>
        <halign>
          <label text="Description:" yalign="0" xalign="100" width="80"/>
          <hwrapalign name="property_description" expand="true">
          </hwrapalign>
        </halign>
      </valign>
    </notepage>
    <notepage title="Arbitrary">
      <valign spacing="5" border="5">
        <halign>
          <label text="Set Attribute:" width="80" xalign="100"/>
          <entry name="properties_arbitrary_attrib" onenter="properties_get_arbitrary"/>
        </halign>
        <halign>
          <label text="To Value:" width="80" xalign="100"/>
          <entry name="properties_arbitrary_value" onenter="properties_set_arbitrary"/>
        </halign>
	<halign expand="true" width="150">
	  <halign width="80" expand="false" fill="true"/>
	  <button label="Set" onclick="properties_set_arbitrary" width="160"/>
	</halign>
      </valign>
    </notepage>
  </notebook>
</window>

<norender name="integer">
  <temporary>
        <halign>
          <label name="element" text="Integer:" width="80" xalign="100"/>
          <spinner max="1000000" min="-1000" value="0" onchange="properties_value_changed"/>
        </halign>
  </temporary>
</norender>

<norender name="float">
  <temporary>
        <halign>
          <label name="element" text="Float:" width="80" xalign="100"/>
          <spinner max="1000000" min="-10000000" value="0" onchange="properties_value_changed"/>
        </halign>
  </temporary>
</norender>

<norender name="function">
  <temporary>
        <halign>
          <label name="element" text="Function:" width="80" xalign="100"/>
          <entry onenter="properties_string_changed"/>
        </halign>
  </temporary>
</norender>

<norender name="string">
  <temporary>
        <halign>
          <label name="element" text="String:" width="80" xalign="100"/>
          <entry onenter="properties_string_changed"/>
        </halign>
  </temporary>
</norender>

<norender name="boolean">
  <temporary>
        <halign>
          <label name="element" text="Boolean:" width="80" xalign="100"/>
          <radio-group >
            <radio name="true" onselect="properties_boolean_changed" label="True" selected="false"/>
            <radio name="false" onselect="properties_boolean_changed" label="False" selected="false"/>
            <radio name="unset" onselect="properties_boolean_changed" label="Unset" selected="true"/>
          </radio-group>
        </halign>
  </temporary>
</norender>

<norender name="choice">
  <temporary>
        <halign>
          <label name="element" text="Choice:" width="80" xalign="100"/>
          <dropdown editable="false" onselect="properties_dropdown_changed"/>
        </halign>
  </temporary>
</norender>


<norender name="percentage">
  <temporary>
        <halign>
          <label name="element" text="Percentage:" width="80" xalign="100"/>
          <spinner max="100" min="0" value="100" onchange="properties_value_changed"/>
        </halign>
  </temporary>
</norender>




<?javascript

function important_properties (element)
{
    node = enode ("window.elements");
    try {
	stembuilder_element = node.children_attrib ("element", element);
   
	element = stembuilder_element[0];
    } catch (e) {
	return (null);
    }

    important = element.attrib.important;
    attribs = important.split (",");

    hash = new Object;
    for (attrib in attribs) {
	hash[attrib] = 1;
    }

    // We cheat a little and add a bunch of real common ones, as well as
    // ones that are normally implemented by parents (usually containers)
    hash.expand = 1;
    hash.fill = 1;
    hash.width = 1;
    hash.height = 1;
    hash["x-fixed"] = 1;
    hash["y-fixed"] = 1;

    return (hash);
}

function xml_for_attribute (node, attribute)
{
    try {
        value_desc = node.attrib_value_type(attribute);
    } catch (e) {
	// unknowns revert to string type (freeform entry) 
	value_desc = "string";
    }

    basename = "norender." + value_desc;
    n = enode (basename);
    if (n == null) {
	print ("ACK! Unknown value type:", value_desc);
	n = enode ("norender.string");
	value_desc = "string";
    }

    label = n.child ("label.element");
    label.attrib.text = attribute + ":";

    temp = n.child ("temporary");
    temp.attrib.attribute = attribute;

    switch (value_desc) {
	case "float":
        case "percentage":
	case "integer":
	    i = n.child ("spinner");
	    i.attrib.value = node.attribval[attribute];
	    break;
	case "function":
	case "string":
	    i = n.child ("entry");
	    i.attrib.text = node.attrib[attribute];
	    break;
	case "boolean":
	    //print ("setting initial value for attribute", attribute, "to", node.attrib[attribute]);

	    /* first step is to reset all the selected nodes */
	    radios = n.children_attrib_rx ("selected", ".*");
	    for (radio in radios) {
		radio.attrib.selected = "";
	    }

	    if (node.attrib[attribute] == "") {
		i = n.child ("radio.unset");
	    } else {
		if (node.attrib_is_true (attribute)) {
		    i = n.child ("radio.true");
		} else {
		    i = n.child ("radio.false");
		}
    	    }
	    i.attrib.selected = "true";

	    break;

	case "choice":
	    
	    try {
		strings = n.children ("string");
		for (string in strings) {
		    string.destroy ();
		}
	    } catch (e) {}

	    i = n.child ("dropdown");
	    
	    try {
		c = node.attrib_possible_values (attribute);
		choices = c.split (",");
		for (choice in choices) {
		    s = i.new_child ("string");
		    s.attrib.text = choice;
		}
	    } catch (e) { 
		print ("Error getting choices for node", node.path + ".  You should fix this!"); 
		print ("possible_values is", node.attrib_possible_values (attribute)); 
	    }

	    // Set value of dropdown 
	    i.attrib.value = node.attrib[attribute];

	    break;

	default:
	    print ("Unknown type", value_desc);
    }
	  
    return (n.get_child_xml());
}

function properties_working_node ()
{
    window = enode ("window.properties");
    path = window.attrib.working_node;
    
    if (path == "")
	return (null);

    working_node = enode (path);
    return (working_node);
}
	
function properties (ctree, ctree_row)
{
    // Get the destination node that this entry is referring to
    dest_node = enode(ctree_row.attrib["dest-node"]);

    if (dest_node == "")
	return;

    // Clean out all the temporary nodes used for last item
    window = enode ("window.properties");
    try {
	nodes = window.children ("temporary");
	for (node in nodes) {
	    node.destroy ();
	}
    } catch (e) {}
    
    // Clear previous dropdown setting stuff
    clear_dropdowns ();
    
    // save the working node here..
    window.attrib.working_node = dest_node.path;

    valign = enode ("valign.common_properties");
    
    // Check the important properties, and make an entry for each
    prop_hash = important_properties (dest_node.type);
    attributes = dest_node.supported_attribs();
    
    try {
	for (attrib in attributes) {
	    if (prop_hash[attrib]) {
		xml = xml_for_attribute (dest_node, attrib);
		valign.append_xml (xml);
	    }
	}
    } catch (e) {}

    enode ("entry.properties_name").attrib.text = dest_node.attrib.name;
}

function properties_dropdown_selected (node)
{
    attrib = node.attrib.text;
    dest = properties_working_node ();
    valign = enode ("valign.all_properties");
    
    // Clean out all the old stuff.. 
    try {
	nodes = valign.children ("temporary");
	for (n in nodes) {
	    n.destroy ();
	}
    } catch (e) {}

    // Get description
    try {
    	description = dest.attrib_description(attrib);
    } catch (e) {
	description = "";
    }

    // we have to do funky things to make it look good.. 
    try {
	d = enode ("hwrapalign.property_description");
	t = d.new_child ("temporary");
	words = description.split(" ");
    	for (word in words) {
	    n = t.new_child ("label");
	    n.attrib.text = word + " ";
	}
    } catch (e) {}

    xml = xml_for_attribute (dest, attrib);
    valign.append_xml (xml);
}

function properties_get_arbitrary (node)
{
    attrib_node = enode ("entry.properties_arbitrary_attrib");
    value_node = enode ("entry.properties_arbitrary_value");
    dest = properties_working_node ();
   
    attribute = attrib_node.attrib.text;
    value = dest.attrib[attribute];

    value_node.attrib.text = value;
}

function properties_set_arbitrary (node)
{
    attrib_node = enode ("entry.properties_arbitrary_attrib");
    value_node = enode ("entry.properties_arbitrary_value");
    dest = properties_working_node ();
   
    attribute = attrib_node.attrib.text;
    value = value_node.attrib.text;

    if (attribute != "")
	dest.attrib[attribute] = value;
}

function clear_dropdowns ()
{
    enode ("dropdown.set").attrib.text = "";
    enode ("dropdown.supported").attrib.text = "";
}

function properties_set_attribs_reload (node)
{
    dest = properties_working_node ();
    attributes = dest.list_set_attribs();

    clear_dropdowns ();

    /* clean out old entries */
    node.destroy_children ();
    
    try {
	attributes.sort ();
	for (attrib in attributes) {
	    n = node.new_child ("string");
	    n.attrib.text = attrib;
	}
    } catch (e) {}
}

function properties_supported_attribs_reload (node)
{
    dest = properties_working_node ();
    if (!dest)
	return;

    attributes = dest.supported_attribs();

    clear_dropdowns ();
    
    /* clean out old entries */
    node.destroy_children ();
    
    try {
	attributes.sort ();
	for (attrib in attributes) {
	    n = node.new_child ("string");
	    n.attrib.text = attrib;
	}
    } catch (e) {}
}


/*******************************************************************
 * The rest deal with callbacks from the various things above      *
 *******************************************************************/

function properties_boolean_changed (node)
{
    // Find out what attribute this is for.
    temp = node.parent ("temporary");
    attribute = temp.attrib.attribute;
    
    dest = properties_working_node ();
    if (node.attrib.name == "unset") {
	dest.attrib[attribute] = "";
    } else {
	dest.attrib[attribute] = node.attrib.name;
    }
}

function properties_dropdown_changed (node)
{
    // Find out what attribute this is for.
    temp = node.parent ("temporary");
    attribute = temp.attrib.attribute;
  
    dest = properties_working_node ();
    dest.attrib[attribute] = node.attrib.text;
}

function properties_value_changed (node)
{
    // Find out what attribute this is for.
    temp = node.parent ("temporary");
    attribute = temp.attrib.attribute;
   
    dest = properties_working_node ();
    dest.attrib[attribute] = node.attrib.value;
}

function properties_string_changed (node)
{
    // Find out what attribute this is for.
    temp = node.parent ("temporary");
    attribute = temp.attrib.attribute;
    
    dest = properties_working_node ();
    dest.attrib[attribute] = node.attrib.text;
}

function properties_name_changed (node)
{
    dest = properties_working_node ();
    dest.attrib.name = node.attrib.text;
}

?>