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

Commit 17feb6e

Browse files
Merge pull request #1985 from livecode/extension-sample_snippet_support
[[ Extensions ]] Add support for snippets and sample stacks
2 parents ea0f3b1 + 219694b commit 17feb6e

8 files changed

+268
-82
lines changed

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 128 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ function revIDEExtensions pType, pStatus, pWithoutInvisible
167167

168168
# Repeat over the extension array looking for elements with matching type
169169
local tExtensions, tExtension
170-
repeat for each key tExtensionKey in sExtensions
171-
put sExtensions[tExtensionKey] into tExtension
170+
repeat for each key tCacheId in sExtensions
171+
put sExtensions[tCacheId] into tExtension
172172
if tExtension["name"] is empty then
173-
delete variable sExtensions[tExtensionKey]
173+
__extensionCacheRemove tCacheId
174174
next repeat
175175
end if
176176
if pType is not empty and tExtension["type"] is not pType then
@@ -1049,43 +1049,48 @@ private command __MapCodeLibraryForIDE pFolder
10491049
end repeat
10501050
end __MapCodeLibraryForIDE
10511051

1052-
private command __LoadExtension pCacheIndex, pSourceType, pSourceFile, pFolder, pStatus, @xError
1052+
private command __LoadExtension pCacheIndex, pExtensionType, pSourceType, \
1053+
pSourceFile, pFolder, pStatus, @xError
1054+
revInternal__Log "Message", the params
10531055
if xError is empty then
10541056
local tFileToLoad
1055-
if pSourceType is "lcb" then
1056-
local tResources, tModule, tCode
1057-
put revIDEExtensionBytecodeFilename(true) into tFileToLoad
1058-
put pFolder & slash & tFileToLoad into tModule
1059-
if there is no file tModule then
1060-
put revIDEExtensionBytecodeFilename(false) into tFileToLoad
1057+
if not __extensionNeedsLoad(pExtensionType) then
1058+
put "installed" into pStatus
1059+
else
1060+
if pSourceType is "lcb" then
1061+
local tResources, tModule, tCode
1062+
put revIDEExtensionBytecodeFilename(true) into tFileToLoad
10611063
put pFolder & slash & tFileToLoad into tModule
1064+
if there is no file tModule then
1065+
put revIDEExtensionBytecodeFilename(false) into tFileToLoad
1066+
put pFolder & slash & tFileToLoad into tModule
1067+
end if
1068+
put pFolder & slash & "resources" into tResources
1069+
put pFolder & slash & "code" into tCode
1070+
# map code before loading extension
1071+
if there is a folder tCode then
1072+
__MapCodeLibraryForIDE tCode
1073+
end if
1074+
# If we have a resources folder then load with resource path
1075+
if there is a folder tResources then
1076+
load extension from file tModule with resource path tResources
1077+
else
1078+
load extension from file tModule
1079+
end if
1080+
else
1081+
set the itemdelimiter to "."
1082+
revInternal__LoadLibrary item 1 of pSourceFile, pFolder & slash & pSourceFile
1083+
put pSourceFile into tFileToLoad
10621084
end if
1063-
put pFolder & slash & "resources" into tResources
1064-
put pFolder & slash & "code" into tCode
1065-
# map code before loading extension
1066-
if there is a folder tCode then
1067-
__MapCodeLibraryForIDE tCode
1068-
end if
1069-
# If we have a resources folder then load with resource path
1070-
if there is a folder tResources then
1071-
load extension from file tModule with resource path tResources
1085+
if the result is not empty then
1086+
put toUpper(char 1 of the result) & \
1087+
char 2 to -1 of the result into xError
1088+
put "error" into pStatus
10721089
else
1073-
load extension from file tModule
1090+
put "installed" into pStatus
10741091
end if
1075-
else
1076-
set the itemdelimiter to "."
1077-
revInternal__LoadLibrary item 1 of pSourceFile, pFolder & slash & pSourceFile
1078-
put pSourceFile into tFileToLoad
1079-
end if
1080-
if the result is not empty then
1081-
put toUpper(char 1 of the result) & \
1082-
char 2 to -1 of the result into xError
1083-
put "error" into pStatus
1084-
else
1085-
put "installed" into pStatus
10861092
end if
10871093
end if
1088-
10891094
__extensionPropertySet pCacheIndex, "status", pStatus
10901095
__extensionPropertySet pCacheIndex, "error", xError
10911096
__extensionPropertySet pCacheIndex, "file", tFileToLoad
@@ -1112,15 +1117,17 @@ private command __revIDELCBExtensionLoad pID, pFolder, pVersion, pStatus, \
11121117
revIDEExtensionGetLoadOnStartup(pID) into tLoadOnStartup
11131118
end if
11141119
if not pIsStartup or tLoadOnStartup is not false then
1115-
__LoadExtension tCacheIndex, "lcb", pSourceFile, pFolder, pStatus, pError
1120+
__LoadExtension tCacheIndex, pAdditionalInfoA["type"], "lcb", pSourceFile, \
1121+
pFolder, pStatus, pError
11161122
-- If we have an error loading, try to recompile the extension
11171123
if pError is not empty then
11181124
if not pIsIDEExtension and pSourceFile is not empty then
11191125
revIDEExtensionCompile pFolder, pSourceFile, tSupportFiles, pFolder, \
11201126
revIDEExtensionBytecodeFilename(true)
11211127
if the result is empty then
11221128
local tNewError
1123-
__LoadExtension tCacheIndex, "lcb", pSourceFile, pFolder, pStatus, tNewError
1129+
__LoadExtension tCacheIndex, pAdditionalInfoA["type"], "lcb", \
1130+
pSourceFile, pFolder, pStatus, tNewError
11241131
put tNewError into pError
11251132
end if
11261133
end if
@@ -1190,6 +1197,25 @@ private function __UseTypeToKey pUseType
11901197
end switch
11911198
end __UseTypeToKey
11921199

