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

load ../src/gnocl.so

set mainBox [gnocl::box -orientation vertical]
set socket [gnocl::socket]
set socketBox [gnocl::box -label ""]
set message [gnocl::label]
set prev [gnocl::button -text "%#Prev" -sensitive 0 \
      -command {incr no -1; loadFile}]
set next [gnocl::button -text "%#Next" -sensitive 0 \
      -command {incr no; loadFile}]
set buttonBox [gnocl::box -buttonType 1 -orientation horizontal \
      -layout start -children [list $prev $next]]
$mainBox add [list $socketBox $message $buttonBox]

set menubar [gnocl::menubar]
set menu [gnocl::menu]
$menu add [gnocl::menuItem label -text "%#Quit" -command exit]
$menubar add [gnocl::menuItem label -text "%__File" -submenu $menu]


gnocl::app testApp -title "Test Application" -contents $mainBox \
      -menubar $menubar

# set files "test-plug.tcl test-box.tcl test-buttonBox.tcl"
set files [lsort [glob "test-*.tcl"]]
set no 0
set pid ""

proc loadFile { } {
   set file [lindex $::files $::no]
   $::socket delete
   set ::socket [gnocl::socket]
   $::socketBox add $::socket
   $::socketBox configure -label $file
   catch {exec $file [$::socket getXID] &} ::pid
   $::message configure -text $::pid
   $::prev configure -sensitive [expr {$::no > 0}]
   $::next configure -sensitive [expr {$::no < [llength $::files] - 1}]
}

loadFile

gnocl::mainLoop

