#!/bin/sh
#
########################################################################
#
# Script for using orb in standalone format for macintosh aqua 
#
# Robert Boyko
# Mar 2004 - completely revised
#
########################################################################
#
 
#
# the next line restarts using wish \
exec wish "$0" "$@"

package require Tk
namespace eval alpha {}
tk appname Alphatk

# MacTk seems to have a bug if we exit using exit.
# see http://www.tcl.tk/software/mac/features.html
tk appname orb
rename exit __exit
proc exit {} {
    destroy .
    # force the exit as well.
    __exit
}

##########################################################################

set VERSION		"v2.0"
set NAME		"orb-$VERSION"
set AQUA 		"$NAME.app/Contents/Resources/Scripts"

#
# look for installation directory if not set 
#
if [ catch {set PROG_HOME [exec printenv ORB_HOME]} err] {
	set path "/Applications/$AQUA"
	if ![ catch {set MY_HOME [exec printenv HOME]} err] {
		set path "$MY_HOME/$AQUA $path"
		set path "$MY_HOME/Applications/$AQUA $path"
		set path "$MY_HOME/Desktop/$AQUA $path"
	}

	# look for the software
	set PROG_HOME 0
	foreach loc $path {
		if [file isdirectory $loc] {
			set PROG_HOME $loc
			break
		}
	}

	# didn't find it
	if { $PROG_HOME == 0 } {
		error "Cannot find $NAME. Please place in Applications or on the desktop."
	}
}

# add main tcl modules
source $PROG_HOME/tcl/orb.tcl
source $PROG_HOME/tcl/xalign.tcl

#
# decide where working directory is
#
if [ catch {set WORKSPACE [exec printenv HOME]} err] {
	set (WORKSPACE) "/tmp"
}

# disable default tcl window when wish is invoked 
wm title . "orb"
wm withdraw .

# start up my window instead, write files to the current workspace
orb_main $PROG_HOME $WORKSPACE
destroy .