1
0
Fork 0

Access menu entries by their name. This way we can avoid fragile absolute

paths. (The label text isn't suitable for this, because it's subject to
translation.)
This commit is contained in:
mfranz 2005-12-09 10:34:43 +00:00
parent 7e982f91c2
commit b8886814ec
2 changed files with 27 additions and 8 deletions

View file

@ -27,6 +27,26 @@ showDialog = func {
props.Node.new({ "dialog-name" : arg[0]}));
}
##
# Enable/disable named menu entry
#
menuEnable = func(name, state) {
foreach (menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) {
if ((n = menu.getNode("name")) != nil and n.getValue() == name) {
menu.getNode("enabled").setBoolValue(state);
return;
}
foreach (item; menu.getChildren("item")) {
if ((n = item.getNode("name")) != nil and n.getValue() == name) {
item.getNode("enabled").setBoolValue(state);
return;
}
}
}
}
########################################################################
# Private Stuff:
########################################################################
@ -47,16 +67,14 @@ INIT = func {
props.globals.getNode("/sim/help/common", 1).setValues(common_aircraft_keys);
# enable "Fuel & Payload" menu entry
if (getprop("/sim/flight-model") == "yasim") {
setprop("/sim/menubar/default/menu[5]/item[0]/enabled", 1);
}
menuEnable("fuel-and-payload", getprop("/sim/flight-model") == "yasim");
# disable "Autopilot" menu entry when KAP140 is used
if (props.globals.getNode("/autopilot/KAP140/locks") != nil) {
setprop("/sim/menubar/default/menu[3]/enabled", 0);
}
menuEnable("autopilot", props.globals.getNode("/autopilot/KAP140/locks") == nil);
}
settimer(INIT, 0);
##
# How many seconds do we show the tip?
#

View file

@ -201,7 +201,7 @@
<label>Tower position</label>
<binding>
<command>dialog-show</command>
<dialog-name>location-of-tower</dialog-name>
<dialog-name>location-of-tower</dialog-name>
</binding>
</item>
@ -209,6 +209,7 @@
<menu>
<label>Autopilot</label>
<name>autopilot</name>
<item>
<label>Autopilot Settings</label>
@ -299,7 +300,7 @@
<item>
<label>Fuel and Payload</label>
<enabled>false</enabled>
<name>fuel-and-payload</name>
<binding>
<command>nasal</command>
<script>gui.showWeightDialog()</script>