#!/bin/sh

GTKDIALOG=gtkdialog

export TMPDIR=/tmp/gtkdialog/examples/"$(basename $0)"
mkdir -p "$TMPDIR"

funcbtnCreate() {
	echo '<button>
			<label>"'"$2"'"</label>
			<action>echo "'"$3"' cboComboBox'$1'"</action>
			<action type="'"$4"'">cboComboBox'$1'</action>
		</button>'
}

funccboCreate() {
	if [ $1 = 0 ]; then
		echo '<combobox>'
	elif [ $1 = 1 ]; then
		echo '<combobox allow-empty="false" value-in-list="true">'
	elif [ $1 = 2 ]; then
		echo '<combobox case-sensitive="true" value-in-list="true">'
	fi
	echo '<variable>cboComboBox'$1'</variable>
			<sensitive>enabled</sensitive>
			<item>cboComboBox'$1'</item>'
	if [ $1 = 0 ]; then
		echo '<item>tag attributes none</item>'
	elif [ $1 = 1 ]; then
		echo '<item>tag attribute allow-empty="false"</item>
			<item>tag attribute value-in-list="true"</item>'
	elif [ $1 = 2 ]; then
		echo '<item>tag attribute case-sensitive="true"</item>
			<item>tag attribute value-in-list="true"</item>'
	fi
	echo '</combobox>
		<hbox homogeneous="true">
			'"$(funcbtnCreate $1 Clear Clearing clear)"'
			'"$(funcbtnCreate $1 Refresh Reloading refresh)"'
		</hbox>'
	if [ $1 -lt 2 ]; then echo '<hseparator></hseparator>'; fi
}

funccboTextCreate() {
	if [ $1 = 0 ]; then
		echo '<comboboxtext fs-action="file">'
	elif [ $1 = 1 ]; then
		echo '<comboboxtext fs-action="file" active="4" button-sensitivity="1">'
	elif [ $1 = 2 ]; then
		echo '<comboboxtext fs-action="file" focus-on-click="false">'
	fi
	echo '<variable>cboComboBoxText'$1'</variable>
			<sensitive>enabled</sensitive>
			<item>cboComboBoxText'$1'</item>
			<item>tag attribute fs-action="file"</item>'
	if [ $1 = 1 ]; then
		echo '<item>tag attribute active="4"</item>
			<item>tag attribute button-sensitivity="1"</item>'
	elif [ $1 = 2 ]; then
		echo '<item>tag attribute focus-on-click="false"</item>'
	fi
	if [ $1 -gt 0 ]; then
		echo '<item>This is the default directive text but the active index will override it if declared</item>
			<default>This is the default directive text but the active index will override it if declared</default>'
	fi
	echo '<input>echo "This came from a shell command"</input>
			<input file>'"$TMPDIR"'/inputfile</input>
			<output file>'"$TMPDIR"'/outputfile</output>
			<action signal="changed">echo "cboComboBoxText'$1' changed to $cboComboBoxText'$1'"</action>
			<action>echo "cboComboBoxText'$1' action for default signal triggered"</action>
			<action type="command">echo "cboComboBoxText'$1' action type for default signal triggered"</action>
		</comboboxtext>
		<hbox homogeneous="true">
			'"$(funcbtnCreate Text$1 Clear Clearing clear)"'
			'"$(funcbtnCreate Text$1 Delete Deleting removeselected)"'
			'"$(funcbtnCreate Text$1 Refresh Reloading refresh)"'
			'"$(funcbtnCreate Text$1 Save Saving save)"'
		</hbox>
		<hbox homogeneous="true">
			'"$(funcbtnCreate Text$1 Disable Disabling disable)"'
			'"$(funcbtnCreate Text$1 Enable Enabling enable)"'
			'"$(funcbtnCreate Text$1 Fileselect """Inserting into""" fileselect)"'
		</hbox>'
	if [ $1 -lt 2 ]; then echo '<hseparator></hseparator>'; fi
}

if [ ! -f "$TMPDIR"/inputfile ]; then
	echo "This came from an input file" > "$TMPDIR"/inputfile
fi

export MAIN_DIALOG='
<window title="ComboBoxText Advanced" resizable="false">
	<vbox>
		<hbox>
			<frame combobox widget (deprecated)>
				<vbox>
					'"$(funccboCreate 0)"'
					'"$(funccboCreate 1)"'
					'"$(funccboCreate 2)"'
				</vbox>
			</frame>
			<frame comboboxtext widget>
				<vbox width-request="300">
					'"$(funccboTextCreate 0)"'
					'"$(funccboTextCreate 1)"'
					'"$(funccboTextCreate 2)"'
				</vbox>
			</frame>
		</hbox>
		<hbox homogeneous="true">
			<button ok></button>
		</hbox>
	</vbox>
	<action signal="hide">exit:Exit</action> 
</window>
'

$GTKDIALOG --program=MAIN_DIALOG

