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

Commit 939f4ca

Browse files
committed
[[ PI ]] Allow custom property editors to be packaged in extensions
1 parent 91f0466 commit 939f4ca

5 files changed

Lines changed: 79 additions & 10 deletions

File tree

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

@@ -882,8 +891,18 @@ private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuil
882891
put empty into tDefaultScript
883892
end if
884893

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

889908
revZipCloseArchive tArchive
@@ -903,7 +922,10 @@ private on __revIDEDeveloperExtensionBuildPackage pFolder, pTargetFolder, @rBuil
903922
return empty
904923
end __revIDEDeveloperExtensionBuildPackage
905924

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

909931
set the itemdelimiter to slash
@@ -1016,6 +1038,19 @@ private function __revIDEDeveloperExtensionAddSpecifiedFilesToPackage pSource, p
10161038
end if
10171039
end if
10181040

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

Toolset/palettes/behaviors/revinspectorbehavior.livecodescript

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,28 @@ on inspectorOpenEditor pEditor
5252

5353
# Find the file for the editor
5454
local tEditorStackPath, tEditorBehaviorPath
55-
put revIDEPaletteResourcePath("editors/" & pEditor & ".livecode") into tEditorStackPath
56-
put revIDEPaletteResourcePath("editors/" & pEditor & ".behavior.livecodescript") into tEditorBehaviorPath
55+
put revIDEPaletteResourcePath("editors/" & pEditor & ".livecode", \
56+
the long id of stack "revInspector") into tEditorStackPath
57+
put revIDEPaletteResourcePath("editors/" & pEditor & ".behavior.livecodescript", \
58+
the long id of stack "revInspector") into tEditorBehaviorPath
59+
5760
# open editor stack if it exists
58-
if there is a file tEditorStackPath then
59-
go invisible stack tEditorStackPath
61+
if there is not a file tEditorStackPath then
62+
# check if an extension has provided its own editor
63+
# it is named <id>.editor.editorName
64+
local tId, tPath
65+
set the itemdelimiter to "."
66+
put item 1 to -3 of pEditor into tId
67+
put revIDEExtensionProperty(tId, "install_path") into tPath
68+
put tPath & "/editors/" & pEditor & ".livecode" into tEditorStackPath
69+
put tPath & "/editors/" & pEditor & ".behavior.livecodescript" into tEditorBehaviorPath
6070
end if
6171

72+
if there is a file tEditorStackPath then
73+
get the long id of stack tEditorStackPath
74+
end if
6275
if there is a file tEditorBehaviorPath then
63-
go invisible stack tEditorBehaviorPath
76+
get the long id of stack tEditorBehaviorPath
6477
end if
6578
end inspectorOpenEditor
6679

Toolset/palettes/inspector/behaviors/revinspectorgroupbehavior.livecodescript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ on propertyRegister pPropertyInfo
2828
break
2929
end switch
3030

31+
inspectorOpenEditor tEditor
32+
3133
# Create the editor (need to decide if it's a classic editor (clone a group)
3234
# or a new widget editor, in which case it's create control.
3335
if there is not a stack tEditor then
3436
put "com.livecode.pi.string" into tEditor
37+
inspectorOpenEditor tEditor
3538
end if
39+
3640
local tEditorBehavior
3741
put tEditor & ".behavior" into tEditorBehavior
3842

notes/feature-custom_editors.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Custom property inspector editors
2+
Extensions may now include their own property inspector editors
3+
for use when editing their properties. The stack containing the
4+
editor, and the behavior must be named <extension id>.editor.<name>.livecode
5+
and <extension id>.editor.<name>.behavior.livecodescript respectively.
6+
7+
The editor stack must contain one group called "template", which is the
8+
editor. It is cloned onto the inspector stack when any property that
9+
uses it as an editor is inspected.
10+
11+
Please see the [property inspector feature note](https://github.com/livecode/livecode-ide/blob/develop/notes/feature-property_inspector.md#editors)
12+
for more details on property inspector editors.
13+

notes/feature-property_inspector.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ override the defaults.
9999
### Editors
100100

101101
Currently an editor must be a stack consisting of a group named
102-
"template" and a button named "behavior". The property inspector looks
103-
up the specified editor for a given property, clones the template
104-
group, and sets its behavior to the long id of the button.
102+
"template", together with an editor behavior script-only stack.
103+
The property inspector looks up the specified editor for a given
104+
property, clones the template group, and sets its behavior to the
105+
stack script.
105106

106107
The behavior script must at a minimum implement the following three handlers:
107108

@@ -165,3 +166,6 @@ There are also some bespoke editors for particular object properties:
165166
It is our intention that ultimately a widget alone will be able to
166167
function as a property editor, however currently this feature is not
167168
available.
169+
170+
See the [editors folder of the IDE repository](https://github.com/livecode/livecode-ide/tree/develop/Toolset/palettes/inspector/editors)
171+
for more examples of property inspector editors.

0 commit comments

Comments
 (0)