diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index d61d3bb9e027e09bc5657e46c8d85a57beae961a..d8d47d7105390a8622d56a4cb9ae8ddf888c0200 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -924,7 +924,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key, std::vector<onelab::string> ps; _onelabClient->get(ps, name); - bool noChoices = true, noClosed = true; + bool noChoices = true, noClosed = true, noMultipleChoice = true; if(ps.size()){ if(fopt.count("ReadOnly") && fopt["ReadOnly"][0]) ps[0].setValue(val); // use local value @@ -933,6 +933,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key, // keep track of these attributes, which can be changed server-side if(ps[0].getChoices().size()) noChoices = false; if(ps[0].getAttribute("Closed").size()) noClosed = false; + if(ps[0].getAttribute("MultipleChoice").size()) noMultipleChoice = false; } else{ ps.resize(1); @@ -942,6 +943,8 @@ void Msg::ExchangeOnelabParameter(const std::string &key, if(copt.count("Kind")) ps[0].setKind(copt["Kind"][0]); if(noChoices && copt.count("Choices")) ps[0].setChoices(copt["Choices"]); if(noClosed && copt.count("Closed")) ps[0].setAttribute("Closed", copt["Closed"][0]); + if(noMultipleChoice && copt.count("MultipleChoice")) + ps[0].setAttribute("MultipleChoice", copt["MultipleChoice"][0]); _setStandardOptions(&ps[0], fopt, copt); _onelabClient->set(ps[0]); #endif diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index f74ac1bd3d5fc3ebf88f5f0ba6ec2bec22016175..55e8ec30ec404871a0dbb53815229c74d9a7ff46 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -1140,6 +1140,17 @@ static void onelab_string_input_choice_cb(Fl_Widget *w, void *data) Fl_Input_Choice *o = (Fl_Input_Choice*)w; onelab::string old = strings[0]; strings[0].setValue(o->value()); + std::string choices; + for(int i = 0; i < o->menubutton()->menu()->size(); i++){ + if(o->menubutton()->menu()[i].flags & FL_MENU_TOGGLE){ + if(o->menubutton()->menu()[i].flags & FL_MENU_VALUE) + choices += "1"; + else + choices += "0"; + } + } + if(choices.size()) + strings[0].setAttribute("MultipleChoice", choices); onelab::server::instance()->set(strings[0]); autoCheck(old, strings[0]); } @@ -1170,6 +1181,22 @@ static void onelab_input_choice_file_merge_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); } +static void multiple_choice_menu_cb(Fl_Widget *w, void *data) +{ + Fl_Menu_Button *menu = (Fl_Menu_Button*)w; + std::string val; + for (int i = 0; i < menu->size() - 1; i++) { + const Fl_Menu_Item &item = menu->menu()[i]; + if(item.value() && item.label()){ + if(val.size()) val += ", "; + val += item.label(); + } + } + Fl_Input_Choice *but = (Fl_Input_Choice*)data; + but->value(val.c_str()); + but->do_callback(); +} + Fl_Widget *onelabGroup::_addParameterWidget(onelab::string &p, Fl_Tree_Item *n, bool highlight, Fl_Color c) { @@ -1212,13 +1239,19 @@ Fl_Widget *onelabGroup::_addParameterWidget(onelab::string &p, Fl_Tree_Item *n, // general string input Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, ww, 1); + std::string multipleChoice = p.getAttribute("MultipleChoice"); + if(multipleChoice.size()) + but->menubutton()->callback(multiple_choice_menu_cb, but); std::vector<Fl_Menu_Item> menu; for(unsigned int j = 0; j < p.getChoices().size(); j++){ char *str = strdup(p.getChoices()[j].c_str()); _treeStrings.push_back(str); bool divider = (p.getKind() == "file" && j == p.getChoices().size() - 1); - Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : 0}; + int choice = multipleChoice.size() ? FL_MENU_TOGGLE : 0; + if(multipleChoice.size() > j && multipleChoice[j] == '1') + choice |= FL_MENU_VALUE; + Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : choice}; menu.push_back(it); } if(p.getKind() == "file"){