Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 476fbb5

Browse files
authored
Merge pull request #1605 from livecode/pi-script_only_behaviors
Pi script only behaviors
2 parents c8e865c + 40cf1e9 commit 476fbb5

2 files changed

Lines changed: 92 additions & 6 deletions

File tree

Toolset/palettes/inspector/editors/com.livecode.pi.script.behavior.livecodescript

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
on editorInitialize
33
set the editorMinWidth of me to 230
44
set the editorMaxWidth of me to 0
5-
disable button "edit script" of me
6-
disable button "inspect object" of me
5+
disable button "edit script" of me
6+
disable button "inspect object" of me
77
end editorInitialize
88

99
on editorUpdate
@@ -127,12 +127,91 @@ on editorGoToObject
127127
end editorGoToObject
128128

129129
on popupMenu
130-
set the text of button "Menu" of me to "Select Behavior" & return & revIDEObjectSelectionMenu("", "button,stack")
130+
local tMenu, tObject
131+
132+
put the cSelectedObjects of this stack into tObject
133+
134+
put "Select Behavior" & return & revIDEObjectSelectionMenu("", "button,stack") into tMenu
135+
put return & "Create behavior from script only stack/|create behavior" after tMenu
136+
put return & tab & "Create stack with empty script/|create empty behavior" & return after tMenu
137+
if word 1 to -1 of the script of tObject is empty then
138+
put "(" after tMenu
139+
end if
140+
put tab & "Create stack using existing control script/|create behavior from script" after tMenu
141+
set the text of button "Menu" of me to tMenu
131142
popup button "Menu" of me at the mouseLoc
132143
end popupMenu
133144

134145
on menuPick pObject
135-
set the itemdelimiter to "|"
136-
put the last item of pObject into field 1 of me
137-
valueChanged
146+
local tAction
147+
148+
set the itemdelimiter to "|"
149+
put item -1 of pObject into tAction
150+
151+
switch tAction
152+
case "create empty behavior"
153+
case "create behavior from script"
154+
local tError, tSuggestedName, tStackName
155+
local tTargetObject, tFilename, tStack
156+
157+
put the cSelectedObjects of this stack into tTargetObject
158+
put revIDEStackOfObject(tTargetObject) into tStack
159+
put the effective filename of tStack into tDefaultFilename
160+
161+
ask revIDELocalise("Please enter a name for the script only stack") with the short name of tTargetObject && "Behavior"
162+
if it is empty then exit menuPick
163+
put it into tStackName
164+
put word 1 to -1 of line 1 of tStackName into tStackName
165+
replace quote with "'" in tStackName
166+
167+
if tDefaultFilename is not empty then
168+
set the itemDelimiter to "/"
169+
put tStackName & ".livecodescript" into the last item of tDefaultFilename
170+
else
171+
put tStackName & ".livecodescript" into tDefaultFilename
172+
end if
173+
174+
ask file revIDELocalise("Please specify a location for the script only stack") with tDefaultFilename
175+
if it is empty then exit menuPick
176+
put it into tFilename
177+
178+
lock messages
179+
create invisible stack tStackName
180+
close stack tStackName
181+
set the filename of stack tStackName to tFilename
182+
set the scriptOnly of stack tStackName to true
183+
184+
if tAction is "create behavior from script" then
185+
set the script of stack tStackName to the script of tTargetObject
186+
end if
187+
188+
save stack tStackName
189+
put the result into tError
190+
unlock messages
191+
192+
if tError is empty then
193+
local tStackFiles
194+
195+
set the behavior of tTargetObject to the long id of stack tStackName
196+
put the stackFiles of tStack into tStackFiles
197+
put tStackName & "," & tFilename into line (the number of lines of tStackFiles + 1) of tStackFiles
198+
revIDESetStackFilesProperty tStack, empty, tStackFiles
199+
200+
if tAction is "create behavior from script" then
201+
set the script of tTargetObject to empty
202+
else
203+
edit script of stack tStackName
204+
end if
205+
end if
206+
207+
if tError is not empty then
208+
answer error tError
209+
end if
210+
break
211+
212+
default
213+
set the itemdelimiter to "|"
214+
put the last item of pObject into field 1 of me
215+
valueChanged
216+
end switch
138217
end menuPick
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Create script only stack behavior
2+
The menu for assigning a behavior to a control has two additional options:
3+
- Create behavior from new script only stack
4+
- Create behavior using control script and script only stack
5+
Either option will prompt you for a stack name and a location for the script only stack.
6+
The new stack will be saved, assigned as the behavior of the control, and then added
7+
to the stackfiles property of control's stack.

0 commit comments

Comments
 (0)