#!/bin/bash

FILE_PATH=$1

# Edit file with maximized yad window and capture the output
EDITED_CONTENT=$(yad --text-info \
    --title="Edit $FILE_PATH" \
    --filename="$FILE_PATH" \
    --editable \
    --maximized \
    --fontname="Ubuntu Mono 12" \
    --button="Cancel:1" \
    --button="Save and Continue:2")

case $? in
    2) 
        echo "$EDITED_CONTENT" > "$FILE_PATH"
        echo "File saved and continuing..."
	exit 2
        ;;
    1) 
        echo "Edit cancelled"
        exit 1
	;;
    0) 
        echo "Edit cancelled"
        exit 1
        ;;
esac


# just closing the dialog window exits with a 0 return code, so use return code 2 to indicate success / continue
