; $Id: db_get_new_name.pro,v 1.7 2005/02/08 17:01:16 azuah Exp $
;###############################################################################
;
; NAME:
;   DB_GET_NEW_NAME
;
; PURPOSE:
;   A small utility widget program used for modifying the name/label
;   of an tree item in the Data Browser's data/visualization tree
;   widgets.
;
; CATEGORY:
;   Data Browser
;
; AUTHOR:
;   Robert M. Dimeo, Ph.D.
;   NIST Center for Neutron Research
;   100 Bureau Drive
;   Gaithersburg, MD 20899
;   Phone: (301) 975-8135
;   E-mail: robert.dimeo@nist.gov
;   http://www.ncnr.nist.gov/staff/dimeo
;   Feb, 2003
;
; 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 or if the code in this file is
;  included in another product.
;
;###############################################################################



;===============================================================================
; DB_GNN_Event
;
; PURPOSE:
;   Main event handler for app.
;
; PARAMETERS:
;   event [in] - the event structure to be handled
;
pro DB_GNN_Event,event
widget_control,event.top,get_uvalue = pState
field_id = widget_info(event.top,find_by_uname = 'NAME_FIELD')
uname = widget_info(event.id,/uname)
case uname of
'NAME_FIELD':	$
	begin
		widget_control,field_id,get_value = value
		(*pState).new_name = value[0]
	end
'ACCEPT':	$
	begin
		widget_control,field_id,get_value = value
		(*pState).new_name = value[0]
                widget_control,event.top,/destroy
	end
'CANCEL':	$
	begin
		(*pState).cancel = 1
                widget_control,event.top,/destroy
	end
else:
endcase

end
;-------------------------------------------------------------------------------



;===============================================================================
; DB_Get_New_Name
;
; PURPOSE:
;   Entry point and dialog builder for application.
;
; PARAMETERS:
;   name [in] - the current value of the item to be modified.
;
; KEYWORDS:
;   group_leader [in] - the ID of the parent widget from which this
;                       dialog was launched.
;
; RETURN VALUE:
;   A structure containing the following two fields
;   NAME: new value for item name
;   CANCEL: 0 if false, 1 if true(ie cancel button used)
;
function db_get_new_name,GROUP_LEADER =group_leader,name
new_name = name

if (n_elements(group_leader) eq 0) then begin
    group_leader = 0L
    modal = 0
    tlb = widget_base(tlb_frame_attr=1,title='New Label',/col)
endif else begin
    modal = 1
    tlb = widget_base(group_leader=group_leader,tlb_frame_attr=1,modal=modal,title='New Label',/col)
endelse

field = cw_field(tlb,value = name,uname = 'NAME_FIELD',title = 'NAME',/return_events)
row_base = widget_base(tlb,/row,/align_center)
acptTip = 'Save changes and exit'
cancTip = 'Discard changes and exit'
void = widget_button(row_base,value='Accept',uname='ACCEPT',tooltip=acptTip)
void = widget_button(row_base,value='Cancel',uname='CANCEL',tooltip=cancTip)

widget_control,tlb,/realize
state = { name:name, cancel:0, new_name:name }
pState = ptr_new(state)
widget_control,tlb,set_uvalue = pState
xmanager,'db_gnn',tlb,no_block=modal,event_handler = 'db_gnn_event'
new_name = (*pState).new_name
cancel = (*pState).cancel
ptr_free,pState
return,{name:new_name,cancel:cancel}
end
