#! /bin/bash

# Copyright (C) 2017 Paweł Pijanowski under GNU GPL 3 license.
# last edit 2017/04/04

DIALOGMENU="yad --window-icon=accessories-text-editor --width=300 --height=180 --center"
TITLE="--always-print-result --dialog-sep --image=accessories-text-editor --title="
TEXT="--text="
MENU="--list --column=Pick --column=Info"
OKEXIT=" --button=Ok:0 --button=Exit:1"
EXIT="--button=Exit:1"
TITLETEXT="Panel edit"

# choose a panel to be edited by a text editor
if [ -f /usr/bin/fbpanel ] && [ -f /usr/bin/tint2 ]; then

# if two panels installed
CHOICES=`$DIALOGMENU $TITLE"$TITLETEXT" $OKEXIT $MENU $TEXT"Choose panel to edit:" \
Fbpanel "Fbpanel" \
Tint2 "Tint2"`

	if [ "$?" = "0" ]; then
		CHOICE=`echo $CHOICES | cut -d "|" -f 1`
	else
		exit 0
	fi

	if [ "$CHOICE" = "Fbpanel" ]; then
		sparky-editor ~/.config/fbpanel/default
	
	elif [ "$CHOICE" = "Tint2" ]; then
		sparky-editor ~/.config/tint2/tint2rc
	
	else
		exit 0
	fi

# if fbpanel installed only
elif [ -f /usr/bin/fbpanel ]; then
	sparky-editor ~/.config/fbpanel/default

# if tint2 installed only
elif [ -f /usr/bin/tint2 ]; then
	sparky-editor ~/.config/tint2/tint2rc
else
	$DIALOGMENU $TITLE"$TITLETEXT" $EXIT $TEXT"No Fbpanel nor Tint2 installed. Exiting..."
	exit 0
fi

exit 0



