pro xwrite_hist_event, event
;
;
;
common xwrite_hist_blk2, result, result0, sea_str
;
qdebug = 1
if (qdebug) then print, event_name(event)
widget_control,event.top,get_uvalue=all
;
case (strtrim(event_name(event),2)) of
   ;----------------- Button Events ------------------------
   "BUTTON":begin                               ; option selection
      case strupcase(get_wvalue(event.id)) of
	 ;------ Main buttons
         "QUIT": begin
		widget_control, event.top,/destroy
	    endcase
         "RECORD TO HISTORY": begin
		widget_control, all.id_info, get_value=info
		file_append, all.backup_file, ['----------------- '+!stime+' ------------------------', info]
		;
		if (all.qwrite_hist) then begin
		    task_pn = concat_dir(getenv('MDI_TASK_DIR'), 'egse_cmd')
		    for i=0,n_elements(info)-1 do begin
		        cmd = [task_pn, 'log', info(i)]
		        print, cmd
		        spawn, cmd, result, /noshell
		    end
		    widget_control, all.id_cmd,  set_value=result
		end else begin
		    widget_control, all.id_cmd,  set_value='Write to .HIS Disabled.  Temp file only. ' + !stime
		end
	    endcase
	 "CLEAR": begin
		widget_control, all.id_info, set_value=''
		widget_control, all.id_cmd,  set_value=''
	    endcase
          else: message,/info,"UNKNOWN BUTTON:   " + strupcase(get_wvalue(event.id))
       endcase
   endcase 
   ;----------------- Text Events ------------------------
   "TEXT_CH": begin
	  case event.id of
	    all.id_info: begin
			end
	    all.id_cmd: begin
			end
	  endcase
	end

   ;----------------- List Events ------------------------
   "LIST": begin
	case event.id of
	    00: begin
	       end
	endcase
   endcase
endcase

widget_control,event.top, set_uvalue=all, bad_id=destroyed	;update structure holding all of the info

return
end

;-------------------------------------------------------------
pro xwrite_hist, sttim, entim, mnem, infil=infil, every=every, eof=eof, all_opt=all_opt, nohist=nohist
;
;+
;NAME:
;	xwrite_hist
;PURPOSE:
;	To accept user inputs to be logged to the EGSE history file
;SAMPLE CALLING SEQUENCE:
;	xwrite_hist
;HISTORY:
;	Created 15-Sep-95 by M.Morrison
;	 2-Dec-95 (MDM) - had a time stamp also placed in the ASCII temp file
;	 2-Dec-95 (MDM) - Added a /NOHIST option to disable the writting to the
;			  history file.
;-

common xwrite_hist_blk2, result, result0, sea_str

sea_str = strarr(5)
result = ''
result0 = ''
;
font = get_xfont(closest=13,/only_one)
if (getenv('MDI_DEF_FONT') ne "") then font = getenv('MDI_DEF_FONT')
widget_control, default_font=font
device, font=font

base0=widget_base(/column,title='X WRITE_HIST', xoff=0, yoff=0)
xmenu, ['QUIT', 'Record to History', 'Clear'], $
	base0, $
	buttons=main_buts, /row

;-------------------------

base_group3=widget_base(base0, /row, /frame)
base3_col1 = widget_base(base_group3, /column, /frame)
lab_base3_col1 = widget_label(base3_col1, value = 'Inputs')
id_info = widget_text(base3_col1, xsize=100, ysize=20, /scroll, /edit)
widget_control, id_info, /append


;-------------------

base_group2 = widget_base(base0, /row, /frame)
base2_col1 = widget_base(base_group2, /column, /frame)
lab_base2_col1 = widget_label(base2_col1, value = 'Messages from Last Logging')
id_cmd = widget_text(base2_col1, xsize=100, ysize=1, value='')

;--------------------------

backup_file = concat_dir(getenv('MDI_TEMP_DIR'), 'xwrite_hist.' + ex2fid(anytim2ex(!stime)))
all = {base:base0, $
	id_info: id_info, $
	id_cmd:  id_cmd, $
	backup_file: backup_file, $
	qwrite_hist: 1-keyword_set(nohist), $
	junk:0}

widget_control,set_uvalue=all, base0
widget_control,base0,/realize
widget_control,set_uvalue=all, base0
xmanager, 'xwrite_hist', base0

return
end
