7 Replies Latest reply on Jun 26, 2009 3:04 PM by micahjwalter

    Dynamically Create Dialogs?

    micahjwalter Level 1

      I am trying to figure out a way to dynamically create a dialog box... essentially I would like a dialog with a row for each item in an array...

       

      However, I am kind of stuck with the Lua syntax for doing this.. any ideas?

       

      my skeleton dialog is something like this --  this successfully creates a dialog with one row, but I can't figure out how to loop this so it would build multiple rows based on the number of iterations in the loop...

       

      local f = LrView.osFactory()

       

      local myRow = f:row {

           spacing = f:label_spacing(),

       

           f:edit_field {

                fill_horizonal = 1,

                width_in_chars = 25,

                value = 'test',

           },

       

           f:push_button {

                width = 50,

                title = 'Up',

                enabled = true,

           },

       

           f:push_button {

           width = 50,

           title = 'Down',

           enabled = true,

           },

      }

       

       

       

      -- set up the column ---------------------------------

       

      local contents = f:column {

           spacing = f:control_spacing(),

           fill = 1,

           myRow

      }                                  

       

        • 1. Re: Dynamically Create Dialogs?
          Drarvik Adobe Employee

          You could take an approach like in the following example.

          (I'm including the full source code for a functional, though completely useless, plug-in.)

           

          -- ExportMenuItem.lua:

           

          local LrDialogs = import 'LrDialogs'
          local LrView = import'LrView'
          local LrBinding = import 'LrBinding'
          local LrFunctionContext = import 'LrFunctionContext'

           


          local f = LrView.osFactory()

           

          function showDialog(context)
              local props = LrBinding.makePropertyTable(context)

           

              local content = f:column {
                  f:static_text {
                      title = "how many rows?"
                  },
                 
                  f:edit_field {
                      bind_to_object = props,
                      value = LrView.bind("numRows")
                  }
              }

           

              local result = LrDialogs.presentModalDialog({ contents = content })
             
              if result == 'ok' then
                  LrDialogs.message("Creating " .. tostring(props.numRows) .. " rows...")
                 
                  local count = tonumber(props.numRows)

           

                  local rows = {}
                 
                  for i = 1, count do
                      rows[i] = f:static_text {
                          title = tostring(i)
                      }
                  end
                 
                  local content2 = f:column(rows)
                 
                  LrDialogs.presentModalDialog( { contents = content2 })
              end
          end

           

          LrFunctionContext.callWithContext("theName", showDialog)

           

           

           

           

          -- Info.lua:

           

          return {
             
              LrSdkVersion = 1.3,
              LrSdkMinimumVersion = 1.3, -- minimum SDK version required by this plug-in

           

              LrToolkitIdentifier = 'com.adobe.lightroom.sdk.workaround',
             
              -- Add the menu item to the File menu
              LrExportMenuItems = {
                  title = "dynamic",
                  file = "ExportMenuItem.lua",
              },

           

              VERSION = { major=3, minor=0, revision=0, build=200001, beta=1, display="something" },
          }

          • 2. Re: Dynamically Create Dialogs?
            micahjwalter Level 1

            Thanks for the reply. This seems to work.. sort of... doing it this was displays the correct number of rows, however, they are not spaced very nicely. I am guessing this is due to lack of the spacing = f:control_spacing(), fill = 1, lines that were originally in the f:column. However, I can't figure out where to put those now that I am doing f:column(myRows). What am I missing here?

             

            -m

             

            local f = LrView.osFactory()

             

            local myRows = {}

             

            -- set up a rows -------------------------------------

            for i=0, 6 do

                 myRows[i] = f:row {

                                spacing = f:label_spacing(),

             

                                f:edit_field {

                                fill_horizonal = 1,

                                width_in_chars = 25,

                                value = 'ceremony',

                                },

             

                                f:push_button {

                                width = 50,

                                title = 'Up',

                                enabled = true,

                                },

             

                                f:push_button {

                                width = 50,

                                title = 'Down',

                                enabled = true,

                                },

                           }

            end

             

             

             

            -- set up the column ---------------------------------

             

            local contents = f:column( myRows )

             

             

            -- show the dialog box

            local result = LrDialogs.presentModalDialog(

            {

            title = "Categories",

            contents = contents,

            } )                                                           

            • 3. Re: Dynamically Create Dialogs?
              escouten Adobe Employee

              Where you currently have

              local myRows = {}

              you could instead write:

              local myRows = {
                   spacing = f:control_spacing(),
                   fill = 1,
              }
              
              • 4. Re: Dynamically Create Dialogs?
                micahjwalter Level 1

                Thanks Eric,

                That worked perfectly..

                -m

                • 5. Re: Dynamically Create Dialogs?
                  micahjwalter Level 1

                  Now that I have this working though... I need to bind to the text fields... using bind 'subFolders[i]' doesn't seem to work... currently placing value = subfolders[i] works to fill each field with the string, but if a user edits the string, I need to be able to store that back into subFolders...

                   

                  for i=0, #subFolders do

                       myRows[i] = f:row {

                       spacing = f:label_spacing(),

                   

                           

                       f:edit_field {

                       fill_horizonal = 1,

                       width_in_chars = 25,

                       value = subFolders[i],

                       },

                   

                       f:push_button {

                       width = 50,

                       title = 'Up',

                       enabled = true,

                       },

                   

                       f:push_button {

                       width = 50,

                       title = 'Down',

                       enabled = true,

                       },

                  }

                  end    

                  • 6. Re: Dynamically Create Dialogs?
                    escouten Adobe Employee

                    Eww... known issue that bindings and arrays don't really interact very well.

                     

                    Might have to resort to some ugly hack like flattening the array into the property table (i.e. instead of subfolders[ i ], use propertyTable[ "subfolders_" .. tostring( i ) ] ).

                    • 7. Re: Dynamically Create Dialogs?
                      micahjwalter Level 1

                      Hmm, right now it basically builds the list of text fields as it should, but doesn't display the initial values...

                       

                      I'll try your suggestion... currently I have copied subFolders from the propertyTable

                       

                      local subFolders = propertyTable.subFolders

                       

                      ultimately I just need to be able to display the initial values, let the user edit them, and then save when they hit OK or revert back to initial if they hit cancel

                       

                      -m