#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

load ../src/gnocl.so

set menubar [gnocl::menubar]

set menu [gnocl::menu]
set check1Win [gnocl::menuItem checkButton -text "%__Check" \
      -accelerator "<Alt>h" \
      -variable check1 -command "check %w %v ::check1"]
set onOffWin [gnocl::menuItem checkButton -text "%__On Off" \
      -variable onOff -onValue on -offValue off \
      -accelerator "<control>C" -command "check %w %v ::onOff"]
$menu add $check1Win
$menu add $onOffWin
$menu add [gnocl::menuItem separator]
$menu add [gnocl::menuItem label -text "%_C_heck on" -tooltip "check on"\
      -command "$check1Win setValue 1" -accelerator "<control>h"]
$menu add [gnocl::menuItem label -text "%_Ch_eck off" -tooltip "check off"\
      -command "$check1Win setValue 0" -accelerator "<shift><control>h"]
$menu add [gnocl::menuItem label -text "%_O_nOff on" -tooltip "onOff on"\
      -command "$onOffWin setValue on"]
$menu add [gnocl::menuItem label -text "%_OnO_ff off" -tooltip "onOff off"\
      -command "$onOffWin setValue off"]

$menubar add [gnocl::menuItem label -text "%__First" -submenu $menu]

set subMenu [gnocl::menu]
$subMenu add [gnocl::menuItem label -text "%_Label _1" \
      -tooltip "label 1" -command "puts label1"]
$subMenu add [gnocl::menuItem label -text "%_Label _2" \
      -tooltip "label 2" -command "puts label2"]
$subMenu add [gnocl::menuItem label -text "%_Label _3" \
      -tooltip "label 3" -command "puts label3"]

set popup [gnocl::menu -tearoff 0]
$popup add [gnocl::menuItem label -text "%_Pop _1" -tooltip "pop 1" -command "puts pop1"]
$popup add [gnocl::menuItem label -text "%_Pop _2" -tooltip "pop 2" -command "puts pop2"]
$popup add [gnocl::menuItem label -text "%_Pop _3" -tooltip "pop 3" -command "puts pop3"]

set menu [gnocl::menu]
$menu add [gnocl::menuItem label -text "%_S_ubmenu" -submenu $subMenu]
$menu add [gnocl::menuItem checkButton -text "%__Check2" \
      -command "puts check2"]
$menu add [gnocl::menuItem label -text "%__Popup" -accelerator "<control>P" \
      -command "$popup popup"]
$menubar add [gnocl::menuItem label -text "%__Second" -submenu $menu]

set menu [gnocl::menu]
$menu add [gnocl::menuItem label -text "%_With _gif" \
      -icon "%/./nodiaminus.gif" -command {puts "with gif"}]
$menu add [gnocl::menuItem label -text "%_With _png" \
      -icon "%/./nodiaminus.png" -command {puts "with png"}]
$menu add [gnocl::menuItem label -text "%__No icon" -icon "" \
      -command {puts "no icon"}]
$menu add [gnocl::menuItem label -text "%__Stock icon" -icon "%#Save" \
      -command {puts "stock icon"}]
$menubar add [gnocl::menuItem label -text "%__Third" -submenu $menu]

proc check { win val var } {
   puts -nonewline "value is now \"$val\" == \""
   puts -nonewline [$win getValue]
   if { [string length $var] > 0 } {
      puts -nonewline "\" == \""
      puts -nonewline [set $var]
   }
   puts "\""
}

if { $argc == 1 } {
   set win [gnocl::plug [lindex $argv 0] -child $menubar]
} else {
   gnocl::app MenuTest -title "Menu Tests" -menubar $menubar \
         -statusbar [gnocl::appBar]
   # gnocl::window -child $menubar
}

gnocl::mainLoop

