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

Commit 603d14a

Browse files
authored
Merge pull request #1838 from livecode/feature-extension_standalone_settings
[[ ExtensionStandaloneSettings ]] Add mechanism for extensions standalone settings
2 parents 833802d + ae3c945 commit 603d14a

11 files changed

Lines changed: 434 additions & 133 deletions

Toolset/libraries/revidedeveloperextensionlibrary.livecodescript

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ private function __revIDEDeveloperExtensionFetchFolderDetails pFolder, pFile
293293
if tDetailsA["defaultscript"] is not empty then
294294
put pFolder & "/support/defaultscript.livecodescript" into tDetailsA["defaultscript_file"]
295295
end if
296+
297+
# Custom PI editors
298+
local tEditorsFolder, tEditors
299+
put pFolder & slash & "editors" into tEditorsFolder
300+
if there is a folder tEditorsFolder then
301+
put __revIDEDeveloperExtensionListResourcesRecursive(tEditorsFolder, "") into tEditors
302+
put tEditors into tDetailsA["editors"]
303+
end if
304+
296305
return tDetailsA
297306
end __revIDEDeveloperExtensionFetchFolderDetails
298307

@@ -883,8 +892,18 @@ private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuil
883892
put empty into tDefaultScript
884893
end if
885894

895+
local tEditors
896+
put (pFolder & slash & "editors") into tEditors
897+
if there is not a folder tEditors then
898+
put empty into tEditors
899+
end if
900+
886901
if tError is empty then
887-
put __revIDEDeveloperExtensionAddSpecifiedFilesToPackage(tFullPath, pFolder, tArchive, pFolder & slash & "module.lcm", tIcon, tRetinaIcon, tGuide, tDocs, tResources, tCode, tInterfaceFile, tDefaultScript) into tError
902+
put __revIDEDeveloperExtensionAddSpecifiedFilesToPackage(\
903+
tFullPath, pFolder, tArchive, pFolder & slash & "module.lcm", \
904+
tIcon, tRetinaIcon, tGuide, tDocs, tResources, tCode, \
905+
tInterfaceFile, tDefaultScript, tEditors) \
906+
into tError
888907
end if
889908

890909
revZipCloseArchive tArchive
@@ -904,7 +923,10 @@ private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuil
904923
return empty
905924
end __revIDEDeveloperExtensionBuildPackage
906925

907-
private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage pSource, pFolder, pArchive, pModule, pIcon, pRetinaIcon, pGuide, pDocs, pResourcesFolder, pCodeFolder, pInterfaceFile, pDefaultScript
926+
private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage \
927+
pSource, pFolder, pArchive, pModule, pIcon, pRetinaIcon, pGuide, \
928+
pDocs, pResourcesFolder, pCodeFolder, pInterfaceFile, \
929+
pDefaultScript, pEditors
908930
local tError
909931

910932
set the itemdelimiter to slash
@@ -1017,6 +1039,19 @@ private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage pSource, p
10171039
end if
10181040
end if
10191041

1042+
# Add editors
1043+
if tError is empty and pEditors is not empty then
1044+
local tEditors
1045+
put __revIDEDeveloperExtensionListResourcesRecursive(pEditors, "") into tEditors
1046+
repeat for each line tLine in tEditors
1047+
revZipAddItemWithFile pArchive, "editors/" & tLine, pEditors & slash & tLine
1048+
1049+
if the result begins with "ziperr" then
1050+
__revIDEDeveloperExtensionSendWarning "couldn't add editors" && pEditors & slash & tLine
1051+
end if
1052+
end repeat
1053+
end if
1054+
10201055
return tError
10211056
end __revIDEDeveloperExtensionAddSpecifiedFilesToPackage
10221057

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 125 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,33 @@ function revIDEExtensionProperties pTypeID
111111
return sExtensionProperties[pTypeID]
112112
end revIDEExtensionProperties
113113

114+
# organise the property info into the structure that the inspectors
115+
# expect, namely [<section>]["grouplist"][<group>]["proplist"][<prop>]
116+
private function __OrganiseInspectorMetadata pDataA
117+
local tExtensionPropsInfoA
118+
repeat for each key tProp in pDataA
119+
local tSection, tGroup, tOrder, tPropInfoA
120+
put pDataA[tProp] into tPropInfoA
121+
put pDataA[tProp]["order"] into tOrder
122+
put pDataA[tProp]["label"] into tGroup
123+
put pDataA[tProp]["section"] into tSection
124+
put tPropInfoA into tExtensionPropsInfoA[tSection]["grouplist"][tGroup]["proplist"][tProp]
125+
126+
put true into tExtensionPropsInfoA[tSection]["grouplist"][tGroup]["widget_prop"]
127+
put tOrder into tExtensionPropsInfoA[tSection]["grouplist"][tGroup]["order"]
128+
end repeat
129+
return tExtensionPropsInfoA
130+
end __OrganiseInspectorMetadata
131+
114132
function revIDEExtensionPropertiesInfo pTypeId, pOrganise
115133
local tPropsA, tExtensionPropsInfoA
116134
put revIDEExtensionProperties(pTypeId) into tPropsA
117135

