8 Replies Latest reply on Jan 25, 2017 12:17 AM by kimaldis

    setActiveSources not updating in side panel

    kimaldis Level 1

      catalog:setActiveSources() when called from a plugin changes the source but doesn't update the selection correctly in the list in the left hand panel. For example, I have a collection, say, "Clients" selected. I use setActiveSources() to change to, say, "Portraits". Although the source has changed and the change is reflected in the Image Display Area, the Filmsrip and the toolbar, "Clients" collection remains highlighted in the collections panel.

       

      Any idea why and how to update highlighting to the correct source?

       

      thanks.

        • 1. Re: setActiveSources not updating in side panel
          johnrellis Most Valuable Participant

          This was an outstanding bug in the user interface for many years. It could happen when clicking in the source column of Library, and it could happen when a plugin invoked catalog:setActiveSources().   After a couple of attempts, Adobe seems to have fixed it for most people in 2015.8 / 6.8: Lightroom : Selected Published Folder or Collection is not deselected if a folder is selected | Photoshop Family Custome…

           

          Verify you have 2015.8 / 6.8 by doing Help > System Info (the LR updater often fools people into thinking they have the "latest").

          • 2. Re: setActiveSources not updating in side panel
            kimaldis Level 1

            Lightroom version: CC 2015.8 [ 1099473 ] Is what I see. nothing about 6.8. I'm a subscriber so I'm using the Creative Cloud updater and this has nothing to update. OS X 10.12.2

            • 3. Re: setActiveSources not updating in side panel
              johnrellis Most Valuable Participant

              So you have the "latest" version.   Looks like the bug wasn't completely fixed.  (It no longers happen for me, either when using LR directly or via my Any Source plugin.)   I suggest posting details to the bug report above (version number, steps to make the bug happen, Windows or Mac, etc.). 

               

              In this case, however, unless you can provide exact steps for reproducing the bug that Adobe can replicate, I think it is unlikely they will take any action (based on past experience).  It was only when I was able to provide them with a catalog and exact steps did they address the problem.

              • 4. Re: setActiveSources not updating in side panel
                kimaldis Level 1

                the call is nested in pcalls, asynctasks and callwithcontexts, which might have something to do with it. I'll spend an hour or so on it, see if I can't narrow it down a bit further or figure a work around. I'll post if I do.

                 

                thanks for you time, John.

                • 5. Re: setActiveSources not updating in side panel
                  johnrellis Most Valuable Participant

                  For what it might be worth, here is the function my Any Source plugin uses to set the active sources, view filters, and selection. It works around a number of issues, some of which may have been specific to older versions of LR.  You can ignore the lock() and unlock() -- they are there to provide mutual exclusion with another task that accesses global state (it's a myth that LR tasks are non-preemptive -- many SDK API calls can yield to other tasks).

                   

                  --[[----------------------------------------------------------------------------
                  private state
                  setState (state)
                  
                  Sets the active sources, filter, and selection to be "state" (see the
                  description of "queue" above), returning "state".  We have to iterate
                  changing these, because they don't always "take" the first time around (a
                  general problem with many functions in the SDK).
                  ------------------------------------------------------------------------------]]
                  
                  function setState (state)
                      lock ()
                  
                      local function setValues (label, set, compare)
                          local newState
                          local n, MaxIterations = 1, 100
                          while n <= MaxIterations do
                              set (state)
                              newState = getState ()
                              if compare (state, newState) then break end
                              LrTasks.sleep (0)
                              n = n + 1
                              end
                          if n > MaxIterations then
                              Debug.lognpp ("setState failed", state, newState)
                              end
                          end
                  
                      setValues ("sources",
                          function (s) catalog:setActiveSources (s.sources) end,
                          function (s1, s2)
                              return deepEqual (s1.sources, s2.sources) end)
                      setValues ("filter",
                          function (s) catalog:setViewFilter (s.filter) end,
                          function (s1, s2) return deepEqual (s1.filter, s2.filter) end)
                  
                      if state.selectedPhoto ~= nil then
                          setValues ("selectedPhotos",
                              function (s)
                                  catalog:setSelectedPhotos (s.selectedPhoto, s.selectedPhotos)
                                  end,
                              function (s1, s2)
                                  return s1.selectedPhoto == s2.selectedPhoto and
                                      deepEqual (s1.selectedPhotos, s2.selectedPhotos)
                                  end)
                          end
                              --[[ Bug in LR 4 and 5 SDK -- can't clear the current
                              selection.  catalog:setSelectedPhotos (nil, {}) results in
                              "assertion failed!". ]]
                             
                      unlock ()
                      return state
                      end   
                  
                  • 6. Re: setActiveSources not updating in side panel
                    johnrellis Most Valuable Participant

                    Two other things to try:

                     

                    1. When setting the current sources, first set it to All Photographs, do LrTasks.sleep (0) (a magic form of yield that sometimes fixed my issues by seemingly giving the rest of LR a chance to run), then set it to the desired state. The bug referenced above seemed to occur when switch the selection from a collection to a folder or vice versa.

                     

                    2. Make sure that if you're invoking catalog:setActiveSources() as the result of a callback from an LrView control, you wrap the call in an async task.  Here's another code fragment from my plugin describing why:

                     

                    --[[----------------------------------------------------------------------------
                    void 
                    selectionChanged (SearchableItems si, array of source sources)
                    
                    Invoked whenever the user types into the edit field of the SearchableItems.
                    Changes the active sources to the ones currently matching the user input.
                    ------------------------------------------------------------------------------]]
                    
                    function selectionChanged (si, sources)
                        if sources and #sources > 0 then 
                            LrTasks.startAsyncTask (showErrors (function ()
                                LrTasks.pcall (function () catalog:setActiveSources (sources) end)
                                end))
                                --[[ Without an async task, we get the error message "Yielding is
                                not allowed within a C or metamethod call" when setting a
                                collection as the source, but not a folder.  The pcall()
                                protects against "assertion failed" that can result from
                                "sources" containing invalid poison folders from inconsistent
                                catalogs created by buggy LR, probably in migration from
                                Windows to Mac.]]
                            end
                        end
                    
                    • 7. Re: setActiveSources not updating in side panel
                      kimaldis Level 1

                      Thanks again, John. I'll post back in a couple of days when I've had a chance to check these out. Much appreciated.

                      • 8. Re: setActiveSources not updating in side panel
                        kimaldis Level 1

                        It seems to be working now; good and bad in more or less equal parts because not a great deal has changed, meaning it hasn't really gone away.

                         

                        That said, I think it may have to do with unfound images in collections I'm switching to and from. I have a whole older chunk of the catalogue that sits on another disk and I found that when I started testing using collections without any of the older images in it all started to behave. So I attached the drive and it all started working again. And it continued to work even after I removed the drive. Maybe it was some kind of caching issue, or not.

                         

                        When it was failing it seemed to be exclusively related to the library and develop modules. If I switched to Map or Print the active source became shown correctly selected in the panel but reverted to incorrectly selected when I switched back to either dev or library.

                         

                        That's all I have for now, I'm afraid. More if it happens.