- move bo105's Dialog class here; replaces gui.loadXMLDialog()
- fix indentation
This commit is contained in:
parent
d583bbcb4f
commit
8aa5947e7a
1 changed files with 66 additions and 39 deletions
105
Nasal/gui.nas
105
Nasal/gui.nas
|
@ -144,65 +144,92 @@ Widget = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# load XML dialog
|
# Dialog class. Maintains one XML dialog.
|
||||||
# node ... target node (name must be "dialog")
|
# prop ... target node (name must be "dialog")
|
||||||
# path ... file path relative to $FG_ROOT
|
# path ... file path relative to $FG_ROOT
|
||||||
#
|
#
|
||||||
# return value:
|
|
||||||
# target node on success, nil otherwise
|
|
||||||
#
|
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# var dlg = props.globals.getNode("/sim/gui/dialogs/foo-config/dialog", 1);
|
# var dlg = gui.Dialog.new("/sim/gui/dialogs/foo-config/dialog",
|
||||||
# loadXMLDialog(dlg, "Aircraft/foo/foo_config.xml");
|
# "Aircraft/foo/foo_config.xml");
|
||||||
# fgcommand("dialog-show", dlg);
|
# dlg.open();
|
||||||
|
# dlg.close();
|
||||||
#
|
#
|
||||||
loadXMLDialog = func(node, path) {
|
Dialog = {
|
||||||
if (node.getName() != "dialog") {
|
new : func(prop, path) {
|
||||||
print("loadXMLDialog: node name must be 'dialog'");
|
var m = { parents : [Dialog] };
|
||||||
return nil;
|
m.path = path;
|
||||||
}
|
m.prop = isa(props.Node, prop) ? prop : props.globals.getNode(prop, 1);
|
||||||
fgcommand("loadxml", props.Node.new({"filename": path, "targetnode": node.getPath()}));
|
m.state = 0;
|
||||||
var name = node.getNode("name");
|
m.loaded = 0;
|
||||||
if (name == nil) {
|
return m;
|
||||||
print("loadXMLDialog: XML dialog must have <name>");
|
},
|
||||||
return nil;
|
# doesn't need to be called explicitly, but can be used to force a reload
|
||||||
}
|
load : func {
|
||||||
node.getNode("dialog-name", 1).setValue(name.getValue());
|
if (me.prop.getName() != "dialog") {
|
||||||
fgcommand("dialog-new", node);
|
die("Dialog class: node name must be 'dialog'");
|
||||||
node;
|
}
|
||||||
}
|
fgcommand("loadxml", props.Node.new({"filename": me.path,
|
||||||
|
"targetnode": me.prop.getPath()}));
|
||||||
|
var name = me.prop.getNode("name");
|
||||||
|
if (name == nil) {
|
||||||
|
die("Dialog class: XML dialog must have <name>");
|
||||||
|
}
|
||||||
|
me.prop.getNode("dialog-name", 1).setValue(name.getValue());
|
||||||
|
fgcommand("dialog-new", me.prop);
|
||||||
|
me.loaded = 1;
|
||||||
|
},
|
||||||
|
open : func {
|
||||||
|
if (!me.loaded) {
|
||||||
|
me.load(me.prop, me.path);
|
||||||
|
}
|
||||||
|
fgcommand("dialog-show", me.prop);
|
||||||
|
me.state = 1;
|
||||||
|
},
|
||||||
|
close : func {
|
||||||
|
fgcommand("dialog-close", me.prop);
|
||||||
|
me.state = 0;
|
||||||
|
},
|
||||||
|
toggle : func {
|
||||||
|
me.state ? me.close() : me.open();
|
||||||
|
},
|
||||||
|
is_open : func {
|
||||||
|
me.state;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Open property browser with given target path.
|
# Open property browser with given target path.
|
||||||
#
|
#
|
||||||
property_browser = func(dir = "/") {
|
property_browser = func(dir = "/") {
|
||||||
var dlgname = "property-browser";
|
var dlgname = "property-browser";
|
||||||
foreach (var module; keys(globals)) {
|
foreach (var module; keys(globals)) {
|
||||||
if (find("__dlg:" ~ dlgname, module) >= 0) {
|
if (find("__dlg:" ~ dlgname, module) >= 0) {
|
||||||
globals[module].clone(dir);
|
return globals[module].clone(dir);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
setprop("/sim/gui/dialogs/" ~ dlgname ~ "/last", dir);
|
||||||
setprop("/sim/gui/dialogs/" ~ dlgname ~ "/last", dir);
|
fgcommand("dialog-show", props.Node.new({"dialog-name": dlgname}));
|
||||||
fgcommand("dialog-show", props.Node.new({"dialog-name": dlgname}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Open one property browser per /browser[] property, where each contains
|
# Open one property browser per /browser[] property, where each contains
|
||||||
# the target path. On the command line use --prop:browser=orientation
|
# the target path. On the command line use --prop:browser=orientation
|
||||||
#
|
#
|
||||||
settimer(func {
|
settimer(func {
|
||||||
foreach (var b; props.globals.getChildren("browser")) {
|
foreach (var b; props.globals.getChildren("browser")) {
|
||||||
var path = b.getValue();
|
var path = b.getValue();
|
||||||
if (path != nil and size(path)) {
|
if (path != nil and size(path)) {
|
||||||
property_browser(path);
|
property_browser(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
props.globals.removeChildren("browser");
|
props.globals.removeChildren("browser");
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue