#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

UseGettext {$NSCDE_ROOT/share/locale;NsCDE-Subpanel:$NSCDE_ROOT/share/locale;NsCDE-Subpanels}
WindowLocaleTitle {Subpanels Manager}
WindowSize 606 572
Colorset 22

Init
Begin
   Set $SubpanelNo = (GetScriptArgument 1)

   If $SubpanelNo == {} Then
   Begin
      Quit
   End

   # Fill the App List on the left with all apps found by fvwm-menu-desktop
   Set $AppListTmpFileCmd = {mktemp -t tmp.XXXXXXXX.AppLst.XXXXXXXX}
   Set $AppListTmpFile = (GetOutput $AppListTmpFileCmd 1 -1)
   Set $AppListToFileCmd = {fvwm-menu-desktop --mini-icon-dir "$FVWM_USERDIR/icons" --enable-mini-icons -s 32 --include-items none --theme NsCDE --desktop nscde | }
                           { egrep '^\+ \".*\" Exec exec .*' | sort -u | grep -n '' | }
                           { $NSCDE_TOOLSDIR/ised -c 's/^\([[:digit:]]\+\):+ "\(.*\)" Exec exec \(.*\)/\1%\2\3/g' -o -f - | }
                           { $NSCDE_TOOLSDIR/ised -c "s/'/\\\\\\\\\"/g" -o -f - | }
                           { $NSCDE_TOOLSDIR/ised -c "s/\$NSCDE_ROOT/\$[NSCDE_ROOT]/g" -o -f - > "} $AppListTmpFile {"}
   Set $AppListToFile = (GetOutput $AppListToFileCmd 1 -1)
   Set $FmtAppListCmd = {cut -d"%" -f 2 < "} $AppListTmpFile {" | tr '\n' '|' | sed 's/|$//g'}
   Set $FmtAppList = (GetOutput $FmtAppListCmd 1 -1)
   ChangeTitle 3 $FmtAppList

   # Find out if we are going to read subpanel data from the system or user Subpanels.actions file
   Set $ChkActionsCmd = {egrep '^S} $SubpanelNo {,.*' "$FVWM_USERDIR/Subpanels.actions"}
   Set $ChkActions = (GetOutput $ChkActionsCmd 1 -1)
   If $ChkActions <> {} Then
   Begin
      Set $SubpanelActionsRead = {$FVWM_USERDIR/Subpanels.actions}
   End
   Else
   Begin
      Set $SubpanelActionsRead = {$NSCDE_DATADIR/defaults/Subpanels.actions}
   End
   Set $UserSubpanelActionsFile = {$FVWM_USERDIR/Subpanels.actions}
   Set $SystemSubpanelActionsRead = {$NSCDE_DATADIR/defaults/Subpanels.actions}

   # Fill the Subpanel app List on the right with all entries found there.
   Set $SubpListTmpFileCmd = {mktemp -t tmp.XXXXXXXX.SubpLst.XXXXXXXX}
   Set $SubpListTmpFile = (GetOutput $SubpListTmpFileCmd 1 -1)
   Set $SubpListToFileCmd = {egrep '^S} $SubpanelNo {,ENTRY,.*,.*,.*,.*' "} $SubpanelActionsRead {" | grep -n '' | sed 's/:/,/' > "} $SubpListTmpFile {"}
   Set $SubpListToFile = (GetOutput $SubpListToFileCmd 1 -1)
   Set $FmtSubpListCmd = {cut -d"," -f 4 < "} $SubpListTmpFile {" | tr '\n' '|' | sed 's/|$//g'}
   Set $FmtSubpList = (GetOutput $FmtSubpListCmd 1 -1)

   # Added for Localization of existing default entries.
   Set $LocalizedListTmpFile = (GetOutput {mktemp -t tmp.XXXXXXXX.SubpLocLst.XXXXXXXX} 1 -1)
   Do {Exec echo '} $FmtSubpList {' > '} $LocalizedListTmpFile {'}
   Set $FmtLocalizedSubpListCmd = {$NSCDE_TOOLSDIR/usleep 250000 ; cat '} $LocalizedListTmpFile {'}
   Set $FmtLocalizedSubpList = (GetOutput $FmtLocalizedSubpListCmd 1 -1)

   ChangeTitle 4 $FmtLocalizedSubpList

   Set $SubpanelNameCmd = {egrep '^S} $SubpanelNo {,NAME,.*' "} $SubpanelActionsRead {" | cut -d"," -f3 | $NSCDE_TOOLSDIR/ised -c 's/^\$\[gt\.\(.*\)\]/\1/g' -o -f -}
   Set $SubpanelName = (GetOutput $SubpanelNameCmd 1 -1)
   Set $NewWinTitle = (Gettext {Subpanels Manager: Subpanel}) { } $SubpanelNo { (} (Gettext $SubpanelName) {)}
   ChangeWindowTitle $NewWinTitle

   # Defaults
   Set $NewAppType = {}
   Set $Perform = 1

   Set $DefaultFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 11} 1 -1)
   ChangeFont 14 $DefaultFont
   ChangeFont 18 $DefaultFont
   ChangeFont 15 $DefaultFont

   Set $BtnFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 15} 1 -1)
   ChangeFont 20 $BtnFont
   ChangeFont 21 $BtnFont
   ChangeFont 22 $BtnFont
   ChangeFont 23 $BtnFont

   Set $LabelFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 14} 1 -1)
   ChangeFont 1 $LabelFont
   ChangeFont 2 $LabelFont
   ChangeFont 3 $LabelFont
   ChangeFont 4 $LabelFont
   ChangeFont 7 $LabelFont
   ChangeFont 13 $LabelFont
   ChangeFont 9 $LabelFont
   ChangeFont 11 $LabelFont

   # Key bindings
   Key Q C 22 1 {KeyClose}
   Key Return M 20 1 {KeyApply}
   Key Return C 21 1 {KeySave}
   Key Escape A 22 1 {KeyClose}
   Key F1 A 23 1 {KeyHelp}
   Key Help A 23 1 {KeyHelp}
   Key Insert A 5 2 {KeyInsert}
   Key Delete A 6 2 {KeyDelete}

   # Locale stuff: Hack to keep leading or ending space(s)
   # which will be trimmed by LocaleTitle Widget directive.
   ChangeLocaleTitle 18 (GetTitle 18)

   # X compositor bug workaround
   Set $RedrawSelf = (GetOutput {echo $NSCDE_REDRAW_WORKAROUND} 1 1)

   # Nasty workaround because ForeColor of the TextField
   # widget is not applied and global value is used anyway.
   # How it works: if wanted Colorset is applied with
   # ChangeColorset to (any?) other widget after initialization
   # of the script, colorset foreground color will be properly
   # applied to TextField widget too. Even if fake widget is
   # hidden, this workaround still works as it should.
   # We define hidden PushButton widhet on the end of the script
   # and send string "workaround" to routine 1 of the TextField
   # widget ("1 : " can be attached to any widget in fact ...).
   # This routine than changes the colorset of the hidden
   # PushButton widget, and this then triggers change in buggy
   # TextField to be applied.
   # This bug can be seen when default colorset for the script has
   # different foreground color than colorset applied to the
   # TextField widget. Another possible workaround is to define
   # globally back/fore/sh/hi colors for the script instead of
   # (or after definition) of a colorset, but this is unflexible,
   # since script background cannot be changed dinamically or
   # from outside of the script as colorset functionality allows.
   Do {Schedule 50 SendToModule SubpanelMgr SendString 25 1 workaround}
   Do {Schedule 250 SendToModule SubpanelMgr SendString 25 1 workaround}
   Do {Schedule 350 SendToModule SubpanelMgr SendString 25 1 workaround}
