daily pastebin goal
12%
SHARE
TWEET

FG All Keys v.2

a guest May 5th, 2013 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var showAllKeysDialog = func {
  2.     var node = props.globals.getNode("/input/keyboard");
  3.     var def = props.Node.new({ filename : getprop("/sim/fg-root")~"/keyboard.xml", targetnode : "/input/keyboard-default" });
  4.     fgcommand("loadxml",def);
  5.                
  6.     var name = "Allkeys";
  7.    
  8.     var toggle = size(arg) > 0 and arg[0] != nil and arg[0] > 0;
  9.     if (toggle and contains(dialog, name)) {
  10.         fgcommand("dialog-close", props.Node.new({ "dialog-name": name }));
  11.         delete(dialog, name);
  12.         return;
  13.     }
  14.  
  15.     dialog[name] = Widget.new();
  16.     dialog[name].set("layout", "vbox");
  17.     dialog[name].set("default-padding", 0);
  18.     dialog[name].set("name", name);
  19.  
  20.     # title bar
  21.     var titlebar = dialog[name].addChild("group");
  22.     titlebar.set("layout", "hbox");
  23.     titlebar.addChild("empty").set("stretch", 1);
  24.     titlebar.addChild("text").set("label", "All keys by category");
  25.     titlebar.addChild("empty").set("stretch", 1);
  26.  
  27.     var w = titlebar.addChild("button");
  28.     w.set("pref-width", 16);
  29.     w.set("pref-height", 16);
  30.     w.set("legend", "");
  31.     w.set("default", 1);
  32.     w.set("key", "esc");
  33.     w.setBinding("nasal", "delete(gui.dialog, \"" ~ name ~ "\")");
  34.     w.setBinding("dialog-close");
  35.  
  36.     dialog[name].addChild("hrule");
  37.  
  38.     # key listing
  39.     var keydefs=[];
  40.     foreach (var key; node.getChildren("key")) {
  41.       var name_node=key.getChild("name");
  42.       var desc_node=key.getChild("desc");
  43.       if (key.getChild("mod-shift") != nil) var mshf_node=key.getChild("mod-shift").getChild("desc");
  44.       else var mshf_node = nil;
  45.       if (name_node != nil) {
  46.         var nme = name_node.getValue();
  47.         var custom=1;
  48.         if (desc_node != nil) {
  49.           var desc = desc_node.getValue();
  50.           if (desc == getprop("/input/keyboard-default/key["~key.getIndex()~"]/desc")) custom = 0;
  51.         } else var desc="";
  52.         if (mshf_node != nil) {
  53.           var mshf = mshf_node.getValue();
  54.           if (mshf == getprop("/input/keyboard-default/key["~key.getIndex()~"]/mod-shift/desc")) custom=0;
  55.         } else var mshf="";
  56.         if (nme != getprop("/input/keyboard-default/key["~key.getIndex()~"]/name") and
  57.            nme != getprop("/input/keyboard-default/key["~key.getIndex()~"]/mod-shift/name")) custom = 1;
  58.         if (custom == 1) nme = nme ~" (c)";
  59.        
  60.         if (desc_node != nil) {
  61.           if (key.getChild("category") != nil) append(keydefs, [nme, desc, key.getChild("category").getValue()]);
  62.           else append(keydefs, [nme, desc, "None"]);
  63.         }
  64.         if (mshf_node != nil) {
  65.           if (key.getChild("mod-shift").getChild("category") != nil)
  66.               append(keydefs, ["Shift-"~nme, mshf, key.getChild("mod-shift").getChild("category").getValue()]);
  67.           else append(keydefs, ["Shift-"~nme, mshf, "None"]);
  68.         }
  69.       }
  70.     }
  71.     keydefs = sort(keydefs, func(a, b) { cmp(a[2],b[2]); });
  72.     var cat = "";
  73.     var text="";
  74.     foreach (var key; keydefs) {
  75.       if (cmp(key[2], cat) != 0) {
  76.         text = text ~ (text == "" ? "" : "\n") ~ key[2] ~ ":\n";
  77.         cat=key[2];
  78.       }
  79.       text = text ~ key[0] ~ " ... " ~ key[1] ~ "\n";
  80.     }
  81.     node.setValues({"text": text});
  82.  
  83.     # scrollable text area
  84.     if (node.getNode("text") != nil) {
  85.         dialog[name].set("resizable", 1);
  86.         dialog[name].addChild("empty").set("pref-height", 10);
  87.  
  88.         var width = 500;
  89.         var height = screenHProp.getValue() - 100;
  90.         if (height < 200) {
  91.             height = 200;
  92.         }
  93.  
  94.         var w = dialog[name].addChild("textbox");
  95.         w.set("padding", 4);
  96.         w.set("halign", "fill");
  97.         w.set("valign", "fill");
  98.         w.set("stretch", "true");
  99.         w.set("slider", 20);
  100.         w.set("pref-width", width);
  101.         w.set("pref-height", height);
  102.         w.set("editable", 0);
  103.         w.set("property", node.getPath() ~ "/text");
  104.     } else {
  105.         dialog[name].addChild("empty").set("pref-height", 8);
  106.     }
  107.     fgcommand("dialog-new", dialog[name].prop());
  108.     showDialog(name);
  109. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top