; $Id: define_vmPDFReader.pro,v 1.3 2005/09/29 20:14:47 azuah Exp $
;###############################################################################
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used of if the code in this file is
;  included in another product.
;
;###############################################################################
;
;************************************************************************************************
function define_vmPDFReader,tlb=tlb
;************************************************************************************************
;
compile_opt strictarr
;
;
PDFReader=''
file=sourceroot()+"pdfreader.txt"
if (file_test(file)) then begin
	openr,unit,file,/get_lun
	readf,unit,PDFReader
	free_lun,unit
endif
;
if (PDFReader ne '' and PDFReader ne ' ') then begin
	message=["Your pdf reader is already defined as follows:",'',PDFReader,'',$
			"Do you wish to redefine your pdf reader?"]
	if (n_elements(tlb) gt 0) then begin
		res=dialog_message(message,/question,/default_no,dialog_parent=tlb)
	endif else begin
		res=dialog_message(message,/error,/default_no)
	endelse
	if (res eq "Yes") then PDFReader='' else return,2
endif
;
;
; UNIX platforms only - if the PDF reader is not specified attempt to locate one.
if (strlowcase(!version.os_family) eq "unix") then begin
	readers = ['acroread','kghostview','xpdf']   ; programs to search for
	ind = 0
	while ((PDFReader eq '' or PDFReader eq ' ') and ind lt 3) do begin
		cmd = 'which '+readers[ind]
		spawn, cmd,result   ; problems in IDL5.4 if attempt to assign PDFReader to 'spawn'
		PDFReader=result[0] ; result directly - result is an array after first attempt.
		ind = ind + 1
	endwhile
endif
;
; All platforms - if the PDF reader is not specified launch a dialog that asks to set it.
if (PDFReader eq '' or PDFReader eq ' ') then begin
	ptext="Please specify your PDF reader"
;	path="C:\Program Files\Adobe"
        path = getenv('HOMEDRIVE')+"\Program Files\Adobe"
	if (n_elements(tlb) gt 0) then begin
		PDFReader = dialog_pickfile(dialog_parent=tlb,/read,title=ptext,path=path)
	endif else begin
		PDFReader = dialog_pickfile(/read,title=ptext,path=path)
	endelse
endif
;
; If the pdfReader was picked then save it.
if (PDFReader ne '' and PDFReader ne ' ') then begin
	file=sourceroot()+"pdfreader.txt"
	openw,unit,file,/get_lun
	printf,unit,PDFReader
	free_lun,unit
endif else begin
	return,-1
endelse
;
end


