Search code examples
bashshelldialogdebianzenity

Zenity file selection displaying


so im trying to do a delete function inside zenity . I managed to let the user input his desired path and then i want to display all the files that are present inside it . I found out how to do it and i know it work but no with zenity . The next window (file selection) is not poping up and my program get back to the menu. thanks here is my code.Thanks u for your help and time!

#!/bin/bash

function Ddate()
{
    zenity --info \
    --title "Date and Time" \
    --text "Today is $(date)"
}

function Dcalendar()
{
    zenity --forms \
    --title "Scheduler" \
    --text "Pick a date" \
    --add-calendar "Calendar" \
    --add-entry "Reminder"
}

function Ddelete()
{   
    directory=$(zenity --entry \
    --text "Enter a path" \
    --title "Delete" )
    if [ -z "$directory" ];then
    directory=$ pwd
    else
        if [ -d "$directory" ];then
            zenity --file-selection --filename=$(directory)
        fi 
    fi

}

while true;
do
choice="$(zenity --height 275 --width 450 \
--list \
--title="" \
--column="Function" --column="Description" \
    Date 'Display the actual date and time.' \
    Calendar 'Display an interactive calendar.' \
    Delete 'Let you delete a file.' \
    Exit 'To quit this script.')"

case $choice in
    Date) Ddate;;
    Calendar) Dcalendar;;
    Delete) Ddelete;;
    Exit) break;;

esac

done

Solution

  • To fix my problem, i understand the meaning behind the $? escape code . In each window $? control the ok and cancel button taking value 0 and 1 respectively. Inside my program I cleared the $? first because of the previous window , a value can be already set in, and set a variable ret to $? meaning if someone press ok or cancel it continue to the next window or goes back to the root window.

    function Ddelete()
    {   
        directory=$(zenity --entry \
        --text "Enter a path" \
        --title "Delete" )
        if [ -z "$directory" ];then
        directory=$ pwd
        else
            if [ -d "$directory" ];then
                clear $?
                Spath=$(zenity --file-selection --filename=$(directory))
                ret=$?
            fi 
        fi
    
    }