|
157 | 157 | return
|
158 | 158 | return chosen
|
159 | 159 |
|
| 160 | +/* |
| 161 | + * Returns the length of a common prefix in a list, if any |
| 162 | + * Requires a SORTED list |
| 163 | + */ |
| 164 | +/proc/find_string_list_prefix(var/list/inputlist) |
| 165 | + if(!inputlist.len) |
| 166 | + return |
| 167 | + if(inputlist.len==1) |
| 168 | + return inputlist[1] |
| 169 | + var/i = 0 |
| 170 | + var/first = "[inputlist[1]]" |
| 171 | + var/last = "[inputlist[inputlist.len]]" |
| 172 | + while(i < length(first) && first[i+1] == last[i+1]) |
| 173 | + i++ |
| 174 | + return i |
| 175 | + |
| 176 | +/* |
| 177 | + * Returns a choice from an input typelist, given a string filter |
| 178 | + * If only one thing is returned, just gives us that with no input list. |
| 179 | + */ |
| 180 | +/proc/filter_typelist_input(input_text, input_heading, var/list/matches) |
| 181 | + if(!matches.len) |
| 182 | + return |
| 183 | + if(matches.len==1) |
| 184 | + return matches[1] |
| 185 | + matches = sortList(matches) |
| 186 | + var/prefix = "" |
| 187 | + var/common = find_string_list_prefix(matches) |
| 188 | + if(common) |
| 189 | + prefix = copytext("[matches[1]]", 1, common+1) |
| 190 | + var/foundpartial = findlasttext(prefix, "/") |
| 191 | + if(foundpartial) |
| 192 | + prefix = copytext(prefix, 1, foundpartial) |
| 193 | + common = foundpartial |
| 194 | + var/list/results = list() |
| 195 | + for(var/x in matches) |
| 196 | + if(common) |
| 197 | + results += copytext("[x]", common) |
| 198 | + else |
| 199 | + results += "[x]" |
| 200 | + var/newvalue = input("[input_text][(input_text && prefix) ? "\n" : ""][prefix ? "Prefix: [prefix]" : ""]",input_heading) as null|anything in results |
| 201 | + if(isnull(newvalue)) |
| 202 | + return |
| 203 | + if(prefix) |
| 204 | + newvalue = text2path(prefix + newvalue) |
| 205 | + else |
| 206 | + newvalue = text2path(newvalue) |
| 207 | + return newvalue |
| 208 | + |
160 | 209 | /*
|
161 | 210 | * Returns list containing all the entries from first list that are not present in second.
|
162 | 211 | * If skiprep = 1, repeated elements are treated as one.
|
|
0 commit comments