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

[[ Bug 22113 ]] Fixes for custom property editor in PI #2069

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
script "com.livecode.pi.customprops.behavior"
local sPropSet, sHilitePath
local sLastHilite

on editorInitialize
put empty into sPropSet
set the pathDelimiter of widget "array" of me to numToCodepoint(11)
put the editorLabel of me into field "rowlabel" of me
set the rowShowLabel of me to false
set the label of button "customPropertySet" of group "Set buttons" of me to "customKeys"
Expand Down Expand Up @@ -66,10 +68,14 @@ on editorUpdate
else
local tKey
fetchArrayDataOnPath tPath, tValue[sPropSet], tKey
set the itemDelimiter to the pathDelimiter of widget "array" of me
if the result is empty then
put tKey into field "value" of me
put item -1 of tPath into field "key" of me
select the text of field "key" of me
if the text of field "value" of me is not tKey or \
the text of field "key" of me is not item -1 of tPath then
put tKey into field "value" of me
put item -1 of tPath into field "key" of me
select the text of field "key" of me
end if
else
put empty into field "key" of me
put empty into field "value" of me
Expand Down Expand Up @@ -154,6 +160,7 @@ end editorResize

on setPropSet pArray
local tValue
set the arrayData of widget "array" of me to pArray
put the editorValue of me into tValue
put pArray into tValue[sPropSet]
set the editorValue of me to tValue
Expand All @@ -162,8 +169,12 @@ end setPropSet

on setArrayDataOnPath pValue, pPath, @xArray
local tKey
set the itemDelimiter to the pathDelimiter of widget "array" of me
put item 1 of pPath into tKey
if the number of items in pPath is 1 then
if tKey is not among the keys of xArray then
exit setArrayDataOnPath
end if
put pValue into xArray[tKey]
else
delete item 1 of pPath
Expand All @@ -173,11 +184,15 @@ end setArrayDataOnPath

on setArrayKeyOnPath pKey, pPath, @xArray
local tKey
set the itemDelimiter to the pathDelimiter of widget "array" of me
put item 1 of pPath into tKey
if the number of items in pPath is 1 then
if tKey is not among the keys of xArray then
exit setArrayKeyOnPath
end if
local tSubArray
put xArray[item 1 of pPath] into tSubArray
delete variable xArray[item 1 of pPath]
put xArray[tKey] into tSubArray
delete variable xArray[tKey]
put tSubArray into xArray[pKey]
else
delete item 1 of pPath
Expand All @@ -187,6 +202,7 @@ end setArrayKeyOnPath

on deleteArrayKeyOnPath pPath, @xArray
local tKey
set the itemDelimiter to the pathDelimiter of widget "array" of me
put item 1 of pPath into tKey
if the number of items in pPath is 1 then
delete variable xArray[item 1 of pPath]
Expand All @@ -198,6 +214,7 @@ end deleteArrayKeyOnPath

on addArrayKeyOnPath pPath, @xArray
local tKey
set the itemDelimiter to the pathDelimiter of widget "array" of me
put item 1 of pPath into tKey
if the number of items in pPath is 1 then
put "" into xArray[item 1 of pPath]
Expand All @@ -209,6 +226,7 @@ end addArrayKeyOnPath

on fetchArrayDataOnPath pPath, pArray, @rData
local tKey
set the itemDelimiter to the pathDelimiter of widget "array" of me
put item 1 of pPath into tKey
if the number of items in pPath is 1 then
if tKey is not among the keys of pArray then
Expand All @@ -225,7 +243,9 @@ end fetchArrayDataOnPath

on dataChanged
checkRehilite
setPropSet the arrayData of widget 1 of me
if not the result then
setPropSet the arrayData of widget 1 of me
end if
end dataChanged

on valueChanged
Expand All @@ -237,7 +257,7 @@ end valueChanged
private command valueChangedOnPath pPath
if pPath is empty then
# Don't update anthing
exit valueChangedOnPath
return false
end if
local tArray
put the arrayData of widget 1 of me into tArray
Expand All @@ -259,6 +279,8 @@ private command valueChangedOnPath pPath
end if
setArrayDataOnPath field "value" of me, pPath, tArray
setPropSet tArray

return true
end valueChangedOnPath

on keyChanged
Expand All @@ -267,17 +289,17 @@ on keyChanged
keyChangedOnPath tPath
end keyChanged

local sLastHilite
private command keyChangedOnPath pPath
set the itemDelimiter to the pathDelimiter of widget "array" of me
if pPath is empty then
# Don't update anthing
exit keyChangedOnPath
return false
end if

local tNewKey
put field "key" of me into tNewKey
if tNewKey is item -1 of pPath then
exit keyChangedOnPath
return false
end if

local tArray
Expand All @@ -300,7 +322,10 @@ private command keyChangedOnPath pPath

put tNewKey into item -1 of pPath
put pPath into sHilitePath
put pPath into sLastHilite
unlock screen

return true
end keyChangedOnPath

on propSetRenamed pFrom, pTo
Expand Down Expand Up @@ -378,8 +403,11 @@ end hiliteChanged

on checkRehilite
# Check to see if the key or value has changed
local tDidUpdate
keyChangedOnPath sLastHilite
put the result into tDidUpdate
valueChangedOnPath sLastHilite
put the result or tDidUpdate into tDidUpdate

# Store the existing hilited path
put the hilitedElement of widget "array" of me into sLastHilite
Expand All @@ -391,6 +419,8 @@ on checkRehilite

set the disabled of field "value" of me to sLastHilite is empty
set the disabled of field "key" of me to sLastHilite is empty

return tDidUpdate
end checkRehilite

function arrayKeysAreNumeric pArrayA
Expand Down
1 change: 1 addition & 0 deletions notes/bugfix-22113.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Fix behavior of custom property inspector when editing a key or adding a new element