Viewing contents of file '../idllib/contrib/tappin/graffer/graff_fname.pro'
;+
; GRAFF_FNAME
; Get a graffer filename
;
; Usage:
; file = graff_fname(topid, ifile, dir)
;
; Return:
; file string The filename (graffer.grf if null)
;
; Arguments:
; topid long input Widget ID of group leader
; ifile string input Initial value of file name in widget
; dir string in/out Directory where the file is to be
; found
; use_timer byte input Whether to use the timer events to
; keep it on top
;
; History:
; Original: 18/8/95; SJT
; Add timer event to push to front if obscured: 23/8/95; SJT
; Add file & dir arguments: Sep 95; SJT
; Add CAPTURE key to text inputs: 6/2/97; SJT
;-
function Gr_fn_event, event
widget_control, event.id, get_uvalue = but
widget_control, event.handler, get_uvalue = fwid
txt = ''
file = ''
dir = ''
iexit = 0
case but of
'DO': begin
widget_control, fwid(0), get_value = file
widget_control, fwid(1), get_value = dir
if (file eq '') then file = 'graffer.grf'
case !Version.os of
'vms': separator = ']'
'windows': separator = '\'
'Win32': separator = '\'
'MacOS': separator = "\"
Else: separator = '/' ; Unixen
endcase
if (rstrpos(dir, separator) ne strlen(dir)-1) then $
dir = dir+separator
iexit = 1
if (gr_file_exist(dir+file)) then $
if (not gr_overwrt(event.top, default = 0)) then iexit = 0
end
'DONT': begin
iexit = -1
end
'FILE': grf_focus_enter, fwid(1)
'DIR': grf_focus_enter, fwid(0)
'POP': begin
widget_control, event.top, /show
widget_control, event.id, timer = 2.
end
endcase
rv = {id:event.id, top:event.top, handler:event.handler, $
Exited:iexit, value:[file, dir]}
return, rv
end
function Graff_fname, topid, ifile, dir, use_timer
if (n_elements(dir) eq 0) then dir = ''
widget_control, topid, sensitive = 0
tlb = widget_base(title = 'Graffer file', group_leader = topid, $
resource = 'Graffer')
base = widget_base(/column, tlb)
jb = widget_base(base, /column)
fwid = graff_enter(jb, value = ifile, xsize = 30, label = $
'File:', /capture, uvalue = 'FILE')
dwid = graff_enter(jb, value = dir, xsize = 30, label = $
'Directory:', /capture, uvalue = 'DIR')
jb = widget_base(base, /row, uvalue = 'POP')
junk = widget_button(jb, value = ' Do it ', uvalue = 'DO')
junk = widget_button(jb, value = ' Cancel ', uvalue = 'DONT')
;junk = cw_bgroup(base, ['Done', 'Cancel'], /row, uvalue = 'ACTION', $
; button_uvalue = [1, -1])
; RYO widget management to allow us to get the values back from
; the event handler without using a common block, even after the
; hierarchy has been destroyed.
widget_control, tlb, /real
widget_control, base, event_func = 'gr_fn_event', $
set_uvalue = [fwid, dwid]
if (use_timer) then widget_control, jb, timer = 2.
Try_again:
repeat begin
ev = widget_event(tlb)
endrep until (ev.exited ne 0)
if (ev.exited eq -1) then file = '' $
else begin
file = ev.value(0)
dir = ev.value(1)
endelse
widget_control, ev.top, /destroy
widget_control, topid, /sensitive
return, file
end