5 Replies Latest reply on May 20, 2015 10:45 PM by WDBerlin

    LrView: Binding to multiple keys in both directions

    WDBerlin

      Dear all,

       

      I want to bind a view (popup) to more then one key in Binding table. It is no problem to do from table to view. It's clear to me, how operation = function( binder, values, fromTable ) works. But not the other way round. How can I retrieve the new value of the view in this function? Is it in "values" with a special key? As this table is not standard, I don't find a way to debug it. If I could: how to set the values in the binding table? Via the special table "values" or have I to return a table of key/value pairs?

       

      Kind regrads,

       

      Wolfgang

        • 1. Re: LrView: Binding to multiple keys in both directions
          johnrellis Most Valuable Participant

          I've wondered that myself.  The SDK guide doesn't give an example of going the other way, e.g. when "fromTable" is false.  But perhaps you could also use a "transform" function to get the from the pop-up -- see page 106 of the SDK Guide.

          • 2. Re: LrView: Binding to multiple keys in both directions
            WDBerlin Level 1

            Hi,

            obviously nobody has an idea and I tried everything without success. Is there a chance to get an answer from Adobe?

            • 3. Re: LrView: Binding to multiple keys in both directions
              johnrellis Most Valuable Participant
              Is there a chance to get an answer from Adobe?

              It's not very likely, unfortunately.  Adobe hasn't actively participated in this forum for a number of years.

              • 4. Re: LrView: Binding to multiple keys in both directions
                johnrellis Most Valuable Participant
                But perhaps you could also use a "transform" function to get the from the pop-up -- see page 106 of the SDK Guide.

                I just wrote a sample following the hints in the SDK guide, and the transform() function passed to LrView.bind() does indeed report the new value of the control.  For example:

                 

                local LrBinding = import 'LrBinding'
                local LrDialogs = import 'LrDialogs'
                local LrFunctionContext = import 'LrFunctionContext'
                local LrView = import 'LrView'
                
                local bind = LrView.bind
                local f = LrView.osFactory()
                
                LrFunctionContext.postAsyncTaskWithContext ("showDialog", function (context)
                    local prop = LrBinding.makePropertyTable (context)
                    prop.checkbox = false
                    local controls = f:column {bind_to_object = prop,
                        spacing = f:control_spacing (),
                        f:checkbox {title = "Change popup", value = bind ("checkbox")},
                        f:popup_menu {
                            items = {{title = "a", value = "a"}, {title = "b", value = "b"}},
                            value = bind {keys = {"checkbox"},
                                operation = function (binder, values, fromTable)
                                    if fromTable then return values.checkbox and "b" or "a"
                                        end
                                    return LrBinding.kUnsupportedDirection
                                    end,
                                transform = function (value, fromModel)
                                    if fromModel then
                                        prop.sTrue = value
                                    else
                                        prop.sFalse = value
                                        end
                                    return value
                                    end}},
                        f:row {f:static_text {title = "popup fromModel = true:"},
                            f:static_text {title = bind ("sTrue")}},
                        f:row {f:static_text {title = "popup fromModel = false:"},
                            f:static_text {title = bind ("sFalse")}}}
                    local result = LrDialogs.presentModalDialog {title = "simple_list test",
                        contents = controls}
                    end)
                
                • 5. Re: LrView: Binding to multiple keys in both directions
                  WDBerlin Level 1

                  Oh, that works - with a slight difference: I use transform for "toTable" and operation for "fromTable" direction like this:

                   

                  factory:checkbox

                  {

                      title = "TEST",

                      value = LrView.bind

                          {keys = {"clearMarks", "whichMark"},

                              operation =

                              function(binding, values, fromTable)

                                  if fromTable then

                                      return (values.clearMarks and (values.whichMark ~= 3))      --show "checked" only when value == checked AND whichMark (set by another popup) ≠ 3

                                  end

                                  return LrBinding.kUnsupportedDirection

                              end,    --end function

                              transform =

                              function(value, fromTable)

                                  if not fromTable then

                                      dialBinding.clearMarks = value   --allows to set "checked" in binding-table when checkbox is enabled

                                      return LrBinding.kUnsupportedDirection   -- value is not used any longer

                                  else

                                      return value  -- the value given by operation. It also works with "return value" for both directions but i think it's clearer this way

                                  end

                              end,

                          },

                      enabled = LrView.bind

                          {key="whichMark",

                              transform =

                              function(val, fromTable)

                                  if fromTable then

                                      return val~=3

                                  end

                                  return LrBinding.kUnsupportedDirection

                              end,    --end function

                          },

                      checked_value = true,

                      unchecked_value = false,

                  },