#!/bin/sh

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

TMPDIR=/tmp/gtkdialog/examples/"`basename $0`"
mkdir -p "$TMPDIR"

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

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 function="command">echo "cboComboBoxText'$1' action function 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

MAIN_DIALOG='
<window title="ComboBoxText Advanced" resizable="false">
	<vbox>
		<frame comboboxtext widget>
			<vbox width-request="300">
				'"`funccboTextCreate 0`"'
				'"`funccboTextCreate 1`"'
				'"`funccboTextCreate 2`"'
			</vbox>
		</frame>
		<hbox homogeneous="true">
			<button ok></button>
		</hbox>
	</vbox>
</window>
'
export MAIN_DIALOG

case $1 in
	-d | --dump) echo "$MAIN_DIALOG" ;;
	*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