1200+
private function __extensionHasID pType
1201+
switch pType
1202+
case "snippet"
1203+
return false
1204+
default
1205+
return true
1206+
end switch
1207+
end __extensionHasID
1208+
1209+
private function __extensionNeedsLoad pType
1210+
switch pType
1211+
case "snippet"
1212+
case "sample"
1213+
return false
1214+
default
1215+
return true
1216+
end switch
1217+
end __extensionNeedsLoad
1218+
11931219
private command __revIDELCSExtensionLoad pFullPath, pFolder, pVersion, pStatus, \
11941220
pError, pIsIDEExtension, pSourceFile, pAdditionalInfoA, pIsStartup
11951221

@@ -1203,27 +1229,35 @@ private command __revIDELCSExtensionLoad pFullPath, pFolder, pVersion, pStatus,
12031229
__extensionPropertySet tCacheIndex, "install_path", pFolder
12041230
end if
12051231

1232+
if pAdditionalInfoA is empty then
1233+
put __fetchExtensionManifestData(pFolder, pSourceFile) into pAdditionalInfoA
1234+
end if
1235+
1236+
local tType
1237+
put pAdditionalInfoA["type"] into tType
1238+
12061239
# Update name, status, error, and whether the extension comes with the IDE
12071240
local tId
1241+
if __extensionHasID(tType) then
12081242
try
12091243
put the short name of stack (pFolder & slash & pSourceFile) into tId
12101244
catch pError
12111245
end try
1246+
else
1247+
# The manifest should contain an id
1248+
put pAdditionalInfoA["name"] into tId
1249+
end if
12121250

12131251
local tLoadOnStartup
1214-
if pError is empty then
1252+
if pError is empty and __extensionNeedsLoad(tType) then
12151253
put revIDEExtensionGetLoadOnStartup(tID) into tLoadOnStartup
12161254
end if
1217-
if not pIsStartup or tLoadOnStartup is not false then
1218-
__LoadExtension tCacheIndex, "lcs", pSourceFile, pFolder, pStatus, pError
1255+
if not pIsStartup or (tLoadOnStartup is not false) then
1256+
__LoadExtension tCacheIndex, tType, "lcs", pSourceFile, pFolder, pStatus, pError
12191257
else
12201258
__extensionPropertySet tCacheIndex, "status", "unloaded"
12211259
end if
12221260

1223-
if pAdditionalInfoA is empty then
1224-
put __fetchExtensionManifestData(pFolder, pSourceFile) into pAdditionalInfoA
1225-
end if
1226-
12271261
__extensionPropertySet tCacheIndex, "name", tId
12281262
__extensionPropertySet tCacheIndex, "type_id", tId & "." & pVersion
12291263