End

PeriodicTasks
Begin
   Set $MSG=(ReceivFromScript $BROWSER)
   If $MSG <> {No message} Then
   Begin
      ChangeTitle 12 $MSG
      ChangeIcon 17 $MSG
   End
End

QuitFunc
Begin
   Do {Exec exec rm -f "} $AppListTmpFile {" "} $SubpListTmpFile {" "} $SubpListTmpNewFile {" "} $SubpNewActionsPart {" "} $LocalizedListTmpFile {"}
End

Widget 1
   Property
   Size 280 20
   Position 312 10
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   LocaleTitle {Existing Items in Subpanel:}
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 2
   Property
   Size 280 20
   Position 12 10
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   LocaleTitle {Available Applications:}
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 3
   Property
   Size 280 202
   Position 12 40
   Type List
   Flags NoReliefString
   Value 0
   Title {}
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
         Set $FocusOnList = {Applications}

         ChangeColorset 8 20
         ChangeColorset 10 20
         ChangeColorset 12 20

         # Hide this if it was selected in previous click
         HideWidget 15
         HideWidget 16

         Set $SelectedIndex = (GetValue 3)
         Set $GetAppIdxNameCmd = {egrep "^} $SelectedIndex {%.*" "} $AppListTmpFile {" | cut -d"%" -f 2}
         Set $GetAppIdxIconCmd = {egrep "^} $SelectedIndex {%.*" "} $AppListTmpFile {" | cut -d"%" -f 3}
         Set $GetAppIdxCmdCmd = {egrep "^} $SelectedIndex {%.*" "} $AppListTmpFile {" | cut -d"%" -f 4}
         Set $GetAppIdxName = (GetOutput $GetAppIdxNameCmd 1 -1)
         Set $GetAppIdxIcon = (GetOutput $GetAppIdxIconCmd 1 -1)
         Set $GetAppIdxCmd = (GetOutput $GetAppIdxCmdCmd 1 -1)
         Set $GetAppIdxCmdType = (GetOutput $GetAppIdxCmdCmd 1 1)
         ChangeTitle 8 $GetAppIdxName
         ChangeTitle 10 $GetAppIdxCmd
         ChangeTitle 12 $GetAppIdxIcon
         ChangeIcon 17 $GetAppIdxIcon

         Set $Fix14 = 1

         If $GetAppIdxCmdType == {f_ToggleFvwmModule} Then
         Begin
            ChangeValue 14 3
            Set $Fix14 = 0
         End

         If $GetAppIdxCmdType == {f_ToggleFvwmFunc} Then
         Begin
            ChangeValue 14 3
            Set $Fix14 = 0
         End

         If $GetAppIdxCmdType == {f_ToggleExecWindow} Then
         Begin
            ChangeValue 14 3
            Set $Fix14 = 0
         End

         If $GetAppIdxCmdType == {Module} Then
         Begin
            ChangeValue 14 2
            Set $Fix14 = 0
         End

         # Take Widget 4 value and hide it while selecting from this list
         # use it later as entry point below
         Set $SubpListSelected = (GetValue 4)

         # Fix this if it was changed by Widget 4 List click
         If $Fix14 <> 0 Then
         Begin
            ChangeValue 14 1
         End
         ChangeValue 18 0
         ShowWidget 18

         # Stupid TextField colorset bug workaround
         ChangeColorset 25 20
      End
