Adobe 65007312 Programming Guide - Page 101
Binding combo box selections, automatically reflected in the combo box
UPC - 883919154398
View all Adobe 65007312 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 101 highlights
CHAPTER 5: Creating a User Interface for Your Plug-in Binding UI values to data values 101 local LrFunctionContext = import "LrFunctionContext" local LrStringUtils = import "LrStringUtils" local LrView = import "LrView" LrFunctionContext.callWithContext( 'bindingExample', function( context ) local f = LrView.osFactory() local properties = LrBinding.makePropertyTable( context ) properties.format = "jpeg" local contents = f:column { spacing = f:control_spacing(), bind_to_object = properties, f:popup_menu { items = { { title = "JPEG", value = "jpeg" }, { title = "TIFF", value = "tiff" }, }, value = LrView.bind 'format', value_equal = function( value1, value2 ) return LrStringUtils.lower( value1 ) == LrStringUtils.lower( value2 ) end, }, f:edit_field { immediate = true, value = LrView.bind 'format', }, } local result = LrDialogs.presentModalDialog( { title = "Dialog Example", contents = contents, } ) end ) Binding combo box selections For a combo box, the user can enter text in the edit-field portion, which becomes the new control value. If you select an item from the menu portion, that item value becomes the control value; this provides an input shortcut for the user. Unlike the pop-up menu, the combo box menu items are simple values; if you need to localize them, you must do so when building the item array. This example shows how to create a dynamic menu for a combo box that gives previously-entered values as menu choices. This code: X Binds the value and items of the combo box to data properties storeValue and storeItems. X Creates an observer for the storeValue property, so that a change in that property (caused by entering a new value in the combo box) calls a function. Z The observer function checks to see if the current value is already in the items list (stored in storeItems), and if it is not, adds it to the list. Z Because of the binding, any change the function makes to the storeItems property is automatically reflected in the combo box items. local LrBinding = import "LrBinding" local LrDialogs = import "LrDialogs" local LrFunctionContext = import "LrFunctionContext" local LrStringUtils = import "LrStringUtils"