#!/usr/bin/install-menu
#
# Generates pekwm menus for all registered applications.

!include menu.h
compat="menu-1"
outputencoding="LOCALE"

genmenu="debian-menu"
rootprefix="/etc/pekwm/"
userprefix=".pekwm"
treewalk="(M)"

# formatting functions
function pwindent()=nstring(level(), "\t")
function pwquote($expr)="\"" $expr "\""

function pwit($it)=" " $it " = "
function pwlab($lb)=ifnempty($lb, " " pwquote($lb) " ")
function pwcom($cm)=ifnempty($cm, "{ Actions = \"Exec " esc($cm,"\"") " &\" } ")
function pwres($cm)=ifnempty($cm, "{ Actions = \"RestartOther " $cm "\" } ")

# Submenu = "submenu-label" {
function pwsubmenu($item,$label)=pwindent() $item " =" pwlab($label) "{\n"

# item = "opt-label" { Actions = "opt-command" }
function pwrestart($item,$label,$com)=pwindent() $item " =" pwlab($label) pwres($com) "\n"

# item = "opt-label" { Actions = "opt-command" }
function pwitem($item,$label,$com)=pwindent() $item " =" pwlab($label) pwcom($com) "\n"

supported
    x11=    pwitem("Entry", title(), $command)
    wm=    pwrestart("Entry", title(), $command)
    text=   pwitem("Entry", title(), term())
endsupported

preoutput= "# Menu config for pekwm\n\n"

# Used to ommit the topmost menu creation if there is only one
function checklevel($content)=ifeqelse(level(),"0",ifneq(entrycount(),"1",$content),$content)

startmenu= checklevel(pwsubmenu("Submenu", title()))
endmenu= checklevel(pwindent() "} \n")
