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

Commit c5d657e

Browse files
committed
[[ DefaultHandlers ]] Improve default handler construction
This patch reinstates the use of default scripts specified by widgets and allows them to have multiple handlers within them. It also adds the ability to override default scripts for handlers dependent on 'classic' object type, for example different default scripts for a standard button and an option menu. Finally, if a default script override is not present, info from the documentation is used to construct a default handler with params.
1 parent 6b69d1a commit c5d657e

3 files changed

Lines changed: 98 additions & 19 deletions

File tree

Toolset/libraries/revidelibrary.8.livecodescript

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,6 +4135,9 @@ function revIDESpecialFolderPath pKey
41354135
case "Object Property Definitions"
41364136
return item 1 to -3 of the filename of stack "home" & "/Toolset/resources/supporting_files/property_definitions"
41374137
break
4138+
case "Object Default Scripts"
4139+
return item 1 to -3 of the filename of stack "home" & "/Toolset/resources/supporting_files/default_scripts"
4140+
break
41384141
case "Standalone Settings Definitions"
41394142
return item 1 to -3 of the filename of stack "home" & "/Toolset/resources/supporting_files/standalone_settings"
41404143
break
@@ -5496,6 +5499,52 @@ function revIDEDefaultExtensionIcon pType, pRetina
54965499
end switch
54975500
end revIDEDefaultExtensionIcon
54985501

5502+
function revIDEDefaultScript pObject, pHandler
5503+
local tDefaultScript, tType
5504+
put ideObjectTypeFromObject(pObject) into tType
5505+
if word 1 of the name of pObject is "widget" then
5506+
put revIDEWidgetDefaultScript(tType) into tDefaultScript
5507+
else
5508+
put revIDEClassicObjectDefaultScript(tType) into tDefaultScript
5509+
end if
5510+
5511+
lock screen
5512+
lock messages
5513+
create invisible stack "revDefaultScriptHolder"
5514+
try
5515+
set the script of it to tDefaultScript
5516+
catch tError
5517+
end try
5518+
local tHandlers
5519+
put the revAvailableHandlers of it into tHandlers
5520+
delete stack "revDefaultScriptHolder"
5521+
local tHandlerStart, tHandlerEnd, tHandlerInfo, tHandlerInfoLine
5522+
set the wholematches to false
5523+
-- Ensure we don't accidentally match a substring by putting
5524+
-- spaces around the handler name
5525+
put lineOffset(" " & pHandler & " ", tHandlers) into tHandlerInfoLine
5526+
put line tHandlerInfoLine of tHandlers into tHandlerInfo
5527+
-- We want to include any comments before the handler declaration
5528+
-- so find the previous handler
5529+
put word 3 of tHandlerInfo into tHandlerStart
5530+
put word 4 of tHandlerInfo into tHandlerEnd
5531+
repeat while word 1 of line tHandlerStart of tDefaultScript is not empty
5532+
subtract 1 from tHandlerStart
5533+
end repeat
5534+
unlock messages
5535+
unlock screen
5536+
return line tHandlerStart to tHandlerEnd of tDefaultScript
5537+
end revIDEDefaultScript
5538+
5539+
function revIDEClassicObjectDefaultScript pType
5540+
local tFolder
5541+
put revIDESpecialFolderPath("Object Default Scripts") into tFolder
5542+
if there is a stack (tFolder & slash & pType & ".livecodescript") then
5543+
return the script of stack (tFolder & slash & pType & ".livecodescript")
5544+
end if
5545+
return empty
5546+
end revIDEClassicObjectDefaultScript
5547+
54995548
function revIDEWidgetDefaultScript pKind
55005549
return revIDEExtensionProperty(pKind, "defaultScript")
55015550
end revIDEWidgetDefaultScript

Toolset/palettes/script editor/behaviors/revsestackbehavior.livecodescript

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,42 +2949,46 @@ private command appendToList @xList, pValue
29492949
end appendToList
29502950

29512951
local sHandlersA
2952+
private function getHandlerList pObjType
2953+
get the keys of sHandlersA[pObjType]
2954+
sort it
2955+
return it
2956+
end getHandlerList
2957+
29522958
private function revSEDefaultHandlerInfoForObjectType pObjType
29532959
if sHandlersA[pObjType] is not empty then
2954-
return sHandlersA[pObjType]
2960+
return getHandlerList (pObjType)
29552961
end if
29562962

