Skip to content

Commit

Permalink
allow edit hint and code preview to use either textfield or textedito…
Browse files Browse the repository at this point in the history
…r gadgets.

throw an error on startup if neither textfield or texteditor gadgets are present
  • Loading branch information
dmcoles committed Jul 22, 2024
1 parent 99ca070 commit ca106f1
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 40 deletions.
114 changes: 88 additions & 26 deletions codePreviewForm.e
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ OPT MODULE, OSVERSION=37
'reaction/reaction_lib',
'images/bevel',
'gadgets/textEditor','texteditor',
'*textfield',
'gadgets/scroller','scroller',
'graphics/gfxbase',
'images/label','label',
'amigalib/boopsi',
'intuition/intuition',
Expand All @@ -19,6 +21,18 @@ OPT MODULE, OSVERSION=37

EXPORT DEF texteditorbase

CONST TEXTFIELD_TEXT=$84000001
CONST TEXTFIELD_TEXTFONT=$84000003
CONST TEXTFIELD_BORDER_BEVEL=1
CONST TEXTFIELD_BORDER=$8400000C
CONST TEXTFIELD_SIZE=$84000007
CONST TEXTFIELD_READONLY=$8400001F
CONST TEXTFIELD_TOP=$84000005
CONST TEXTFIELD_LINES=$84000009
CONST TEXTFIELD_VISIBLE=$84000008
CONST TEXTFIELD_INSERTTEXT=$84000002


EXPORT ENUM PREVIEWGAD_TEXT, PREVIEWGAD_SCROLL
CONST NUM_PREVIEW_GADS=PREVIEWGAD_SCROLL+1

Expand All @@ -27,13 +41,42 @@ ENDOBJECT

EXPORT PROC create() OF codePreviewForm
DEF gads:PTR TO LONG
DEF tempbase,map
DEF tempbase=0,map
DEF gfxb:PTR TO gfxbase

NEW gads[NUM_PREVIEW_GADS]
self.gadgetList:=gads
NEW gads[NUM_PREVIEW_GADS]

tempbase:=textfieldbase
IF texteditorbase
tempbase:=textfieldbase
textfieldbase:=texteditorbase

self.gadgetList[ PREVIEWGAD_TEXT ]:=NewObjectA( TextEditor_GetClass(), NIL,[
GA_ID, PREVIEWGAD_TEXT,
GA_TEXTEDITOR_WRAPBORDER,-1,
GA_TEXTEDITOR_FIXEDFONT,TRUE,
GA_TEXTEDITOR_HORIZONTALSCROLL, TRUE,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
GA_READONLY, TRUE,
TAG_END])
ELSE
gfxb:=gfxbase
self.gadgetList[ PREVIEWGAD_TEXT ]:=NewObjectA( TextField_GetClass(), NIL,[
GA_ID, PREVIEWGAD_TEXT,
//GA_TEXTEDITOR_WRAPBORDER,-1,
//GA_TEXTEDITOR_FIXEDFONT,TRUE,
//GA_TEXTEDITOR_HORIZONTALSCROLL, TRUE,

GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
TEXTFIELD_TEXTFONT, gfxb.defaultfont,
TEXTFIELD_READONLY, TRUE,
TEXTFIELD_BORDER, TEXTFIELD_BORDER_BEVEL,
TAG_END])
ENDIF

textfieldbase:=texteditorbase

self.gadgetActions:=gads
Expand Down Expand Up @@ -62,15 +105,7 @@ EXPORT PROC create() OF codePreviewForm
LAYOUT_SPACEOUTER, TRUE,
LAYOUT_DEFERLAYOUT, TRUE,

LAYOUT_ADDCHILD, self.gadgetList[ PREVIEWGAD_TEXT ]:=NewObjectA( TextEditor_GetClass(), NIL,[
GA_ID, PREVIEWGAD_TEXT,
GA_TEXTEDITOR_WRAPBORDER,-1,
GA_TEXTEDITOR_FIXEDFONT,TRUE,
GA_TEXTEDITOR_HORIZONTALSCROLL, TRUE,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
GA_READONLY, TRUE,
TAG_END]),
LAYOUT_ADDCHILD, self.gadgetList[ PREVIEWGAD_TEXT ],

LAYOUT_ADDCHILD, self.gadgetList[ PREVIEWGAD_SCROLL ]:=NewObjectA(Scroller_GetClass(),NIL,[
GA_ID, PREVIEWGAD_SCROLL,
Expand All @@ -83,22 +118,37 @@ EXPORT PROC create() OF codePreviewForm
LayoutEnd,
WindowEnd

map:=[GA_TEXTEDITOR_PROP_FIRST, SCROLLER_TOP,
GA_TEXTEDITOR_PROP_ENTRIES, SCROLLER_TOTAL,
GA_TEXTEDITOR_PROP_VISIBLE, SCROLLER_VISIBLE,
TAG_DONE]
IF texteditorbase
map:=[GA_TEXTEDITOR_PROP_FIRST, SCROLLER_TOP,
GA_TEXTEDITOR_PROP_ENTRIES, SCROLLER_TOTAL,
GA_TEXTEDITOR_PROP_VISIBLE, SCROLLER_VISIBLE,
TAG_DONE]
ELSE
map:=[TEXTFIELD_TOP, SCROLLER_TOP,
TEXTFIELD_LINES, SCROLLER_TOTAL,
TEXTFIELD_VISIBLE, SCROLLER_VISIBLE,
TAG_DONE]
ENDIF

SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],0,0,[ICA_MAP,map,ICA_TARGET,self.gadgetList[ PREVIEWGAD_SCROLL ],0])

