当我按下按钮时,我想回显当前选择的列表,但它所做的只是运行我分配给按钮的功能。我希望它检测是否选择了一个列表,如果没有显示另一个 yad 窗口说“请选择一个任务/提醒以使用此按钮!”,但如果选择了某些内容,则显示一个 yad 窗口说“您选择:列表名称列表日期“ 谢谢。
#!/bin/bash
DIRECTORY="$(readlink -f "$(dirname "$(dirname "$0")")")"
AppName="$(cat $DIRECTORY/data/info/appname.inf)"
Used="$(cat $DIRECTORY/data/info/opd)"
#load functions
source "${DIRECTORY}/scripts/functions" || error "failed to source ${DIRECTORY}/scripts/functions"
#Display MainMenu if program has been used before.
if [ $Used == "True" ]; then
#Display Tasks/Reminders if there are any
if [ -d "$DIRECTORY/Tasks" ]; then
while IFS='|' read -r Name Date _; do
if [[ $Name || $Date ]]; then
items+=( "$Name" "$Date" )
else
items+=( "None" "None" )
fi
done < <(sort -t'|' -k2 $DIRECTORY/Tasks/Tasks.txt)
yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='300' --text-align="center" --text="Welcome to $AppName! \nWhat would you like to do?" --button="Add new Task/Reminder"!"${DIRECTORY}/icons/install.png"!'Create a new Task/Reminder':2 --button="Delete Task/Reminder"!"${DIRECTORY}/icons/uninstall.png"!'Delete Task/Reminder':3 --list --column=Task/Reminder "${items[0]}" --column=Date "${items[1]}"
else
yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='100' --text-align="center" --text="Welcome to $AppName! \nWhat would you like to do?" --button="Add new Task/Reminder"!"${DIRECTORY}/icons/install.png"!'Create a new Task/Reminder':2
fi
else #Display StartupMenu.
yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='300' --text-align="center" --text="Thanks for instaling $AppName! \nClick next to learn how to use $AppName." --window-icon="${DIRECTORY}/icons/logo.png" --button=Cancel!"${DIRECTORY}/icons/exit.png"!'Exit':0 --button='Next'!"${DIRECTORY}/icons/forward.png"!'Continue.':1
fi
button=$? #get exit code to determine which button was pressed.
if [ $button -eq 0 ];then
echo "True" > $DIRECTORY/data/info/opd
elif [ $button -eq 1 ];then
bash "$DIRECTORY/scripts/firstrun/learn"
elif [ $button -eq 2 ];then
nameofnew="$(yad --entry --window-icon="${DIRECTORY}/icons/logo.png" --separator='\n' --title="Create a new Task/Reminder" --center --text-align="center" --entry-label="Name of new Task/Reminder:")"
selecteddate="$(yad --calendar --window-icon="${DIRECTORY}/icons/logo.png" --title="Select a date" --height="200" --width="400")"
yad --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" --title="Is this correct?" --center --width='300' --height='300' --text-align="center" --text="Is this correct? \nName of Task/Reminder: '$nameofnew'\nSelected date for new Task/Reminder: '$selecteddate'" --button="No"!"${DIRECTORY}/icons/exit.png"!'No':2 --button='Yes'!"${DIRECTORY}/icons/check.png"!'yes':3
elif [ $button -eq 3 ];then
if [ -d "$DIRECTORY/Tasks" ]; then
yad
else
g
fi
elif [ $button -eq 252 ];then
exit 0
else
error "Unkown button input recived: $button"
fi