End

Widget 4
   Property
   Size 280 202
   Position 312 40
   Type List
   Flags NoReliefString
   Value 0
   Title {}
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
         Set $FocusOnList = {Subpanel}

         ChangeColorset 8 22
         ChangeColorset 10 22
         ChangeColorset 12 22

         # Stupid TextField colorset bug workaround
         ChangeColorset 25 22

         Set $SelectedSubpIndex = (GetValue 4)
         Set $GetSubpIdxNameCmd = {egrep "^} $SelectedSubpIndex {,.*" "} $SubpListTmpFile {" | cut -d"," -f 4}
         Set $GetSubpIdxTypeCmd = {egrep "^} $SelectedSubpIndex {,.*" "} $SubpListTmpFile {" | cut -d"," -f 5}
         Set $GetSubpIdxIconCmd = {egrep "^} $SelectedSubpIndex {,.*" "} $SubpListTmpFile {" | cut -d"," -f 6}
         Set $GetSubpIdxCmdCmd = {egrep "^} $SelectedSubpIndex {,.*" "} $SubpListTmpFile {" | cut -d"," -f 7}
         Set $GetSubpIdxName = (GetOutput $GetSubpIdxNameCmd 1 -1)
         Set $GetSubpIdxType = (GetOutput $GetSubpIdxTypeCmd 1 -1)
         Set $GetSubpIdxIcon = (GetOutput $GetSubpIdxIconCmd 1 -1)
         Set $GetSubpIdxCmd = (GetOutput $GetSubpIdxCmdCmd 1 -1)
         ChangeTitle 8 $GetSubpIdxName
         ChangeTitle 10 $GetSubpIdxCmd
         ChangeTitle 12 $GetSubpIdxIcon
         ChangeIcon 17 $GetSubpIdxIcon

         If $GetSubpIdxType == {FVWM-M} Then
         Begin
            ChangeValue 14 2
            ChangeValue 18 0
            HideWidget 18
         End
         If $GetSubpIdxType == {FVWM-F} Then
         Begin
            ChangeValue 14 3
            ChangeValue 18 0
            HideWidget 18
         End
         If $GetSubpIdxType == {OTHER} Then
         Begin
            ChangeValue 14 4
            ChangeValue 18 0
            HideWidget 18
         End
         If $GetSubpIdxType == {} Then
         Begin
            ChangeValue 14 1
            ChangeValue 18 0
            ShowWidget 18
         End
         If $GetSubpIdxType == {NOCHK} Then
         Begin
            ChangeValue 14 1
            ChangeValue 18 1
            ShowWidget 18
         End

         If (StrCopy $GetSubpIdxType 1 6) == {CHECK:} Then
         Begin
            ChangeValue 14 5
            ChangeValue 18 0
            ShowWidget 18

            ShowWidget 15
            ShowWidget 16

            ChangeTitle 16 (StrCopy $GetSubpIdxType 7 99)
         End
         Else
         Begin
            HideWidget 15
            HideWidget 16
         End

         # We are now working with subpanel list, not all apps list,
         # unselect selected on apps list.
         ChangeValue 3 0

         # Stupid TextField colorset bug workaround
         ChangeColorset 25 22
      End