map:=[
SCROLLER_TOP, GA_TEXTEDITOR_PROP_FIRST,
SCROLLER_TOTAL, GA_TEXTEDITOR_PROP_ENTRIES,
SCROLLER_VISIBLE, GA_TEXTEDITOR_PROP_VISIBLE,
TAG_DONE]
IF texteditorbase
map:=[
SCROLLER_TOP, GA_TEXTEDITOR_PROP_FIRST,
SCROLLER_TOTAL, GA_TEXTEDITOR_PROP_ENTRIES,
SCROLLER_VISIBLE, GA_TEXTEDITOR_PROP_VISIBLE,
TAG_DONE]
ELSE
map:=[
SCROLLER_TOP, TEXTFIELD_TOP,
SCROLLER_TOTAL, TEXTFIELD_LINES,
SCROLLER_VISIBLE, TEXTFIELD_VISIBLE,
TAG_DONE]
ENDIF

SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_SCROLL ],0,0,[ICA_MAP,map,ICA_TARGET,self.gadgetList[ PREVIEWGAD_TEXT ],0])

textfieldbase:=tempbase
IF tempbase THEN textfieldbase:=tempbase

ENDPROC

Expand All @@ -115,15 +165,27 @@ EXPORT PROC showCode(strStream:PTR TO stringStreamer) OF codePreviewForm
strStream.reset()
win:=Gets(self.windowObj,WINDOW_WINDOW)
top:=Gets(self.gadgetList[ PREVIEWGAD_SCROLL ],SCROLLER_TOP)
DoGadgetMethodA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GM_TEXTEDITOR_CLEARTEXT, 0]:gp_texteditor_cleartext)
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_QUIET,1,TAG_END])
IF texteditorbase
DoGadgetMethodA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GM_TEXTEDITOR_CLEARTEXT, 0]:gp_texteditor_cleartext)
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_QUIET,1,TAG_END])
ELSE
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[TEXTFIELD_TEXT,'',0])
ENDIF
WHILE strStream.readLine(str)<>-1
str[StrLen(str)+1]:=0
str[StrLen(str)]:="\n"
DoGadgetMethodA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GM_TEXTEDITOR_INSERTTEXT, 0, str, GV_TEXTEDITOR_INSERTTEXT_BOTTOM]:gp_texteditor_inserttext)
IF texteditorbase
DoGadgetMethodA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GM_TEXTEDITOR_INSERTTEXT, 0, str, GV_TEXTEDITOR_INSERTTEXT_BOTTOM]:gp_texteditor_inserttext)
ELSE
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[TEXTFIELD_INSERTTEXT,str,0])
ENDIF
ENDWHILE
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_QUIET,FALSE,TAG_END])
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_PROP_FIRST,top,TAG_END])
IF texteditorbase
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_QUIET,FALSE,TAG_END])
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[GA_TEXTEDITOR_PROP_FIRST,top,TAG_END])
ELSE
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_TEXT ],win,0,[TEXTFIELD_TOP,top,TAG_END])
ENDIF
SetGadgetAttrsA(self.gadgetList[ PREVIEWGAD_SCROLL ],win,0,[SCROLLER_TOP,top,TAG_END])

ENDPROC
Expand Down
61 changes: 48 additions & 13 deletions reactionObject.e
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ OPT MODULE,OSVERSION=37
'gadgets/integer','integer',
'gadgets/checkbox','checkbox',
'gadgets/textEditor','texteditor',
'*textfield',
'images/label','label',
'amigalib/boopsi',
'gadtools',
Expand All @@ -21,6 +22,12 @@ OPT MODULE,OSVERSION=37

MODULE '*stringlist','*reactionForm','*fileStreamer','*sourceGen'

CONST TEXTFIELD_TEXT=$84000001
CONST TEXTFIELD_BORDER_BEVEL=1
CONST TEXTFIELD_BORDER=$8400000C
CONST TEXTFIELD_SIZE=$84000007
CONST TEXTFIELD_READONLY=$8400001F

EXPORT DEF texteditorbase

// These are not yet all implemented but included here to define the ids
Expand Down Expand Up @@ -364,14 +371,31 @@ ENDPROC res=MR_OK

PROC create() OF hintEditForm
DEF gads:PTR TO LONG
DEF tempbase
DEF tempbase=0

