int List::add(const std::string value) { *tail = ListElem(value); tail->next = new ListElem(); tail = tail->next; return 0; }
void Options::handle(View* view, OptionSet set, int lastIndex) { vector<ListElem> options; options.emplace_back("Change settings:", ListElem::TITLE); for (OptionId option : optionSets.at(set)) options.push_back(ListElem(names.at(option), getValueString(option, getValue(option))).setTip(hints.at(option))); options.emplace_back("Done"); auto index = view->chooseFromList("", options, lastIndex, getMenuType(set)); if (!index || (*index) == optionSets.at(set).size()) return; OptionId option = optionSets.at(set)[*index]; changeValue(option, getValue(option), view); handle(view, set, *index); }
bool Options::handleOrExit(View* view, OptionSet set, int lastIndex) { if (!optionSets.count(set)) return true; vector<ListElem> options; options.emplace_back("Change settings:", ListElem::TITLE); for (OptionId option : optionSets.at(set)) options.push_back(ListElem(names.at(option), getValueString(option, getValue(option))).setTip(hints.at(option))); options.emplace_back("Done"); if (lastIndex == -1) lastIndex = optionSets.at(set).size(); auto index = view->chooseFromList("", options, lastIndex, getMenuType(set)); if (!index) return false; else if (index && (*index) == optionSets.at(set).size()) return true; OptionId option = optionSets.at(set)[*index]; changeValue(option, getValue(option), view); return handleOrExit(view, set, *index); }
vector<View::ListElem> View::getListElem(const vector<string>& v) { function<ListElem(const string&)> fun = [](const string& s) -> ListElem { return ListElem(s); }; return transform2<ListElem>(v, fun); }