@@ -1245,7 +1279,7 @@ private command __revIDELCSExtensionLoad pFullPath, pFolder, pVersion, pStatus,
12451279
__extensionPropertySet tCacheIndex, "source_file", pSourceFile
12461280
__extensionPropertySet tCacheIndex, "ide", pIsIDEExtension
12471281
__extensionPropertySet tCacheIndex, "source_type", "lcs"
1248-
__extensionPropertySet tCacheIndex, "type", "library"
1282+
__extensionPropertySet tCacheIndex, "type", pAdditionalInfoA["type"]
12491283
__extensionPropertySet tCacheIndex, "uservisible", true
12501284
__extensionPropertySet tCacheIndex, "support_files", pAdditionalInfoA["support_files"]
12511285

@@ -1261,6 +1295,14 @@ private command __revIDELCSExtensionLoad pFullPath, pFolder, pVersion, pStatus,
12611295
end if
12621296
end if
12631297

1298+
# If this is not startup, then auto-launch snippet or sample stack
1299+
if not pIsStartup then
1300+
if tType is "snippet" then
1301+
revIDEExtensionShowSnippet pFolder & slash & pSourceFile
1302+
else if tType is "sample" then
1303+
revIDEExtensionOpenSample pFolder & slash & pSourceFile
1304+
end if
1305+
end if
12641306
return pError
12651307
end __revIDELCSExtensionLoad
12661308

@@ -1273,7 +1315,7 @@ command revIDEExtensionReload pTypeId
12731315
end if
12741316
local tError, tDataA
12751317
put sExtensions[tCacheIndex] into tDataA
1276-
__LoadExtension tCacheIndex, tDataA["source_type"], \
1318+
__LoadExtension tCacheIndex, tDataA["type"], tDataA["source_type"], \
12771319
tDataA["source_file"], tDataA["install_path"], \
12781320
"", tError
12791321
if tError is not empty then
@@ -1547,3 +1589,46 @@ command revIDEExtensionIconFromType pType, pID, @rIconName, @rIconPath
15471589
break
15481590
end switch
15491591
end revIDEExtensionIconFromType
1592+
1593+
command revIDEExtensionShowSnippet pSourceFile
1594+
local tSnippet
1595+
put revIDEUTF8FileContents(pSourceFile) into tSnippet
1596+
lock screen
1597+
revIDEOpenPalette("snippet viewer")
1598+
dispatch "revIDESnippetViewerSetSnippet" to stack \
1599+
revIDEPaletteToStackName("snippet viewer") with tSnippet
1600+
unlock screen
1601+
end revIDEExtensionShowSnippet
1602+
1603+
local sSampleFileName
1604+
local sOpenedStacksA
1605+
on ideOpenStack pCard
1606+
local tStack
1607+
put the long id of the owner of pCard into tStack
1608+
if tStack is the long id of stack sSampleFileName then
1609+
## Clear the filename to force the user to choose save location if saving the stack
1610+
put the short name of tStack into sOpenedStacksA[sSampleFileName]
1611+
set the filename of tStack to empty
1612+
put empty into sSampleFileName
1613+
revIDEUnsubscribe "ideOpenStack"
1614+
end if
1615+
end ideOpenStack
1616+
1617+
command revIDEExtensionLaunchSampleStack pSampleStack
1618+
// Check if the sample stack has already been opened,
1619+
// i.e. if its name is mapped in the array. If so, just
1620+
// open it.
1621+
if there is a stack (sOpenedStacksA[pSampleStack]) then
1622+
open stack sOpenedStacksA[pSampleStack]
1623+
exit revIDEExtensionLaunchSampleStack
1624+
end if
1625+
1626+
// Otherwise open the stack from the file. Wait until we
1627+
// get the openStack message before emptying the filename
1628+
// otherwise we will get a long id clash
1629+
revIDESubscribe "ideOpenStack"
1630+
put pSampleStack into sSampleFileName
1631+
1632+
## Open the sample stack
1633+
open stack pSampleStack
1634+
end revIDEExtensionLaunchSampleStack

Toolset/libraries/revidelibrary.8.livecodescript

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4348,7 +4348,7 @@ Returns a list of all the display names of stacks recognised by the IDE as a pal
43484348
*/
43494349
function revIDEAvailablePalettes
43504350
return "Menubar,Tools,Inspector,Message Box,Project Browser,Extension Manager,Extension Builder,Start Center,Welcome,Menu Builder,Message Watcher,Plugin Preferences," \
4351-
& "Standalone Settings,About,Dictionary,Guide,Resource Center,Preferences,Search"
4351+
& "Standalone Settings,About,Dictionary,Guide,Resource Center,Preferences,Search,Snippet Viewer"
43524352
end revIDEAvailablePalettes
43534353