NEW gads[NUM_HINT_GADS]
self.gadgetList:=gads
NEW gads[NUM_HINT_GADS]

tempbase:=textfieldbase
textfieldbase:=texteditorbase
IF texteditorbase
tempbase:=textfieldbase
textfieldbase:=texteditorbase

self.gadgetList[ HINTGAD_TEXT ]:=NewObjectA( TextEditor_GetClass(), NIL,[
GA_ID, HINTGAD_TEXT,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
GA_READONLY, FALSE,
TAG_END])
ELSE
self.gadgetList[ HINTGAD_TEXT ]:=NewObjectA( TextField_GetClass(), NIL,[
GA_ID, HINTGAD_TEXT,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
GA_READONLY, FALSE,
TEXTFIELD_BORDER, TEXTFIELD_BORDER_BEVEL,
TAG_END])
ENDIF

self.gadgetActions:=gads
self.windowObj:=WindowObject,
Expand Down Expand Up @@ -400,12 +424,7 @@ PROC create() OF hintEditForm
LAYOUT_SPACEOUTER, TRUE,
LAYOUT_DEFERLAYOUT, TRUE,

LAYOUT_ADDCHILD, self.gadgetList[ HINTGAD_TEXT ]:=NewObjectA( TextEditor_GetClass(), NIL,[
GA_ID, HINTGAD_TEXT,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
GA_READONLY, FALSE,
TAG_END]),
LAYOUT_ADDCHILD, self.gadgetList[ HINTGAD_TEXT ],

LAYOUT_ADDCHILD, LayoutObject,
LAYOUT_ORIENTATION, LAYOUT_ORIENT_HORIZ,
Expand All @@ -428,7 +447,7 @@ PROC create() OF hintEditForm
LayoutEnd,
WindowEnd

textfieldbase:=tempbase
IF tempbase THEN textfieldbase:=tempbase

self.gadgetActions[HINTGAD_CANCEL]:=MR_CANCEL
self.gadgetActions[HINTGAD_OK]:=MR_OK
Expand All @@ -441,15 +460,31 @@ PROC end() OF hintEditForm
ENDPROC

PROC editHint(comp:PTR TO reactionObject) OF hintEditForm
DEF res,newval
DEF res,newval,strval,vallen

newval:=comp.hintText.makeTextString()
SetGadgetAttrsA(self.gadgetList[ HINTGAD_TEXT ],0,0,[GA_TEXTEDITOR_CONTENTS,newval,0])
IF texteditorbase
SetGadgetAttrsA(self.gadgetList[ HINTGAD_TEXT ],0,0,[GA_TEXTEDITOR_CONTENTS,newval,0])
ELSE
SetGadgetAttrsA(self.gadgetList[ HINTGAD_TEXT ],0,0,[TEXTFIELD_TEXT,newval,0])
ENDIF
DisposeLink(newval)

res:=self.showModal()
IF res=MR_OK
newval:=DoMethod(self.gadgetList[ HINTGAD_TEXT ], GM_TEXTEDITOR_EXPORTTEXT);
IF texteditorbase
newval:=DoMethod(self.gadgetList[ HINTGAD_TEXT ], GM_TEXTEDITOR_EXPORTTEXT);
ELSE
SetGadgetAttrsA(self.gadgetList[ HINTGAD_TEXT ],0,0,[TEXTFIELD_READONLY,TRUE,0])
vallen:=Gets(self.gadgetList[ HINTGAD_TEXT ], TEXTFIELD_SIZE)
strval:=Gets(self.gadgetList[ HINTGAD_TEXT ], TEXTFIELD_TEXT)
newval:=AllocVec(vallen+1,0)
IF (vallen<>0) AND (strval<>0)
CopyMem(strval,newval,vallen)
ENDIF
newval[vallen]:=0
SetGadgetAttrsA(self.gadgetList[ HINTGAD_TEXT ],0,0,[TEXTFIELD_READONLY,FALSE,0])
ENDIF
comp.hintText.setFromTextString(newval)
FreeVec(newval)
ENDIF
Expand Down
3 changes: 2 additions & 1 deletion rebuild.e
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ PROC openClasses()
ledbase:=OpenLibrary('images/led.image',0)
smartbitmapbase:=OpenLibrary('images/smartbitmap.image',0)
titlebarbase:=OpenLibrary('images/titlebar.image',0)
IF (texteditorbase=NIL) AND (textfieldbase=NIL) THEN Throw("LIB","text")
ENDPROC

PROC closeClasses()
Expand Down Expand Up @@ -3719,7 +3720,7 @@ EXCEPT DO
CASE "fuel"
errorRequest(0,'Error','Unable to open fuelgauge.gadget')
CASE "text"
errorRequest(0,'Error','Unable to open textfield.gadget')
errorRequest(0,'Error','Unable to open textfield.gadget and texteditor.gadget,\nyou must have at least one of these')
CASE "file"
errorRequest(0,'Error','Unable to open getfile.gadget')
CASE "font"
Expand Down

0 comments on commit ca106f1

Please sign in to comment.