End

Widget 5
   Property
   Size 40 40
   Position 132 248
   Type ItemDraw
   Flags NoReliefString Left
   Colorset 22
   Icon NsCDE/ArrowRight.xpm
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 5 2
      End
      2 :
      Begin
         If $FocusOnList == {Applications} Then
         Begin
            ChangeIcon 5 NsCDE/ArrowRightP.xpm

            If $SubpListSelected == 0 Then
            Begin
               Set $SubpListSelected = 1
            End
            Set $NewRowNo = (Add $SubpListSelected 1)

            If (GetValue 14) == 1 Then
               Set $NewAppType = {}
            If (GetValue 14) == 2 Then
               Set $NewAppType = {FVWM-M}
            If (GetValue 14) == 3 Then
               Set $NewAppType = {FVWM-F}
            If (GetValue 14) == 4 Then
               Set $NewAppType = {OTHER}
            If (GetValue 14) == 5 Then
               Set $NewAppType = {CHECK:}

            If (GetValue 18) == 1 Then
               Set $NewAppType = {NOCHK}

            If (GetValue 14) == 5 Then
            Begin
               Set $WhatToCheck = (GetTitle 16)
               Set $CleanWhatToCheckCmd = {echo "} $WhatToCheck {" | tr -d '[[:cntrl:]][[:punct:]][[:blank:]]'}
               Set $CleanWhatToCheck = (GetOutput $CleanWhatToCheckCmd 1 -1)
               Set $NewAppType = $NewAppType $CleanWhatToCheck
            End

            Set $CheckCharsTitleCmd = {echo "} (GetTitle 8) {" | egrep "(,|')"}
            Set $CheckCharsTitle = (GetOutput $CheckCharsTitleCmd 1 -1)
            If $CheckCharsTitle <> {} Then
            Begin
               Do {f_Notifier "Subpanel Manager" "Dismiss" "NsCDE/Warning.xpm" "Application name cannot contain , or ' chars."}
               Set $Perform = 0
            End
            Else
            Begin
               Set $Perform = 1
            End

            Set $StrippedAppIdxIconPathCmd = {$NSCDE_TOOLSDIR/strip_icon_path '} $GetAppIdxIcon {'}
            Set $StrippedAppIdxIconPath = (GetOutput $StrippedAppIdxIconPathCmd 1 -1)

            Set $CheckCharsIconCmd = {echo "} $StrippedAppIdxIconPath {" | egrep "(,|')"}
            Set $CheckCharsIcon = (GetOutput $CheckCharsIconCmd 1 -1)
            If $CheckCharsIcon <> {} Then
            Begin
               Do {f_Notifier "Subpanel Manager" "Dismiss" "NsCDE/Warning.xpm" "Application icon name cannot contain , or ' chars."}
               Set $Perform = 0
            End
            Else
            Begin
               Set $Perform = 1
            End

            # Important to quote command name with ' and not " because of $ and the rest ...
            Set $CheckCharsCmdCmd = {echo '} (GetTitle 10) {' | egrep "(,|')"}
            Set $CheckCharsCmd = (GetOutput $CheckCharsCmdCmd 1 -1)
            If $CheckCharsCmd <> {} Then
            Begin
               Do {f_Notifier "Subpanel Manager" "Dismiss" "NsCDE/Warning.xpm" "Application command line cannot contain , or ' chars."}
               Set $Perform = 0
            End
            Else
            Begin
               Set $Perform = 1
            End

            If $Perform == 1 Then
            Begin
               Set $NewAppToSubpCmd = {echo '} $NewRowNo {,S} $SubpanelNo {,ENTRY,} (GetTitle 8) {,} $NewAppType {,}
                                   $StrippedAppIdxIconPath {,} (GetTitle 10) {'}
               Set $NewAppToSubp = (GetOutput $NewAppToSubpCmd 1 -1)

               Set $SubpListTmpNewFileCmd = {mktemp -t tmp.XXXXXXXX.SubpNewLst.XXXXXXXX}
               Set $SubpListTmpNewFile = (GetOutput $SubpListTmpNewFileCmd 1 -1)

               Set $CreateNewListCmd = {(sed -n '1,} $SubpListSelected {p' < "} $SubpListTmpFile {"; echo '} $NewAppToSubp
                                    {'; sed -n '} $NewRowNo {,$p' < "} $SubpListTmpFile {") > "} $SubpListTmpNewFile {"}
               Set $CreateNewList = (GetOutput $CreateNewListCmd 1 -1)

               Set $SubpListMoveTmpFileCmd = {cut -d"," -f 2- < "} $SubpListTmpNewFile {" | grep -n '' | sed 's/:/,/' > "} $SubpListTmpFile {"}
               Set $SubpListMoveTmpFile = (GetOutput $SubpListMoveTmpFileCmd 1 -1)

               Set $FmtSubpListCmd = {cut -d"," -f 4 < "} $SubpListTmpFile {" | tr '\n' '|' | sed 's/|$//g'}
               Set $FmtSubpList = (GetOutput $FmtSubpListCmd 1 -1)

               # Added for Localization of existing default entries.
               Do {Exec echo '} $FmtSubpList {' > '} $LocalizedListTmpFile {'}
               Set $FmtLocalizedSubpListCmd = {$NSCDE_TOOLSDIR/usleep 250000 ; cat '} $LocalizedListTmpFile {'}
               Set $FmtLocalizedSubpList = (GetOutput $FmtLocalizedSubpListCmd 1 -1)

               ChangeTitle 4 $FmtLocalizedSubpList
               Do {Exec exec rm -f "} $SubpListTmpNewFile {"}
            End
         End

         Do {Schedule 250 SendToModule SubpanelMgr SendString 5 1 unpress}
      End

      1 :
      Begin
         ChangeIcon 5 NsCDE/ArrowRight.xpm
      End
End

Widget 6
   Property
   Size 40 40
   Position 432 248
   Type ItemDraw
   Flags NoReliefString Left
   Colorset 22
   Icon NsCDE/ArrowLeft.xpm
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 6 2
      End
      2 :
      Begin
         # Remove entries from a panel.
         If $FocusOnList == {Subpanel} Then
         Begin
            ChangeIcon 6 NsCDE/ArrowRightP.xpm

            If (GetValue 4) > 0 Then
            Begin
               Set $SubpListTmpNewFileCmd = {mktemp -t tmp.XXXXXXXX.SubpNewLst.XXXXXXXX}
               Set $SubpListTmpNewFile = (GetOutput $SubpListTmpNewFileCmd 1 -1)

               Set $RemoveAppFromSubpCmd = {egrep -v "^} (GetValue 4) {,.*" "} $SubpListTmpFile {" > "} $SubpListTmpNewFile {"}
               Set $RemoveAppFromSubp = (GetOutput $RemoveAppFromSubpCmd 1 -1)
               Set $SubpListMoveTmpFileCmd = {cut -d"," -f 2- < "} $SubpListTmpNewFile {" | grep -n '' | sed 's/:/,/' > "} $SubpListTmpFile {"}
               Set $SubpListMoveTmpFile = (GetOutput $SubpListMoveTmpFileCmd 1 -1)

               If (GetValue 14) == 5 Then
               Begin
                  ChangeTitle 16 {}
                  ChangeValue 4 0
                  ChangeValue 14 1
                  HideWidget 15
                  HideWidget 16
               End

               Set $FmtSubpListCmd = {cut -d"," -f 4 < "} $SubpListTmpFile {" | tr '\n' '|' | sed 's/|$//g'}
               Set $FmtSubpList = (GetOutput $FmtSubpListCmd 1 -1)

               # Added for Localization of existing default entries.
               Do {Exec echo '} $FmtSubpList {' > '} $LocalizedListTmpFile {'}
               Set $FmtLocalizedSubpListCmd = {$NSCDE_TOOLSDIR/usleep 250000 ; cat '} $LocalizedListTmpFile {'}
               Set $FmtLocalizedSubpList = (GetOutput $FmtLocalizedSubpListCmd 1 -1)

               ChangeTitle 4 $FmtLocalizedSubpList

               Do {Exec exec rm -f "} $SubpListTmpNewFile {"}
            End
         End

         Do {Schedule 250 SendToModule SubpanelMgr SendString 6 1 unpress}
      End

      1 :
      Begin
         ChangeIcon 6 NsCDE/ArrowLeft.xpm
      End
End

Widget 7
   Property
   Size 280 20
   Position 12 284
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   LocaleTitle {Name:}
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 8
   Property
   Size 424 24
   Position 12 308
   Type TextField
   Flags NoReliefString
   Title {}
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 9
   Property
   Size 280 20
   Position 12 346
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   LocaleTitle {Command:}
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 10
   Property
   Size 424 24
   Position 12 370
   Type TextField
   Flags NoReliefString
   Title {}
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 11
   Property
   Size 280 20
   Position 12 412
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   LocaleTitle {Icon File:}
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 12
   Property
   Size 424 24
   Position 12 438
   Type TextField
   Flags NoReliefString
   Title {}
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 13
   Property
   Size 290 20
   Position 542 280
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   LocaleTitle {Type:}
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 14
   Property
   Size 128 26
   Position 446 306
   Type PopupMenu
   Flags NoReliefString Left
   LocaleTitle {Exec Command|Fvwm Module|Fvwm Function|Other|Check For ...}
   Font "xft:::pixelsize=14"
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
         If (GetValue 14) == 5 Then
         Begin
            ShowWidget 15
            ShowWidget 16
         End
         Else
         Begin
            HideWidget 15
            HideWidget 16
         End

         # X compositor bug workaround
         If $RedrawSelf == 1 Then
         Begin
            ChangeValue 14 (GetValue 14)
         End
      End
End

Widget 15
   Property
   Size 280 20
   Position 450 346
   Type ItemDraw
   Flags NoReliefString Left Hidden
   Title {Check for this cmd:}
   Font "xft:::pixelsize=15"
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 16
   Property
   Size 140 26
   Position 450 370
   Type TextField
   Flags NoReliefString Left Hidden NoFocus
   Value 0
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 17
   Property
   Size 66 66
   Position 480 418
   Type ItemDraw
   Flags NoReliefString
   Title {}
   Icon NsCDE/Dtdeflt.m.pm
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
         Set $ARG={FilePicker }
         Set $BROWSER=(LaunchScript $ARG )
      End
End

Widget 18
   Property
   Size 280 26
   Position 12 480
   Type CheckBox
   Flags NoReliefString Left
   Value 0
   Colorset 22
   Title { Do not check for command existance}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 19
   Property
   Size 602 1
   Position 3 516
   Type Rectangle
End

Widget 20
   Property
   Size 120 26
   Position 12 532
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Apply}
   Font "xft:::pixelsize=15"
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 20 1
      End
      1 :
      Begin
         Set $SubpNewActionsPartCmd = {mktemp -t tmp.XXXXXXXX.SubpNewActP.XXXXXXXX}
         Set $SubpNewActionsPart = (GetOutput $SubpNewActionsPartCmd 1 -1)

         Set $CreateUserActionsCfgCmd = {[ ! -r "} $UserSubpanelActionsFile {" ] && touch "} $UserSubpanelActionsFile {"}
         Set $CreateUserActionsCfg = (GetOutput $CreateUserActionsCfgCmd 1 -1)

         Set $TransferRestOfTheActionsCmd = {egrep -v "^S} $SubpanelNo {," "} $UserSubpanelActionsFile {" > "} $SubpNewActionsPart {"}
         Set $TransferRestOfTheActions = (GetOutput $TransferRestOfTheActionsCmd 1 -1)

         Set $WriteActionsFileCmd = {(egrep "^S} $SubpanelNo {,(NAME|WIDTH|ENABLED),.*" "} $SubpanelActionsRead {"; cut -d"," -f 2- < "} 
                                     $SubpListTmpFile {") >> "} $SubpNewActionsPart {"}
         Set $WriteActionsFile = (GetOutput $WriteActionsFileCmd 1 -1)

         Set $BackupActionsFileCmd = {mkdir -p "$FVWM_USERDIR/tmp"; cp -f "$FVWM_USERDIR/Subpanels.actions" "$FVWM_USERDIR/tmp/Subpanels.actions.old"}
         Set $BackupActionsFile = (GetOutput $BackupActionsFileCmd 1 -1)

         Set $WriteFinalActionsFileCmd = {cat "} $SubpNewActionsPart {" > "$FVWM_USERDIR/Subpanels.actions"}
         Set $WriteFinalActionsFile = (GetOutput $WriteFinalActionsFileCmd 1 -1)

         Set $GenerateFvwmButtonsCfg2Cmd = {"$NSCDE_TOOLSDIR/generate_subpanels" -w > "$FVWM_USERDIR/Subpanels.fvwm2.fvwmgen"}
         Set $GenerateFvwmButtonsCfg3Cmd = {"$NSCDE_TOOLSDIR/generate_subpanels" -f > "$FVWM_USERDIR/Subpanels.fvwm3.fvwmgen"}
         Set $GenerateFvwmButtonsCfg2 = (GetOutput $GenerateFvwmButtonsCfg2Cmd 1 -1)
         Set $GenerateFvwmButtonsCfg3 = (GetOutput $GenerateFvwmButtonsCfg3Cmd 1 -1)

         Do {f_ReadCfg Subpanels}
         Do {Schedule 400 KillModule FvwmButtons NsCDE-Subpanel} $SubpanelNo
         Do {Schedule 1800 Exec exec $[NSCDE_TOOLSDIR]/xdowrapper}
      End
End

Widget 21
   Property
   Size 120 26
   Position 168 532
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Save}
   Font "xft:::pixelsize=15"
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 21 1
      End
      1 :
      Begin
         SendSignal 20 1
         Quit
      End
End

Widget 22
   Property
   Size 120 26
   Position 322 532
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Cancel}
   Font "xft:::pixelsize=15"
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 22 1
      End
      1 :
      Begin
         Quit
      End
End

Widget 23
   Property
   Size 120 26
   Position 476 532
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Help}
   Font "xft:::pixelsize=15"
   Colorset 22
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 23 1
      End
      1 :
      Begin
         Do {f_DisplayURL "$[gt.Subpanels Manager]" html/NsCDE-SubpanelMgr.html}
      End
End

Widget 24
   Property
   Size 460 20
   Position 12 440
   Type ItemDraw
   Flags NoReliefString Left Hidden
   Title {}
   ForeColor {Red}
   BackColor {White}
   Main
      Case message of
      SingleClic :
      Begin
      End
End

# Nasty workaround because ForeColor of the TextField
# widget is not applied and global value is used anyway.
# See end of the Init procedure for explanation.
Widget 25
   Property
   Size 40 10
   Position 10 10
   Type PushButton
   Flags NoReliefString NoFocus Hidden
   Title {XXXXXXXXXXXXXXXXXXXXXXXXXXX}
   Main
      Case message of
      # Nasty workaround because ForeColor of the TextField
      # widget is not applied and global value is used anyway.
      # See end of the Init procedure for explanation.
      1 :
      Begin
         If (LastString) == {workaround} Then
         Begin
            ChangeColorset 25 20
         End
      End
End

