I am writing an XPCE-program in which a user can enter a text in a text window which is then processed further by a Prolog program (say, by running a spelling check).
Thus, I would need a text window in which one can enter text freely (including paragraphs, punctuation marks etc.) and then store the text in a Prolog variable for further processing.
This is easy (and works well) using a text_item as follows:
send(D, append(new(Text, text_item('Enter Text'))))
However, this only allows to enter a single line, which is unsuitable for longer texts.
The "editor" environment looks well suited to this task; and I can create an editor using
send(D, append(new(Text1,editor),below))
Here, one can enter a text of many lines, including paragraphs etc. But now, how do I access the text entered by the user? It is apparently not stored in the variable Text1. I read about a text_buffer, but I do not know how to link it to the editor.
adapted from XPCE guide
:- use_module(library(pce)).
multiline_input(Text) :-
new(D, dialog('Prompting for name')),
send(D, append, new(TI, editor)),
send(D, append,
button(ok, message(D, return,
TI?contents))),
send(D, append,
button(cancel, message(D, return, @nil))),
send(D, default_button, ok), % Ok: default button
get(D, confirm, Answer), % This blocks!
send(D, destroy),
Answer \== @nil, % canceled
get(Answer, value, Text).
Just replaced text_item with editor, getting its content, and then getting value out of it.