property-browser property-browser vbox 3 hbox 1 /sim/gui/dialogs/property-browser/title true true property-list 450 250 /sim/gui/dialogs/property-browser/list dialog-apply property-list nasal hbox 2 true /sim/gui/dialogs/property-browser/label 190 input 190 /sim/gui/dialogs/property-browser/input var self = cmdarg(); var dlgname = self.getNode("name").getValue(); var dlg = props.globals.getNode("/sim/gui/dialogs/" ~ dlgname, 1); var title = dlg.getNode("title", 1); var label = dlg.getNode("label", 1); var input = dlg.getNode("input", 1); var list = dlg.getNode("list", 1); var node = nil; # selected node entry (props.Node) var dir = nil; # current directory (string) var update_interval = 2; var root_title = "Internal Properties"; var no_selection = "[none]"; update = func(w) { self.setValues({"dialog-name": dlgname, "object-name": w}); fgcommand("dialog-update", self); } squeeze = func(s, n) { if (size(s) <= n or n < 7) { return s; } var l = substr(s, 0, (n - 3) / 2); var r = substr(s, size(s) + size(l) + 3 - n); return l ~ "..." ~ r; } select = func { var lst = list.getValue(); node = props.globals.getNode(lst); if (node == nil) { node = props.globals; } if (size(node.getChildren())) { dir = node.getPath(); title.setValue(node.getPath() == "" ? root_title : lst); node = nil; label.setValue(no_selection); input.setValue(""); } else { var name = node.getName(); var index = node.getIndex(); var type = node.getType(); if (index) { name ~= "[" ~ index ~ "]"; } var value = nil; if (type == "BOOL") { value = node.getBoolValue() ? "true" : "false"; title.setValue("Hint: Ctrl-click toggles bool values"); settimer(func {title.setValue(dir) }, 5); } elsif (type == "STRING") { value = node.getValue(); } elsif (type == "NONE") { value = ""; } elsif (type != "ALIAS") { value = node.getValue() ~ ""; } label.setValue(squeeze(name, 30)); input.setValue(value); } update("input"); } set = func { if (node != nil) { node.setValue(input.getValue()); } } clone = func { var name = "property-browser--" ~ int(rand() * 10000000); var base = "/sim/gui/dialogs/" ~ name ~ "/"; setprop(base ~ "/last", dir); self.setValues({ "name": name, "dialog-name": name, "group[0]/text/property": base ~ "title", "property-list/property": base ~ "list", "group[1]/text/property": base ~ "label", "group[1]/input/property": base ~ "input", }); fgcommand("dialog-new", self); fgcommand("dialog-show", self); } auto_update = func { list.setValue(dir); update("property-list"); if (update_interval) { settimer(auto_update, update_interval); } } dir = dlg.getNode("last") != nil ? dlg.getNode("last").getValue() : "/"; list.setValue(dir); select(); auto_update(); update_interval = 0; if (find("--", dlgname) >= 0) { props.globals.getNode("/sim/gui/dialogs", 1).removeChildren(dlgname); } else { dlg.getNode("last", 1).setValue(dir); }