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

Commit 6b69d1a

Browse files
committed
[[ DefaultHandlers ]] Add lines in handler list for default handler addition in SE
This patch uses the docs library to fetch all the per-object-type messages to populate the handler list. When choosing a new default handler to add form the list, the handler is added to the script editor field.
1 parent 59d79ff commit 6b69d1a

4 files changed

Lines changed: 208 additions & 63 deletions

File tree

Toolset/libraries/revidedocumentationlibrary.livecodescript

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ function ideDocsFetchLCSElementOfType pEntryName, pType, pElement
190190
return ideDocsFetchElementOfType(pEntryName, "LiveCode Script", pType, pElement)
191191
end ideDocsFetchLCSElementOfType
192192

193+
/*
194+
Fetch all docs element of the given type in the LiveCode script dictionary.
195+
196+
Returns:
197+
A numerically keyed array of data, each element of which is an array of data
198+
pertaining to a LiveCode script dictionary entry with the given type.
199+
*/
200+
function ideDocsFetchLCSElementsOfType pType
201+
return __ideDocsFetchData("", "LiveCode Script", pType)
202+
end ideDocsFetchLCSElementsOfType
203+
193204
/*
194205
Fetch the data for LiveCode builder dictionary entries with name <pEntryName>
195206
@@ -228,6 +239,17 @@ function ideDocsFetchLCBElementOfType pEntryName, pType, pElement
228239
return ideDocsFetchElementOfType(pEntryName, "LiveCode Builder", pType, pElement)
229240
end ideDocsFetchLCBElementOfType
230241

242+
/*
243+
Fetch all docs element of the given type in the LiveCode builder dictionary.
244+
245+
Returns:
246+
A numerically keyed array of data, each element of which is an array of data
247+
pertaining to a LiveCode builder dictionary entry with the given type.
248+
*/
249+
function ideDocsFetchLCBElementsOfType pType
250+
return __ideDocsFetchData("", "LiveCode Builder", pType)
251+
end ideDocsFetchLCBElementsOfType
252+
231253
/*
232254
Fetch the data for entries in the API for extension <pID> with name <pEntryName>
233255
@@ -272,6 +294,19 @@ function ideDocsFetchExtensionElementOfType pID, pEntryName, pType, pElement
272294
return ideDocsFetchElementOfType(pEntryName, tLibraryName, pType, pElement)
273295
end ideDocsFetchExtensionElementOfType
274296

297+
/*
298+
Fetch all docs element of the given type in the LiveCode script dictionary.
299+
300+
Returns:
301+
A numerically keyed array of data, each element of which is an array of data
302+
pertaining to a LiveCode script dictionary entry with the given type.
303+
*/
304+
function ideDocsFetchExtensionElementsOfType pID, pType
305+
local tLibraryName
306+
put revIDEExtensionProperty(pID, "title") into tLibraryName
307+
return __ideDocsFetchData("", tLibraryName, pType)
308+
end ideDocsFetchExtensionElementsOfType
309+
275310
/*
276311
Returns a list of library names, one per line, which have API entries in the dictionary.
277312
*/

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

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -340,61 +340,16 @@ command loadScript
340340
# OK-2008-07-07 : Bug 6746
341341
seUpdateCheckSum sObjectId, tScript
342342
else
343-
# AL-2015-09-21: Tweaked logic for default script
344-
local tType, tStyle
345-
put word 1 of the name of sObjectID into tType
346-
if tType is among the items of "button,field,stack,graphic,scrollbar" then
347-
put the style of sObjectId into tStyle
348-
else if tType is "widget" then
349-
put the kind of sObjectID into tStyle
350-
else -- groups, cards, images and players have no style property so just pass empty
351-
put empty into tStyle
352-
end if
353-
354-
local tDefaultScript
355-
put seDefaultScript(tType, tStyle) into tDefaultScript
356-
textSetScriptRaw tDefaultScript
357-
358-
local tDefaultSelection
359-
put seDefaultScriptSelection(tType, tStyle) into tDefaultSelection
360-
361-
# OK-2008-08-19 : When a default script is put into an object, the object should be marked as modified
362-
# in the script editor, as the script in the field is not the same as the object's actual script.
363-
if tDefaultScript is not empty then
364-
seSetObjectState sObjectId, "edited"
365-
end if
366-
367-
# OK-2008-07-07 : Bug 6746 - When a default script was loaded, it means the object's actual script was empty,
368-
# therefore the checksum should represent this.
369-
local tEmpty
370-
put empty into tEmpty
371-
seUpdateChecksum sObjectId, tEmpty
372-
373-
if tDefaultSelection is not empty then
374-
# Try is needed here to allow the IDE to add objects to a script editor before opening it
375-
try
376-
select char (item 1 of tDefaultSelection) to (item 2 of tDefaultSelection) of field "Script" of me
377-
378-
# OK-2009-01-17 : Bug 7601 - When a script is first loaded, slastSelectedChunk may be empty
379-
# or incorrect as the user has not yet done a selection to trigger selectedChanged and update it.
380-
put tDefaultSelection into sLastSelectedChunk
381-
end try
382-
else
383-
select before field "Script" of me
384-
end if
343+
select before field "Script" of me
385344
end if
386345
end if
387346

