#!/bin/sh
#This is a script for Velocity by Kyle Davis
#NOTE:  we use echo -en for things that go to Velocity to avoid a blank line in our context menus

version="1.1"
name="Word/Line Count"
authors="Kyle Davis"
about="Counts words or lines in a text file."
mimetypes="text/"
dependancies="gdialog,wc"
needterm=""
multiplefiles=""
localonly="Yes"

case $1 in
	--get-info)
		echo -en "$version\n$name\n$authors\n$about\n$mimetypes\n$dependancies\n$needterm\n$multiplefiles\n$localonly"
		;;
	--execute)
		shift;windowx=$1
		shift;windowy=$1
		shift;windowwidth=$1
		shift;windowheight=$1
		shift;location=$1
		#start deps
		shift;dgdialog=$1
		shift;dwc=$1
		#end deps
		shift;file=$1
		shift;mimetype=$1

		#To avoid GTK+ warnings in gdialog's return data
		export LC_ALL="POSIX"
		gd2versions="`echo -en 'Gnome gdialog 2.2.\nGnome gdialog 2.1.'`";
		gdialog2=`$dgdialog --version 2>&1 | grep -F "$gd2versions"`;
		if [ ! "$gdialog2" ]; then
			t=`$dgdialog --title "$name" --radiolist "Count what:  Words or Lines?" 300 200 2 "Word Count" "" "1" "Line Count" "" "0" 2>&1 | tail -n 1`;
		else
			t=`$dgdialog --title "$name" --menu "Count what:  Words or Lines?" 300 200 3 "None" "" "Word Count" "" "Line Count" "" 2>&1 | tail -n 1`;
		fi
		c="exit";
		cd "$location"
		if [ "$t" = "Word Count" ]; then
			c=`$dwc -w "$file"`;
		fi
		if [ "$t" = "Line Count" ]; then
			c=`$dwc -l "$file"`;
		fi
		cd -
		if [ "$c" != "exit" ]; then
			$dgdialog --title "$name" --msgbox "$t: $c" $windowx $windowy
		fi
		;;
	*)
		echo "This should only be used by Velocity."
		;;
esac