118136
if pOrganise then
119-
# If pOrganise is true, organise the property info into the structure that the property
120-
# inspector expects, namely [<section>]["grouplist"][<group>]["proplist"][<prop>]
121-
repeat for each key tProp in tPropsA
122-
local tSection, tGroup, tOrder, tPropInfoA
123-
put tPropsA[tProp] into tPropInfoA
124-
put tPropsA[tProp]["order"] into tOrder
125-
put tPropsA[tProp]["label"] into tGroup
126-
put tPropsA[tProp]["section"] into tSection
127-
put tPropInfoA into tExtensionPropsInfoA[tSection]["grouplist"][tGroup]["proplist"][tProp]
128-
129-
put true into tExtensionPropsInfoA[tSection]["grouplist"][tGroup]["widget_prop"]
130-
put tOrder into tExtensionPropsInfoA[tSection]["grouplist"][tGroup]["order"]
131-
end repeat
137+
return __OrganiseInspectorMetadata(tPropsA)
132138
else
133-
put tPropsA into tExtensionPropsInfoA
139+
return tPropsA
134140
end if
135-
return tExtensionPropsInfoA
136141
end revIDEExtensionPropertiesInfo
137142

138143
function revIDEExtensionProperty pKind, pProperty
@@ -146,6 +151,25 @@ function revIDEExtensionProperty pKind, pProperty
146151
return __extensionPropertyGet(tExtensionID, pProperty)
147152
end revIDEExtensionProperty
148153

154+
function revIDEExtensionStandaloneSettings pID
155+
# Get the internal cache index
156+
local tCacheIndex
157+
put __extensionCacheID("name", pID) into tCacheIndex
158+
159+
return __extensionPropertyGet(tCacheIndex, "standaloneSettings")
160+
end revIDEExtensionStandaloneSettings
161+
162+
function revIDEExtensionStandaloneSettingsInfo pTypeId, pOrganise
163+
local tPropsA, tExtensionPropsInfoA
164+
put revIDEExtensionStandaloneSettings(pTypeId) into tPropsA
165+
166+
if pOrganise then
167+
return __OrganiseInspectorMetadata(tPropsA)
168+
else
169+
return tPropsA
170+
end if
171+
end revIDEExtensionStandaloneSettingsInfo
172+
149173
##############################
150174
# PRIVATE INSTALLATION PROCESS
151175
##############################
@@ -477,112 +501,105 @@ end __extensionUninstallComplete
477501
##############################
478502
# PRIVATE SHARED
479503
##############################
504+
private command __ProcessInspectorMetadata @xMetadataA
505+
repeat for each key tKey in xMetadataA
506+
local tLabel, tSection
507+
if xMetadataA[tKey]["section"] is empty then
508+
put "Basic" into xMetadataA[tKey]["section"]
509+
end if
510+
511+
if xMetadataA[tKey]["label"] is empty then
512+
put tKey into xMetadataA[tKey]["label"]
513+
end if
514+
515+
# Process value options, default and delimiter
516+
replace comma with return in xMetadataA[tKey]["options"]
517+
replace "\n" with return in xMetadataA[tKey]["delimiter"]
518+
if xMetadataA[tKey]["default"] is not empty then
519+
replace "\n" with return in xMetadataA[tKey]["default"]
520+
end if
521+
522+
if xMetadataA[tKey]["user_visible"] is empty then
523+
put true into xMetadataA[tKey]["user_visible"]
524+
end if
525+
526+
if xMetadataA[tKey]["properties"] is not empty then
527+
-- If there is a 'properties' value, delete the key
528+
-- and replace it with that value
529+
local tInfo, tNewKey
530+
put xMetadataA[tKey] into tInfo
531+
put tInfo["properties"] into tNewKey
532+
delete variable xMetadataA[tKey]
533+
delete variable tInfo["properties"]
534+
put tInfo into xMetadataA[tNewKey]
535+
end if
536+
end repeat
537+
end __ProcessInspectorMetadata
480538

