#!/bin/bash

##This app was developed by MX Devs 2023 and released under GPLv3
### version 2310-01

TEXTDOMAINDIR=/usr/share/locale 
export TEXTDOMAIN="mxfb-accessories"
source gettext.sh

### desktop file strings
#Translator Note - desktop file Name field
Name="$(gettext 'Shortcuts')"
#Translator Note - desktop file Comment field
Comment="$(gettext 'Shows frequently used key shortcuts')"

### buttons
export BTN_CLOSE=$(gettext "Close")  ; BTN_CLOSE+='!window-close'
#Translator Note - button to open the fluxbox 'keys' file in text editor
export BTN_EDIT=$(gettext "Edit keys file") ; BTN_EDIT+='!edit'

###

#Translator Note - Window title, keybindings = shortcut keys
TITLE="$(gettext 'MX-Fluxbox Keybindings')"
CLASS="mxfb-keybindings"
ICONPATH=/usr/share/pixmaps/mxfb-keybindings.png
tempfile1=/tmp/kb-1.txt

### cleanup
trap "rm -f $tempfile1" EXIT

###Tab 1

fkey=$RANDOM

#Translator Note - opens mx-fluxbox manual
LINE_1B_1="$(gettext 'Manual - MX Fluxbox')"
#Translator Note - translate key names for your language if necessary
LINE_1B_2="$(gettext 'Ctrl F1')"
#Translator Note - opens mx manual
LINE_1C_1="$(gettext 'Manual - MX Linux')"
#Translator Note - translate key names for your language if necessary
LINE_1C_2="$(gettext 'Shift F1')"
#Translator Note - opens mx-tools application
LINE_1D_1="$(gettext 'MX-Tools')"
#Translator Note - translate key names for your language if necessary
LINE_1D_2="$(gettext 'Ctrl F5')"
#Translator Note - launches the screen magnifier
LINE_1E_1="$(gettext 'Screen Magnifier')"
#Translator Note - translate key names for your language if necessary
LINE_1E_2="$(gettext 'Ctrl Alt M')"
#Translator Note - go to the next virtual workspace
LINE_1F_1="$(gettext 'Next Workspace')"
#Translator Note - mouse action
LINE_1F_2="$(gettext 'Scroll Wheel Up')"
LINE_1F_3="$(gettext '   or')"
#Translator Note - translate key names for your language if necessary
LINE_1F_4="$(gettext 'Ctrl Alt') "
#Translator Note - go to the previous virtual workspace
LINE_1G_1="$(gettext 'Previous Workspace')"
#Translator Note - mouse action
LINE_1G_2="$(gettext 'Scroll Wheel Down')"
LINE_1G_3="$(gettext '   or')"
#Translator Note - translate key names for your language if necessary
LINE_1G_4="$(gettext 'Ctrl Alt') "

yad --plug=$fkey --tabnum=1 \
--form --columns=3 --scroll \
--field="$LINE_1B_1":LBL \
--field="$LINE_1C_1":LBL \
--field="$LINE_1D_1":LBL \
--field="$LINE_1E_1":LBL \
--field="$LINE_1F_1":LBL \
--field="$LINE_1F_3":LBL \
--field="$LINE_1G_1":LBL \
--field="$LINE_1G_3":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field="$LINE_1B_2":LBL \
--field="$LINE_1C_2":LBL \
--field="$LINE_1D_2":LBL \
--field="$LINE_1E_2":LBL \
--field="$LINE_1F_2":LBL \
--field="$LINE_1F_4":LBL \
--field="$LINE_1G_2":LBL \
--field="$LINE_1G_4":LBL \
>$tempfile1 &

###Tab 2

#Translator Note - opens application finder
LINE_2A_1="$(gettext 'All Apps')"
#Translator Note - translate key names for your language if necessary
LINE_2A_2="$(gettext 'Left Super')"
#Translator Note - opens run dialog
LINE_2B_1="$(gettext 'Run')"
#Translator Note - translate key names for your language if necessary
LINE_2B_2="$(gettext 'Ctrl F2')"
#Translator Note - opens file manager
LINE_2C_1="$(gettext 'File Manager')"
#Translator Note - translate key names for your language if necessary
LINE_2C_2="$(gettext 'Ctrl F3')"
#Translator Note - opens terminal
LINE_2D_1="$(gettext 'Terminal')"
#Translator Note - translate key names for your language if necessary
LINE_2D_2="$(gettext 'Ctrl Alt T')"
#Translator Note - opens screenshot app
LINE_2E_1="$(gettext 'Screen Capture')"
#Translator Note - translate key names for your language if necessary
LINE_2E_2="$(gettext 'Alt Q')"
#Translator Note - delayed screenshot
LINE_2F_1="$(gettext 'Delayed Screen Capture')"
#Translator Note - translate key names for your language if necessary
LINE_2F_2="$(gettext 'Ctrl Alt Q')"
#Translator Note - turn compositor on/off
LINE_2G_1="$(gettext 'Compositor off/on')"
#Translator Note - that is a zero; translate key names for your language if necessary
LINE_2G_2="$(gettext 'Ctrl Alt 0')"

yad --plug=$fkey --tabnum=2 \
--form --columns=3 --scroll \
--field="$LINE_2A_1":LBL \
--field="$LINE_2B_1":LBL \
--field="$LINE_2C_1":LBL \
--field="$LINE_2D_1":LBL \
--field="$LINE_2E_1":LBL \
--field="$LINE_2F_1":LBL \
--field="$LINE_2G_1":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field="$LINE_2A_2":LBL \
--field="$LINE_2B_2":LBL \
--field="$LINE_2C_2":LBL \
--field="$LINE_2D_2":LBL \
--field="$LINE_2E_2":LBL \
--field="$LINE_2F_2":LBL \
--field="$LINE_2G_2":LBL \
>>$tempfile1 &
    
