8 Replies Latest reply on Jul 8, 2009 3:47 AM by Gene McCullagh

    Making data persistent

    Gene McCullagh Most Valuable Participant (Moderator)

      I suspect the answer to this is staring me in the face but I just don't seem to be able to see it.

       

      If I provide a field in the Plugin Manager for a user to enter info, such as a serial number, how do I make that data persistent? That is, user enters the info and (1) I replace the field with some indication that the info has been entered (2) never ask the user for the info again.

       

      Thanks!

        • 1. Re: Making data persistent
          john beardsworth Adobe Community Professional & MVP

          Gene

           

          You do this via LrPrefs. So set up a variable in the top section:

           

                local prefs = import 'LrPrefs'.prefsForPlugin()

           

          Now we've something to play with. This records a value into the preference:

           

               prefs.MyVariable = "whatever"

           

          To recall it next time, and guard against it not being there, check it's there

           

               if prefs.MyVariable then

               staticTextBox.title = prefs.MyVariable
               else
               staticTextBox.title = ' '
               end

           

          Without this process      staticTextBox.title = prefs.MyVariable would fail if the preference didn't exist.

           

          It's worth opening up the LR prefs file to have a look at what's happening

           

          John

          • 2. Re: Making data persistent
            Gene McCullagh Most Valuable Participant (Moderator)

            Thanks John! That's excellent. I looked at preferences but just couldn't noodle it out. Your example cleared the haze!

             

            Do you mean com.adobe.Lightroom2.plist when you say LR Prefs?

            • 3. Re: Making data persistent
              john beardsworth Adobe Community Professional & MVP

              Yes, Gene, so you can see exactly how your info is being stored or remove it and test how the plug-in would perform if your plugin was being installed for the first time. Prefs seems to get written to the plist file immediately, so you can hack it with test values, but remember it is rewritten by LR when you exit. It seems incorruptible....

               

              John

              1 person found this helpful
              • 4. Re: Making data persistent
                Gene McCullagh Most Valuable Participant (Moderator)

                Thanks John! Worked like a charm!

                • 5. Re: Making data persistent
                  DawMatt Level 3

                  johnbeardy wrote:

                   

                  Prefs seems to get written to the plist file immediately, so you can hack it with test values, but remember it is rewritten by LR when you exit. It seems incorruptible....

                  Not on Windows.  Corruptions can and do occur.  On Windows you really need to shutdown LR before making any mods to the preferences file.  If nothing else LR is unlikely to reread the preferences file till the next restart, and it writes the file on output, so any changes you make would be lost anyway.

                   

                  An alternative to deleting the prefs in the file to simulate a fresh install - include a "Reset preferences to defaults" button somewhere that set all your preferences to nil.  I've started doing that in my Plugin Manager info provider.  It really helps when you change the way preferences work in pre-release versions.

                   

                  Matt

                  1 person found this helpful
                  • 6. Re: Making data persistent
                    john beardsworth Adobe Community Professional & MVP

                    Sure, when developing a plug-in one can hack the file in a way that makes it unreadable and I do prefer to close LR, hack, and restart. But when I'm confident of what I'm doing, there's no need.

                     

                    John

                    • 7. Re: Making data persistent
                      DawMatt Level 3

                      OK. Just wanted to remind people that the preferences file needs to be treated with care. Would hate for someone less confident than us to wreck their configuration because they were "following our advice" to directly edit the preferences file while LR was open.

                       

                      Matt

                      • 8. Re: Making data persistent
                        Gene McCullagh Most Valuable Participant (Moderator)

                        I always keep a spare copy I create prior to hacking away!

                         

                        I'd recommend that as a standard practice just in case.