Query about list_dialog()
Tony Balinski
ajbj at free.fr
Tue Jan 9 22:12:16 CET 2007
Quoting YT Lim <ytlim23 at yahoo.com.au>:
> Not sure if this has been asked before. Is there a way
> to move the highlight bar to a specific line in the
> list_dialog box when it pops up?
>
> Send instant messages to your online friends http://au.messenger.yahoo.com
No there is not. For that sort of thing I add a prefix to the line I
would like to have highlighted (usually ">> ") and another (" ") to
all the other lines. If the list dialog returns an empty string (when
no line was selected), I look in the list string for a line with my
"pre-selected" prefix. Something like:
list = "a\nb\nc" # three line list string
# "pre-select" b
selline = "b"
# add prefix to all lines
list_for_dlg = "\n" replace_in_string(list, "^", " ", "regex") "\n"
list_for_dlg = replace_in_string(list_for_dlg, "\n" selline "\n", \
"\n>> " selline "\n", \
"regex")
# call
sel = list_dialog("select a line", list_for_dlg, "OK", "Cancel")
if ($list_dialog_button != 1)
return
if (sel == "") {
# remove lines with non-selected prefix
sel = replace_in_string(list_for_dlg, "^ .*\n", "", "regex")
# remove "pre-selected" prefix
sel = replace_in_string(sel, "^\\>\\> ", "", "regex")
# remove newlines
sel = replace_in_string(sel, "\n", "")
} else {
# remove any prefix on selected line returned by list_dialog()
sel = replace_in_string(sel, "^.. ", "", "regex")
}
It's a bit clumsy and visually rather unappealing, but it works well enough.
In future, extending list_dialog() could allow for preselecting a line (I did
some work on handling "keyword parameters" to functions, for calls like
sel = list_dialog("choose a line", \
.select="multiple", \
.preselect=b, \
list, \
.buttons = {"OK", "Cancel"})
Tony
More information about the Discuss
mailing list