3 Replies Latest reply on Sep 25, 2011 5:13 PM by areohbee

    User color choice not saved in export preset?

    Mario Zimmermann

      I'm currently writing my first plugin and still in a learning curve.

       

      My export plugin has a color_well control to choose a color. I have defined a default value of LrColor(1,1,1) which works well.

      However, the chosen color is not saved so every time the export dialog is used, it comes up with the default color value and the previously chosen color is lost.

       

      What am I doing wrong?

       

      Thanks,

      Mario

       

      Code snippet:

       

      myPlugin.exportPresetFields = {

          { key = 'borderColor', default = LrColor(1,1,1) },

       

          ...more keys

      }

       

       

      function myPlugin.sectionForFilterInDialog( viewFactory, propertyTable )

          return {

              viewFactory:row {

                  viewFactory:color_well {

                      value = LrView.bind('borderColor'),

                  }

              },

          }

      end

        • 1. Re: User color choice not saved in export preset?
          areohbee Level 5

          I don't see anything wrong, but its entirely possible that the color object is not being serialized / de-serialized the way you want.

           

          Try saving the r,g, & b components individually.

           

          Maybe somebody else knows how to define a metamethod or something so it's saved and restored properly...?

           

          PS - Once upon a time I tried saving tables in preferences (which is essentially what the export preset fields are), but I had serious performance problems, and ultimately unrecoverable corruption of the preferences for my plugin (I don't think table saving is reliable - maybe it doesn't handle meta-table items properly or referential "loops"...?), so I stopped. Now, I use pseudo table save methods (storing each member individually, with index as part of key...).

          1 person found this helpful
          • 2. Re: User color choice not saved in export preset?
            Mario Zimmermann Level 1

            Many thanks for the reply and sorry for the delay. It took me DAYS to figure out how to save the r,g & b components.

            Finally, I succeeded with this method:

             

            myPlugin.exportPresetFields = {

                { key = 'color_r', default = 1 },

                { key = 'color_g', default = 1 },

                { key = 'color_b', default = 1 },

            }

             

            function myPlugin.sectionForFilterInDialog( viewFactory, propertyTable )

                return {

                    viewFactory:row {

                        viewFactory:color_well {

                            value = LrView.bind({

                                 key = 'borderColor',

                                 transform = function ( value, fromTable )

                                      if fromTable then

                                          return LrColor(propertyTable.color_r, propertyTable.color_g, propertyTable.color_b)

                                      else

                                          propertyTable.color_r = value:red()

                                          propertyTable.color_g = value:green()

                                          propertyTable.color_b = value:blue()

                                          return LrBinding.kUnsupportedDirection

                                      end

                                 end

                            })

                        },

                    },

                }

            end

            • 3. Re: User color choice not saved in export preset?
              areohbee Level 5

              Congrats Mario - looks like a good "work-around".

              (the binding/transform functions are tricky business - I'd like to see some enhancement to the documentation for this subject).

              -R