Adobe 65007312 Programming Guide - Page 100

Binding pop-up menu selections, shows up immediately as the value of the pop-up control.

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"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204

C
HAPTER
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",
value = 1 },
{ title = "Second item",
value = 2 },
{ title = "Third item",
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
.)
E
XAMPLE
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.
E
XAMPLE
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"