Lightroom SDK: ability to bind to leaf nodes in tree-structured preference objects, and observe changes.

  • 1
  • Idea
  • Updated 5 years ago
I've been experimenting with tree-structure preferences - a very useful feature that I have avoided ever since I corrupted my preferences when I used said feature back in Lr2.

It seems as long as one does the right thing(s), it's entirely possible to (reliably) save a table of prefs, however there seems to be no way to observe changes to the leaf nodes of such a table when edited via user/UI-view.

Also, I've been able to get the editing to work via special transform function in a custom binding, but not using any simple built-in binding object / key...

Example code:

local function chgTest( call )
local props = LrBinding.makePropertyTable( call.context )
local function ch( id, props, name, value )
Debug.pause( name, value )
end
props.myprop = { ['myin'] = "t", ['myin2'] = "t2" }
--view:setObserver( props, 'myin', ExtendedManager, ch ) -- looking for wrong thing
--view:setObserver( props, 'myin2', ExtendedManager, ch ) -- ditto
view:setObserver( props, 'myprop', ExtendedManager, ch ) -- only sees changes to table proper, not leaf nodes.
local vi = {}
vi[#vi + 1] = vf:row {
vf:edit_field {
value=LrView.bind {
bind_to_object = {}, -- props, -- doesn't matter
key = 1, -- heckL anything non-nil, except boolean, works here.
transform=function( value, toUi )
if toUi then
return props['myprop']['myin']
else
props['myprop']['myin'] = value -- unobservable
props['myprop'] = props['myprop'] -- observed as generic table change
end
end,
}
},
vf:edit_field {
value=LrView.bind {
bind_to_object = {}, -- props, -- doesn't matter
key = 1, -- heckL anything non-nil, except boolean, works here.
transform=function( value, toUi )
if toUi then
return props['myprop']['myin2']
else
props['myprop']['myin2'] = value
end
end,
}
}
}
local b = app:show{ info="pic",
viewItems = vi,
}
Debug.pauseIf( b ~= 'cancel', props['myprop']['myin'], props['myprop']['myin2'] )
end

- editing works, change handler doesn't (no changes are observable, without forcing a change to the table value itself (e.g. props['myprop'] = props['myprop']), but then one can't tell which leaf property changed.

Rob
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes

Posted 6 years ago

  • 1
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
Perhaps a simple solution is to support keys in array format, e.g.

key = { "myprop", "myin" }