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

# example of entry widget

namespace eval gnocl {
   variable appId gnoclEntryTest
}

load ../src/gnocl.so

set box [gnocl::box -orientation vertical]
set elems {default gnome file number icon pixmap} 
foreach el $elems {
   set ${el}id [gnocl::entry -type $el -variable ${el}var]
   $box add [set ${el}id]
   if { [string compare $el default] != 0 } {
      [set ${el}id] configure -historyId $el
      [set ${el}id] loadHistory
   }
}
$box add [gnocl::label -text "try drag and drop between icon and pixmap,\nor between two instances of this program."]

$box add [gnocl::button -text "Print values" -command print]
$box add [gnocl::button -text "Save values" -command save]

$numberid configure -title "Calculate a number for the entry"
$fileid configure -title "Choose a file"

proc print {} {
   puts ""
   foreach el $::elems {
      if { [string compare $el default] != 0 } {
         [set ::${el}id] saveHistory
      }
   }
}

proc print {} {
   puts ""
   foreach el $::elems {
      puts -nonewline "$el: \""
      puts -nonewline [[set ::${el}id] getValue]
      puts -nonewline "\" == \""
      puts -nonewline [set ::${el}var]
      puts "\""
      if { [string compare $el default] != 0 } {
         [set ::${el}id] appendHistory [set ::${el}var]
      }
   }
}

if { $argc == 1 } {
   set win [gnocl::plug [lindex $argv 0] -child $box]
} else {
   set win [gnocl::window -child $box]
}

gnocl::mainLoop