481-
function __extensionFetchPropertyMetadata pXMLTree, pProperty, pElement
482-
local tNode
483-
put revXMLMatchingNode(pXMLTree, "package", "metadata", "key", pProperty &"." & pElement, 1) into tNode
484-
if tNode is not empty then
485-
return revXMLNodeContents(pXMLTree, tNode)
486-
end if
487-
488-
return empty
489-
end __extensionFetchPropertyMetadata
490-
491-
function __extensionPropertyInfoFromManifest pManifestPath
539+
private function __extensionPropertyInfoFromManifest pId, pManifestPath
492540
if not there is a file pManifestPath then return empty
493541
# Create the XML tree
494-
local tXMLTree, tProperties, tExtensionData
542+
local tXMLTree, tProperties, tExtensionData, tPropertyNodes
495543
put revXMLCreateTreeFromFile(pManifestPath,true,true,false) into tXMLTree
496544

497-
# Process the general property metadata into an array
498-
local tMetadataNodes, tMetadataA, tKeys, tValue
499-
put revXMLChildNames(tXMLTree, "package",return,"metadata",true) into tMetadataNodes
500-
set the itemdelimiter to "."
501-
repeat for each line tMetadata in tMetadataNodes
502-
put revXMLAttribute(tXMLTree,"package" & "/" & tMetadata,"key") into tKeys
503-
put revXMLNodeContents(tXMLTree,"package" & "/" & tMetadata) into tValue
504-
repeat with x = the number of items in tKeys down to 1
505-
get tValue
506-
put empty into tValue
507-
put it into tValue[item x of tKeys]
508-
end repeat
509-
union tMetadataA with tValue recursively
510-
end repeat
545+
put revXMLChildNames(tXMLTree,"package",return,"property",true) into tPropertyNodes
511546

512-
put revXMLChildNames(tXMLTree,"package",return,"property",true) into tProperties
513-
local tOrder, tPropertyDataA
547+
local tCacheID
548+
put __extensionCacheID("name", pID) into tCacheId
514549

515-
local tMetadataKeys
516-
put the keys of tMetadataA into tMetadataKeys
517-
sort tMetadataKeys
518-
sort tMetadataKeys by tMetadataA[each]["order"]
519-
repeat for each line tKey in tMetadataKeys
520-
local tPropertyInfo
521-
put revIDEPropertyInfo(tKey) into tPropertyInfo
522-
if tPropertyInfo is empty then
523-
next repeat
524-
end if
525-
add 1 to tOrder
526-
union tMetadataA[tKey] with tPropertyInfo
527-
put tMetadataA[tKey] into tPropertyDataA[tKey]
528-
put tOrder into tPropertyDataA[tKey]["order"]
550+
local tPropertyNames, tPropertyXMLData
551+
repeat for each line tPropertyNode in tPropertyNodes
552+
local tName
553+
put revXMLAttribute(tXMLTree,"package" & "/" & tPropertyNode,"name") into tName
554+
put __extensionPropertyGet(tCacheId, tName) into tPropertyXMLData[tName]["data"]
555+
put revXMLAttribute(tXMLTree,"package" & "/" & tPropertyNode,"set") into \
556+
tPropertyXMLData[tName]["set"]
557+
put revXMLAttribute(tXMLTree,"package" & "/" & tPropertyNode,"get") into \
558+
tPropertyXMLData[tName]["get"]
529559
end repeat
560+
put the keys of tPropertyXMLData into tPropertyNames
561+
sort tPropertyNames by tPropertyXMLData[each]["data"]["order"]
530562

531-
repeat for each line tProperty in tProperties
532-
add 1 to tOrder
533-
local tName
534-
put revXMLAttribute(tXMLTree,"package" & "/" & tProperty,"name") into tName
535-
536-
put tMetadataA[tName] into tPropertyDataA[tName]
563+
local tOrder, tPropertyDataA
564+
repeat for each line tProperty in tPropertyNames
565+
local tIDEPropertyInfo, tPropertyInfoA
566+
put tPropertyXMLData[tProperty]["data"] into tPropertyInfoA
567+
put revIDEPropertyInfo(tProperty) into tIDEPropertyInfo
568+
if tIDEPropertyInfo is not empty then
569+
add 1 to tOrder
570+
union tPropertyInfoA with tIDEPropertyInfo
571+
put tPropertyInfoA into tPropertyDataA[tProperty]
572+
put tOrder into tPropertyDataA[tProperty]["order"]
573+
else
574+
put tPropertyInfoA into tPropertyDataA[tProperty]
575+
end if
537576

538-
local tReadOnly
539-
get revXMLAttribute(tXMLTree,"package" & "/" & tProperty,"set")
540-
if it is empty or it begins with "xmlerr" then
577+
local tReadOnly, tSetter
578+
put tPropertyXMLData[tProperty]["set"] into tSetter
579+
if tSetter is empty or tSetter begins with "xmlerr" then
541580
put true into tReadOnly
542581
else
543582
put false into tReadOnly
544583
end if
545-
put tReadOnly into tPropertyDataA[tName]["read_only"]
584+
put tReadOnly into tPropertyDataA[tProperty]["read_only"]
546585