29572963
local tMessages
29582964
put ideDocsFetchLCSElementsOfType("message") into tMessages
2959-
2965+
29602966
local tMessageList
29612967
repeat for each element tElement in tMessages
29622968
local tAssociations
29632969
put tElement["Associations"] into tAssociations
29642970
filter elements of tAssociations with pObjType
29652971
if tAssociations is not empty then
2966-
appendToList tMessageList, tElement["display name"]
2972+
put tElement into tMessageList[tElement["display name"]]
29672973
end if
29682974
end repeat
2969-
sort tMessageList
29702975
put tMessageList into sHandlersA[pObjType]
2971-
return tMessageList
2976+
return getHandlerList(pObjType)
29722977
end revSEDefaultHandlerInfoForObjectType
29732978

29742979
private function revSEDefaultHandlerInfoForWidget pWidgetKind
29752980
if sHandlersA[pWidgetKind] is not empty then
2976-
return sHandlersA[pWidgetKind]
2981+
return getHandlerList(pWidgetKind)
29772982
end if
29782983
local tMessages
29792984
put ideDocsFetchExtensionElementsOfType(pWidgetKind, "message") into tMessages
29802985

29812986
local tMessageList
29822987
repeat for each element tElement in tMessages
2983-
appendToList tMessageList, tElement["display name"]
2988+
put tElement into tMessageList[tElement["display name"]]
29842989
end repeat
2985-
sort tMessageList
29862990
put tMessageList into sHandlersA[pWidgetKind]
2987-
return tMessageList
2991+
return getHandlerList(pWidgetKind)
29882992
end revSEDefaultHandlerInfoForWidget
29892993

29902994
function revSEDefaultHandlers
@@ -3009,19 +3013,39 @@ function revSEDefaultHandlersForObject pObj
30093013
return revSEDefaultHandlerInfoForObjectType(tType)
30103014
end revSEDefaultHandlersForObject
30113015

3012-
private function revSEDefaultScriptOfHandler pHandler
3013-
// At the moment, don't try to find default scripts anywhere
3014-
local tDefaultHandler
3015-
put "on" && pHandler & return into tDefaultHandler
3016-
put return after tDefaultHandler
3017-
put "end" && pHandler after tDefaultHandler
3016+
function revSEConstructDefaultScript pObj, pHandler
3017+
local tType
3018+
put word 1 of the name of pObj into tType
3019+
if tType is "widget" then
3020+
put the kind of pObj into tType
3021+
end if
3022+
3023+
local tInfo
3024+
put sHandlersA[tType][pHandler] into tInfo
30183025

3019-
return tDefaultHandler
3020-
end revSEDefaultScriptOfHandler
3026+
local tScript
3027+
-- Don't include summary for now as it has some docs specific markup
3028+
--put "--" && tInfo["Summary"] & return into tScript
3029+
put "on" && pHandler after tScript
3030+
repeat with x = 1 to the number of elements in tInfo["params"]
3031+
if x is not 1 then
3032+
put "," after tScript
3033+
end if
3034+
put " " & tInfo["params"][x]["name"] after tScript
3035+
end repeat
3036+
put return & return & "end" && pHandler after tScript
3037+
return tScript
3038+
end revSEConstructDefaultScript
30213039

30223040
command revSEAddDefaultHandler pHandler
3023-
local tDefaultScript
3024-
put revSEDefaultScriptOfHandler(pHandler) into tDefaultScript
3041+
local tDefaultScript, tObject
3042+
revSEGetCurrentObject
3043+
put the result into tObject
3044+
put revIDEDefaultScript(tObject, pHandler) into tDefaultScript
3045+
3046+
if tDefaultScript is empty then
3047+
put revSEConstructDefaultScript(tObject, pHandler) into tDefaultScript
3048+
end if
30253049

30263050
local tNewScript
30273051
put revSEGetScript() into tNewScript
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
script "com.livecode.interface.classic.Button"
2+
-- Sent when the mouse is released after clicking
3+
-- pMouseButton specifies which mouse button was pressed
4+
on mouseUp pMouseButton
5+
6+
end mouseUp

0 commit comments

Comments
 (0)