1 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # Filename: package/.../stone/stone_gui_dialog.sh
5 # Copyright (C) 2007 - 2008 The OpenSDE Project
6 # Copyright (C) 2004 - 2006 The T2 SDE Project
7 # Copyright (C) 1998 - 2003 Clifford Wolf
9 # More information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; version 2 of the License. A copy of the
14 # GNU General Public License can be found in the file COPYING.
15 # --- SDE-COPYRIGHT-NOTE-END ---
17 # Filename: gui_dialog.sh
20 # This file provides the gui-functions implemented with
21 # the use of dialog, i.e. a curses based menu-frontend.
23 gui_dialog_lines
="$( stty size | cut -d' ' -f1 )"
24 gui_dialog_columns
="$( stty size | cut -d' ' -f2 )"
26 gui_dialog_s70
=$
(( gui_dialog_columns
- 10 ))
27 gui_dialog_s62
=$
(( gui_dialog_columns
- 18 ))
28 gui_dialog_s15
=$
(( gui_dialog_lines
- 10 ))
31 dialog
--stdout --title 'STONE - Setup Tool ONE - System Configuration' "$@"
35 # [ the following variables act as staticly declared variables in functions (in
36 # C), i.e. they keep their content even after return of the certain function
37 # to be used again and again in this function. ]
39 # Important is to know that an element of `gui_menu_tree_name' corresponds
40 # to an element of `gui_menu_tree_value' by the same number, i.e.
41 # gui_menu_tree_value[0] contains the value of gui_menu_tree_name[0]
43 declare -a gui_menu_tree_name
44 declare -a gui_menu_tree_value
47 # Use: gui_menu "ID" "Title" "Text" "Action" [ "Text" "Action" [ .. ] ]
50 # `cmd_ar' acts as a kind of mapper between the choosen category
51 # and the function's/command's name that is responsible for what
52 # next is to do. This command/function is finally executed.
55 # Although dialog does folding itself, we're forced
56 # to do it directly, because we need the number of
57 # lines to compute the size of a widget.
58 local id
="$1" title
="$( echo "$2" | fmt -$gui_dialog_s62 )"
59 local y_text
=$
( echo "$title" |
wc -l ) y_menu
=$
(( ($#-2) / 2 ))
60 local nr
=1 x
="'" y choosen
= ; shift 2
62 [ $
(( $y_text + $y_menu )) -gt $gui_dialog_s15 ] && \
63 y_menu
=$
(( gui_dialog_s15
- y_text
))
65 if [ $id = main
] ; then local cmd
="gui_dialog --cancel-label Exit"
66 elif [ "$gui_nocancel" = 1 ] ; then cmd
="gui_dialog --no-cancel"
67 else local cmd
="gui_dialog --cancel-label Back" ; fi
69 # In case of having been in the current menu before (found out by
70 # checking the current ID for the ones saved in `gui_menu_tree_name[]'),
71 # make the old item be cursored again.
73 for (( count
=$gui_menu_tree_id; $count >= 0; count--
))
75 if [ "${gui_menu_tree_name[$count]}" = $id ] ; then
76 default
="${gui_menu_tree_value[$count]}"
77 gui_menu_tree_id
=$
(( $count - 1 ))
82 cmd
="$cmd --default-item \${default:-0}"
83 cmd
="$cmd --menu '${title//$x/$x\\$x$x}'"
84 cmd
="$cmd $(( $y_text + $y_menu + 6 )) $gui_dialog_s70 $y_menu"
86 while [ $# -gt 0 ] ; do
88 if [ -z "$default" -a "$y" != "$2" ] ; then
93 # this line should become a blank one
96 # the purpose of this line is only to
97 # display additional information about
99 cmd
="$cmd '-' '${1//$x/$x\\$x$x}'"
102 cmd
="$cmd $nr '${1//$x/$x\\$x$x}'"
110 # `choosen' gets the choosen item that represents in fact
111 # the dereferencer for `cmd_ar'.
112 choosen
="$(eval "$cmd")"
114 if [ $?
-eq 0 ]; then
115 # if enter is pressed on an ``additional information line'',
117 [ "$choosen" = "-" ] && return 0
119 gui_menu_tree_id
=$
(( $gui_menu_tree_id + 1 ))
120 gui_menu_tree_name
[$gui_menu_tree_id]=$id
121 gui_menu_tree_value
[$gui_menu_tree_id]=$choosen
123 eval "${cmd_ar[$choosen]}"
130 # Use: gui_input "Text" "Default" "VarName"
133 local headlines
="$( echo "$1" | fmt -$gui_dialog_s62 )" \
134 height
=$
(( $
(echo "$headlines" |
wc -l) + 7 )) tmp cmd
136 if [ "$gui_nocancel" = 1 ] ; then cmd
="gui_dialog --no-cancel"
137 else local cmd
="gui_dialog --cancel-label Back" ; fi
139 if tmp
="$($cmd --inputbox "$headlines" $height $gui_dialog_s70 "$2")"; then
144 # Use: gui_message "Text"
147 local headlines
="$( echo "$1" | fmt -$gui_dialog_s62 )"
148 gui_dialog
--msgbox "$headlines" \
149 $
(( $
( echo "$headlines" |
wc -l ) + 4 )) $gui_dialog_s70
152 # Use: gui_yesno "Text"
155 local headlines
="$( echo "$1" | fmt -$gui_dialog_s62 )"
156 gui_dialog
--yesno "$headlines" \
157 $
(( $
( echo "$headlines" |
wc -l ) + 4 )) $gui_dialog_s70
161 # Use: gui_edit "Text" "File"
165 for x
in $EDITOR vi nvi emacs xemacs pico
; do
166 if type -p $x > /dev
/null
167 then xx
=$x ; break ; fi
172 gui_message
"Cannot find any editor. Make sure \$EDITOR is set."
176 # Use: gui_cmd "Title" "Command"
177 # (Title isn't used in this GUI type)
180 read -p "Press ENTER to continue."