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

Commit 418bdb1

Browse files
Merge pull request #1656 from livecode/feature-default_handlers
[[ DefaultHandlers ]] Add lines in handler list for default handler addition in SE
2 parents 66ad21c + cfcf4f6 commit 418bdb1

9 files changed

Lines changed: 325 additions & 63 deletions

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/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/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

0 commit comments

Comments
 (0)