388-
# Only load the previous context if we didn't use the default script and default selection,
389-
# otherwise these will get overriden and the selection will be wrong.
390-
if tDefaultSelection is empty then
391-
# The lock messages is required, because otherwise an exitField is received before the contextLoad
392-
# can execute, causing the context to be overwritten just before we load it. Not currently sure why
393-
# this happens...
394-
lock messages
395-
contextLoad
396-
unlock messages
397-
end if
347+
# The lock messages is required, because otherwise an exitField is received before the contextLoad
348+
# can execute, causing the context to be overwritten just before we load it. Not currently sure why
349+
# this happens...
350+
lock messages
351+
contextLoad
352+
unlock messages
398353

399354
# As we have changed the selection, update the rest of the script editor to reflect this
400355
--selectionUpdateRequest

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

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ command initializeWithoutGrabbingFocus
3131
end initializeWithoutGrabbingFocus
3232

3333
command updateSelectedHandler
34+
if the cSelectedHandler of me is empty then
35+
set the hilitedLines of field "Handlers" of me to empty
36+
exit updateSelectedHandler
37+
end if
38+
3439
local tLineNumber
3540
put 1 into tLineNumber
3641

@@ -133,6 +138,22 @@ command update
133138
call "revSEGetHandlerList" to the cCaller of me
134139
put the result into tHandlers
135140

141+
local tDefaultHandlers, tIndex
142+
put revSEDefaultHandlers() into tDefaultHandlers
143+
set the wholematches to false
144+
145+
local tCanAdd
146+
repeat for each line tLine in tDefaultHandlers
147+
if lineOffset(tLine, tHandlers) is not 0 then
148+
next repeat
149+
end if
150+
if tCanAdd is empty then
151+
put tLine into tCanAdd
152+
else
153+
put return & tLine after tCanAdd
154+
end if
155+
end repeat
156+
136157
filterHandlerNames tHandlers
137158

138159
if sePrefGet("editor,sortHandlerList") is "alphabetical" then
@@ -148,12 +169,22 @@ command update
148169
sort tHandlers by handlerTypeSortCallback(word 1 of each) & word 2 of each
149170
end if
150171

172+
if tHandlers is not empty then
173+
put return &return after tHandlers
174+
end if
175+
put tCanAdd after tHandlers
176+
151177
# Populate the handlers field with the formatted list of handlers
152178
local tText, tIcon
153179
repeat for each line tHandler in tHandlers
154-
local tParseHandler
180+
local tParseHandler, tHandlerExists
181+
put true into tHandlerExists
155182
put word 1 to 2 of tHandler into tParseHandler
156183

184+
if the number of words in tHandler is 1 then
185+
put false into tHandlerExists
186+
end if
187+
157188
put "<p>" after tText
158189

159190
local tIsPrivate
@@ -162,12 +193,19 @@ command update
162193
put true into tIsPrivate
163194
delete char 1 of tParseHandler
164195
end if
165-
166-
put getIcon(char 1 of tParseHandler, tIsPrivate) into tIcon
196+
197+
if tHandlerExists then
198+
put getIcon(char 1 of tParseHandler, tIsPrivate) into tIcon
199+
if tIcon is not empty then
200+
delete char 1 of tParseHandler
201+
end if
202+
else
203+
put the id of image "icon-add.png" of stack "revIcons" into tIcon
204+
end if
205+
167206
if tIcon is not empty then
168207
put merge("<sup shift=2><img src=[[tICon]]></img></sup>") after tText
169208
end if
170-
delete char 1 of tParseHandler
171209

172210
put tParseHandler & "</p>" after tText
173211
end repeat
@@ -221,23 +259,40 @@ command resize
221259
unlock screen
222260
end resize
223261

224-
command closeAccept
225-
lock screen
226-
local tHandler
227-
put line (the hilitedLine of field "Handlers" of me) of the cHandlers of field "Handlers" of me into tHandler
228-
262+
command jumpToHandler pHandler
229263
local tLineNumber
230-
put word 3 of tHandler into tLineNumber
264+
put word 3 of pHandler into tLineNumber
231265

232266
# OK-2009-03-03: Bug 7450 - Also return the handler type, this will allow us to detect
233267
# if the handler line number is wrong (due to uncompiling script).
234-
set the cChoice of me to tLineNumber & comma & word 2 of tHandler & comma & word 1 of tHandler
268+
set the cChoice of me to tLineNumber & comma & word 2 of pHandler & comma & word 1 of pHandler
235269

