Adobe 65007312 Programming Guide - Page 96

Simple bindings, For some other common types of binding, you can use an

Page 96 highlights

CHAPTER 5: Creating a User Interface for Your Plug-in Binding UI values to data values 96 You can then use the shortcut to specify dynamic property values: ... viewFactory:static_text { title = bind 'mySetting', ... The required argument of LrView.bind() is the key name; by default, this is in the table that is already bound to the UI element; that is, the value of bind_to_object in the same UI element. This is inherited in the view hierarchy, but can be overridden at any level. You can override the bound table for a specific binding by passing the LrView.bind() function a table containing both the key and the table it comes from: visible = LrView.bind { key = "mySetting", bind_to_object = "myTable" } This allows you to bind different properties in one view object to keys in different tables. The bound table is typically the export-settings table, since your UI is typically a way for your user to see and set these values. The SDK makes this default case easy for sections that you define for the Export dialog. In views created with sectionsForTopOfDialog and sectionsForBottomOfDialog, the value of bind_to_object for the entire view hierarchy is set automatically to the export-settings table passed along with the view factory. See "Adding custom sections to the Plug-in Manager" on page 32. Simple bindings The simplest binding is between a property in the LrView object and a settings key of the same datatype, and simply keeps the two synchronized. For example: visible = LrView.bind( "LR_export_useSubfolder" ) In this case, both the local property (visible) and the bound table item (a Lightroom-defined export setting) have Boolean values. Setting the use-subfolder preference to true (in the Export dialog, for instance) makes the control visible. For some other common types of binding, you can use an LrBinding function as the value assignment; for example: visible = LrBinding.negativeOfKey( "LR_export_useSubfolder" ) This binds the property to the opposite of the table value; that is, setting the use-subfolder preference to true hides the control. The binding works in both directions; that is, hiding the control would also set LR_export_useSubfolder to true. This function can be used to negate numeric as well as Boolean values; for example, a value of 2 would become -2. Although negativeOfKey() works both ways, and with numeric values, the other LrBinding functions can be used only with Boolean values, and work only in one direction; a change in the bound table sets the bound property value, but not the reverse. The LrBinding functions allow you to: X Set a Boolean property to the opposite of a Boolean key value, or a numeric property to the negation of a numeric key value (LrBinding.negativeOfKey). X Set a Boolean property when a key value is or is not present (LrBinding.keyIsNil, keyIsNotNil). X Set a Boolean property when a key value is or is not equal to a specific value (LrBinding.keyEquals, keyIsNot).

  • 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
96
You can then use the shortcut to specify dynamic property values:
...
viewFactory:static_text {
title = bind 'mySetting'
,
...
The required argument of
LrView.bind()
is the key name; by default, this is in the table that is already
bound to the UI element; that is, the value of
bind_to_object
in the same UI element. This is inherited in
the view hierarchy, but can be overridden at any level.
You can override the bound table for a specific binding by passing the
LrView.bind()
function a table
containing both the key and the table it comes from:
visible = LrView.bind { key = "mySetting", bind_to_object = "myTable" }
This allows you to bind different properties in one view object to keys in different tables.
The bound table is typically the export-settings table, since your UI is typically a way for your user to see
and set these values. The SDK makes this default case easy for sections that you define for the Export
dialog. In views created with
sectionsForTopOfDialog
and
sectionsForBottomOfDialog
, the value of
bind_to_object
for the entire view hierarchy is set automatically to the export-settings table passed
along with the view factory. See
“Adding custom sections to the Plug-in Manager” on page 32
.
Simple bindings
The simplest binding is between a property in the
LrView
object and a settings key of the same datatype,
and simply keeps the two synchronized. For example:
visible = LrView.bind( "LR_export_useSubfolder" )
In this case, both the local property (
visible
) and the bound table item (a Lightroom-defined export
setting) have Boolean values. Setting the use-subfolder preference to true (in the Export dialog, for
instance) makes the control visible.
For some other common types of binding, you can use an
LrBinding
function as the value assignment; for
example:
visible = LrBinding.negativeOfKey( "LR_export_useSubfolder" )
This binds the property to the opposite of the table value; that is, setting the use-subfolder preference to
true hides the control. The binding works in both directions; that is, hiding the control would also set
LR_export_useSubfolder
to true. This function can be used to negate numeric as well as Boolean values;
for example, a value of 2 would become -2.
Although
negativeOfKey()
works both ways, and with numeric values, the other
LrBinding
functions
can be used only with Boolean values, and work only in one direction; a change in the bound table sets the
bound property value, but not the reverse. The
LrBinding
functions allow you to:
X
Set a Boolean property to the opposite of a Boolean key value, or a numeric property to the negation
of a numeric key value (
LrBinding.negativeOfKey
).
X
Set a Boolean property when a key value is or is not present (
LrBinding.keyIsNil
,
keyIsNotNil
).
X
Set a Boolean property when a key value is or is not equal to a specific value (
LrBinding.keyEquals
,
keyIsNot
).