2006-02-15 10:33:38 +00:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<PropertyList>
|
|
|
|
<x>-20</x>
|
|
|
|
<y>-20</y>
|
|
|
|
<name>nasal-console</name>
|
2009-01-10 21:59:27 +00:00
|
|
|
<dialog-name>nasal-console</dialog-name>
|
2006-02-15 10:33:38 +00:00
|
|
|
<layout>vbox</layout>
|
2009-01-10 21:59:27 +00:00
|
|
|
<resizable>true</resizable>
|
2006-02-15 10:33:38 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
<group>
|
|
|
|
<layout>hbox</layout>
|
|
|
|
<empty><stretch>1</stretch></empty>
|
|
|
|
|
|
|
|
<text>
|
|
|
|
<label>Nasal Console</label>
|
|
|
|
</text>
|
|
|
|
|
|
|
|
<empty><stretch>1</stretch></empty>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<pref-width>16</pref-width>
|
|
|
|
<pref-height>16</pref-height>
|
|
|
|
<legend></legend>
|
|
|
|
<keynum>27</keynum>
|
|
|
|
<border>2</border>
|
|
|
|
|
|
|
|
<binding>
|
|
|
|
<command>dialog-close</command>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
</group>
|
2006-02-15 10:33:38 +00:00
|
|
|
|
2007-03-26 15:25:27 +00:00
|
|
|
<hrule/>
|
2006-02-15 10:33:38 +00:00
|
|
|
|
|
|
|
<textbox>
|
2007-03-28 14:59:22 +00:00
|
|
|
<name>editfield</name>
|
2006-02-15 10:33:38 +00:00
|
|
|
<halign>fill</halign>
|
2009-01-10 21:59:27 +00:00
|
|
|
<valign>fill</valign>
|
|
|
|
<stretch>true</stretch>
|
2006-02-15 12:15:37 +00:00
|
|
|
<pref-width>450</pref-width>
|
2007-03-28 14:59:22 +00:00
|
|
|
<pref-height>200</pref-height>
|
2009-01-28 21:12:15 +00:00
|
|
|
<padding>6</padding>
|
2006-02-15 10:33:38 +00:00
|
|
|
<slider>20</slider>
|
|
|
|
<editable>true</editable>
|
2009-01-20 22:52:57 +00:00
|
|
|
<wrap>false</wrap>
|
2009-01-09 12:11:23 +00:00
|
|
|
<font>
|
2017-11-12 15:55:25 +00:00
|
|
|
<property>sim/gui/selected-style/fonts/nasal-editor</property>
|
2009-01-09 12:11:23 +00:00
|
|
|
</font>
|
2007-03-28 14:59:22 +00:00
|
|
|
<property>/sim/gui/dialogs/nasal-console/edit</property>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
2007-03-29 14:53:40 +00:00
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>select(active)</script>
|
|
|
|
</binding>
|
2006-02-15 10:33:38 +00:00
|
|
|
</textbox>
|
|
|
|
|
2013-02-08 19:42:25 +00:00
|
|
|
<loglist>
|
|
|
|
<halign>fill</halign>
|
|
|
|
<valign>fill</valign>
|
|
|
|
<stretch>true</stretch>
|
|
|
|
<pref-width>450</pref-width>
|
|
|
|
<pref-height>200</pref-height>
|
|
|
|
<padding>6</padding>
|
|
|
|
</loglist>
|
|
|
|
|
2006-02-15 10:33:38 +00:00
|
|
|
<group>
|
|
|
|
<layout>hbox</layout>
|
2007-03-28 14:59:22 +00:00
|
|
|
<halign>fill</halign>
|
|
|
|
<default-padding>4</default-padding>
|
2006-02-15 10:33:38 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
<button-template>
|
2008-08-05 05:28:27 +00:00
|
|
|
<enabled>false</enabled>
|
2006-02-15 10:33:38 +00:00
|
|
|
<halign>fill</halign>
|
2009-01-28 21:12:15 +00:00
|
|
|
<stretch>true</stretch>
|
2007-03-28 14:59:22 +00:00
|
|
|
<pref-width>20</pref-width>
|
|
|
|
<pref-height>20</pref-height>
|
|
|
|
<one-shot>0</one-shot>
|
|
|
|
<live>1</live>
|
|
|
|
<legend>## 1 ##</legend>
|
|
|
|
<property>## /sim/gui/dialogs/nasal-console/tab-down[1] ##</property>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>## select(1) ##</script>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-update</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
</button-template>
|
|
|
|
</group>
|
|
|
|
|
|
|
|
<hrule/>
|
2006-02-15 10:33:38 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
<group>
|
|
|
|
<layout>hbox</layout>
|
|
|
|
<default-padding>4</default-padding>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<legend>?</legend>
|
2009-01-10 21:59:27 +00:00
|
|
|
<pref-width>20</pref-width>
|
|
|
|
<pref-height>20</pref-height>
|
2007-03-28 14:59:22 +00:00
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>help()</script>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-update</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<empty><stretch>1</stretch></empty>
|
|
|
|
|
|
|
|
<button>
|
2012-09-12 22:29:46 +00:00
|
|
|
<legend>Copy to Clipboard</legend>
|
2007-03-28 14:59:22 +00:00
|
|
|
<key>Ctrl-c</key>
|
2012-09-12 22:29:46 +00:00
|
|
|
<key-desc>Copy buffer contents to clipboard</key-desc>
|
|
|
|
<equal>true</equal>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>active and copy()</script>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-update</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<legend>Paste from Clipboard</legend>
|
|
|
|
<key>Ctrl-v</key>
|
|
|
|
<key-desc>Paste clipboard contents into active buffer</key-desc>
|
|
|
|
<equal>true</equal>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>active and paste()</script>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-update</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<legend>Clear</legend>
|
|
|
|
<key>Ctrl-x</key>
|
|
|
|
<key-desc>Clear buffer</key-desc>
|
2007-03-28 14:59:22 +00:00
|
|
|
<equal>true</equal>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>active and clear()</script>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-update</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button>
|
2007-03-29 14:53:40 +00:00
|
|
|
<legend>Dump</legend>
|
|
|
|
<key>Ctrl-d</key>
|
2012-09-12 22:29:46 +00:00
|
|
|
<key-desc>Dump buffer contents to console</key-desc>
|
2007-03-28 14:59:22 +00:00
|
|
|
<equal>true</equal>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>active and dump()</script>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<legend>Execute</legend>
|
|
|
|
<default>true</default>
|
|
|
|
<equal>true</equal>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name>editfield</object-name>
|
|
|
|
</binding>
|
|
|
|
<binding>
|
|
|
|
<command>nasal</command>
|
|
|
|
<script>active and execute()</script>
|
|
|
|
</binding>
|
|
|
|
</button>
|
2006-02-15 10:33:38 +00:00
|
|
|
</group>
|
2007-03-28 14:59:22 +00:00
|
|
|
|
|
|
|
<nasal>
|
|
|
|
<open>
|
2009-01-10 21:59:27 +00:00
|
|
|
var self = cmdarg();
|
2007-04-01 13:38:35 +00:00
|
|
|
var dlg = props.globals.getNode("/sim/gui/dialogs/nasal-console", 1);
|
2007-03-28 14:59:22 +00:00
|
|
|
var kbdctrl = props.globals.getNode("/devices/status/keyboard/ctrl", 1);
|
|
|
|
var edit = dlg.getNode("edit", 1);
|
2007-06-17 14:21:29 +00:00
|
|
|
if (!contains(globals, "__nasal_console"))
|
2007-03-29 14:53:40 +00:00
|
|
|
globals["__nasal_console"] = {};
|
2007-06-17 14:21:29 +00:00
|
|
|
|
2007-03-29 14:53:40 +00:00
|
|
|
var locals = globals["__nasal_console"];
|
2007-03-28 14:59:22 +00:00
|
|
|
var numtabs = size(dlg.getChildren("code"));
|
2007-06-17 14:21:29 +00:00
|
|
|
if (!numtabs)
|
2007-03-28 14:59:22 +00:00
|
|
|
numtabs = 10;
|
|
|
|
|
|
|
|
var dump = func {
|
2007-03-29 14:53:40 +00:00
|
|
|
gui.dialog_apply("nasal-console", "editfield");
|
|
|
|
select(active);
|
2007-03-28 14:59:22 +00:00
|
|
|
rule = "--------------------------------------------------------------------------------";
|
|
|
|
print(rule ~ "\n");
|
|
|
|
print(edit.getValue());
|
|
|
|
print(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
var clear = func {
|
|
|
|
edit.setValue("");
|
2007-03-29 14:53:40 +00:00
|
|
|
select(active);
|
2007-03-28 14:59:22 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 22:29:46 +00:00
|
|
|
var copy = func {
|
|
|
|
gui.dialog_apply("nasal-console", "editfield");
|
|
|
|
select(active);
|
|
|
|
clipboard.setText( edit.getValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
var paste = func {
|
|
|
|
edit.setValue( clipboard.getText() );
|
|
|
|
select(active);
|
|
|
|
}
|
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
var execute = func(what = nil) {
|
2007-06-17 14:21:29 +00:00
|
|
|
var num = what != nil ? what.getIndex() : active;
|
|
|
|
var tag = "<nasal-console/#" ~ num ~ ">";
|
2007-03-28 14:59:22 +00:00
|
|
|
var err = [];
|
2007-06-17 14:21:29 +00:00
|
|
|
if (what == nil)
|
2007-03-28 14:59:22 +00:00
|
|
|
what = edit;
|
2007-06-17 14:21:29 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
var f = call(func { compile(what.getValue(), tag) }, nil, nil, nil, err);
|
|
|
|
if (size(err)) {
|
|
|
|
print(tag ~ ": " ~ err[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
f = bind(f, globals);
|
|
|
|
call(f, nil, nil, locals, err);
|
2007-06-17 14:21:29 +00:00
|
|
|
debug.printerror(err);
|
2007-03-28 14:59:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 21:59:27 +00:00
|
|
|
var tabs = self.getNode("group[1]");
|
2007-03-28 14:59:22 +00:00
|
|
|
var select = func(which, init = 0) {
|
|
|
|
if (active) { # false in help mode
|
|
|
|
dlg.getNode("active").setIntValue(active);
|
2007-06-17 14:21:29 +00:00
|
|
|
if (!init)
|
2007-06-22 14:13:30 +00:00
|
|
|
dlg.getChild("code", active).setValue(string.trim(edit.getValue()));
|
2007-03-28 14:59:22 +00:00
|
|
|
}
|
|
|
|
if (kbdctrl.getValue()) {
|
|
|
|
execute(dlg.getChild("code", which));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
active = which;
|
2007-06-17 14:21:29 +00:00
|
|
|
foreach (var c; dlg.getChildren("tab-down"))
|
2007-03-28 14:59:22 +00:00
|
|
|
c.setBoolValue(c.getIndex() == active);
|
2007-06-17 14:21:29 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
dlg.getNode("active").setIntValue(active = which);
|
|
|
|
edit.setValue(dlg.getChild("code", active).getValue());
|
|
|
|
}
|
2012-09-12 22:29:46 +00:00
|
|
|
var get_button_desc = func (b) {
|
|
|
|
var sep = " ... ";
|
|
|
|
var key=b.getChild("key");
|
|
|
|
var desc=b.getChild("key-desc");
|
|
|
|
if( !isa(key, props.Node) or !isa(desc, props.Node) )
|
|
|
|
return "";
|
|
|
|
return " "~key.getValue() ~sep~desc.getValue() ~"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
var key_bindings = (func {
|
|
|
|
var desc = "";
|
|
|
|
var buttons = self.getNode("group[2]").getChildren("button");
|
|
|
|
foreach(var b; buttons) desc ~= get_button_desc(b);
|
|
|
|
return desc;
|
|
|
|
})();
|
2007-03-28 14:59:22 +00:00
|
|
|
|
|
|
|
var help = func {
|
|
|
|
active = 0;
|
2007-06-17 14:21:29 +00:00
|
|
|
foreach (var c; dlg.getChildren("tab-down"))
|
2007-03-28 14:59:22 +00:00
|
|
|
c.setBoolValue(0);
|
2007-06-17 14:21:29 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
edit.setValue("Keys:\n"
|
2009-01-22 23:29:57 +00:00
|
|
|
~ " tab ... leave edit mode (visible text cursor)\n"
|
2007-03-28 14:59:22 +00:00
|
|
|
~ " return ... execute active code\n"
|
2012-09-12 22:29:46 +00:00
|
|
|
~ key_bindings
|
2009-01-22 23:29:57 +00:00
|
|
|
~ " esc ... close dialog\n\n"
|
|
|
|
~ "Ctrl-click on tab buttons executes code without\n"
|
|
|
|
~ "switching to the tab. Add more <code> properties\n"
|
|
|
|
~ "in ~/.fgfs/autosave.xml for more tab buttons.");
|
2007-03-28 14:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# setup tab buttons and properties from the template
|
|
|
|
tabs.removeChildren("button");
|
|
|
|
var template = tabs.getNode("button-template");
|
|
|
|
var d = dlg.getPath();
|
|
|
|
for (var i = 1; i <= numtabs; i += 1) {
|
|
|
|
var button = tabs.getChild("button", i, 1);
|
|
|
|
var state = dlg.getChild("tab-down", i, 1);
|
|
|
|
state.setBoolValue(0);
|
|
|
|
|
|
|
|
props.copy(template, button);
|
2008-08-05 05:28:27 +00:00
|
|
|
button.getNode("enabled").setBoolValue(1);
|
2007-03-28 14:59:22 +00:00
|
|
|
button.getNode("legend").setIntValue(i);
|
|
|
|
button.getNode("binding[1]/script").setValue("select(" ~ i ~ ")");
|
|
|
|
button.getNode("property").setValue(state.getPath());
|
|
|
|
var c = dlg.getChild("code", i);
|
|
|
|
if (c == nil or c.getType() == "NONE") {
|
|
|
|
c = dlg.getChild("code", i, 1);
|
|
|
|
c.setValue("");
|
|
|
|
c.setAttribute("userarchive", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edit.setValue("");
|
|
|
|
var active = dlg.getNode("active", 1).getValue();
|
2007-06-17 14:21:29 +00:00
|
|
|
if (active == nil)
|
2007-03-28 14:59:22 +00:00
|
|
|
active = 1;
|
2007-06-17 14:21:29 +00:00
|
|
|
|
2007-03-28 14:59:22 +00:00
|
|
|
select(active, 1);
|
|
|
|
</open>
|
|
|
|
</nasal>
|
2006-02-15 10:33:38 +00:00
|
|
|
</PropertyList>
|