Debian Codegraph @

gui/dialogs/property-browser.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <PropertyList>
4 <name>property-browser</name>
5 <layout>vbox</layout>
6 <resizable>true</resizable>
7 <default-padding>3</default-padding>
8
9 <group>
10 <layout>vbox</layout>
11 <group>
12 <layout>hbox</layout>
13
14 <default-padding>1</default-padding>
15
16 <text>
17 <name>title</name>
18 <label>/</label>
19 <property>/sim/gui/dialogs/property-browser/title</property>
20 <live>true</live>
21 </text>
22
23 <empty><stretch>true</stretch></empty>
24
25 <button>
26 <legend>Clone</legend>
27 <pref-width>60</pref-width>
28 <pref-height>20</pref-height>
29 <border>2</border>
30 <binding>
31 <command>nasal</command>
32 <script>clone(dir)</script>
33 </binding>
34 </button>
35 <button>
36 <legend>/</legend>
37 <pref-width>20</pref-width>
38 <pref-height>20</pref-height>
39 <binding>
40 <command>nasal</command>
41 <script>
42 select("/");
43 </script>
44 </binding>
45 </button>
46 <button>
47 <legend>?</legend>
48 <key>?</key>
49 <pref-width>20</pref-width>
50 <pref-height>20</pref-height>
51 <binding>
52 <command>dialog-show</command>
53 <dialog-name>help-property-browser</dialog-name>
54 </binding>
55 </button>
56 <button>
57 <legend>X</legend>
58 <key>Esc</key>
59 <pref-width>20</pref-width>
60 <pref-height>20</pref-height>
61 <binding>
62 <command>dialog-close</command>
63 </binding>
64 </button>
65 </group>
66 </group>
67
68 <hrule/>
69
70 <property-list>
71 <name>property-list</name>
72 <pref-height>500</pref-height>
73 <halign>fill</halign>
74 <valign>fill</valign>
75 <stretch>true</stretch>
76 <property>/sim/gui/dialogs/property-browser/list</property>
77 <binding>
78 <command>dialog-apply</command>
79 <object-name>property-list</object-name>
80 </binding>
81 <binding>
82 <command>nasal</command>
83 <script>select()</script>
84 </binding>
85 </property-list>
86
87 <group>
88 <layout>hbox</layout>
89 <default-padding>2</default-padding>
90
91 <empty><whatever/></empty>
92
93 <text>
94 <label>--</label>
95 <live>true</live>
96 <halign>fill</halign>
97 <stretch>true</stretch>
98 <property>/sim/gui/dialogs/property-browser/label</property>
99 <pref-width>170</pref-width>
100 </text>
101
102 <input>
103 <name>input</name>
104 <halign>fill</halign>
105 <stretch>true</stretch>
106 <pref-width>170</pref-width>
107 <property>/sim/gui/dialogs/property-browser/input</property>
108 </input>
109
110 <button>
111 <legend>Set</legend>
112 <pref-width>50</pref-width>
113 <default>true</default>
114 <binding>
115 <command>dialog-apply</command>
116 <object-name>input</object-name>
117 </binding>
118 <binding>
119 <command>nasal</command>
120 <script>set()</script>
121 </binding>
122 </button>
123 </group>
124
125 <nasal>
126 <open>
127 <![CDATA[
128 var self = cmdarg(); # the node tree representing this dialog as seen in this XML
129 var startdir = props.globals.getNode("/sim/gui/dialogs/property-browser-startdir", 1);
130 var dlgname = self.getNode("name").getValue();
131
132 # props holding values of the dialog elements
133 var dlg = props.globals.getNode("/sim/gui/dialogs/" ~ dlgname, 1);
134 var title = dlg.getNode("title", 1);
135 var label = dlg.getNode("label", 1);
136 var input = dlg.getNode("input", 1);
137 var list = dlg.getNode("list", 1);
138
139 var node = nil; # selected node entry (props.Node)
140 var dir = nil; # current directory (string)
141 var update_interval = 2;
142 var no_selection = "[none]";
143
144 var update = func(w) {
145 self.setValues({ "dialog-name": dlgname, "object-name": w });
146 fgcommand("dialog-update", self);
147 }
148
149 var select = func(path = nil) {
150
151 # Shift-click adds the selected property to the property display
152 # Shift-Alt-click adds all children of the selected property to the property display
153 # Shift-Ctrl-click removes all properties from the display
154 var update_prop_display = func(n) {
155 if (n.getPath() != "" and getprop("/devices/status/keyboard/shift")) {
156 if (getprop("/devices/status/keyboard/ctrl"))
157 return screen.property_display.reset();
158 if (!n.getAttribute("children"))
159 screen.property_display.add(n);
160 elsif (getprop("/devices/status/keyboard/alt"))
161 screen.property_display.add(n.getChildren());
162 }
163 };
164
165 if (path == nil) {
166 var lst = list.getValue();
167 }
168 else {
169 var lst = path;
170 }
171 node = props.globals.getNode(lst);
172 if (node == nil)
173 node = props.globals;
174
175 update_prop_display(node);
176
177 if (node.getAttribute("children")) {
178 dir = node.getPath();
179 title.setValue(node.getPath() == "" ? "Property Browser" : lst);
180 node = nil;
181 label.setValue(no_selection);
182 input.setValue("");
183 list.setValue(dir);
184 update("property-list");
185 } else {
186 var name = node.getName();
187 var index = node.getIndex();
188 var type = node.getType();
189 if (index)
190 name ~= "[" ~ index ~ "]";
191
192 var value = nil;
193 if (type == "BOOL") {
194 value = node.getBoolValue() ? "true" : "false";
195 title.setValue("Hint: Ctrl-click toggles bool values");
196 settimer(func title.setValue(dir), 5, 1);
197 } elsif (type == "STRING") {
198 value = node.getValue();
199 } elsif (type == "NONE") {
200 value = "";
201 } elsif (type != "ALIAS") {
202 value = node.getValue() ~ "";
203 }
204 label.setValue(string.squeeze(name, 30));
205 input.setValue(value);
206 }
207 update("input");
208 }
209
210 var set = func {
211 if (node != nil)
212 node.setValue(input.getValue());
213 }
214
215 var clone = func(start) {
216 startdir.setValue(start);
217 var base = props.globals.getNode("/sim/gui/dialogs", 1);
218 var name = "property-browser";
219 var new_ = base.addChild(name, 1);
220 var path = new_.getPath();
221 var i = new_.getIndex();
222 if (! self.getNode("x", 1).getIntValue()) {
223 self.getNode("x").setValue(self.getNode("__bx", 1).getValue() or 40);
224 }
225 if (! self.getNode("y", 1).getIntValue()) {
226 self.getNode("y").setValue(self.getNode("__by", 1).getValue() or -40);
227 }
228
229 # update the property paths for dialog elements...
230 self.setValues({
231 "name": name~"["~i~"]",
232 "dialog-name": name~"["~i~"]" ,
233 "group[0]/group[0]/text/property": path ~ "/title",
234 "property-list/property": path ~ "/list",
235 "group[1]/text/property": path ~ "/label",
236 "group[1]/input/property": path ~ "/input",
237 "x": self.getNode("x").getIntValue() + 20,
238 "y": self.getNode("y").getIntValue() - 20,
239 });
240
241 # ... and create new dialog
242 fgcommand("dialog-new", self);
243 fgcommand("dialog-show", self);
244 }
245
246 # this function removes the selection marker from the list
247 var auto_update = func {
248 list.setValue(dir);
249 update("property-list");
250 if (update_interval)
251 settimer(auto_update, update_interval, 1);
252 }
253
254 dir = startdir.getValue();
255 if (dir == nil) {
256 dir = "/";
257 startdir.setValue(dir);
258 }
259 list.setValue(dir);
260 select();
261 auto_update();
262 ]]>
263 </open>
264
265 <close>
266 <![CDATA[
267 update_interval = 0;
268 dlg.remove();
269 startdir.setValue(dir);
270 ]]>
271 </close>
272 </nasal>
273 </PropertyList>