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

# this is an example for the text widget
# TODO: font, foreground and background

load ../src/gnocl.so

# create submenu for menu "File" 
# with standard items "New" and "Quit" (text and icon)
set menu [gnocl::menu]
$menu add [gnocl::menuItem label -text "%#New" -command new]
$menu add [gnocl::menuItem label -text "%#Print" \
      -command {puts [$::txtID getChars 0 end]}]
$menu add [gnocl::menuItem separator]
$menu add [gnocl::menuItem label -text "%#Quit" -command exit]

# create menu "File"
set file [gnocl::menuItem label -text "File" -submenu $menu]

# create menu "Edit"
set menu [gnocl::menu -children [list \
      [gnocl::menuItem label -text "%#Cut" -command cut] \
      [gnocl::menuItem label -text "%#Copy" -command copy] \
      [gnocl::menuItem label -text "%#Paste" -command paste]]]

set edit [gnocl::menuItem label -text "Edit" -submenu $menu]

# create menu "Help" with submenu "About" (text and icon)
set help [gnocl::menuItem label -text "Help" -submenu \
   [gnocl::menu -children \
   [gnocl::menuItem label -text "%#About" -command about]]]

# create toolbar with icons "Quit" and "New"
set toolbar [gnocl::toolbar -style both]
$toolbar add item -text "Quit" -icon "%#Quit" -tooltip "Tooltip Quit" \
            -command exit
$toolbar add space
$toolbar add item -text "Cut" -icon "%#Cut" -tooltip "Tooltip new" \
      -command cut
$toolbar add item -text "Copy" -icon "%#Copy" -tooltip "Tooltip new" \
      -command copy
$toolbar add item -text "Paste" -icon "%#Paste" -tooltip "Tooltip new" \
      -command paste

# create text widget
set txtID [gnocl::text -editable 1]
# create gnome application
gnocl::app testApp -title "Test of Text Widget" \
      -menubar [gnocl::menubar -children [list $file $edit $help]] \
      -statusbar [gnocl::appBar] \
      -toolbar $toolbar \
      -contents $txtID

proc copy {}   { $::txtID copy }
proc cut {}    { $::txtID cut }
proc paste {}  { $::txtID paste }
proc new {}    { $::txtID remove 0 end }

proc about {} {
   gnocl::about -title "Text Test Application" -authors {{P.G. Baum}} \
         -version [gnocl::info version] -copyright "(c) 2001 P.G. Baum"
}

$txtID insert 0 "The quick brown fox jumps over the lazy dog." \
      -foreground blue

if { [info exists tk_patchLevel] } {
   wm withdraw .
} else {
   gnocl::mainLoop
}
