diff --git a/Toolset/palettes/inspector/editors/com.livecode.pi.script.behavior.livecodescript b/Toolset/palettes/inspector/editors/com.livecode.pi.script.behavior.livecodescript index 4cae6421ea..4aad7ceeb4 100644 --- a/Toolset/palettes/inspector/editors/com.livecode.pi.script.behavior.livecodescript +++ b/Toolset/palettes/inspector/editors/com.livecode.pi.script.behavior.livecodescript @@ -2,8 +2,8 @@ on editorInitialize set the editorMinWidth of me to 230 set the editorMaxWidth of me to 0 - disable button "edit script" of me - disable button "inspect object" of me + disable button "edit script" of me + disable button "inspect object" of me end editorInitialize on editorUpdate @@ -127,12 +127,91 @@ on editorGoToObject end editorGoToObject on popupMenu - set the text of button "Menu" of me to "Select Behavior" & return & revIDEObjectSelectionMenu("", "button,stack") + local tMenu, tObject + + put the cSelectedObjects of this stack into tObject + + put "Select Behavior" & return & revIDEObjectSelectionMenu("", "button,stack") into tMenu + put return & "Create behavior from script only stack/|create behavior" after tMenu + put return & tab & "Create stack with empty script/|create empty behavior" & return after tMenu + if word 1 to -1 of the script of tObject is empty then + put "(" after tMenu + end if + put tab & "Create stack using existing control script/|create behavior from script" after tMenu + set the text of button "Menu" of me to tMenu popup button "Menu" of me at the mouseLoc end popupMenu on menuPick pObject - set the itemdelimiter to "|" - put the last item of pObject into field 1 of me - valueChanged + local tAction + + set the itemdelimiter to "|" + put item -1 of pObject into tAction + + switch tAction + case "create empty behavior" + case "create behavior from script" + local tError, tSuggestedName, tStackName + local tTargetObject, tFilename, tStack + + put the cSelectedObjects of this stack into tTargetObject + put revIDEStackOfObject(tTargetObject) into tStack + put the effective filename of tStack into tDefaultFilename + + ask revIDELocalise("Please enter a name for the script only stack") with the short name of tTargetObject && "Behavior" + if it is empty then exit menuPick + put it into tStackName + put word 1 to -1 of line 1 of tStackName into tStackName + replace quote with "'" in tStackName + + if tDefaultFilename is not empty then + set the itemDelimiter to "/" + put tStackName & ".livecodescript" into the last item of tDefaultFilename + else + put tStackName & ".livecodescript" into tDefaultFilename + end if + + ask file revIDELocalise("Please specify a location for the script only stack") with tDefaultFilename + if it is empty then exit menuPick + put it into tFilename + + lock messages + create invisible stack tStackName + close stack tStackName + set the filename of stack tStackName to tFilename + set the scriptOnly of stack tStackName to true + + if tAction is "create behavior from script" then + set the script of stack tStackName to the script of tTargetObject + end if + + save stack tStackName + put the result into tError + unlock messages + + if tError is empty then + local tStackFiles + + set the behavior of tTargetObject to the long id of stack tStackName + put the stackFiles of tStack into tStackFiles + put tStackName & "," & tFilename into line (the number of lines of tStackFiles + 1) of tStackFiles + revIDESetStackFilesProperty tStack, empty, tStackFiles + + if tAction is "create behavior from script" then + set the script of tTargetObject to empty + else + edit script of stack tStackName + end if + end if + + if tError is not empty then + answer error tError + end if + break + + default + set the itemdelimiter to "|" + put the last item of pObject into field 1 of me + valueChanged + end switch end menuPick diff --git a/notes/feature-create-script-only-stack-behavior.md b/notes/feature-create-script-only-stack-behavior.md new file mode 100644 index 0000000000..36452a5615 --- /dev/null +++ b/notes/feature-create-script-only-stack-behavior.md @@ -0,0 +1,7 @@ +# Create script only stack behavior +The menu for assigning a behavior to a control has two additional options: +- Create behavior from new script only stack +- Create behavior using control script and script only stack +Either option will prompt you for a stack name and a location for the script only stack. +The new stack will be saved, assigned as the behavior of the control, and then added +to the stackfiles property of control's stack. \ No newline at end of file