# Colorset-Functions
# Written by: Maciej Delmanowski <harnir@linux.net.pl>

SetEnv Colorset-Functions_Path "$[FVWM_CONFIGDIR]/colorsets"
SetEnv Colorset-Functions_Suffix ".cs"
SetEnv Colorset-Functions_Default "DarkDesktop.cs"
SetEnv Colorset-Functions_LastChoosen "$[FVWM_USERDIR]/.LastChoosenColorset"

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# This function will load last choosen colorset, if colorsets/.LastChoosen
# exists. If not, it will load default colorset - colorsets/DarkDesktop and
# save it to colorsets/.LastChoosen

DestroyFunc Colorset-LoadLast
AddToFunc Colorset-LoadLast
+ I Test (f $[Colorset-Functions_LastChoosen]) Read $[Colorset-Functions_LastChoosen]
+ I TestRc (NoMatch) Read $[Colorset-Functions_Path]/$[Colorset-Functions_Default]

DestroyFunc Colorset-Load
AddToFunc Colorset-Load
+ I Read $*
+ I Exec echo "Read $*" | sed -e 's/\ /\\ /g; s/\\ /\ /' > $[Colorset-Functions_LastChoosen]

+ I Test (f $[Colorset-Functions_Path]/$*) Read $[Colorset-Functions_Path]/$*

DestroyFunc Colorset-Save
AddToFunc Colorset-Save
+ I Exec echo "Read $[Colorset-Functions_Path]/$*" > $[Colorset-Functions_LastChoosen]

DestroyMenu /Colorsets
AddToMenu /Colorsets
+ DynamicPopupAction Function /Colorsets-generator

DestroyFunc /Colorsets-generator
AddToFunc /Colorsets-generator
+ I DestroyMenu recreate /Colorsets
+ I AddToMenu /Colorsets
+ I PipeRead 'for i in $[Colorset-Functions_Path]/*$[Colorset-Functions_Suffix]; do \
  name=$(basename "${i}" $[Colorset-Functions_Suffix]); \
  echo \"AddToMenu /Colorsets \'${name}\' Colorset-Load \'${i}\'\"; done'



