- 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:
parent
89bd7a21cd
commit
73c0285ef9
3 changed files with 57 additions and 39 deletions
|
@ -24,7 +24,7 @@
|
|||
# <Shift-TAB> ... like <TAB> but cycles backwards
|
||||
# <CurUp>/<CurDown> ... switch back/forth in the history
|
||||
# <Escape> ... cancel the operation
|
||||
# <Shift-Backspace> ... removes last, whole path element
|
||||
# <Shift-Backspace> ... remove last, whole path element
|
||||
#
|
||||
#
|
||||
# Colors:
|
||||
|
@ -33,25 +33,13 @@
|
|||
# green ... path to existing property
|
||||
# red ... broken path syntax (e.g. "/foo*bar" ... '*' not allowed)
|
||||
# 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>:'.
|
||||
|
||||
|
||||
var kbdevent = _setlistener("/devices/status/keyboard/event", func {
|
||||
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 listener = nil;
|
||||
var input = nil; # what is shown in the popup
|
||||
var explicit_input = nil; # what the user typed (doesn't contain unconfirmed autocompleted parts)
|
||||
var state = nil;
|
||||
|
@ -62,15 +50,32 @@ var history = [];
|
|||
var history_pos = -1;
|
||||
|
||||
|
||||
var handle_key = func(key, shift) {
|
||||
if (!active) {
|
||||
if (key != `/`)
|
||||
return 0; # pass event
|
||||
|
||||
active = 1;
|
||||
var start = func {
|
||||
listener = setlistener("/devices/status/keyboard/event", func(event) {
|
||||
debug.tree(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);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
set_history(-1);
|
||||
|
||||
|
@ -93,11 +98,11 @@ var handle_key = func(key, shift) {
|
|||
s ~= " does not exist";
|
||||
}
|
||||
screen.log.write(s, 1, 1, 1);
|
||||
active = 0;
|
||||
stop(1);
|
||||
return 1;
|
||||
|
||||
} elsif (key == 27) { # escape -> cancel
|
||||
gui.popdown();
|
||||
active = 0;
|
||||
stop(0);
|
||||
return 1;
|
||||
|
||||
} elsif (key == 9) { # tab
|
||||
|
@ -126,18 +131,19 @@ var handle_key = func(key, shift) {
|
|||
print("\n-- property search: '", input, "' ----------------------------------");
|
||||
search(props.globals, input);
|
||||
print("-- done --\n");
|
||||
gui.popdown();
|
||||
active = 0;
|
||||
stop(0);
|
||||
return 1;
|
||||
|
||||
} elsif (key == `*` and state.node != nil and state.value == nil) {
|
||||
debug.tree(state.node);
|
||||
active = 0;
|
||||
stop(1);
|
||||
return 1;
|
||||
|
||||
} elsif (key == `:` and state.node != nil and state.value == nil) {
|
||||
var n = state.node.getAttribute("children") ? state.node : state.parent;
|
||||
gui.property_browser(n);
|
||||
active = 0;
|
||||
stop(1);
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
input ~= chr(key);
|
||||
|
@ -146,13 +152,6 @@ var handle_key = func(key, shift) {
|
|||
history_pos = size(history);
|
||||
}
|
||||
|
||||
if (!active) {
|
||||
append(history, input);
|
||||
history_pos = size(history);
|
||||
gui.popdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
state = parse_input(input);
|
||||
build_completion(explicit_input);
|
||||
|
||||
|
@ -167,7 +166,7 @@ var handle_key = func(key, shift) {
|
|||
color = set_color(0.7, 1, 0.7);
|
||||
|
||||
gui.popupTip(input, 1000000, color);
|
||||
return 1; # yes, we used the key
|
||||
return 1; # we used the key
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
<checkbox>
|
||||
<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>
|
||||
<binding>
|
||||
<command>dialog-apply</command>
|
||||
|
|
23
keyboard.xml
23
keyboard.xml
|
@ -32,8 +32,6 @@ top down before the key bindings are parsed.
|
|||
if (mod == 0 or mod == 1) {
|
||||
controls.ptt(mod + 1);
|
||||
space_release = func { controls.ptt(0) }
|
||||
} else {
|
||||
gui.property_browser();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -369,6 +367,27 @@ top down before the key bindings are parsed.
|
|||
</mod-up>
|
||||
</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">
|
||||
<name>0</name>
|
||||
<desc>Move rudder left.</desc>
|
||||
|
|
Loading…
Reference in a new issue