#!/bin/zsh -f

autoload -U pashua_run

VERSION='0.0.1'

# May 11, 2007

# configure_zsh_templates_gui

# shell script name  shell script function

version="0.0.1"


###############################################################################
 
#  Created by William Scott on May 11, 2007.
#  Copyright (c) 2007. All rights reserved.


#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
#    USA
#    
#    cf. URL:   http://www.fsf.org/licensing/licenses/gpl.html
#
###############################################################################



# Figure out where we are running this from:

WeAreHere=$(dirname $0)

# Define what the dialog should be like
# Take a look at Pashua's Readme file for more info on the syntax

#############################################################
##########       Interface      #############################
#############################################################

# All of this gets put into a single variable called conf:
conf="
        # Set transparency: 0 is transparent, 1 is opaque
        tx1.transparency=0.95
        
        # Heavy metal overdose:
        # tx.appearance=metal
        
        # Set window title
        tx1.windowtitle = ZSH Customizations
        
        #img.type = image
        #img.path = "$(dirname $WeAreHere)"/Resources/zsh_on_osx.png
        #img.maxheight = 100
        
        ####################
        # Introductory text:
        ####################
        tx1.type=text
        tx1.width = 750
        tx1.text = ZSH Templates Customization Assistant.[return]
        
        
        ###############################################################
        # Ask if vi or emacs keybindings should be used:
        ###############################################################
        # Define radiobuttons
        rb1.type = popup
        rb1.width = 300
        rb1.label = Do you want to use vi or emacs keybindings?
        rb1.option = emacs key bindings - the default
        rb1.option = vi key bindings
        rb1.option = Leave everything the way it is now.
        rb1.default = Leave everything the way it is now.
        
        ###############################################################
        # Ask if User and Host completions should be set up:
        ###############################################################
        #tx2.type=text
        #tx2.width = 1050
        #tx2.text = Completions for commands that use usernames and hostnames can draw from customized lists. A GUI can be used to make this easy.
        
        # Define radiobuttons
        rb2.type = popup
        rb2.width = 300
        rb2.label = Do you want to set up USER and HOST customized completions (for commands that use usernames and hostnames)?
        rb2.option = Yes, customize it.
        rb2.option = No, use the default settings.
        rb2.option = Leave everything the way it is now.
        rb2.default = Leave everything the way it is now.
           

        ###############################################################
        # Ask if Fink is present:
        ###############################################################
        # tx3.type=text
        # tx3.width = 1050
        # tx3.text = The scripts check for a Fink installation on startup, but this is only useful to users of Fink.[return](It also checks silently for MacPorts.)        
        
        
        # Define radiobuttons
        rb3.type = popup
        rb3.width = 300
        rb3.label = Do you have Fink installed?
        rb3.option = Yes - this will warn you if Fink cannot be found 
        rb3.option = No - this turns off warnings about Fink 
        rb3.option = Leave everything the way it is now.
        rb3.default = Leave everything the way it is now.   
        
        
        ###############################################################
        # Ask user if idiosyncratic functions should be loaded:
        ###############################################################
       # tx4.type=text
       # tx4.width = 1050
       # tx4.text = There are some functions in these scripts that I like but may annoy you because they alter (improve) the default behavior of commands.
        
        
        # Define radiobuttons
        rb4.type = popup
        rb4.width = 300
        rb4.label = Load optional functions (these alter some properties of existing unix commands)?
        rb4.option = No - the default 
        rb4.option = Yes - see functions.local file for details 
        rb4.option = Leave everything the way it is now.
        rb4.default = Leave everything the way it is now.   
         
        ###############################################################
        # Ask user if crystallography functions should be loaded:
        ###############################################################
        # tx5.type=text
        # tx5.width = 1050
        # tx5.text = There are some functions that you would only use for crystallography programs.  
 
        # Define radiobuttons
        rb5.type = popup
        rb5.width = 300
        rb5.label = Load the crystallography functions? - useless unless you use crystallography software
        rb5.option = No - default
        rb5.option = Yes
        rb5.option = Leave everything the way it is now.
        rb5.default = Leave everything the way it is now.
        

        ###############################################################
        # Ask if user wants to run the X11 customization GUI:
        ###############################################################
        # tx6.type=text
        # tx6.width = 1050
        # tx6.text = Use this to access some \"hidden\" customization options in X11. 

 
        # Define radiobuttons
        rb6.type = popup
        rb6.width = 300
        rb6.label = Do you want to customize the behavior of Apple's X11?
        rb6.option = No, I enjoy having a lobotomized xterm pop up in my face
        rb6.option = Yes
		rb6.option = Leave everything the way it is now.
        rb6.default = Leave everything the way it is now.
        

        ###############################################################
        # Ask if user wants to run the switch_prompt GUI:
        ###############################################################
        # tx7.type=text
        # tx7.width = 1050
        # tx7.text = You can change the zsh prompt to any of several supppled prompt themes. 

 
        # Define radiobuttons
        rb7.type = popup
        rb7.width = 300
        rb7.label = Do you want to see a menu of different prompt themes?
        rb7.option = No, I like what I have now.
        rb7.option = Yes, please activate the switch_prompt GUI.
        rb7.default = No, I like what I have now.


        ###############################################################
        # Ask if user wants to read more:
        ###############################################################
        # tx8.type=text
        # tx8.width = 1050
        # tx8.text = You can change the zsh prompt to any of several supppled prompt themes. 

 
        # Define radiobuttons
        rb8.type = popup
        rb8.width = 300
        rb8.label = Do you want to see more details about these and other options?
        rb8.option = No, I prefer to suffer in silence.
        rb8.option = Yes, please take me to the website.
		rb8.default = No, I prefer to suffer in silence.



    cn.type=cancelbutton
    cn.label=Cancel

               
