#!/bin/bash

#--------------------------------------------------------
#-- setup the path to the dialogs

GBdialogPATH=/usr/local/Gtkbasic-002
INFOWINDOW="$GBdialogPATH/dialog-infowindow/GBdialog-infowindow01"
FILECHOOSER="$GBdialogPATH/dialog-multifilechooser/GBdialog-multifilechooser"


#--------------------------------------------------------
# create a pipe to send text to an infowindow
# This is just to display your choices, you do not need that!

mkfifo /tmp/msgpipe.$$
# 2>/dev/null

newline='\n .............................................................. <EOM>'

echo " $newline">/tmp/msgpipe.$$&
"$INFOWINDOW" "/tmp/msgpipe.$$" &
#gtkbasic002 -d infowindow "/tmp/msgpipe.$$" &


#--------------------------------------------------------
#-- run filechooser, get all selected files in a variable
#-- 2>/dev/null will suppress Gtk-warnings

#-- pass wrong arguments, that shows an error-message

result=`"$FILECHOOSER" 2>/dev/null`

echo "$result"
echo " $result$newline">>/tmp/msgpipe.$$



# -- open a file -----------------------------------

A1="Open a File"
A2="/usr/share/audio"
A3="*.au"
A4="1"
A5="0"
result=`"$FILECHOOSER" "$A1" "$A2" "$A3" "$A4" "$A5" 2>/dev/null`

echo "$result"
echo " $result$newline">>/tmp/msgpipe.$$

# -- open multiple files -----------------------------------

A1="Open Files"
A2="/usr/share/audio"
A3="*.au"
A4="1"
A5="1"
result=`"$FILECHOOSER" "$A1" "$A2" "$A3" "$A4" "$A5" 2>/dev/null`

echo "$result"
echo " $result$newline">>/tmp/msgpipe.$$

# -- save file as -----------------------------------

A1="Save File as"
A2="/usr/share/audio"
A3="*.au"
A4="2"
A5="0"
result=`"$FILECHOOSER" "$A1" "$A2" "$A3" "$A4" "$A5" 2>/dev/null`

echo "$result"
echo " $result$newline">>/tmp/msgpipe.$$

# -- select a folder -----------------------------------

A1="Select a Folder"
A2="/usr/share/audio"
A3="*.au"
A4="3"
A5="0"
result=`"$FILECHOOSER" "$A1" "$A2" "$A3" "$A4" "$A5" 2>/dev/null`

echo "$result"
echo " $result$newline">>/tmp/msgpipe.$$

# -- create a folder -----------------------------------

A1="Create a Folder"
A2="/usr/share/audio"
A3="*.au"
A4="4"
A5="0"
result=`"$FILECHOOSER" "$A1" "$A2" "$A3" "$A4" "$A5" 2>/dev/null`

echo "$result"

#-- clean up the pipe ----------

echo " $result$newline">>/tmp/msgpipe.$$
echo " You now can close this window!$newline">>/tmp/msgpipe.$$
echo " ">>/tmp/msgpipe.$$
sleep 3

rm -f /tmp/msgpipe.$$