1
0
Fork 0

- typeset longer option lists in multiple columns

- make it a tad faster
This commit is contained in:
mfranz 2008-10-07 10:44:45 +00:00
parent fe8f9134ec
commit 363e210fda

View file

@ -1,9 +1,9 @@
var listener = nil;
var cmd = nil;
var data = nil;
var dialog = nil;
var menu = 0;
var translate = { 356: '<', 357: '^', 358: '>', 359: '_' }; var translate = { 356: '<', 357: '^', 358: '>', 359: '_' };
var listener = nil;
var dialog = nil;
var data = nil;
var cmd = nil;
var menu = 0;
var start = func { var start = func {
@ -24,9 +24,9 @@ var start = func {
var stop = func { var stop = func {
dialog.del();
removelistener(listener); removelistener(listener);
listener = nil; listener = nil;
dialog.del();
} }
@ -37,7 +37,7 @@ var handle_key = func(key) {
return 1; return 1;
} elsif (key == 8) { } elsif (key == 8) {
cmd = substr(cmd, 0, size(cmd) - 1); cmd = substr(cmd, 0, size(cmd) - 1);
} elsif (key == 9) { } elsif (key == `\t`) {
menu = !menu; menu = !menu;
} elsif (key == `\n` or key == `\r`) { } elsif (key == `\n` or key == `\r`) {
mode = 2; mode = 2;
@ -62,9 +62,10 @@ var handle_key = func(key) {
} elsif (node.getNode("exit") != nil) { } elsif (node.getNode("exit") != nil) {
mode = 2; mode = 2;
} }
foreach (var c; node.getChildren("key")) if (menu)
if (size(c.getChildren("binding")) or size(c.getChildren("key"))) foreach (var c; node.getChildren("key"))
append(options, c); if (size(c.getChildren("binding")) or size(c.getChildren("key")))
append(options, c);
} }
if (mode and size(bindings)) { if (mode and size(bindings)) {
@ -74,7 +75,7 @@ var handle_key = func(key) {
stop(); stop();
} }
if (mode < 2) if (mode < 2)
dialog.update(cmd, __multikey._ or desc, menu ? options : []); dialog.update(cmd, __multikey._ or desc, options);
return 1; return 1;
} }
@ -122,28 +123,33 @@ var Dialog = {
t.set("label", cmd); t.set("label", cmd);
# option menu # option menu
if (size(options)) { if (var numopt = size(options)) {
dlg.addChild("hrule"); dlg.addChild("hrule");
var g = dlg.addChild("group"); var g = dlg.addChild("group");
g.set("layout", "table"); g.set("layout", "table");
g.set("default-padding", 2); g.set("default-padding", 2);
var column_height = numopt / (1 + (numopt > 15) + (numopt > 30));
forindex (var i; options) { forindex (var i; options) {
var desc = options[i].getNode("desc", 1).getValue() or ""; var col = 3 * int(i / column_height);
var name = options[i].getNode("name", 1).getValue(); var row = math.mod(i, column_height);
var desc = (options[i].getNode("desc", 1).getValue() or "") ~ " ";
var name = " " ~ options[i].getNode("name", 1).getValue();
name = string.replace(name, "%%", "%"); name = string.replace(name, "%%", "%");
var c = g.addChild("text");
c.set("label", name); var o = g.addChild("text");
c.set("row", i); o.set("label", name);
c.set("col", 0); o.set("row", row);
var c = g.addChild("text"); o.set("col", col);
c.set("label", " ... "); var o = g.addChild("text");
c.set("row", i); o.set("label", " ... ");
c.set("col", 1); o.set("row", row);
var c = g.addChild("text"); o.set("col", col + 1);
c.set("label", desc); var o = g.addChild("text");
c.set("row", i); o.set("label", desc);
c.set("col", 2); o.set("row", row);
c.set("halign", "left"); o.set("col", col + 2);
o.set("halign", "left");
} }
} }
me.del(); me.del();