# ============================================================================== # This file contains the following functions: # multichoice # ============================================================================== NEDIT_require_macro_file("element.nm") # ============================================================================== # multichoice(choices, n_opts, label_type): lists the choice text in choices # (each line is a choice) with a button per choice, in a series of dialog # boxes. The lines can be numbered (default), with the line numbers used # for button labels, or the first word (contiguous non-space characters) # can be used as button labels. Up to 7 buttons can be displayed per # dialog. Returns the contents of the line chosen, or "". # # Parameters: # $1 - the choices text # $2 - maximum buttons per dialog (default and maximum 7) # $3 - label type ("word" or "number", default "number") # ============================================================================== define multichoice { s = list_dialog("Choose:", $1, "OK", "Cancel") if ($list_dialog_button == 1) return s return "" } define multichoice_old { # get parameters choices = $1 n_opts = 7 if ($n_args >= 2) n_opts = max(1, min(7, n_opts)) label_type = "number" if ($n_args >= 3) if ($3 == "word") label_type = $3 # remove blank lines from choices while (search_string(choices, "\\n[ \\t]*\\n", 0, "regex") != -1) choices = replace_in_string(choices, "\\n[ \\t]*\\n", "", "regex") # remove leading and trailing \n's if (choices != "") { if (substring(choices, 0, 1) == "\n") choices = substring(choices, 1) if (choices != "") if (substring(choices, -1) == "\n") choices = substring(choices, 0, -1) } if (choices == "") return choices # get number of lines n_choices = element_n(choices) while (choices != "") { text = "" # subset of choices from which to choose the result disptext = "" # text to display in the dialog labels = "" # button labels text = element_from_to(choices, 0, n_opts - 1) choices = element_from_to(choices, n_opts) max_choice = 0 for (i = 0, choice_text = element_i(text, i); \ choice_text != ""; \ i++, choice_text = element_i(text, i)) { if (search_string(choice_text, "\t", 0) != -1) choice_text = replace_in_string(choice_text, "\t", " ") max_choice++ if (label_type == "word") { labels = labels \ replace_in_string(choice_text, \ "[\t ]*([^\t ]+).*", "\\1", "regex") "\n" disptext = disptext choice_text "\n" } else { labels = labels i+1 "\n" disptext = disptext i+1 " ==> " choice_text "\n" } } if (choices != "") { labels = labels "more" max_choice++ } res = 0 if (max_choice == 1) res = dialog(disptext, element_i(labels, 0)) else if (max_choice == 2) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1)) else if (max_choice == 3) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1), \ element_i(labels, 2)) else if (max_choice == 4) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1), \ element_i(labels, 2), element_i(labels, 3)) else if (max_choice == 5) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1), \ element_i(labels, 2), element_i(labels, 3), \ element_i(labels, 4)) else if (max_choice == 6) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1), \ element_i(labels, 2), element_i(labels, 3), \ element_i(labels, 4), element_i(labels, 5)) else if (max_choice == 7) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1), \ element_i(labels, 2), element_i(labels, 3), \ element_i(labels, 4), element_i(labels, 5), \ element_i(labels, 6)) else if (max_choice == 8) res = dialog(disptext, element_i(labels, 0), element_i(labels, 1), \ element_i(labels, 2), element_i(labels, 3), \ element_i(labels, 4), element_i(labels, 5), \ element_i(labels, 6), element_i(labels, 7)) if (res == 0) return "" else if (res <= n_opts) return element_i(text, res - 1) } return "" }