236270
if the cCallback of me is not empty then
237271
send the cCallback of me to the cCallbackTarget of me
238272
end if
239273

240274
hideGroup
275+
end jumpToHandler
276+
277+
command closeAccept
278+
lock screen
279+
local tHandler
280+
put line (the hilitedLine of field "Handlers" of me) of the cHandlers of field "Handlers" of me into tHandler
281+
282+
if the number of words in tHandler is 1 then
283+
-- Adding a default handler
284+
revSEAddDefaultHandler tHandler
285+
update
286+
set the wholematches to false
287+
local tLine
288+
put lineOffset(tHandler, the cHandlers of field "Handlers" of me) into tLine
289+
select line tLine of field "Handlers" of me
290+
put line tLine of the cHandlers of field "Handlers" of me into tHandler
291+
end if
292+
293+
-- Select the (now) extant handler
294+
jumpToHandler tHandler
295+
241296
unlock screen
242297
end closeAccept
243298

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,106 @@ on revSESetScript pScript
29312931
dispatch "textSetScript" to field "Script" of me with pScript
29322932
end revSESetScript
29332933

2934+
function revSEGetScript pScript
2935+
dispatch function "textGetScript" to field "Script" of me
2936+
return the result
2937+
end revSEGetScript
2938+
29342939
on revSEIndentScript
29352940
dispatch "scriptFormat" to field "Script" of me with "script"
29362941
end revSEIndentScript
2942+
2943+
private command appendToList @xList, pValue
2944+
if xList is not empty then
2945+
put return & pValue after xList
2946+
else
2947+
put pValue into xList
2948+
end if
2949+
end appendToList
2950+
2951+
local sHandlersA
2952+
private function revSEDefaultHandlerInfoForObjectType pObjType
2953+
if sHandlersA[pObjType] is not empty then
2954+
return sHandlersA[pObjType]
2955+
end if
2956+
2957+
local tMessages
2958+
put ideDocsFetchLCSElementsOfType("message") into tMessages
2959+
2960+
local tMessageList
2961+
repeat for each element tElement in tMessages
2962+
local tAssociations
2963+
put tElement["Associations"] into tAssociations
2964+
filter elements of tAssociations with pObjType
2965+
if tAssociations is not empty then
2966+
appendToList tMessageList, tElement["display name"]
2967+
end if
2968+
end repeat
2969+
sort tMessageList
2970+
put tMessageList into sHandlersA[pObjType]
2971+
return tMessageList
2972+
end revSEDefaultHandlerInfoForObjectType
2973+
2974+
private function revSEDefaultHandlerInfoForWidget pWidgetKind
2975+
if sHandlersA[pWidgetKind] is not empty then
2976+
return sHandlersA[pWidgetKind]
2977+
end if
2978+
local tMessages
2979+
put ideDocsFetchExtensionElementsOfType(pWidgetKind, "message") into tMessages
2980+
2981+
local tMessageList
2982+
repeat for each element tElement in tMessages
2983+
appendToList tMessageList, tElement["display name"]
2984+
end repeat
2985+
sort tMessageList
2986+
put tMessageList into sHandlersA[pWidgetKind]
2987+
return tMessageList
2988+
end revSEDefaultHandlerInfoForWidget
2989+
2990+
function revSEDefaultHandlers
2991+
local tObject
2992+
revSEGetCurrentObject
2993+
put the result into tObject
2994+
if tObject is empty then
2995+
return empty
2996+
end if
2997+
return revSEDefaultHandlersForObject(tObject)
2998+
end revSEDefaultHandlers
2999+
3000+
function revSEDefaultHandlersForObject pObj
3001+
local tType
3002+
put word 1 of the name of pObj into tType
3003+
if tType is "widget" then
3004+
local tKind
3005+
put the kind of pObj into tKind
3006+
return revSEDefaultHandlerInfoForWidget(tKind)
3007+
end if
3008+
3009+
return revSEDefaultHandlerInfoForObjectType(tType)
3010+
end revSEDefaultHandlersForObject
3011+
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
3018+
3019+
return tDefaultHandler
3020+
end revSEDefaultScriptOfHandler
3021+
3022+
command revSEAddDefaultHandler pHandler
3023+
local tDefaultScript
3024+
put revSEDefaultScriptOfHandler(pHandler) into tDefaultScript
3025+
3026+
local tNewScript
3027+
put revSEGetScript() into tNewScript
3028+
if tNewScript is not empty then
3029+
if the last line of tNewScript is not empty then
3030+
put return after tNewScript
3031+
end if
3032+
put return after tNewScript
3033+
end if
3034+
put tDefaultScript after tNewScript
3035+
revSESetScript(tNewScript)
3036+
end revSEAddDefaultHandler

0 commit comments

Comments
 (0)