PCE Editor - get Text from the Editor Component

Hello,
how can I get the Text from a pce editor?
The Code so far, i did work with is there: dpaste: 2UUGSR2C9

Thanks for reading
Jens

Using text_buffer<-contents. Class editor is a compound object that delegates most of its messages to one of its components, so you can ask for the contents of an editor directly.

If you want the data in a file, there is also ->save.

  %% this add text to editor
  send(D,append,new(TI,editor)),
  send_list(TI,append,
  [ new(TextBuffer, string("FileText"))
  ]),
  %% this give me error: No implementation for <-contents
send_list(Start,append,
[ menu_item(transpileText,message(F,TextBuffer?contents),StartRunText) ]),

Because new(TextBuffer, string("FileText")) creates a string rather than a text_buffer :slight_smile:

ok, but how can i read out the “contents” from a class procedure transpileText :-> ?

on Editor content of a string that is 10 chars in size, I get:
0
10

  transpile_text(F,Text) :-
    get(F,member,dialog,D),
    get(D,member,editor,E),
    get(E,selection,point(Start,End)), writeln(Start), writeln(End),
    get(E,text_buffer,TB),
    writeln("-----"),
    write(TB),writeln(" gett3").

But, how can I read the contents of text_buffer ?

send(D,append,new(TI,editor)),
send(D,append,
	button(transpile,
		message(@prolog,transpile_text,TI))).

transpile_text(F) :-
  get(F,selection,point(Start,End)), writeln(Start), writeln(End),
  get(F,text_buffer,B),
  get(B,contents,V),
  writeln("-----"),
  writeln(V),writeln( F ).

This Code will add a gui editor to a dialog, and a button, to take action “transpile_text”-
When I click the button, transpile_text is called, and the output will be ( a Text of 3 letters):

0
3
-----
@235...
@135...

but instead the @references, I would get the content/Text which is in the Editor at current time, where the button was clicked.
How can I do this ?

This gets you an xpce string object. That is why you get the @xxxx. Use

get(B, contents, string(S))

to get a Prolog string (or object(V, string(S)), but better to it in one step.

3 Likes

okay, this does works !!!
Thank you, you made my day.

But there is a disadvantage of the Editor:
when I scroll down with the cursor/caret, there give no line limits.
This means, when I hold the return/enter or especially the down-cursor key for a while, the result of the returned Text will be the last line number, in which the user (me) scrolls.
This means, when I press cursor-down for 1000 Lines, the text buffer will have 1000 Lines.
The Editor seems to be not care about such things.
Is there a workaround or a methode to fix this ?