43544354
function revIDEPaletteToStackName pPalette
@@ -4397,6 +4397,8 @@ function revIDEPaletteToStackName pPalette
43974397
return "revDictionary"
43984398
case "resource center"
43994399
return "revResourceCenter"
4400+
case "snippet viewer"
4401+
return "revIDESnippetViewer"
44004402
end switch
44014403
end revIDEPaletteToStackName
44024404

@@ -4624,6 +4626,7 @@ command revIDEOpenPalette pPaletteName
46244626
case "standalone settings"
46254627
case "message watcher"
46264628
case "tools"
4629+
case "snippet viewer"
46274630
palette stack tStackName
46284631
break
46294632
case "search"

Toolset/palettes/extension manager/revideextensionmanagerbehavior.livecodescript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on preOpenStack
1212
# Navigation
1313
addFrameItem "widget","header", "navigation", "Widgets", "", "","showList", the long id of me,"widget"
1414
addFrameItem "library","header", "navigation", "Libraries", "", "","showList", the long id of me,"library"
15+
addFrameItem "sample","header", "navigation", "Sample Stacks", "", "","showList", the long id of me,"sample"
16+
addFrameItem "snippet","header", "navigation", "Snippets", "", "","showList", the long id of me,"snippet"
1517
addFrameItem "store","header", "navigation", "Store", "", "","showExtensionStore", the long id of me,"store"
1618
addFrameItem "install", "header", "action", "Install extension", "plus", "","installNew", the long id of me
1719

Toolset/palettes/extension manager/revideextensionmanagerlistbehavior.livecodescript

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -186,38 +186,19 @@ on cancelExtensionInstall pExtensionIdentifier
186186
revIDECancelInstallExtension pExtensionIdentifier
187187
end cancelExtensionInstall
188188

189-
local sSampleFileName
190-
local sOpenedStacksA
191-
on launchExtensionSampleStack pSampleStack
192-
// Check if the sample stack has already been opened,
193-
// i.e. if its name is mapped in the array. If so, just
194-
// open it.
195-
if there is a stack (sOpenedStacksA[pSampleStack]) then
196-
open stack sOpenedStacksA[pSampleStack]
197-
exit launchExtensionSampleStack
198-
end if
199-
200-
// Otherwise open the stack from the file. Wait until we
201-
// get the openStack message before emptying the filename
202-
// otherwise we will get a long id clash
203-
revIDESubscribe "ideOpenStack"
204-
put pSampleStack into sSampleFileName
205-
206-
## Open the sample stack
207-
open stack pSampleStack
189+
on launchExtensionSampleStack pExtensionId
190+
local tSourceFolder, tSourceFile
191+
put revIDEExtensionProperty(pExtensionId, "install_path") into tSourceFolder
192+
put revIDEExtensionProperty(pExtensionId, "source_file") into tSourceFile
193+
revIDEExtensionLaunchSampleStack tSourceFolder & slash & tSourceFile
208194
end launchExtensionSampleStack
209195

210-
on ideOpenStack pCard
211-
local tStack
212-
put the long id of the owner of pCard into tStack
213-
if tStack is the long id of stack sSampleFileName then
214-
## Clear the filename to force the user to choose save location if saving the stack
215-
put the short name of tStack into sOpenedStacksA[sSampleFileName]
216-
set the filename of tStack to empty
217-
put empty into sSampleFileName
218-
revIDEUnsubscribe "ideOpenStack"
219-
end if
220-
end ideOpenStack
196+
on showExtensionSnippet pExtensionId
197+
local tSourceFolder, tSourceFile
198+
put revIDEExtensionProperty(pExtensionId, "install_path") into tSourceFolder
199+
put revIDEExtensionProperty(pExtensionId, "source_file") into tSourceFile
200+
revIDEExtensionShowSnippet tSourceFolder & slash & tSourceFile
201+
end showExtensionSnippet
221202

222203
on ideExtensionStatusChanged pStatus
223204
local tElement, tRow, tIdentifier, tStatus, tProgress

0 commit comments

Comments
 (0)