"; # end of conf

pashua_run "$conf"        
        


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

 

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













#############################################################
##########   Begin Actual Program ###########################
#############################################################
print ""
print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "

    
##  emacs or vi keybindings?

print "ZSH \e[1m Keybindings\e[0m: "

if [[ "$rb1" == *vi*  ]]; then
	print "Changing to \e[1mvi keybindings\e[0m."
	print "Delete the file ~/.zsh/zshvi or run this again to undo this setting."
	touch ~/.zsh/zshvi
elif [[ "$rb1" == *emacs* ]]; then
	print "Changing to \e[1memacs keybindings\e[0m."
	/bin/rm -f ~/.zsh/zshvi
else
	print "Leaving this setting unchanged."
fi

print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""

## User and Host completion setup

print "ZSH \e[1m User and Host completions \e[0m customization: "

if [[ "$rb2" == *Yes*  ]]; then
	autoload -U user_setup host_setup
	user_setup
	host_setup	
	print "Customized user and host completions will work in the next shell session"	
elif [[ "$rb2" == *No*  ]]; then
	print "When you are ready, issue the commands \e[1muser_setup\e[0m and \e[1mhost_setup\e[0m "
else
	print "Leaving this setting unchanged."
fi

print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""

## Ask about fink

print "\e[1m Fink \e[0m setup: "

if [[ "$rb3" == *No*  ]]; then
	print "Creating the file \e[1m~/.zsh/finknowarn \e[0mto suppress shell warning dialogue."
	touch ~/.zsh/finknowarn
elif [[ "$rb3" == *Yes*  ]]; then
	print "A warning will be issued if the startup scripts fail to find Fink."
else
	print "Leaving this setting unchanged."
fi

print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""

## Optional functions

print "\e[1m Possibly annoying Functions: \e[0m"

if [[ "$rb4" == *Yes*  ]]; then
	print "Creating the file \e[1m~/.zsh/zlocalfxn\e[0m to activate these functions."
	touch ~/.zsh/zlocalfxn
elif [[ "$rb4" == *No*  ]]; then
	print "Deleting the file \e[1m~/.zsh/zlocalfxn\e[0m to deactivate these functions."
	/bin/rm -f ~/.zsh/zlocalfxn

else
	print "Leaving this setting unchanged."
fi

print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""

## Crystallography functions

print "\e[1m Crystallography Functions: \e[0m"

if [[ "$rb5" == *Yes* ]]; then
	print "Creating the files \e[1m~/.zsh/zxtalfxn\e[0m and \e[1m~/.zsh/use_xtal_env\e[0m to activate these functions."
	touch ~/.zsh/zxtalfxn
	touch ~/.zsh/use_xtal_env
elif [[ "$rb5" == *No*  ]]; then
	print "Deleting the file \e[1m~/.zsh/zxtalfxn\e[0m to deactivate these functions."
	/bin/rm -f ~/.zsh/zxtalfxn  ~/.zsh/use_xtal_env

else
	print "Leaving this setting unchanged."
fi


print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""

## X11 Customizations

print "\e[1m X11 customization: \e[0m"

if [[ "$rb6" == *Yes*  ]]; then
	autoload -U customize_x11_gui
	print "Running customization GUI"
	customize_x11_gui	
elif [[ "$rb6" == *No*  ]]; then
	print "When you are ready, issue the commands \e[1mcustomize_x11_gui\e[0m "
else
	print "Leaving these settings unchanged."
fi
print ""
print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""
## Read more?

if [[ "$rb7" == *Yes*  ]]; then
	print "Opening prompt menu"
	autoload -U switch_prompt
	switch_prompt
else
	print "Issue the command \e[1m switch_prompt \e[0m if you decide you want to do this."
fi
print ""
print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""
## Read more?

if [[ "$rb8" == *Yes*  ]]; then
	print "Opening web page..."
	open http://xanana.ucsc.edu/xtal/wiki/index.php/ZSH_on_OS_X
else
	print "Issue the command \e[1m help_zsh_templates \e[0m for further information."
fi
print ""
print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""
# This file keeps the dialogue prompting from happening again
touch ~/.zsh/configure_zsh_templates
print "Issue the command \e[1m configure_zsh_templates\e[0m if you need to do this again."
print ""
print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""
print "Issue the command \e[1m switch_prompt \e[0m if you want to change the prompt."
print ""
print "\e[1m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m "
print ""


############ END #############################
