Adding A Data Observer; Set Up The Dialog And Table - Adobe 65007312 - Photoshop Lightroom Programmer's Manual

Mac
Hide thumbs Also See for 65007312 - Photoshop Lightroom:
Table of Contents

Advertisement

C
9: Getting Started: A Tutorial Example
HAPTER

Adding a data observer

The most flexible way of connecting to your data is to create an observer for the property table; this is an
independent object that is notified of changes in the table, and can take any action in response to the
change, including setting UI values in any way you want.
This example demonstrates how to set up an observer that is notified when a data value changes, and how
to define a function that responds to that notification by setting UI values.

Set up the dialog and table

1. Edit the
function MyHWLibraryItem.showCustomDialogWithObserver()
-- body of function
end
2. Within this function, make the function-context call you need for the property table:
LrFunctionContext.callWithContext( "showCustomDialogWithObserver",
end )
3. In this context, create the observable table, and add a property named
initial value:
4. Obtain a view factory and use it to create a static text field, which initially displays the static value of
the property. (We will put it into the view hierarchy later.)
local f = LrView.osFactory() -- obtain the view factory object
local showValue_st = f:static_text { -- create the label control
The
title
in the data table,
current value. So far, if the property value changes, it will not change the text in the control.
5. Create an edit box (which we will also add to the view hierarchy later). Notice that this box updates its
value
local updateField = f:edit_field { -- create an edit box
value = "Enter some text", -- initial text, not bound to data
immediate = true -- update value with every keystroke
}
LibraryMenuItem.lua
-- body of function
-- body of function
local props = LrBinding.makePropertyTable( context )
props.myObservedString = "This is a string" -- new prop with initial value
title = props.myObservedString,-- set text to the static property value
text_color = LrColor( 1, 0, 0 ) -- set color to a new color object
}
, which is the displayed text, is assigned to be the current value of the property we defined
props.myObservedString
with every keystroke:
file to create a new function,
function( context )
. This is not a dynamic binding, just an assignment to the
Adding a data observer 180
showCustomDialogWithObserver()
myObservedString
:
, with an

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Photoshop lightroom sdk 3.0

Table of Contents