Adobe 65007312 Programming Guide - Page 100
Binding pop-up menu selections, shows up immediately as the value of the pop-up control.
UPC - 883919154398
View all Adobe 65007312 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 100 highlights
CHAPTER 5: Creating a User Interface for Your Plug-in Binding UI values to data values 100 Binding pop-up menu selections The pop-up menu and the menu component of a combo box allow you to specify a set of choices, using an items table; each item entry is a table containing a title and value. The title is localizable display text, that appears in the menu (see Chapter 7, "Using ZStrings for Localization"). items = { { title = "First item", { title = "Second item", { title = "Third item", value = 1 }, value = 2 }, value = 3 }, }, The value of the item that the user selects from the menu becomes the control's value. For the pop-up menu, the title becomes the control's title, and is displayed in the control when the menu is not shown. (For the combo box, the displayed text is the value, or the result of the value_to_string function; see "Edit-field view properties" on page 92.) EXAMPLE 3: This code fragment adds a pop-up menu to the previous example, with the currently selected value from the menu similarly bound to a static text value: f:group_box { title = "Popup Menu", fill_horizontal = 1, spacing = f:control_spacing(), f:popup_menu { value = bind 'my_value', -- current value bound to same key as static text items = { -- the menu items and their values { title = "Value 1", value = 'value_1' }, { title = "Value 2", value = 'value_2' }, { title = "Value 3", value = 'value_3' }, } }, f:static_text { fill_horizontal = 1, title = bind 'my_value', -- bound to same key as current selection }, }, } You can bind the items property to a settings key to create a dynamic menu. However, you can only set the whole menu at once; you cannot bind individual item values. EXAMPLE 4: This code binds the currently selected value from a pop-up menu to the same key as an editable text value. The user can change this value by entering any text in the edit field; the entered text shows up immediately as the value of the pop-up control. However, since the user can enter any text, that text might not match the menu items. This code shows how to use the pop-up control's value_equal function to do a case-insensitive comparison of the user-entered value with the item values. The function is called for each item until it returns true, or has gone through all the items. X If the entered text matches one of the item values (that is, the function returns true), the matching item becomes the selected item in the pop-up menu, and the item's title text is displayed in the pop-up control. X If the function goes through all the items without finding a match, the pop-up control shows no selection; that is, it appears blank, and the next time the user pops up the menu, none of the items is in the selected state. The entered value remains in the pop-up control's value property. local LrDialogs = import "LrDialogs"