From 467b4eef163047ea8049a58ae34c250052d3dc3b Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Mon, 3 Jan 2011 17:28:40 +0000 Subject: [PATCH] Add function to allow the binding of a menu item to be configured through Nasal using a symbolic name. Usage: gui.menuBind("radio", "dialogs.Radio.open()"); --- Nasal/gui.nas | 17 +++++++++++++++++ gui/menubar.xml | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/Nasal/gui.nas b/Nasal/gui.nas index 2d2d9c52b..ee7cb8e4a 100644 --- a/Nasal/gui.nas +++ b/Nasal/gui.nas @@ -49,6 +49,23 @@ var menuEnable = func(searchname, state) { } } +## +# Set the binding for a menu item to a Nasal script, +# typically a dialog open() command. +# +var menuBind = func(searchname, command) { + foreach (var menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) { + foreach (item; menu.getChildren("item")) { + foreach (name; item.getChildren("name")) { + if (name.getValue() == searchname) { + item.getNode("binding", 1).getNode("command", 1).setValue("nasal"); + item.getNode("binding", 1).getNode("script", 1).setValue(command); + fgcommand("gui-redraw"); + } + } + } + } +} ## # Set mouse cursor coordinates and shape (number or name), and return diff --git a/gui/menubar.xml b/gui/menubar.xml index 07e5b09ed..0d2cc528f 100644 --- a/gui/menubar.xml +++ b/gui/menubar.xml @@ -273,6 +273,7 @@ + autopilot-settings dialog-show autopilot @@ -378,6 +379,7 @@ + map dialog-show map @@ -403,6 +405,7 @@ + radio dialog-show radios @@ -411,6 +414,7 @@ + gps dialog-show gps