abstract sclass DynAskUserQuestions extends DynModule { S question, answer; visualize { if (empty(question)) newQuestion(); JLabel lblQ = fontSizePlus(3, makeBold(dm_fieldLabel('question))); componentPopupMenuItem(lblQ, "Suggest question...", r { inputText("Question", question, voidfunc(S s) { setField(question := s) }) }); ret withRightMargin(makeForm2( "Say...", withBottomMargin(15, lblQ), "Human answer:", centerAndEastWithMargin(onEnter(dm_fieldTextField('answer), rThread submit), jbutton("Submit", rThread submit)), "", withBottomMargin(withTopMargin(15, rightAlignedButtons("Ask me something else", rThread newQuestion))))); } abstract S makeAQuestion(); void newQuestion enter { setFields(answer := "", question := makeAQuestion()); if (empty(question)) ret with infoBox("Got nothing to ask"); programLogStructure(litorderedmap(+question)); vmBus_send('showingQuestion, module(), question); } void submit enter { programLogStructure(litorderedmap(+question, +answer)); vmBus_send('userAnsweredQuestion, module(), question, answer); dm_addQAndA(question, answer); infoBox(confirmationText()); newQuestion(); } S confirmationText() { ret "[saved] " + question + " => " + answer; } }