#!/bin/bash

# This example requires bash.

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

treWidth=320; treHeight=200

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

funcinputCreate() {
	local -a stockids=("gtk-connect" "gtk-copy" "gtk-cut" "gtk-delete" "gtk-directory"
		"gtk-disconnect" "gtk-edit" "gtk-execute" "gtk-file" "gtk-find")
	local -a iconnames=("abiword" "geany" "gimp" "gnumeric" "inkscape" "midori"
		"scribus" "top" "viewnior" "xarchive")

	for f in 0 1 2 3 4 5 6 7 8 9; do
		if [ $1 = 1 ]; then
			echo -n "${stockids[$f]}|"
		elif [ $1 = 2 ]; then
			echo -n "${iconnames[$f]}|"
		fi
		echo "$RANDOM|$RANDOM|$RANDOM|$RANDOM"
	done
}; export -f funcinputCreate

functreCreate() {
	echo '<label>Column 0|Column 1|Column 2|Column 3</label>
			<variable>'$1'</variable>
			<width>'$treWidth'</width>
			<height>'$treHeight'</height>
			<action>echo "'$1'=$'$1' action for default signal triggered"</action>
			<action signal="row-activated">echo "'$1'=$'$1' row-activated signal detected"</action>
			<action signal="cursor-changed">echo "'$1'=$'$1' cursor-changed signal detected"</action>
		</tree>
		<hbox homogeneous="true">
			'"`funcbtnCreate $1 Disable gtk-no Disabling`"'
			'"`funcbtnCreate $1 Enable gtk-yes Enabling`"'
			'"`funcbtnCreate $1 Clear gtk-clear Clearing`"'
			'"`funcbtnCreate $1 Removeselected gtk-delete Deleting`"'
			'"`funcbtnCreate $1 Refresh gtk-refresh Refreshing`"'
		</hbox>'
}

export MAIN_DIALOG='
<window title="Tree Input Advanced" resizable="false">
	<vbox>
		<hbox>
			<vbox>
				<text justify="2">
					<label>"'"<input> (text only)
selection-mode='0' (none)

exported-column='0' (default)"'"</label>
				</text>
				<tree selection-mode="0">
					<input>bash -c "funcinputCreate 0"</input>
					'"`functreCreate tre0`"'
			</vbox>
			<vseparator></vseparator>
			<vbox>
				<text justify="2">
					<label>"'"<input stock-column='0'> (text and stock icons)
selection-mode='1' (single - default)
headers-visible='false'
exported-column='1'"'"</label>
				</text>
				<tree exported-column="1" headers-visible="false">
					<input stock-column="0">bash -c "funcinputCreate 1"</input>
					'"`functreCreate tre1`"'
			</vbox>
		</hbox>
		<hseparator></hseparator>
		<hbox>
			<vbox>
				<text justify="2">
					<label>"'"<input icon-column='0'> (text and theme icons)
selection-mode='2' (browse)
headers-clickable='false'
exported-column='2'"'"</label>
				</text>
				<tree selection-mode="2" exported-column="2" headers-clickable="false">
					<input icon-column="0">bash -c "funcinputCreate 2"</input>
					'"`functreCreate tre2`"'
			</vbox>
			<vseparator></vseparator>
			<vbox>
				<text justify="2">
					<label>"'"<input> (default theme icon)
selection-mode='3' (multiple)
rules-hint='true'
exported-column='3'"'"</label>
				</text>
				<tree icon-name="geany" selection-mode="3" exported-column="3" rules-hint="true">
					<input>bash -c "funcinputCreate 0"</input>
					'"`functreCreate tre3`"'
			</vbox>
		</hbox>
		<hseparator></hseparator>
		<hbox homogeneous="true">
			<button ok></button>
		</hbox>
	</vbox>
</window>
'

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