Added support for 'check boxes' to the menu system.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@801 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2003-02-22 22:42:24 +00:00
parent 394d982ad6
commit a2e54e5f32
2 changed files with 115 additions and 15 deletions
+2 -1
View File
@@ -161,7 +161,8 @@ INPUT_install_libdir_VALIDATOR=validate_path
# Show the menu and let people set things # Show the menu and let people set things
do_menu main do_menu main config.state
echo "Configuration complete."
# Set INSTALL_LIBDIR and INSTALL_BINDIR by to their set values, replacing # Set INSTALL_LIBDIR and INSTALL_BINDIR by to their set values, replacing
# '$prefix' to the prefix set. # '$prefix' to the prefix set.
+113 -14
View File
@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
MENU_ITEM_TYPES="MENU CHOICE INPUT" MENU_ITEM_TYPES="MENU CHOICE INPUT CHECK"
MENU_ITEM_TYPE_MENU_INIT=menu_init_menu MENU_ITEM_TYPE_MENU_INIT=menu_init_menu
MENU_ITEM_TYPE_MENU_PRINT_VALUE=menu_print_value_menu MENU_ITEM_TYPE_MENU_PRINT_VALUE=menu_print_value_menu
@@ -35,6 +35,11 @@ MENU_ITEM_TYPE_INPUT_HANDLER=menu_handle_input
MENU_ITEM_TYPE_INPUT_SAVE=menu_save_input MENU_ITEM_TYPE_INPUT_SAVE=menu_save_input
MENU_ITEM_TYPE_INPUT_PROCESS=menu_process_input MENU_ITEM_TYPE_INPUT_PROCESS=menu_process_input
MENU_ITEM_TYPE_CHECK_INIT=menu_init_check
MENU_ITEM_TYPE_CHECK_PRINT_VALUE=menu_print_value_check
MENU_ITEM_TYPE_CHECK_HANDLER=menu_handle_check
MENU_ITEM_TYPE_CHECK_SAVE=menu_save_check
MENU_ITEM_TYPE_CHECK_PROCESS=menu_process_check
# Description: Check if a string can be used as a path. # Description: Check if a string can be used as a path.
# No checks are done if the path really exists. # No checks are done if the path really exists.
@@ -121,7 +126,7 @@ menu_init_choice() {
# Description: Initialise this input menu # Description: Initialise this input menu
# Arguments: $1 - the name of the input menu # Arguments: $1 - the name of the input menu
menu_init_input() { menu_init_input() {
local MENU TEMP_VALUE TEMP_DEFAULT local MENU TEMP_VALUE
MENU="$1" MENU="$1"
eval TEMP_VALUE="\$INPUT_${MENU}_VALUE" eval TEMP_VALUE="\$INPUT_${MENU}_VALUE"
if [ -z "$TEMP_VALUE" ]; then if [ -z "$TEMP_VALUE" ]; then
@@ -131,6 +136,32 @@ menu_init_input() {
eval INPUT_${MENU}_OLD_VALUE="\$TEMP_VALUE" eval INPUT_${MENU}_OLD_VALUE="\$TEMP_VALUE"
} }
# Description: Initialise this checkbox
# Arguments: $1 - the name of the checkbox
menu_init_check() {
local CHECKBOX TEMP_VALUE TEMP_DEFAULT
CHECKBOX="$1"
eval TEMP_VALUE="\$CHECK_${CHECKBOX}_VALUE"
eval TEMP_DEFAULT="\$CHECK_${CHECKBOX}_DEFAULT"
# Make sure the default is either 'CHECKED' or 'UNCHECKED'
case "$TEMP_DEFAULT" in
yes|Yes|YES|checked|Checked|CHECKED|1|true|True|TRUE)
TEMP_DEFAULT=CHECKED
;;
*)
TEMP_DEFAULT=UNCHECKED
;;
esac
eval CHECK_${CHECKBOX}_DEFAULT="\$TEMP_DEFAULT"
if [ -z "$TEMP_VALUE" ]; then
TEMP_VALUE="$TEMP_DEFAULT"
eval CHECK_${CHECKBOX}_VALUE="\$TEMP_DEFAULT"
fi
eval CHECK_${CHECKBOX}_OLD_VALUE="\$TEMP_VALUE"
}
# Description: Print the string describing the value of a menu item. # Description: Print the string describing the value of a menu item.
# Arguments: $1 - the type of menu item # Arguments: $1 - the type of menu item
# $2 - the name of the menu item # $2 - the name of the menu item
@@ -142,7 +173,7 @@ menu_print_value() {
"$PRINT_VALUE" "$2" "$PRINT_VALUE" "$2"
} }
# Description: Print the string describing the value this menu # Description: Print the string describing the value of this menu
# Arguments: $1 - the name of the menu item # Arguments: $1 - the name of the menu item
# Outputs: The string describing the value of this menu # Outputs: The string describing the value of this menu
menu_print_value_menu() { menu_print_value_menu() {
@@ -165,13 +196,35 @@ EOF
# Arguments: $1 - the name of the input menu item # Arguments: $1 - the name of the input menu item
# Outputs: The value of the given input menu # Outputs: The value of the given input menu
menu_print_value_input() { menu_print_value_input() {
local TEMP_VALUE TEMP_TITLE local TEMP_VALUE
eval TEMP_VALUE="\$INPUT_$1_VALUE" eval TEMP_VALUE="\$INPUT_$1_VALUE"
cat << EOF cat << EOF
$TEMP_VALUE $TEMP_VALUE
EOF EOF
} }
# Description: Print the value of this checkbox
# Arguments: $1 - the name of the checkbox item
# Outputs: The value of the given checkbox
menu_print_value_check() {
local TEMP_VALUE TEMP_DEFAULT
eval TEMP_VALUE="\$CHECK_$1_VALUE"
eval TEMP_DEFAULT="\$CHECK_$1_DEFAULT"
if [ "$TEMP_VALUE" = "CHECKED" ]; then
if [ "$TEMP_DEFAULT" = "CHECKED" ]; then
echo "Yes (default)"
else
echo "Yes"
fi
else
if [ "$TEMP_DEFAULT" = "CHECKED" ]; then
echo "No"
else
echo "No (default)"
fi
fi
}
# Description: Print the string describing the value of a menu item. # Description: Print the string describing the value of a menu item.
# Arguments: $1 - the type of menu item # Arguments: $1 - the type of menu item
# $2 - the name of the menu item # $2 - the name of the menu item
@@ -370,6 +423,21 @@ EOF
eval "INPUT_${ITEM}_VALUE"=\"\$NEW_VALUE\" eval "INPUT_${ITEM}_VALUE"=\"\$NEW_VALUE\"
} }
# Description: Process an checkbox-type menu item
# Arguments: $1 - The name of the checkbox
menu_handle_check() {
local ITEM OLD_VALUE NEW_VALUE
ITEM="$1"
eval OLD_VALUE="\$CHECK_${ITEM}_VALUE"
if [ "$OLD_VALUE" = "CHECKED" ]; then
NEW_VALUE="UNCHECKED"
else
NEW_VALUE="CHECKED"
fi
eval "CHECK_${ITEM}_VALUE"=\"\$NEW_VALUE\"
}
# Description: echo the current state of a menu item in a form that can be # Description: echo the current state of a menu item in a form that can be
# executed to restore the state. # executed to restore the state.
# Arguments: $1 - the type of menu item # Arguments: $1 - the type of menu item
@@ -422,6 +490,19 @@ INPUT_${MENU}_VALUE='$TEMP_VALUE'
EOF EOF
} }
# Description: echo the current state of an check box in a form that can be
# executed to restore the state.
# Arguments: $1 - the name of the checkbox
# Outputs: The string describing the value of the checkbox
menu_save_check() {
local CHECKBOX TEMP_VALUE
CHECKBOX="$1"
eval TEMP_VALUE="\$CHECK_${CHECKBOX}_VALUE"
cat << EOF
CHECK_${CHECKBOX}_VALUE='$TEMP_VALUE'
EOF
}
# Description: Perform the actions associated with the choice made for a # Description: Perform the actions associated with the choice made for a
# menu items. # menu items.
# Arguments: $1 - the type of menu item # Arguments: $1 - the type of menu item
@@ -466,17 +547,35 @@ menu_process_input() {
: :
} }
do_menu() { # Description: Perform the actions associated with the status of a
if [ -e config.state ]; then # check box.
. config.state # Arguments: $1 - the name of the check box
menu_process_check() {
local CHECKBOX TEMP_VALUE TEMP_ACTION
CHECKBOX="$1"
eval TEMP_VALUE="\$CHECK_${CHECKBOX}_VALUE"
eval TEMP_ACTION="\$CHECK_${CHECKBOX}_OPTION_${TEMP_VALUE}_ACTION"
if [ -n "$TEMP_ACTION" ]; then
$TEMP_ACTION
fi fi
menu_init MENU "$@" }
menu_handle MENU "$@"
do_menu() {
local START_MENU SAVE_FILE
START_MENU="$1"
SAVE_FILE="$2"
if [ -n "$SAVE_FILE" -a -e config.state ]; then
. config.state
fi
menu_init MENU "$1"
menu_handle MENU "$1"
echo echo
echo "Saving configuration..." if [ -n "$SAVE_FILE" ]; then
menu_save MENU "$@" > config.state echo "Saving choices..."
echo "Propagating configuration..." menu_save MENU "$1" > config.state
menu_process MENU "$@" fi
echo "Configuration complete." echo "Propagating choices..."
menu_process MENU "$1"
} }