;+
; Project     : SOHO - CDS     
;                   
; Name        : QLDS_STORE_CURRENT
;               
; Purpose     : Store any QLDS in the cache on it's storage handle.
;               
; Explanation : The CDS QuickLook memory management system is designed to
;               minimize the time spent by display routines fetching their
;               data. This is done by having a common block (QLSAVE) that
;               functions as a cache memory, storing the most recently used
;               QuckLook Data Structure. Other QLDS'es are stored on handles.
;               
;               If there is a QLDS stored in the cache and if it is not
;               already been saved, we make sure that there is a storage
;               handle for it, and stores the QLDS there.
;               
; Use         : QLDS_STORE_CURRENT
;    
; Inputs      : None.
;               
; Opt. Inputs : None.
;               
; Outputs     : None.
;               
; Opt. Outputs: None.
;               
; Keywords    : None.
;
; Calls       : datatype()
;
; Common      : QLSAVE: See QLDS_CHECKIN
;
;               QLMGR: See QLMGR
;               
; Restrictions: None.
;               
; Side effects: None.
;               
; Category    : QuickLook, Management
;               
; Prev. Hist. : None.
;
; Written     : Stein Vidar Hagfors Haugan, ItA/UiO, 11-June-1994
;               
; Modified    : SVHH, 2-March-1995, Removed CDSNOTIFY calls
;               Version 2, SVHH, 15 July 1997
;                       Using handles instead of widget bases for storage
;                       (immune against xkill and /all that..).
;
; Version     : 2, 15 July 1997
;-            


PRO qlds_store_current
  common QLSAVE,QLDS,saved
  common QLMGR,QL_ID,QL_DATA
  
  IF N_elements(saved) eq 0 THEN BEGIN
     saved = 0
     return
  EndIF
  
;  IF !DEBUG ne 0 THEN $
;       cdsnotify,'QLDS_STORE_CURRENT:'+DATATYPE(QLDS)+' '+trim(saved)
  
  IF DATATYPE(QLDS) eq 'STC' and NOT saved THEN BEGIN ; It's there, all right
     store_h = QL_DATA(QLDS.QL_NO).storage_h
     IF handle_info(store_h,/valid_id) eq 0 THEN BEGIN
        store_h = handle_create()
        QL_DATA(QLDS.QL_NO).storage_h=store_h
        QL_DATA(QLDS.QL_NO).stored=0
     EndIF
;      IF !DEBUG ne 0 THEN cdsnotify,'Storing current!'
     QL_DATA(QLDS.QL_NO).stored=1
     handle_value,store_h,QLDS,/set,/NO_COPY
  EndIF
  saved = 1
END