###Tab 3

#Translator Note - window command
LINE_3A_1="$(gettext 'Minimize')"
#Translator Note - translate key names for your language if necessary
LINE_3A_2="$(gettext 'Alt F9')"
#Translator Note - window command
LINE_3B_1="$(gettext 'Maximize')"
#Translator Note - translate key names for your language if necessary
LINE_3B_2="$(gettext 'Alt F10')"
#Translator Note - window command
LINE_3C_1="$(gettext 'Close')"
#Translator Note - translate key names for your language if necessary
LINE_3C_2="$(gettext 'Alt F4')"
#Translator Note - window action
LINE_3D_1="$(gettext 'Move (drag titlebar)')"
LINE_3D_2="$(gettext 'Left click')"
#Translator Note - window action
LINE_3E_1="$(gettext 'Resize (drag lower R corner)')"
#Translator Note - translate key names for your language if necessary
LINE_3E_2="$(gettext 'Alt Right click')"
#Translator Note - window action
LINE_3F_1="$(gettext 'Hide All')"
#Translator Note - translate key names for your language if necessary
LINE_3F_2="$(gettext 'Alt D')"
#Translator Note - opens workspace menu
LINE_3G_1="$(gettext 'Workspace Menu (on desktop)')"
#Translator Note - mouse action
LINE_3G_2="$(gettext 'Middle click')"
#Translator Note - opens root menu
LINE_3H_1="$(gettext 'Root Menu (on desktop)')"
#Translator Note - mouse action
LINE_3H_2="$(gettext 'Right click')"

yad --plug=$fkey --tabnum=3 \
--form --columns=3 --scroll \
--field="$LINE_3A_1":LBL \
--field="$LINE_3B_1":LBL \
--field="$LINE_3C_1":LBL \
--field="$LINE_3D_1":LBL \
--field="$LINE_3E_1":LBL \
--field="$LINE_3F_1":LBL \
--field="$LINE_3G_1":LBL \
--field="$LINE_3H_1":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field="$LINE_3A_2":LBL \
--field="$LINE_3B_2":LBL \
--field="$LINE_3C_2":LBL \
--field="$LINE_3D_2":LBL \
--field="$LINE_3E_2":LBL \
--field="$LINE_3F_2":LBL \
--field="$LINE_3G_2":LBL \
--field="$LINE_3H_2":LBL \
>>$tempfile1 &
    
###Tab 4
#Translator Note - option for window tiling
LINE_4A_1="$(gettext 'One-Half')"
#Translator Note - translate key names for your language if necessary
LINE_4A_2="$(gettext 'Ctrl 1/2/3/4')"
LINE_4B_1="$(gettext '   or (on keypad)')"
#Translator Note - translate key names for your language if necessary
LINE_4B_2="$(gettext 'Alt 2,4,6,8')"
#Translator Note - option for window tiling
LINE_4C_1="$(gettext 'One-Quarter')"
#Translator Note - translate key names for your language if necessary
LINE_4C_2="$(gettext 'Ctrl 5/6/7/8')"
LINE_4D_1="$(gettext '   or (on keypad)')"
#Translator Note - translate key names for your language if necessary
LINE_4D_2="$(gettext 'Alt 1,3,7,9')"
#Translator Note - option for window tiling
LINE_4E_1="$(gettext 'One-Third')"
#Translator Note - translate key names for your language if necessary
LINE_4E_2="$(gettext 'Ctrl 9')"
#Translator Note - option for window tiling
LINE_4F_1="$(gettext 'Fullscreen')"
#Translator Note - translate key names for your language if necessary
LINE_4F_2="$(gettext 'Ctrl 0')"

yad --plug=$fkey --tabnum=4 \
--form --columns=3 --scroll \
--field="$LINE_4A_1":LBL \
--field="$LINE_4B_1":LBL \
--field="$LINE_4C_1":LBL \
--field="$LINE_4D_1":LBL \
--field="$LINE_4E_1":LBL \
--field="$LINE_4F_1":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field=":":LBL \
--field="$LINE_4A_2":LBL \
--field="$LINE_4B_2":LBL \
--field="$LINE_4C_2":LBL \
--field="$LINE_4D_2":LBL \
--field="$LINE_4E_2":LBL \
--field="$LINE_4F_2":LBL \
>>$tempfile1 &
    
###Main Tab
#Translator Note - short descriptive text on main window of mxfb-keybindings
TEXT1="$(gettext 'This tool displays default shortcuts ("keys") that are frequently used.')"

#Translator Note - tab label
TABTEXT_1="$(gettext 'GENERAL')"
#Translator Note - tab label
TABTEXT_2="$(gettext 'PROGRAMS')"
#Translator Note - tab label
TABTEXT_3="$(gettext 'WINDOWS')"
#Translator Note - tab label - tiling as in arrangement of non-overlapping windows on a screen
TABTEXT_4="$(gettext 'TILING')"

yad --notebook --key=$fkey --tab="<b>$TABTEXT_1</b>" --tab="<b>$TABTEXT_2</b>" --tab="<b>$TABTEXT_3</b>" --tab="<b>$TABTEXT_4</b>" --tab-pos=left \
--title="$TITLE" --class="$CLASS" --window-icon="$ICONPATH" \
--width=550 --height=450 --borders=10 --center --buttons-layout=spread \
--text="\n<b>$TEXT1</b>\n" --text-align=center \
--button="${BTN_EDIT}":7 --button="${BTN_CLOSE}":6

ret=$?

case $ret in
    6 | 252 )
        exit
    ;;

    7 )
        fpad $HOME/.fluxbox/keys
    ;;
esac
