; ;------------------------------------------------------------------ ; function filespec,inspec ; ; Parse file specification inspec for tilde and wildcards: ; print,'new file spec: inspec=',inspec ptilde = strpos(inspec,'~') if ptilde eq 0 then begin ; tilde in first position pwild = strpos(inspec,'*') if pwild ge 0 then begin ; both tilde and wild are in string pslash = strpos(inspec,'/') if pslash eq 1 then begin ; ~/[with *] fspec = strsub(inspec,'~',expand_path('~')) endif else begin ; ~xxxx/[with *] fspec = expand_path(strmid(inspec,0,pslash+1)) + $ strmid(inspec,pslash+1,strlen(inspec)) endelse endif else begin ; ~[without *] fspec = expand_path(inspec) endelse endif else begin ; no tilde in pos 0 (may or may not have *) fspec = inspec endelse return,fspec end ; ;------------------------------------------------------------------ ; function checkfile, flnm,path,nf ; ; Return flnm if it exists, else try to construct a valid file path ; using path+flnm (return full path if successful, otherwise return null) ; 10/18: this does not cover case where selected file is actually a ; dir and that dir contains only 1 file (nf=1) ; ;print,'checkfile: flnm=',flnm,' path=',path files = findfile(flnm,count=nf) if nf ge 1 then return,flnm if nf eq 0 then begin files = findfile(path+flnm,count=nf) if nf ge 1 then return,path+flnm files = findfile(path+'/'+flnm,count=nf) if nf ge 1 then return,path+'/'+flnm endif return,'' end ; ;------------------------------------------------------------------ ; pro finder_event, ev common wfinder, fspec,files,file,defflnm,wfspec,wlist,wextern,openproc,$ hlpfile ; widget_control,ev.id,get_uvalue=uval case uval of "DONE": begin widget_control,/destroy,ev.top ; quit button return end "OPEN": begin if file eq '' then begin print,'>>> No current file selection' return endif ; ; We've got a selected file name -- set external text widget (if it exists), ; and call the procedure input to filefinder function with the selected ; file as the only parameter: ; widget_control,wextern,set_value=file,bad_id=badid call_procedure,openproc,file return end "NCDUMP": begin if file eq '' then begin print,'>>> No current file selection' return endif print,' ' print,'-----------------------------------------------------------' print,'NCDUMP FOR FILE ',file,':' spawn,'ls -l ' + file print,' ' spawn,'ncdump -h ' + file print,'-----------------------------------------------------------' print,' ' print,'NCDUMP DONE.' print,' ' return end "DEFAULT": begin print,'Setting default netcdf file name or directory ',defflnm widget_control,wfspec,set_value=defflnm fspec = filespec(defflnm) files = findfile(fspec,count=nfiles) widget_control,wlist,set_value=files end "HELP": begin print,'help (filefinder)' popup_help,hlpfile,'FILEFINDER' return end "WLIST": begin ; a file has been selected from files list: nf = 0 chfile = checkfile(files(ev.index),fspec,nf) case nf of 0: begin print,'cannot find file ',files(ev.index) return end 1: begin file = chfile print,'Selected file ',file return end else: begin fspec = chfile widget_control,wfspec,set_value=fspec files = findfile(fspec,count=nfiles) widget_control,wlist,set_value=files return end endcase return end "TXT_FSPEC": begin ; ; Receive new file spec. Modify the input string if necessary before ; passing to findfile: ; If input string (value(0)) does not have a tilde, then findfile will ; work without modification (input string may or may not have '*') ; If input string has a tilde '~', then findfile does not work, so: ; (assume if string contains '~' it is in first position) ; a) if string does not have '*', use expand_path to expand the tilde ; b) if string has both '~' and '*' then expand_path does not work, so: ; 1) if ~/xx*xx, then substitute '~' with home (expand_path('~')) ; 2) if ~xxxx/xx*xx, then substitute ~xxxx with expand_path('~xxxx') ; widget_control,ev.id,get_value=value fspec = filespec(value(0)) files = findfile(fspec,count=nfiles) widget_control,wlist,set_value=files if fspec ne '' then begin print,format="('New file specification: ',a,' (nfiles=',i4,')')",$ fspec,nfiles endif else begin ; null fspec means cwd: cd & cd,current=fspec print,format="('New file spec (cwd): ',a,' (nfiles=',i3,')')",$ fspec,nfiles endelse if fspec ne value(0) then widget_control,wfspec,set_value=fspec return end else: print,'filefinder: unknown user value=',uval endcase return end ; ;------------------------------------------------------------------- ; function filefinder,inspec,wext,openpro,helpfile common wfinder, fspec,files,file,defflnm,wfspec,wlist,wextern,openproc,$ hlpfile ; ; On input: ; inspec = initial file spec ; wext= id of text widget of calling procedure which is displaying ; current file selection (when OPEN button is selected here, the ; current file selection is displayed in wext) (not used if < 0) ; openpro = string containing name of procedure to call when OPEN ; button is hit. This pro will be called with a single input ; parameter being the current selected file (file) ; helpfile = path to help text for filefinder ; During execution: ; fspec = file specification (from editable text widget wfspec) ; files = files matching file spec ; (from findfile(fspec) and shown in list widget wlist) ; file = current file selection (selected from list widget wlist) ; On output: ; widget id of base widget is returned (this enables calling procedure ; to destroy it if desired ; fspec = inspec & defflnm = inspec wextern = wext openproc = openpro hlpfile = helpfile files = findfile(fspec,count=nfiles) file = '' ; ; Base window for file finder: ; finderbase = widget_base(title='FILE FINDER',/column) ; ; Editable text widget for file spec: ; base = widget_base(finderbase,/frame,/column) wlab_fspec = widget_label(base,value='File Specification:') wfspec = widget_text(base,/editable,/no_newline,ysize=1,value=fspec,$ uvalue="TXT_FSPEC") ; ; Display files matching file spec in list widget: ; base = widget_base(finderbase,/frame,/column) wlab_list = widget_label(base,value='Names matching file specification:') wlist = widget_list(base,value=files,ysize=20,uvalue="WLIST") ; ; Controls: ; base = widget_base(finderbase,/frame,row=2) open = widget_button(base,value="OPEN",uvalue="OPEN") info = widget_button(base,value="NCDUMP",uvalue="NCDUMP") help = widget_button(base,value="HELP",uvalue="HELP") done = widget_button(base,value="DONE",uvalue="DONE") default = widget_button(base,value="DEFAULT DIR",uvalue="DEFAULT") ; widget_control,finderbase,/realize offxy = offset(wext,finderbase) widget_control,finderbase,tlb_set_xoffset=offxy(0),tlb_set_yoffset=offxy(1) xmanager,'finder',finderbase return,finderbase end