#!/bin/sh

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

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

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

funcentCreate() {
	echo '<variable>entEntry'$1'</variable>
			<action>echo "entEntry'$1' action for default signal triggered"</action>
			<action signal="changed">echo "entEntry'$1' changed to $entEntry'$1'"</action>
			<action signal="activate">echo "entEntry'$1' Enter key-press detected"</action>
			<action signal="primary-icon-press">echo "entEntry'$1' primary icon press detected"</action>
			<action signal="primary-icon-release">echo "entEntry'$1' primary icon release detected"</action>
			<action signal="secondary-icon-press">echo "entEntry'$1' secondary icon press detected"</action>
			<action signal="secondary-icon-release">echo "entEntry'$1' secondary icon release detected"</action>
		</entry>'
	if [ $2 = 1 ]; then echo '<vseparator></vseparator>'; fi
	if [ $3 = 1 ]; then echo '</hbox><hseparator></hseparator><hbox>'; fi
}

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

MAIN_DIALOG='
<window title="Entry Advanced" width-request="700" resizable="false">
	<vbox>
		<frame entry widget>
			<vbox>
				<hbox>
					<entry activates-default="true">
						<default>activates-default</default>
						'"`funcentCreate 0 0 0`"'
					<button can-default="true" has-default="true" tooltip-text="can-default, has-default">
						<label>Default</label>
						<variable>btnDefault</variable>
						<action>echo "btnDefault action for default signal triggered"</action>
					</button>
				</hbox>
				<hseparator></hseparator>
				<hbox>
					<entry editable="false">
						<default>editable</default>
						'"`funcentCreate 1 1 0`"'
					<entry has-frame="false">
						<default>has-frame</default>
						'"`funcentCreate 2 0 1`"'
					<entry max-length="16">
						<default>max-length</default>
						'"`funcentCreate 3 1 0`"'
					<entry primary-icon-name="gnumeric">
						<default>primary-icon-name</default>
						'"`funcentCreate 4 0 1`"'
					<entry primary-icon-stock="gtk-about" primary-icon-activatable="false">
						<default>primary-icon-stock, primary-icon-activatable</default>
						'"`funcentCreate 5 1 0`"'
					<entry primary-icon-stock="gtk-select-font"
						primary-icon-tooltip-markup="<span fgcolor='"'darkred'"'><b>primary-icon</b></span>-<i>tooltip</i>-<u>markup</u>">
						<default>primary-icon-stock, primary-icon-tooltip-markup</default>
						'"`funcentCreate 6 0 1`"'
					<entry primary-icon-stock="gtk-help" primary-icon-tooltip-text="primary-icon-tooltip-text">
						<default>primary-icon-stock, primary-icon-tooltip-text</default>
						'"`funcentCreate 7 1 0`"'
					<entry progress-fraction="0.25">
						<default>progress-fraction</default>
						'"`funcentCreate 8 0 1`"'
					<entry secondary-icon-name="gnumeric">
						<default>secondary-icon-name</default>
						'"`funcentCreate 9 1 0`"'
					<entry secondary-icon-stock="gtk-about" secondary-icon-activatable="false">
						<default>secondary-icon-stock, secondary-icon-activatable</default>
						'"`funcentCreate 10 0 1`"'
					<entry secondary-icon-stock="gtk-select-font"
						secondary-icon-tooltip-markup="<span fgcolor='"'darkblue'"'><b>secondary-icon</b></span>-<i>tooltip</i>-<u>markup</u>">
						<default>secondary-icon-stock, secondary-icon-tooltip-markup</default>
						'"`funcentCreate 11 1 0`"'
					<entry secondary-icon-stock="gtk-help" secondary-icon-tooltip-text="secondary-icon-tooltip-text">
						<default>secondary-icon-stock, secondary-icon-tooltip-text</default>
						'"`funcentCreate 12 0 1`"'
					<entry truncate-multiline="true">
						<default>truncate-multiline</default>
						'"`funcentCreate 13 1 0`"'
					<entry text="text (similar to <default> except that GTK sets it after widget realization which emits a signal)">
						'"`funcentCreate 14 0 1`"'
					<entry width-chars="30">
						<default>width-chars</default>
						'"`funcentCreate 15 1 0`"'
					<entry visibility="false" invisible-char="120" tooltip-text="visibility, invisible-char">
						<default>The password is Fidelio</default>
						'"`funcentCreate 16 0 1`"'
					<entry>
						<default>"<width>, <height> (equivalent to width-request and height-request)"</default>
						<height>50</height>
						<width>250</width>
						'"`funcentCreate 17 1 0`"'
					<entry xalign="0.5">
						<default>xalign</default>
						'"`funcentCreate 18 0 0`"'
				</hbox>
				<hseparator></hseparator>
				<entry fs-action="file" block-function-signals="true">
					<input>echo "This came from a shell command, and function signals are blocked"</input>
					<output file>'"$TMPDIR"'/outputfile</output>
					'"`funcentCreate 19 0 0`"'
				<hbox homogeneous="true">
					'"`funcbtnCreate 19 Disable Disabling disable`"'
					'"`funcbtnCreate 19 Enable Enabling enable`"'
					'"`funcbtnCreate 19 Clear Clearing clear`"'
					'"`funcbtnCreate 19 Delete Deleting removeselected`"'
					'"`funcbtnCreate 19 Refresh Reloading refresh`"'
					'"`funcbtnCreate 19 Save Saving save`"'
					'"`funcbtnCreate 19 Fileselect """Inserting into""" fileselect`"'
				</hbox>
				<hseparator></hseparator>
				<entry fs-action="folder">
					<input file>'"$TMPDIR"'/inputfile</input>
					<output file>'"$TMPDIR"'/outputfile</output>
					'"`funcentCreate 20 0 0`"'
				<hbox homogeneous="true">
					'"`funcbtnCreate 20 Disable Disabling disable`"'
					'"`funcbtnCreate 20 Enable Enabling enable`"'
					'"`funcbtnCreate 20 Clear Clearing clear`"'
					'"`funcbtnCreate 20 Delete Deleting removeselected`"'
					'"`funcbtnCreate 20 Refresh Reloading refresh`"'
					'"`funcbtnCreate 20 Save Saving save`"'
					'"`funcbtnCreate 20 Fileselect """Inserting into""" fileselect`"'
				</hbox>
			</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
