| 1 |
# FvwmScript File Editor with Help for Fvwm-Crystal |
| 2 |
# Copyright Dominique Michel <[email protected]> 2014 |
| 3 |
# Released under the GNU GPL license v3 or later |
| 4 |
|
| 5 |
# Usage: SetEnv FileEditWithHelp <file_name> |
| 6 |
# Include scripts/FileEditors/<file_name>-Help |
| 7 |
# Script scripts/FileEditors/FileEditWithHelp |
| 8 |
# |
| 9 |
# or simpler: LaunchFileWithHelp <file_name> |
| 10 |
# |
| 11 |
# where <file_name> is the name of the preeference file (must be in $FVWM_USERDIR/preferences) |
| 12 |
# A help file with name <file_name-help> must exist in the same direectory than this script. |
| 13 |
# The environmental variable is unset whn quiting the script. |
| 14 |
|
| 15 |
# $FileEditWithHelp = <file_name> |
| 16 |
|
| 17 |
# Header ̣{{{1 |
| 18 |
UseGettext {$FVWM_USERDIR/locale;fvwm-crystal-script:$FVWM_SYSTEMDIR/locale;fvwm-crystal-script:+} |
| 19 |
WindowLocaleTitle {FVWM-Crystal File Editor} |
| 20 |
|
| 21 |
WindowSize 800 400 |
| 22 |
#WindowPosition 300 300 |
| 23 |
Colorset 1 |
| 24 |
# Dont change it or the text titles will be shorted: |
| 25 |
Font "xft:$[panel_font]:pixelsize:$[panel_font_size]:style:$[panel_font_style]" |
| 26 |
|
| 27 |
# Initialisation {{{1 |
| 28 |
Init |
| 29 |
Begin |
| 30 |
Set $FDIR = (GetOutput {echo "$FVWM_USERDIR"} 1 -1) |
| 31 |
Set $PDIR = $FDIR {/preferences/} |
| 32 |
# Load file |
| 33 |
Set $mfile = $PDIR {$FileEditWithHelp} |
| 34 |
Set $cmd = {cat }$mfile{ | tr '\n' '|'} |
| 35 |
ChangeTitle 1 (GetOutput $cmd 1 -1) |
| 36 |
Set $mediad = (GetTitle 1) |
| 37 |
Set $cmd = {echo }$mfile |
| 38 |
ChangeTitle 2 (GetOutput $cmd 1 -1) |
| 39 |
End |
| 40 |
|
| 41 |
# Periodic Tasks {{{1 |
| 42 |
PeriodicTasks |
| 43 |
Begin |
| 44 |
# use a timer for flickering {{{2 |
| 45 |
If (RemainderOfDiv (GetTime) 1) == 0 Then |
| 46 |
Begin |
| 47 |
# faster if we do nothing here |
| 48 |
Do Nop |
| 49 |
End |
| 50 |
End |
| 51 |
|
| 52 |
# Quit Function {{{1 |
| 53 |
QuitFunc |
| 54 |
Begin |
| 55 |
Do {UnsetEnv FileEditWithHelp} |
| 56 |
# Do {Echo The font: }$SetFont{ is xft:}$FontName{:pixelsize=}$Size{:}$Style |
| 57 |
End |
| 58 |
|
| 59 |
# Main {{{1 |
| 60 |
Widget 1 |
| 61 |
Property |
| 62 |
Flags NoReliefString |
| 63 |
Position 130 45 |
| 64 |
Size 480 315 |
| 65 |
Type List |
| 66 |
# Font "xft:$[panel_font]:size=10:$[panel_font_style]" |
| 67 |
Title { } |
| 68 |
Main |
| 69 |
Case message of |
| 70 |
SingleClic : |
| 71 |
Begin |
| 72 |
Set $mediad = (GetTitle 1) |
| 73 |
Set $mindex = (GetValue 1) |
| 74 |
Set $cmd = {exec echo "}$mediad{"|cut -d '|' -f }$mindex |
| 75 |
Set $Mstring = (GetOutput $cmd 1 -1) |
| 76 |
Set $oldMstring = $Mstring |
| 77 |
HideWidget 14 |
| 78 |
ChangeTitle 14 $Mstring |
| 79 |
ShowWidget 14 |
| 80 |
End |
| 81 |
End |
| 82 |
|
| 83 |
# Label |
| 84 |
Widget 2 |
| 85 |
Property |
| 86 |
Flags NoReliefString Center |
| 87 |
Position 130 5 |
| 88 |
Size 465 35 |
| 89 |
Type ItemDraw |
| 90 |
Title { } |
| 91 |
Main |
| 92 |
Case message of |
| 93 |
SingleClic : |
| 94 |
Begin |
| 95 |
Do Nop |
| 96 |
End |
| 97 |
End |
| 98 |
|
| 99 |
# Label |
| 100 |
Widget 10 |
| 101 |
Property |
| 102 |
Flags NoReliefString Center |
| 103 |
Position 5 5 |
| 104 |
Size 120 35 |
| 105 |
Type ItemDraw |
| 106 |
LocaleTitle {File} |
| 107 |
Main |
| 108 |
Case message of |
| 109 |
SingleClic : |
| 110 |
Begin |
| 111 |
Do Nop |
| 112 |
End |
| 113 |
End |
| 114 |
|
| 115 |
# Launch the Help |
| 116 |
Widget 110 |
| 117 |
Property |
| 118 |
Flags NoReliefString |
| 119 |
Position 5 45 |
| 120 |
Size 120 35 |
| 121 |
Type PushButton |
| 122 |
LocaleTitle {Help} |
| 123 |
Main |
| 124 |
Case message of |
| 125 |
SingleClic : |
| 126 |
Begin |
| 127 |
Set $cmd = {echo $FileEditWithHelp} |
| 128 |
Set $HelpFile = (GetOutput $cmd 1 -1) |
| 129 |
Set $cmd = {Module FvwmForm }$HelpFile{-Dialog} |
| 130 |
Do $cmd |
| 131 |
End |
| 132 |
End |
| 133 |
|
| 134 |
# Add line |
| 135 |
Widget 12 |
| 136 |
Property |
| 137 |
Flags NoReliefString |
| 138 |
Position 625 320 |
| 139 |
Size 170 35 |
| 140 |
Type PushButton |
| 141 |
LocaleTitle {Add line} |
| 142 |
Main |
| 143 |
Case message of |
| 144 |
SingleClic : |
| 145 |
Begin |
| 146 |
Set $cmd = {echo "}$mediad{"|sed -e "s:^.*$:&}$Mstring{|:"} |
| 147 |
Set $mediad = (GetOutput $cmd 1 -1) |
| 148 |
HideWidget 1 |
| 149 |
ChangeTitle 1 $mediad |
| 150 |
ShowWidget 1 |
| 151 |
Set $oldMstring = $Mstring |
| 152 |
End |
| 153 |
End |
| 154 |
|
| 155 |
# Save media dirs |
| 156 |
Widget 13 |
| 157 |
Property |
| 158 |
Flags NoReliefString |
| 159 |
Position 625 280 |
| 160 |
Size 170 35 |
| 161 |
Type PushButton |
| 162 |
LocaleTitle {Save} |
| 163 |
Main |
| 164 |
Case message of |
| 165 |
SingleClic : |
| 166 |
Begin |
| 167 |
Set $cmd = {PipeRead "printf %s \"}$mediad{\"| tr '|' '\\n' > }$mfile{"} |
| 168 |
Do $cmd |
| 169 |
End |
| 170 |
End |
| 171 |
|
| 172 |
# Edit entry |
| 173 |
Widget 14 |
| 174 |
Property |
| 175 |
Flags NoReliefString |
| 176 |
Position 130 365 |
| 177 |
Size 480 35 |
| 178 |
Type TextField |
| 179 |
Title { } |
| 180 |
#Value 1 |
| 181 |
Main |
| 182 |
Case message of |
| 183 |
SingleClic : |
| 184 |
Begin |
| 185 |
Set $Mstring = (GetTitle 14) |
| 186 |
End |
| 187 |
1 : |
| 188 |
Begin |
| 189 |
Set $Mstring = (GetTitle 14) |
| 190 |
End |
| 191 |
End |
| 192 |
|
| 193 |
# Remove string |
| 194 |
Widget 15 |
| 195 |
Property |
| 196 |
Flags NoReliefString |
| 197 |
Position 5 360 |
| 198 |
Size 120 35 |
| 199 |
Type PushButton |
| 200 |
LocaleTitle {Remove} |
| 201 |
Main |
| 202 |
Case message of |
| 203 |
SingleClic : |
| 204 |
Begin |
| 205 |
Set $cmd = {echo "}$mediad{"|sed -e "s:}$oldMstring{|::"} |
| 206 |
Set $mediad = (GetOutput $cmd 1 -1) |
| 207 |
HideWidget 1 |
| 208 |
ChangeTitle 1 $mediad |
| 209 |
ShowWidget 1 |
| 210 |
End |
| 211 |
End |
| 212 |
|
| 213 |
# Update string |
| 214 |
Widget 16 |
| 215 |
Property |
| 216 |
Flags NoReliefString |
| 217 |
Position 625 360 |
| 218 |
Size 170 35 |
| 219 |
Type PushButton |
| 220 |
LocaleTitle {Update} |
| 221 |
Main |
| 222 |
Case message of |
| 223 |
SingleClic : |
| 224 |
Begin |
| 225 |
Set $cmd = {echo "}$mediad{"|sed -e "s:}$oldMstring{:}$Mstring{:"} |
| 226 |
# Do {Echo cmd=}$cmd |
| 227 |
Set $mediad = (GetOutput $cmd 1 -1) |
| 228 |
HideWidget 1 |
| 229 |
ChangeTitle 1 $mediad |
| 230 |
ShowWidget 1 |
| 231 |
Set $oldMstring = $Mstring |
| 232 |
End |
| 233 |
End |
| 234 |
|
| 235 |
# vim:ft=fvwm |