Page 1 of 1
Default Script
Posted: Mon Aug 13, 2018 6:12 pm
by pink
How do I add a default script to a widget?
I tried manually adding a "Support" folder and a defaultscript.livecodescript file, but it did not get included.
Re: Default Script
Posted: Mon Aug 13, 2018 10:25 pm
by livecodeali
support should be lowercase, although possibly that isn't the issue if you're on an os with a case insensitive file system.
Your default script stack needs to be named "your.widget.identifier.__DefaultScript", eg:
Code: Select all
script "com.livecode.widget.navbar.__DefaultScript"
Other than that, the only reason I can think that it wouldn't work is a script parsing error in the default script...
Actually, what do you mean by 'didn't get included'?
Re: Default Script
Posted: Mon Aug 13, 2018 11:46 pm
by pink
by didn't get included, I meant that it didn't show up when I tested the widget and opened the script
the script is named:
Code: Select all
script "community.livecode.madpink.buttonbar.__DefaultScript"
and the widget is named:
Code: Select all
widget community.livecode.madpink.buttonbar
do I need to include anything in the widget to look for the script's existence?
Re: Default Script
Posted: Tue Aug 14, 2018 8:52 am
by livecodeali
No, it should happen automatically. However, I'm wondering if there may be a docs issue here - we changed default scripts so that the handlers specified show up in the left hand side, rather than the script actually being automatically filled in - does your default script consist of (a) handler(s) and is its name not showing up in the default handler list?
Re: Default Script
Posted: Tue Aug 14, 2018 3:38 pm
by pink
Thus far I do have 1 handler and it
is showing up on the handler list.
Also, changing the folder name to "support" did not help
Here is my widget so far if looking at helps:
https://github.com/madpink/buttonbar-livecode-builder
Re: Default Script
Posted: Tue Aug 14, 2018 7:57 pm
by bn
Greg,
your default script has some typos
this compiles
Code: Select all
on mouseUp
end mouseUp
--Sent if mType is "Action", need to add more cases as needed
on actionSelected
switch the buttonSelected of me
case 1
--Put Actions here
break
case 2
--Put Actions here
break
end switch
end actionSelected
function getSelected pDelim pType
local tData, tSelected
if pDelim is empty then put ";" into pDelim
if pType is empty then put "label" into pType
put the buttonData of me into tData
repeat for each key tKey in tData
if tData[tKey]["clicked"] then
if tSelected is not empty then
put pDelim after tSelected
end if
put tData[tKey][pType] after tSelected
end if
end repeat
return tSelected
end getSelected
Kind regards
Bernd
Re: Default Script
Posted: Fri Aug 17, 2018 1:51 pm
by pink
I did correct the script, but I still cannot get the default script to work
In fact, I grabbed the tree view widget off github and tried put it into the extension builder, and the default script doesn't show up there either... or is it possible that it doesn't work in "testing" mode?
Re: Default Script
Posted: Fri Aug 17, 2018 3:25 pm
by [-hh]
Setting a default script never worked correctly for me.
It is much easier to set a widget script in your widget in "OnOpen".
Code: Select all
public handler OnOpen()
...
post "if the script of me is empty then set script of me to " & myScript()
end handler
handler myScript () returns String
--> use \q for quote, \n for newline
end myScript
Re: Default Script
Posted: Fri Aug 17, 2018 3:32 pm
by bn
the default script did not work for me either.
I resorted to make a button that sets the script.
but Hermann's solution might be easier.
Kind regards
Bernd
Re: Default Script
Posted: Fri Aug 17, 2018 4:11 pm
by pink
I think I like Hermann's approach better than using the default script as a separate file
Thanks both of you
Re: Default Script
Posted: Wed Aug 22, 2018 3:44 pm
by livecodeali
I'm still confused as to the specific issue here - if the handler shows up in the default handler list (and nothing else) then that is the expected behavior - we did away with default scripts actually populating the script, they merely define a list of handlers for the default handler list.
If I load the tree view with a new identifier I get the same as a tree view in the IDE, namely the four handlers in the left hand side as default handlers.
Although Hermann's method works, it might not always be possible to do such a thing and has different behavior from the other controls, plus you have to write your script with escaped characters - none of which strike me as easier - better to identify the bug if there is one and fix it (it's likely not a difficult fix). On the other hand, the current situation is not idea for what you want to do as I see your default handler is actually split into multiple handler definitions.
Re: Default Script
Posted: Wed Aug 22, 2018 6:24 pm
by pink
the confusion for me really started because I was remembering the default script that used to get populated for certain widgets, and all of the built-in widgets still have the defaultscript.livecodescript file with them. Didn't realize at that time that they were no longer being populated on purpose (really, just assumed I did something)
anyhow, I liked having the basic outline of a script
Re: Default Script
Posted: Fri Sep 11, 2020 4:41 pm
by PaulDaMacMan
[-hh] wrote: ↑Fri Aug 17, 2018 3:25 pm
Setting a default script never worked correctly for me.
It is much easier to set a widget script in your widget in "OnOpen".
Code: Select all
public handler OnOpen()
...
post "if the script of me is empty then set script of me to " & myScript()
end handler
handler myScript () returns String
--> use \q for quote, \n for newline
end myScript
Just wanted to add a note here that HH's method to set a Widget's LCS script doesn't appear to work anymore (LC 9.6.1 Mac), it throws the error "LCB Error script access not allowed". Maybe this was changed for security reasons?
Anyway the defaultscripts do work but they seem a bit tricky to get right. Ensure that your in-line lcdoc mark-up is working correctly or the default script won't show up.
Re: Default Script
Posted: Mon Sep 14, 2020 2:59 am
by mwieder
I'm finding that the default script doesn't show up in the Extension Builder window ("No default script found") but if you click the Edit button the script does appear in the script editor and also populates the default script pane in the Extension Builder.
LC 9.6.1.
Re: Default Script
Posted: Fri Sep 25, 2020 3:22 pm
by PaulDaMacMan
mwieder wrote: ↑Mon Sep 14, 2020 2:59 am
I'm finding that the default script doesn't show up in the Extension Builder window ("No default script found") but if you click the Edit button the script does appear in the script editor and also populates the default script pane in the Extension Builder.
LC 9.6.1.
Yeah, the Extension Builder definitely needs some work:
- I find the same problem with default script not showing in the window until clicking the edit script.
- My SVG icons do not replace or align with the default icon in the Builder window.
- I have to manually delete files in my project folder, clear the Documentation cache folder for my project in the RunRev folder, and quit/relaunch in order for documentation updates to show up in the dictionary.
- I sometimes have to manually delete build files in my project folder and quit/relaunch or the compile log shows "module already loaded" and then won't recompile.