Text editor export text

10 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Text editor export text

The autodocs are very sparse on how to do any importing/exporting of text. How do you get the text via the hook?

  1. TEXT GlobalStringBuffer[1024];
  2. struct GP_TEXTEDITOR_ExportText *GP_TE_ET;
  3.  
  4. GP_TE_ET=IExec->AllocVecTags(sizeof(struct GP_TEXTEDITOR_ExportText),
  5. AVT_Type, MEMF_SHARED,
  6. AVT_ClearWithValue, 0,
  7. TAG_DONE);
  8. IIntuition->IDoMethodA(ChildObjects[GAD_TEXTEDITOR],(Msg)GP_TE_ET);
  9. IExec->FreeVec(GP_TE_ET);
  10.  
  11. uint32
  12. TextEditorExportTextHookFunc(struct Hook *hook,APTR texteditor,struct GP_TEXTEDITOR_ExportText *exportmsg)
  13. {
  14. // what goes in the hook????
  15.  
  16. return(0);
  17. }

What goes in the hook to export the text?

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Text editor export text
  1. struct GP_TEXTEDITOR_ExportText gpteet = { GM_TEXTEDITOR_ExportText,NULL };
  2.  
  3.  
  4.  
  5.  
  6. STRPTR Data = (STRPTR)IDoMethodA(fd->fd_CurrentFile->fn_EditorGadget, (Msg)&gpteet);
  7. if(Data)
  8. {
  9. /* Do stuff with data, write to file etc etc */
  10. IExec=>FreeVec(Data);
  11. }

Nothing goes in the hook, that's not how it works.

The hook is for formatting the text as email / plain text etc


GA_TEXTEDITOR_ExportHook (struct Hook *)
This attribute selects the export hook which can currently
be one of the following values:
GV_TEXTEDITOR_ExportHook_Plain - plain text mode
GV_TEXTEDITOR_ExportHook_EMail - email text mode

The EMail export hook will convert a bold word to "*bold*",
italic words to "/italic/" and underlined words to "_underline_".
It also exports separators such as "" or "".

Custom hooks are currently not supported.

Defaults to GV_TEXTEDITOR_ExportHook_Plain.

Applicability is (OM_NEW, OM_SET, OM_GET)

Note that custom hooks aren't supported (or needed really, in most usage) further to that with the OS4 version as far as I can tel only GV_TEXTEDITOR_ExportHook_Plain works.

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Text editor export text

PS in you example you never set the method in your GP_TEXTEDITOR_ExportText message so it won;t do anything. That might just be an oversite in your forum post but thought I'd point it out just in case...

mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Re: Text editor export text

Go it. Thank you.

trixie
trixie's picture
Offline
Last seen: 5 months 7 hours ago
Joined: 2011-02-03 13:58
Re: Text editor export text

@mritter0

This is how you export text from a TextEditor Gadget:

  1. STRPTR buffer = NULL;
  2.  
  3. buffer = (STRPTR) IIntuition->IDoMethod(gadgets[GID_TEXTEDITOR], GM_TEXTEDITOR_ExportText, NULL);
  4.  
  5. if (buffer)
  6. {
  7. /* do something with the text,
  8.   then dispose of the buffer
  9.   which the export method
  10.   has allocated for you */
  11.  
  12. IExec->FreeVec(buffer);
  13. }

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

TSK
TSK's picture
Offline
Last seen: 5 months 3 weeks ago
Joined: 2011-06-28 02:06
Re: Text editor export text

Thanks from my part as well !

mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Re: Text editor export text

I have had it all working, but turned on -O3 (gcc optimize) and compiled my code, get an error:

warning: dereferencing type-punned pointer will break strict-aliasing rules

Makefile:
CFLAGS = $(INCPATH) -Wall -Werror -Wwrite-strings -Wextra -Wno-unused-parameter -O3

  1. if (ND_CreateMultiple)
  2. {
  3. struct GP_TEXTEDITOR_ExportText GP_TE_ET={ GM_TEXTEDITOR_ExportText,NULL };
  4. STRPTR Data;
  5.  
  6. Data=(STRPTR)IIntuition->IDoMethodA(ChildObjects[GAD_TEXTEDITOR],(Msg)&GP_TE_ET);
  7. if (Data)
  8. {
  9. IUtility->Strlcpy(GlobalStringBuffer,Data,1024);
  10. IExec->FreeVec(Data);
  11. }
  12. }

The warning refers to the IDoMethodA() line. I tried a few things but can't get past it. Any ideas?

thomas
thomas's picture
Offline
Last seen: 10 hours 39 min ago
Joined: 2011-05-16 14:23
Re: Text editor export text

Data=(STRPTR)IIntuition->IDoMethod(ChildObjects[GAD_TEXTEDITOR],GM_TEXTEDITOR_ExportText,NULL);

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Text editor export text

TBH the easiest "fix" is to add -Wno-strict-aliasing to your warning options after -Wall

Building your message in the stack as Thomas suggests gets round this for that specific case, but for more complex message types, that's sometimes less convenient, and you can also get them in calls to GetAttr() .

mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Re: Text editor export text

Thanks, guys

Log in or register to post comments