/*
	datasignature

*!  VERSION 2.0.1  16apr2007

*/

VERSION 10.0

INCLUDE _std_medium
DEFINE _dlght 300
INCLUDE header
HELP hlp1, view("help datasignature")
RESET res1

DIALOG main, label("datasignature - Determine whether data have changed") ///
	tabtitle("Main")
BEGIN
  GROUPBOX gb_mode	_lft	_top	_iwd	_ht8,		///
	label("Action")
  RADIO   rb_display	_ilft	_ss	_ibwd	.,		///
	first 							///
	label("Display datasignature")				///
	onclickon(script sel_set)
  RADIO   rb_confirm	@	_ss	@	.,		///
	label("Confirm that datasignatures match")		///
	onclickon(script sel_confirm) option(confirm)
  RADIO   rb_report	@	_ss	@	.,		///
	label("Show full report comparing datasignatures")	///
	onclickon(script sel_report) option(report)
  RADIO   rb_clear	@	_ss	@	.,		///
	last							///
	label("Clear datasignature")				///
	onclickon(script sel_clear) option(clear)


// controls for -datasignature- and -datasignature set-
  CHECKBOX ck_set	_lft	_xls	_iwd	.,		///
	option(set)						///
	onclickon(program set_on)				///
	onclickoff(script set_off)				///
	label("Store the signature as a characteristic in the dataset")
DEFINE holdy @y
  CHECKBOX ck_reset	@	_ms	@	.,		///
	option(reset)						///
	label("Replace existing signature with the current one")
  CHECKBOX ck_save	@	_ls	@	_ht6h,		///
	groupbox						///
	onclickon(script main_save_on)				///
	onclickoff(script main_save_off)			///
	label("Save a copy of the signature to a file")
  TEXT tx_save		_indent	_ss	_ibwd	.,		///
	label("Filename:")
  FILE fi_save		@	_ss	@	.,		///
	label("Browse...")					///
	option(saving)						///
	filter("Stata Datasignature (*.dtasig)|*.dtasig|All (*.*)|*.*") ///
	defext(dtasig)						///
	save							///
	error("Filename")
  CHECKBOX ck_replace	@	_ms	@	.,		///
	option(replace)						///
	label("Overwrite file if it already exists")

// controls for -datasignature confirm-
  CHECKBOX ck_strict	_lft	holdy	_iwd	.,		///
	option(strict)						///
	label("Strict variable matching")

// controls for -datasignature confirm- and -datasignature report-
  GROUPBOX gb_using	_lft	_ms	@	_ht7,		///
	label("")
  RADIO rb_default	_ilft	_ss	_ibwd	.,		///
	first							///
	option(NONE)						///
	onclickon(main.fi_using.disable)			///
	label("Compare with previously set datasignature")
  RADIO rb_using	@	_ms	@	.,		///
	last							///
	option(NONE)						///
	onclickon(main.fi_using.enable)				///
	label("Compare with datasignature stored in dataset")
  FILE fi_using		_indent2 _ss	_inwd	.,		///
	label("Browse...")					///
	filter("Stata Datasignature (*.dtasig)|*.dtasig|All (*.*)|*.*") ///
	defext(dtasig)						///
	error("Filename of Stata dataset")
END


SCRIPT main_hide_all
BEGIN
	main.ck_set.hide
	main.ck_reset.hide
	main.ck_save.hide
	main.tx_save.hide
	main.fi_save.hide
	main.ck_replace.hide
	main.ck_strict.hide
	main.gb_using.hide
	main.rb_default.hide
	main.rb_using.hide
	main.fi_using.hide
END

SCRIPT sel_set
BEGIN
	script main_hide_all
	main.ck_set.show
	main.ck_reset.show
	main.ck_save.show
	main.tx_save.show
	main.fi_save.show
	main.ck_replace.show
END

SCRIPT sel_confirm
BEGIN
	script main_hide_all
	main.ck_strict.show
	main.gb_using.show
	main.rb_default.show
	main.rb_using.show
	main.fi_using.show
	main.gb_using.setposition . 155
	main.rb_default.setposition . 175
	main.rb_using.setposition . 195
	main.fi_using.setposition . 215
	
END

SCRIPT sel_report
BEGIN
	script main_hide_all
	main.gb_using.show
	main.rb_default.show
	main.rb_using.show
	main.fi_using.show
	main.gb_using.setposition . 135
	main.rb_default.setposition . 155
	main.rb_using.setposition . 175
	main.fi_using.setposition . 195
END

SCRIPT sel_clear
BEGIN
	script main_hide_all
END

PROGRAM set_on
BEGIN
	call main.ck_reset.enable
	call main.ck_save.enable
	if main.ck_save {
		call main.tx_save.enable
		call main.fi_save.enable
		call main.ck_replace.enable
	}
END

SCRIPT set_off
BEGIN
	main.ck_reset.disable
	main.ck_save.disable
	main.tx_save.disable
	main.fi_save.disable
	main.ck_replace.disable
END

SCRIPT main_save_on
BEGIN
	main.tx_save.enable
	main.fi_save.enable
	main.ck_replace.enable
END

SCRIPT main_save_off
BEGIN
	main.tx_save.disable
	main.fi_save.disable
	main.ck_replace.disable
END

PROGRAM saving_output
BEGIN
	put `"""' main.fi_save `"""'
	beginoptions
		option main.ck_replace
	endoptions
END

PROGRAM command
BEGIN
	put "datasignature "
	option main.rb_confirm
	option main.rb_report
	option main.rb_clear
	option main.ck_set
	if main.rb_using & main.rb_using.isvisible() {
		require main.fi_using
		put " using "
		put `"""' main.fi_using `"""'
	}
	beginoptions
		if main.ck_save & main.ck_save.isvisible() {
			require main.fi_save
			put "saving("
			put /program saving_output
			put ") "
		}
		option main.ck_reset
		option main.ck_strict
	endoptions
END
