Debian Codegraph @

gui/dialogs/nasal-console.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <PropertyList>
4 <x>-20</x>
5 <y>-20</y>
6 <name>nasal-console</name>
7 <dialog-name>nasal-console</dialog-name>
8 <layout>vbox</layout>
9 <resizable>true</resizable>
10
11 <group>
12 <layout>hbox</layout>
13
14 <text>
15 <label>Nasal Console</label>
16 </text>
17
18 <empty><stretch>1</stretch></empty>
19
20 <button>
21 <legend>X</legend>
22 <key>Esc</key>
23 <pref-width>20</pref-width>
24 <pref-height>20</pref-height>
25 <binding>
26 <command>dialog-close</command>
27 </binding>
28 </button>
29 </group>
30
31 <hrule/>
32
33 <textbox>
34 <name>editfield</name>
35 <halign>fill</halign>
36 <valign>fill</valign>
37 <stretch>true</stretch>
38 <pref-width>450</pref-width>
39 <pref-height>200</pref-height>
40 <padding>6</padding>
41 <slider>20</slider>
42 <editable>true</editable>
43 <wrap>false</wrap>
44 <font>
45 <property>sim/gui/selected-style/fonts/nasal-editor</property>
46 </font>
47 <property>/sim/gui/dialogs/nasal-console/edit</property>
48 <binding>
49 <command>dialog-apply</command>
50 <object-name>editfield</object-name>
51 </binding>
52 <binding>
53 <command>nasal</command>
54 <script>select(active)</script>
55 </binding>
56 </textbox>
57
58 <loglist>
59 <halign>fill</halign>
60 <valign>fill</valign>
61 <stretch>true</stretch>
62 <pref-width>450</pref-width>
63 <pref-height>200</pref-height>
64 <padding>6</padding>
65 </loglist>
66
67 <group>
68 <layout>hbox</layout>
69 <halign>fill</halign>
70 <default-padding>4</default-padding>
71
72 <button-template>
73 <enabled>false</enabled>
74 <halign>fill</halign>
75 <stretch>true</stretch>
76 <pref-width>20</pref-width>
77 <pref-height>20</pref-height>
78 <one-shot>0</one-shot>
79 <live>1</live>
80 <legend>## 1 ##</legend>
81 <property>## /sim/gui/dialogs/nasal-console/tab-down[1] ##</property>
82 <binding>
83 <command>dialog-apply</command>
84 <object-name>editfield</object-name>
85 </binding>
86 <binding>
87 <command>nasal</command>
88 <script>## select(1) ##</script>
89 </binding>
90 <binding>
91 <command>dialog-update</command>
92 <object-name>editfield</object-name>
93 </binding>
94 </button-template>
95 </group>
96
97 <hrule/>
98
99 <group>
100 <layout>hbox</layout>
101 <default-padding>4</default-padding>
102
103 <button>
104 <legend>?</legend>
105 <pref-width>20</pref-width>
106 <pref-height>20</pref-height>
107 <binding>
108 <command>nasal</command>
109 <script>help()</script>
110 </binding>
111 <binding>
112 <command>dialog-update</command>
113 <object-name>editfield</object-name>
114 </binding>
115 </button>
116
117 <empty><stretch>1</stretch></empty>
118
119 <button>
120 <legend>Copy to Clipboard</legend>
121 <key>Ctrl-c</key>
122 <key-desc>Copy buffer contents to clipboard</key-desc>
123 <equal>true</equal>
124 <binding>
125 <command>nasal</command>
126 <script>active and copy()</script>
127 </binding>
128 <binding>
129 <command>dialog-update</command>
130 <object-name>editfield</object-name>
131 </binding>
132 </button>
133
134 <button>
135 <legend>Paste from Clipboard</legend>
136 <key>Ctrl-v</key>
137 <key-desc>Paste clipboard contents into active buffer</key-desc>
138 <equal>true</equal>
139 <binding>
140 <command>nasal</command>
141 <script>active and paste()</script>
142 </binding>
143 <binding>
144 <command>dialog-update</command>
145 <object-name>editfield</object-name>
146 </binding>
147 </button>
148
149 <button>
150 <legend>Clear</legend>
151 <key>Ctrl-x</key>
152 <key-desc>Clear buffer</key-desc>
153 <equal>true</equal>
154 <binding>
155 <command>nasal</command>
156 <script>active and clear()</script>
157 </binding>
158 <binding>
159 <command>dialog-update</command>
160 <object-name>editfield</object-name>
161 </binding>
162 </button>
163
164 <button>
165 <legend>Dump</legend>
166 <key>Ctrl-d</key>
167 <key-desc>Dump buffer contents to console</key-desc>
168 <equal>true</equal>
169 <binding>
170 <command>dialog-apply</command>
171 <object-name>editfield</object-name>
172 </binding>
173 <binding>
174 <command>nasal</command>
175 <script>active and dump()</script>
176 </binding>
177 </button>
178
179 <button>
180 <legend>Execute</legend>
181 <default>true</default>
182 <equal>true</equal>
183 <binding>
184 <command>dialog-apply</command>
185 <object-name>editfield</object-name>
186 </binding>
187 <binding>
188 <command>nasal</command>
189 <script>active and execute()</script>
190 </binding>
191 </button>
192 </group>
193
194 <nasal>
195 <open>
196 var self = cmdarg();
197 var dlg = props.globals.getNode("/sim/gui/dialogs/nasal-console", 1);
198 var kbdctrl = props.globals.getNode("/devices/status/keyboard/ctrl", 1);
199 var edit = dlg.getNode("edit", 1);
200 if (!contains(globals, "__nasal_console"))
201 globals["__nasal_console"] = {};
202
203 var locals = globals["__nasal_console"];
204 var numtabs = size(dlg.getChildren("code"));
205 if (!numtabs)
206 numtabs = 10;
207
208 var dump = func {
209 gui.dialog_apply("nasal-console", "editfield");
210 select(active);
211 rule = "--------------------------------------------------------------------------------";
212 print(rule ~ "\n");
213 print(edit.getValue());
214 print(rule);
215 }
216
217 var clear = func {
218 edit.setValue("");
219 select(active);
220 }
221
222 var copy = func {
223 gui.dialog_apply("nasal-console", "editfield");
224 select(active);
225 clipboard.setText( edit.getValue() );
226 }
227
228 var paste = func {
229 edit.setValue( clipboard.getText() );
230 select(active);
231 }
232
233 var execute = func(what = nil) {
234 var num = what != nil ? what.getIndex() : active;
235 var tag = "&lt;nasal-console/#" ~ num ~ ">";
236 var err = [];
237 if (what == nil)
238 what = edit;
239
240 var f = call(func { compile(what.getValue(), tag) }, nil, nil, nil, err);
241 if (size(err)) {
242 print(tag ~ ": " ~ err[0]);
243 return;
244 }
245 f = bind(f, globals);
246 call(f, nil, nil, locals, err);
247 debug.printerror(err);
248 }
249
250 var tabs = self.getNode("group[1]");
251 var select = func(which, init = 0) {
252 if (active) { # false in help mode
253 dlg.getNode("active").setIntValue(active);
254 if (!init)
255 dlg.getChild("code", active).setValue(string.trim(edit.getValue()));
256 }
257 if (kbdctrl.getValue()) {
258 execute(dlg.getChild("code", which));
259 return;
260 }
261 active = which;
262 foreach (var c; dlg.getChildren("tab-down"))
263 c.setBoolValue(c.getIndex() == active);
264
265 dlg.getNode("active").setIntValue(active = which);
266 edit.setValue(dlg.getChild("code", active).getValue());
267 }
268 var get_button_desc = func (b) {
269 var sep = " ... ";
270 var key=b.getChild("key");
271 var desc=b.getChild("key-desc");
272 if( !isa(key, props.Node) or !isa(desc, props.Node) )
273 return "";
274 return " "~key.getValue() ~sep~desc.getValue() ~"\n";
275 }
276
277 var key_bindings = (func {
278 var desc = "";
279 var buttons = self.getNode("group[2]").getChildren("button");
280 foreach(var b; buttons) desc ~= get_button_desc(b);
281 return desc;
282 })();
283
284 var help = func {
285 active = 0;
286 foreach (var c; dlg.getChildren("tab-down"))
287 c.setBoolValue(0);
288
289 edit.setValue("Keys:\n"
290 ~ " tab ... leave edit mode (visible text cursor)\n"
291 ~ " return ... execute active code\n"
292 ~ key_bindings
293 ~ " esc ... close dialog\n\n"
294 ~ "Ctrl-click on tab buttons executes code without\n"
295 ~ "switching to the tab. Add more &lt;code> properties\n"
296 ~ "in ~/.fgfs/autosave.xml for more tab buttons.");
297 }
298
299 # setup tab buttons and properties from the template
300 tabs.removeChildren("button");
301 var template = tabs.getNode("button-template");
302 var d = dlg.getPath();
303 for (var i = 1; i &lt;= numtabs; i += 1) {
304 var button = tabs.getChild("button", i, 1);
305 var state = dlg.getChild("tab-down", i, 1);
306 state.setBoolValue(0);
307
308 props.copy(template, button);
309 button.getNode("enabled").setBoolValue(1);
310 button.getNode("legend").setIntValue(i);
311 button.getNode("binding[1]/script").setValue("select(" ~ i ~ ")");
312 button.getNode("property").setValue(state.getPath());
313 var c = dlg.getChild("code", i);
314 if (c == nil or c.getType() == "NONE") {
315 c = dlg.getChild("code", i, 1);
316 c.setValue("");
317 c.setAttribute("userarchive", 1);
318 }
319 }
320
321 edit.setValue("");
322 var active = dlg.getNode("active", 1).getValue();
323 if (active == nil)
324 active = 1;
325
326 select(active, 1);
327 </open>
328 </nasal>
329 </PropertyList>