GetGadgetText / AddGadgetItem not working with EditorGadget?

Just starting out? Need help? Post your questions and find answers here.
DoerrSt
Posts: 2
Joined: Fri Jun 02, 2023 11:22 am

GetGadgetText / AddGadgetItem not working with EditorGadget?

Post by DoerrSt »

Hi,

I am playing around with the EditorGadget and having some issues with setting and getting the text of it. But I am having some issues with the control. To test what I do wrong I used the following code from the documentation:

Code: Select all

  If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    e = EditorGadget(0, 8, 8, 306, 133)
    For a = 0 To 5
      AddGadgetItem(0, a, "Line "+Str(a))
    Next
  EndIf
The Gadget itself stays empty and the java-script console shows some errors:
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (dojo.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (dojo_en-us.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (interact.min.js.map, line 0)
To test it I use the currently available Spiderbasic for Intel Mac, free version. It looks independent of the browser as the issue itself is reproducible using Safari as well as Chrome. Could this be a bug in this version?

Thanks for reading!
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: GetGadgetText / AddGadgetItem not working with EditorGadget?

Post by plouf »

you are using wrong command
manual says ou need to use Get/SETgadgetTExt

your example working

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
e = EditorGadget(0, 8, 8, 306, 133)
For a = 0 To 5
  CurrentText$ = GetGadgetText(0)
  SetGadgetText(0, CurrentText$+"Line "+Str(a)+#CRLF$)
Next
EndIf
Christos
DoerrSt
Posts: 2
Joined: Fri Jun 02, 2023 11:22 am

Re: GetGadgetText / AddGadgetItem not working with EditorGadget?

Post by DoerrSt »

Thank you! That works properly :D

I didn't get getgadgettext (which I tried first) up and running too and fround the example at https://www.purebasic.com/documentation ... adget.html but for sure it could be that it only works with purebasic where I own the full-version.

Anyway, it's working now. Thanks again for the quick response and help!
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: GetGadgetText / AddGadgetItem not working with EditorGadget?

Post by Peter »

Here is a workaround for the missing AddGadgetItem():

Code: Select all

Procedure EditorGadgetAddGadgetItem(EditorGadget, Position, Text.s)
  
  If GadgetType(EditorGadget) <> #PB_GadgetType_Editor : ProcedureReturn : EndIf
  
  Protected GID = GadgetID(EditorGadget)
  
  ! var val = [];
  ! if ($(v_gid.gadget.textbox).val()) val = $(v_gid.gadget.textbox).val().split('\n');
  ! if (val.length == 0) {
  !   val.push(v_text);
  ! } else {
  !   if (v_position == -1) v_position = val.length;
  !   val.splice(v_position, 0, v_text);
  ! }
  ! $(v_gid.gadget.textbox).val(val.join('\n'));  
  
EndProcedure

OpenWindow(0, 0, 0, 300, 400, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 280, 380)

For Counter = 0 To 9
  EditorGadgetAddGadgetItem(0, Counter, "Line " + Str(Counter))
Next

EditorGadgetAddGadgetItem(0, -1, "Line 10")
EditorGadgetAddGadgetItem(0, -1, "Line 11")
Post Reply