1
0
Fork 0

- remove property browser binding from the <SPACE> key

- rename prop-key-handler.nas to prop_key_handler.nas  (the hyphens were
  intentional, exactly to *make* using it as namespace less inviting,
  but times change ...)
- add property browser binding to the '/'-key for when the property key handler
  is turned off (/sim/input/property-key-handler=0). If it's on, use /: or
  /<property>: to open the browser.
- run keyboard event listener only when property key handler is active

I hope that the '/' key can keep this binding even after a keyboard review.
The '/' is just the most natural key for dealing with properties, and it's
far less prominent on non-US-keyboards (e.g. Shift-7 on German keyboards),
so it's not really very well suited for important aircraft functions, anyway.
But I don't insist. :-)
This commit is contained in:
mfranz 2007-11-26 16:12:37 +00:00
parent 89bd7a21cd
commit 73c0285ef9
3 changed files with 57 additions and 39 deletions

View file

@ -24,7 +24,7 @@
# <Shift-TAB> ... like <TAB> but cycles backwards # <Shift-TAB> ... like <TAB> but cycles backwards
# <CurUp>/<CurDown> ... switch back/forth in the history # <CurUp>/<CurDown> ... switch back/forth in the history
# <Escape> ... cancel the operation # <Escape> ... cancel the operation
# <Shift-Backspace> ... removes last, whole path element # <Shift-Backspace> ... remove last, whole path element
# #
# #
# Colors: # Colors:
@ -33,25 +33,13 @@
# green ... path to existing property # green ... path to existing property
# red ... broken path syntax (e.g. "/foo*bar" ... '*' not allowed) # red ... broken path syntax (e.g. "/foo*bar" ... '*' not allowed)
# yellow ... while typing in value for a valid property path # yellow ... while typing in value for a valid property path
# magenta ... while typing search string (except when first char is '/') # magenta ... while typing search string (except when first character is '/')
# #
# #
# For example, to open the property browser in /position/, type '/p<TAB>:'. # For example, to open the property browser in /position/, type '/p<TAB>:'.
var kbdevent = _setlistener("/devices/status/keyboard/event", func { var listener = nil;
var event = cmdarg();
#debug.tree(event);
if (!getprop("/sim/input/property-key-handler") or !event.getNode("pressed").getValue())
return;
var key = event.getNode("key");
var shift = event.getNode("modifier/shift").getValue();
if (handle_key(key.getValue(), shift))
key.setValue(0); # drop key event
});
var active = 0;
var input = nil; # what is shown in the popup var input = nil; # what is shown in the popup
var explicit_input = nil; # what the user typed (doesn't contain unconfirmed autocompleted parts) var explicit_input = nil; # what the user typed (doesn't contain unconfirmed autocompleted parts)
var state = nil; var state = nil;
@ -62,15 +50,32 @@ var history = [];
var history_pos = -1; var history_pos = -1;
var handle_key = func(key, shift) { var start = func {
if (!active) { listener = setlistener("/devices/status/keyboard/event", func(event) {
if (key != `/`) debug.tree(event);
return 0; # pass event if (!event.getNode("pressed").getValue())
return;
var key = event.getNode("key");
var shift = event.getNode("modifier/shift").getValue();
if (handle_key(key.getValue(), shift))
key.setValue(0); # drop key event
});
state = parse_input(input = "");
handle_key(`/`, 0);
}
active = 1;
state = parse_input(input = ""); var stop = func(save_history = 0) {
removelistener(listener);
gui.popdown();
if (save_history) {
append(history, input);
history_pos = size(history);
} }
}
var handle_key = func(key, shift) {
if (key == 357) { # up if (key == 357) { # up
set_history(-1); set_history(-1);
@ -93,11 +98,11 @@ var handle_key = func(key, shift) {
s ~= " does not exist"; s ~= " does not exist";
} }
screen.log.write(s, 1, 1, 1); screen.log.write(s, 1, 1, 1);
active = 0; stop(1);
return 1;
} elsif (key == 27) { # escape -> cancel } elsif (key == 27) { # escape -> cancel
gui.popdown(); stop(0);
active = 0;
return 1; return 1;
} elsif (key == 9) { # tab } elsif (key == 9) { # tab
@ -126,18 +131,19 @@ var handle_key = func(key, shift) {
print("\n-- property search: '", input, "' ----------------------------------"); print("\n-- property search: '", input, "' ----------------------------------");
search(props.globals, input); search(props.globals, input);
print("-- done --\n"); print("-- done --\n");
gui.popdown(); stop(0);
active = 0;
return 1; return 1;
} elsif (key == `*` and state.node != nil and state.value == nil) { } elsif (key == `*` and state.node != nil and state.value == nil) {
debug.tree(state.node); debug.tree(state.node);
active = 0; stop(1);
return 1;
} elsif (key == `:` and state.node != nil and state.value == nil) { } elsif (key == `:` and state.node != nil and state.value == nil) {
var n = state.node.getAttribute("children") ? state.node : state.parent; var n = state.node.getAttribute("children") ? state.node : state.parent;
gui.property_browser(n); gui.property_browser(n);
active = 0; stop(1);
return 1;
} else { } else {
input ~= chr(key); input ~= chr(key);
@ -146,13 +152,6 @@ var handle_key = func(key, shift) {
history_pos = size(history); history_pos = size(history);
} }
if (!active) {
append(history, input);
history_pos = size(history);
gui.popdown();
return 1;
}
state = parse_input(input); state = parse_input(input);
build_completion(explicit_input); build_completion(explicit_input);
@ -167,7 +166,7 @@ var handle_key = func(key, shift) {
color = set_color(0.7, 1, 0.7); color = set_color(0.7, 1, 0.7);
gui.popupTip(input, 1000000, color); gui.popupTip(input, 1000000, color);
return 1; # yes, we used the key return 1; # we used the key
} }

View file

@ -26,7 +26,7 @@
<checkbox> <checkbox>
<halign>left</halign> <halign>left</halign>
<label>Enable '/'-key property handler (see $FG_ROOT/Nasal/prop-key-handler.nas)</label> <label>Enable '/'-key property handler (see $FG_ROOT/Nasal/prop_key_handler.nas)</label>
<property>/sim/input/property-key-handler</property> <property>/sim/input/property-key-handler</property>
<binding> <binding>
<command>dialog-apply</command> <command>dialog-apply</command>

View file

@ -32,8 +32,6 @@ top down before the key bindings are parsed.
if (mod == 0 or mod == 1) { if (mod == 0 or mod == 1) {
controls.ptt(mod + 1); controls.ptt(mod + 1);
space_release = func { controls.ptt(0) } space_release = func { controls.ptt(0) }
} else {
gui.property_browser();
} }
} }
</script> </script>
@ -369,6 +367,27 @@ top down before the key bindings are parsed.
</mod-up> </mod-up>
</key> </key>
<key n="47">
<name>/</name>
<desc>Activate property handler development tool</desc>
<binding>
<condition>
<not>
<property>/sim/input/property-key-handler</property>
</not>
</condition>
<command>nasal</command>
<script>gui.property_browser()</script>
</binding>
<binding>
<condition>
<property>/sim/input/property-key-handler</property>
</condition>
<command>nasal</command>
<script>prop_key_handler.start()</script>
</binding>
</key>
<key n="48"> <key n="48">
<name>0</name> <name>0</name>
<desc>Move rudder left.</desc> <desc>Move rudder left.</desc>