NEDIT_require_macro_file("array_utils.nm") NEDIT_require_macro_file("RSextensions.nm") $RANGESET_SELECTED = "" # ============================================================================== # RangeSet_names(): fetches names of all range sets, creating them if # necessary. Returns the names as a zero-based array, with the newest # range set's name at index 0. # ============================================================================== define RangeSet_names { names = $empty_array ids = $rangeset_list j = 0 for (i = ids[]; i-- > 0; j++) { name = RangeSet_forceName(ids[j]) names[i] = name } return names } # ============================================================================== # RangeSet_ask(prompt): ask for a range set. It prompts for a range set name # with a set of "recently defined" buttons. Returns the selected name # or "". # ============================================================================== define RangeSet_ask { prompt = $1 if (prompt == "") prompt = "Range set name" result = "" names = RangeSet_names() res = array_ask_vals(prompt, names, 1) if ("null" in res) return "" if ("line" in res) if (res["line"] != "") return res["line"] if ("value" in res) return res["value"] return "" } # ============================================================================== # RangeSet_askExisting(prompt [, multi]): ask for a range set. It uses a list # dialog to present a list of existing set names. Returns the selected # name or "". If a second parameter is present, multiple selection is # performed, and an array is returned, empty if nothing selected. # ============================================================================== define RangeSet_askExisting { prompt = $1 if (prompt == "") prompt = "Range set name" if ($n_args > 1) result = $empty_array else result = "" names = RangeSet_names() nNames = names[] if (nNames > 0) { lines = "" width = length(nNames - 1) swidth = replace_in_string(nNames - 1, ".", " ", "regex", "copy") for (i = 0; i < nNames; i++) { nm = replace_in_string(names[i], "\n", "\\n", "copy") lines = lines substring(swidth, 0, length(i)) i ": " nm "\n" } if ($n_args > 1) { sel = list_multisel_dialog(prompt, lines, "OK", "Cancel") #sel = list_dialog(prompt, lines, "OK", "Cancel") if ($list_dialog_button != 1 || sel == "") return result inds = split(replace_in_string(sel, " *(\\d+):.*", "\\1", "regex"), "\n") for (i = 0; i < inds[]; i++) result[i] = names[inds[i]] } else { sel = list_dialog(prompt, lines, "OK", "Cancel") if ($list_dialog_button != 1 || sel == "") return result ind = replace_in_string(sel, " *(\\d+):.*", "\\1", "regex") result = names[ind] } } return result } # ============================================================================== # RangeSet_list_ask(prompt, lines): ask for a range set and a line of text in # the list lines. It prompts for a range set letter with a set of # "recently defined" buttons. Returns the selected list entry and the # selected range set in $RANGESET_SELECTED. # ============================================================================== define RangeSet_list_ask { prompt = $1 if (prompt == "") prompt = "Range set name" lines = $2 line = "" list = $rangeset_list result = "" names = RangeSet_names() res = array_ask_vals(prompt, names, 0, lines) if ("line" in res) line = res["line"] if ("value" in res) result = res["value"] $RANGESET_SELECTED = result return line }