Importing text in texteditor.gadget

4 posts / 0 new
Last post
trixie
trixie's picture
Offline
Last seen: 7 months 3 weeks ago
Joined: 2011-02-03 13:58
Importing text in texteditor.gadget

How would I best go about importing a disk-based plain text file to a texteditor.gadget? I mean, other than read text from the file and copy it to a memory buffer.

The autodoc says that GA_TEXTEDITOR_Contents can take a filehandle when I set my own GA_TEXTEDITOR_ImportHook, but a comment to the latter tag says that custom import hooks are currently not supported.

Also, the autodoc mentions "GM_TEXTEDITOR_Import" (and "GM_TEXTEDITOR_Export" as well) without any other reference.

So I'm a bit puzzled here.

tbreeden
tbreeden's picture
Offline
Last seen: 6 years 9 months ago
Joined: 2010-12-09 03:10
Through trial and error, I

Through trial and error, I have used the Reaction TextEditor in the GuideMaker program I wrote.

FWIW, here is my experience - this is with SDK 53.20, texteditor.gadget 53.15, texteditor.h, v1.22 2008/07/30 (texteditor.gadget v52.1 was bad news, with a freeze bug in it).

I think you are going to have to read the file into memory. At least that is what I ended up doing, and presenting an AmigaGuide node at a time to the user for editing.

You can use a SetGadgetAttrsA() with the TEXTEDITOR_Contents tag to start off or replace all the text. Other tags that seem to work ok were:

TEXTEDITOR_VertScroller, at least on creation of the text editor object. Just make a Reaction scroller object first for it.

GATextAttr, to set the font on creation of the text editor object.

TEXTEDITOR_AreaMarked, get it to tell if any text is currently marked.

also methods, via a call to DoGadgetMethodA()

GMTextEditorInsertText, and I think the .pos specification of the message.

GMTextEditorExportText, DoGadgetMethodA returns a pointer to a null delimited string.

GMTextEditorBlockInfo, fills the message with the limits of the marked area.

GMTextEditorMarkText, works, though I had to add 1 to the .stopcrsrx field in the message to include that column in the marking

GMTextEditorReplace, to replace the marked block with your own text.

I don't think I ever got these to work:

TEXTEDITOR_CursorX/Y to get or set

GMTextEditorARexxCmd

the rest of the features I just left alone, though if they all got implemented and were reliable, it would be a pretty nice gadget.

Tom

Rigo
Rigo's picture
Offline
Last seen: 2 years 6 months ago
Joined: 2011-01-24 21:55
TBH, the autodocs for this

TBH, the autodocs for this gadget are sketchy, to say the least. I just checked the NotePad sources, and it loads the file into a memory block before setting the GA_TEXTEDITOR_Contents attribute.

Because the gadget maintains the text buffer internally, once the OM_SET method returns, you can free your loading buffer, as it's no longer required unless you want to do a "restore" type feature.

Simon

trixie
trixie's picture
Offline
Last seen: 7 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Importing text in texteditor.gadget

@tbreeden

I think you are going to have to read the file into memory.

That's what I feared :-( Another unimplemented feature, sadly.

@Rigo
We're doomed! :-)

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

Log in or register to post comments