547-
if tPropertyDataA[tName]["editor"] is empty then
586+
if tPropertyDataA[tProperty]["editor"] is empty then
548587
local tType
549-
put revXMLAttribute(tXMLTree,"package" & "/" & tProperty,"get") into tType
588+
put tPropertyXMLData[tProperty]["get"] into tType
550589
if tType is "Integer" or tType is "Real" then
551-
put "com.livecode.pi.number" into tPropertyDataA[tName]["editor"]
590+
put "com.livecode.pi.number" into tPropertyDataA[tProperty]["editor"]
552591
else
553-
put "com.livecode.pi." & tolower(tType) into tPropertyDataA[tName]["editor"]
592+
put "com.livecode.pi." & tolower(tType) into tPropertyDataA[tProperty]["editor"]
554593
end if
555594
end if
556-
put tOrder into tPropertyDataA[tName]["order"]
557-
end repeat
558-
559-
repeat for each key tName in tPropertyDataA
560-
local tLabel, tSection
561-
562-
if tPropertyDataA[tName]["section"] is empty then
563-
put "Basic" into tPropertyDataA[tName]["section"]
564-
end if
565-
566-
if tPropertyDataA[tName]["label"] is empty then
567-
put tName into tPropertyDataA[tName]["label"]
568-
end if
569-
570-
# Process value options, default and delimiter
571-
replace comma with return in tPropertyDataA[tName]["options"]
572-
replace "\n" with return in tPropertyDataA[tName]["delimiter"]
573-
if tPropertyDataA[tName]["default"] is not empty then
574-
replace "\n" with return in tPropertyDataA[tName]["default"]
575-
end if
576-
595+
put tOrder into tPropertyDataA[tProperty]["order"]
577596
# Tag the property as a widget property, so we can order them
578597
# correctly after the built-in props for the given section
579-
put true into tPropertyDataA[tName]["widget_prop"]
580-
581-
if tPropertyDataA[tName]["user_visible"] is empty then
582-
put true into tPropertyDataA[tName]["user_visible"]
583-
end if
598+
put true into tPropertyDataA[tProperty]["widget_prop"]
584599
end repeat
585600

601+
__ProcessInspectorMetadata tPropertyDataA
602+
586603
revXMLDeleteTree tXMLTree
587604
return tPropertyDataA
588605
end __extensionPropertyInfoFromManifest
@@ -628,9 +645,9 @@ private command __extensionSetExtensionInfoFromManifest pCacheIndex, pManifestPa
628645
end repeat
629646
end __extensionSetExtensionInfoFromManifest
630647

631-
command __extensionSetPropertyInfoFromManifest pID, pManifest
648+
private command __extensionSetPropertyInfoFromManifest pID, pManifest
632649
local tPropertyInfo
633-
put __extensionPropertyInfoFromManifest(pManifest) into tPropertyInfo
650+
put __extensionPropertyInfoFromManifest(pId, pManifest) into tPropertyInfo
634651
put tPropertyInfo into sExtensionProperties[pID]
635652
end __extensionSetPropertyInfoFromManifest
636653

@@ -1340,6 +1357,11 @@ command revIDEExtensionMetadata pFolder, pFile, pType, @rDataA
13401357
return tResult
13411358
end revIDEExtensionMetadata
13421359

1360+
private command __SetMetadata pKey, pValue, @xArray
1361+
split pKey by "."
1362+
put pValue into xArray[pKey]
1363+
end __SetMetadata
1364+
13431365
private command revIDEExtensionFetchMetadata pManifestPath, @rDataA
13441366
local tDataA
13451367

@@ -1399,7 +1421,7 @@ private command revIDEExtensionFetchMetadata pManifestPath, @rDataA
13991421
if tMetadataValue is empty or tMetadataValue begins with "xmlerr" then
14001422
put empty into tMetadataValue
14011423
end if
1402-
put tMetadataValue into tDataA[tMetadataKey]
1424+
__SetMetadata tMetadataKey, tMetadataValue, tDataA
14031425
end repeat
14041426

14051427
# Fetch extension dependencies
@@ -1439,6 +1461,9 @@ private command revIDEExtensionFetchMetadata pManifestPath, @rDataA
14391461
put true into tDataA["uservisible"]
14401462
end if
14411463

1464+
# Make sure 'inspector' style metadata is processed
1465+
__ProcessInspectorMetadata tDataA["standaloneSettings"]
1466+
14421467
put tDataA into rDataA
14431468
return empty
14441469
end revIDEExtensionFetchMetadata

0 commit comments

Comments
 (0)