#!/home/heller/Deepwoods/HomeLibrarian/bin/LibrWish -f
#!WISHCMD -f
# Program: TkEditLibr
# Tcl version: 7.3 (Tcl/Tk/XF)
# Tk version: 3.6
# XF version: $__lastrelease$
#

global tkedifpath
#set tkeditpath [join [list TKEDITPATH {/}] {}]
set tkeditpath {/home/heller/Deepwoods/HomeLibrarian/TkEditLibr/}

# module inclusion
global env
global xfLoadPath
if {[info exists env(XF_LOAD_PATH)]} {
  if {[string first $env(XF_LOAD_PATH) /usr/local/lib/] == -1} {
    set xfLoadPath $env(XF_LOAD_PATH):$tkeditpath:/usr/local/lib/
  } {
    set xfLoadPath $tkeditpath:/usr/local/lib/
  }
} {
  set xfLoadPath $tkeditpath:/usr/local/lib/
}

global argc
global argv
global tk_version
global xfLoadInfo
global xfLoadPath
set xfLoadInfo 0
set tmpArgv ""
for {set counter 0} {$counter < $argc} {incr counter 1} {
  case [string tolower [lindex $argv $counter]] in {
    {-xfloadpath} {
      incr counter 1
      set xfLoadPath "[lindex $argv $counter]:$xfLoadPath"
    }
    {-xfstartup} {
      incr counter 1
      source [lindex $argv $counter]
    }
    {-xfbindfile} {
      incr counter 1
      set env(XF_BIND_FILE) "[lindex $argv $counter]"
    }
    {-xfcolorfile} {
      incr counter 1
      set env(XF_COLOR_FILE) "[lindex $argv $counter]"
    }
    {-xfcursorfile} {
      incr counter 1
      set env(XF_CURSOR_FILE) "[lindex $argv $counter]"
    }
    {-xffontfile} {
      incr counter 1
      set env(XF_FONT_FILE) "[lindex $argv $counter]"
    }
    {-xfloading} {
      set xfLoadInfo 1
    }
    {-xfnoloading} {
      set xfLoadInfo 0
    }
    {default} {
      lappend tmpArgv [lindex $argv $counter]
    }
  }
}
set argv $tmpArgv
set argc [llength $tmpArgv]
unset counter
unset tmpArgv


# procedure to show window .
proc ShowWindow. {args} {# xf ignore me 7

  # Window manager configurations
  global tk_version
  wm sizefrom . ""
  wm maxsize . 1024 768
  wm title . {Edit Library: (No Open File)}


  # build widget .frame0
  frame .frame0 -relief {raised} \
    -borderwidth {2}

  # build widget .frame0.menubutton1
  menubutton .frame0.menubutton1 \
    -menu {.frame0.menubutton1.m}\
    -text {File}\
    -underline {0}

  # build widget .frame0.menubutton1.m
  menu .frame0.menubutton1.m -tearoff 0
  .frame0.menubutton1.m add command\
    -command {CreateLibr}\
    -label {Create}\
    -underline {0}
  .frame0.menubutton1.m add command\
    -command {OpenLibr}\
    -label {Open}\
    -underline {0}
  .frame0.menubutton1.m add command\
    -command {CloseLibr}\
    -label {Close}\
    -state {disabled}\
    -underline {1}
  .frame0.menubutton1.m add command\
    -command {PrintLabels}\
    -label {PrintLabels}\
    -state {disabled}
  .frame0.menubutton1.m add command\
    -command {PrintCards}\
    -label {PrintCards}\
    -state {disabled}
  .frame0.menubutton1.m add command\
    -command {Exit}\
    -label {Exit}\
    -underline {1}

  # build widget .frame0.menubutton2
  menubutton .frame0.menubutton2 \
    -menu {.frame0.menubutton2.m}\
    -text {Help}\
    -underline {0}

  # build widget .frame0.menubutton2.m
  menu .frame0.menubutton2.m  -tearoff 0
  .frame0.menubutton2.m add command\
    -command {HelpProc}\
    -label {Help}\
    -underline {0}
  .frame0.menubutton2.m add command\
    -command {VersionProc}\
    -label {Version}\
    -underline {0}
  .frame0.menubutton2.m add command\
    -command {CopyingProc}\
    -label {Copying}
  .frame0.menubutton2.m add command\
    -command {WarrantyProc}\
    -label {Warranty}

  # pack widget .frame0
  pack append .frame0 \
    .frame0.menubutton1 {left frame center} \
    .frame0.menubutton2 {right frame center} 

  # build widget .editCardFrame
  frame .editCardFrame 

  # build widget .editCardFrame.editCard
  entry .editCardFrame.editCard \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .editCardFrame.editCard <Key-Return> {EditCardByKey [%W get]}

  # build widget .editCardFrame.label3
  label .editCardFrame.label3 \
    -text {Edit Card:}

  # pack widget .editCardFrame
  pack append .editCardFrame \
    .editCardFrame.label3 {left frame center} \
    .editCardFrame.editCard {left frame center expand fillx} 

  # build widget .deleteCardFrame
  frame .deleteCardFrame 

  # build widget .deleteCardFrame.deleteCard
  entry .deleteCardFrame.deleteCard \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .deleteCardFrame.deleteCard <Key-Return> {DeleteCard [%W get]}

  # build widget .deleteCardFrame.label3
  label .deleteCardFrame.label3 \
    -text {Delete Card:}

  # pack widget .deleteCardFrame
  pack append .deleteCardFrame \
    .deleteCardFrame.label3 {left frame center} \
    .deleteCardFrame.deleteCard {left frame center expand fillx} 

  # build widget .deleteByAuthorFrame
  frame .deleteByAuthorFrame 

  # build widget .deleteByAuthorFrame.deleteByAuthor
  entry .deleteByAuthorFrame.deleteByAuthor \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .deleteByAuthorFrame.deleteByAuthor <Key-Return> {DeleteByAuthor [%W get]}

  # build widget .deleteByAuthorFrame.label3
  label .deleteByAuthorFrame.label3 \
    -text {Delete by Author:}

  # pack widget .deleteByAuthorFrame
  pack append .deleteByAuthorFrame \
    .deleteByAuthorFrame.label3 {left frame center} \
    .deleteByAuthorFrame.deleteByAuthor {left frame center expand fillx} 

  # build widget .deleteByTitleFrame
  frame .deleteByTitleFrame 

  # build widget .deleteByTitleFrame.deleteByTitle
  entry .deleteByTitleFrame.deleteByTitle \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .deleteByTitleFrame.deleteByTitle <Key-Return> {DeleteByTitle [%W get]}

  # build widget .deleteByTitleFrame.label3
  label .deleteByTitleFrame.label3 \
    -text {Delete by Title:}

  # pack widget .deleteByTitleFrame
  pack append .deleteByTitleFrame \
    .deleteByTitleFrame.label3 {left frame center} \
    .deleteByTitleFrame.deleteByTitle {left frame center expand fillx} 

  # build widget .deleteBySubjectFrame
  frame .deleteBySubjectFrame 

  # build widget .deleteBySubjectFrame.deleteBySubject
  entry .deleteBySubjectFrame.deleteBySubject \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .deleteBySubjectFrame.deleteBySubject <Key-Return> {DeleteBySubject [%W get]}

  # build widget .deleteBySubjectFrame.label3
  label .deleteBySubjectFrame.label3 \
    -text {Delete by Subject:}

  # pack widget .deleteBySubjectFrame
  pack append .deleteBySubjectFrame \
    .deleteBySubjectFrame.label3 {left frame center} \
    .deleteBySubjectFrame.deleteBySubject {left frame center expand fillx} 

  # build widget .listCardsFrame
  frame .listCardsFrame 

  # build widget .listCardsFrame.label3
  label .listCardsFrame.label3 \
    -text {List Cards:}

  # build widget .listCardsFrame.listCards
  entry .listCardsFrame.listCards \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .listCardsFrame.listCards <Key-Return> {ListCards [%W get]}

  # pack widget .listCardsFrame
  pack append .listCardsFrame \
    .listCardsFrame.label3 {left frame center} \
    .listCardsFrame.listCards {left frame center expand fillx} 

  # build widget .listTitlesFrame
  frame .listTitlesFrame 

  # build widget .listTitlesFrame.label3
  label .listTitlesFrame.label3 \
    -text {List Titles:}

  # build widget .listTitlesFrame.listTitles
  entry .listTitlesFrame.listTitles \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .listTitlesFrame.listTitles <Key-Return> {ListTitles [%W get]}

  # pack widget .listTitlesFrame
  pack append .listTitlesFrame \
    .listTitlesFrame.label3 {left frame center} \
    .listTitlesFrame.listTitles {left frame center expand fillx} 

  # build widget .listAuthorsFrame
  frame .listAuthorsFrame 

  # build widget .listAuthorsFrame.label3
  label .listAuthorsFrame.label3 \
    -text {List Authors:}

  # build widget .listAuthorsFrame.listAuthors
  entry .listAuthorsFrame.listAuthors \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .listAuthorsFrame.listAuthors <Key-Return> {ListAuthors [%W get]}

  # pack widget .listAuthorsFrame
  pack append .listAuthorsFrame \
    .listAuthorsFrame.label3 {left frame center} \
    .listAuthorsFrame.listAuthors {left frame center expand fillx} 

  # build widget .listSubjectsFrame
  frame .listSubjectsFrame 

  # build widget .listSubjectsFrame.label3
  label .listSubjectsFrame.label3 \
    -text {List Subjects:}

  # build widget .listSubjectsFrame.listSubjects
  entry .listSubjectsFrame.listSubjects \
    -relief {sunken}\
    -state {disabled}
  # bindings
  bind .listSubjectsFrame.listSubjects <Key-Return> {ListSubjects [%W get]}

  # pack widget .listSubjectsFrame
  pack append .listSubjectsFrame \
    .listSubjectsFrame.label3 {left frame center} \
    .listSubjectsFrame.listSubjects {left frame center expand fillx} 

  # build widget .buttons
  frame .buttons \
    -borderwidth {2}

  # build widget .buttons.close
  button .buttons.close \
    -command {CloseLibr}\
    -state {disabled}\
    -text {Close current library}

  # build widget .buttons.create
  button .buttons.create \
    -command {CreateLibr}\
    -text {Create new Library}

  # build widget .buttons.open
  button .buttons.open \
    -command {OpenLibr}\
    -text {Open old library}

  # pack widget .buttons
  pack append .buttons \
    .buttons.create {left frame center} \
    .buttons.open {left frame center} \
    .buttons.close {left frame center} 

  # pack widget .
  pack append . \
    .frame0 {top frame center fillx} \
    .editCardFrame {top frame center fillx} \
    .deleteCardFrame {top frame center expand fillx} \
    .deleteByAuthorFrame {top frame center expand fillx} \
    .deleteByTitleFrame {top frame center expand fillx} \
    .deleteBySubjectFrame {top frame center expand fillx} \
    .listCardsFrame {top frame center expand fillx} \
    .listTitlesFrame {top frame center expand fillx} \
    .listAuthorsFrame {top frame center expand fillx} \
    .listSubjectsFrame {top frame center expand fillx} \
    .buttons {top frame center fillx} 

  if {"[info procs XFEdit]" != ""} {
    XFEditSetShowWindows
    XFMiscBindWidgetTree .xfEdit
  }

  global tk_version
  if {$tk_version >= 3.0} {
    tk_menuBar .frame0 .frame0.menubutton1 .frame0.menubutton2
  } {
    tk_menus . .frame0.menubutton1 .frame0.menubutton2
  }

  .deleteByAuthorFrame.deleteByAuthor insert end {}
  .deleteBySubjectFrame.deleteBySubject insert end {}
  .deleteByTitleFrame.deleteByTitle insert end {}
  .deleteCardFrame.deleteCard insert end {}
  .editCardFrame.editCard insert end {}
  .listAuthorsFrame.listAuthors insert end {}
  .listCardsFrame.listCards insert end {}
  .listSubjectsFrame.listSubjects insert end {}
  .listTitlesFrame.listTitles insert end {}


}


# User defined procedures


# Procedure: AlertBox
proc AlertBox { {alertBoxMessage "Alert message"} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBox
# Description: show alert box
# Arguments: {alertBoxMessage} - the text to display
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBoxFile - to open and read a file automatically
#          AlertBoxFd - to read from an already opened filedescriptor
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxFd
proc AlertBoxFd { {alertBoxInFile ""} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBoxFd
# Description: show alert box containing a filedescriptor
# Arguments: {alertBoxInFile} - a filedescriptor to read. The descriptor
#                               is closed after reading
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBox - to display a passed string
#          AlertBoxFile - to open and read a file automatically
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # check file existance
  if {"$alertBoxInFile" == ""} {
    puts stderr "No filedescriptor specified"
    return
  }

  set alertBoxMessage [read $alertBoxInFile]
  close $alertBoxInFile

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxFile
proc AlertBoxFile { {alertBoxFile ""} {alertBoxCommand ""} {alertBoxGeometry "350x150"} {alertBoxTitle "Alert box"} args} {
# xf ignore me 5
##########
# Procedure: AlertBoxFile
# Description: show alert box containing a file
# Arguments: {alertBoxFile} - filename to read
#            {alertBoxCommand} - the command to call after ok
#            {alertBoxGeometry} - the geometry for the window
#            {alertBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          AlertBox - to display a passed string
#          AlertBoxFd - to read from an already opened filedescriptor
##########
#
# global alertBox(activeBackground) - active background color
# global alertBox(activeForeground) - active foreground color
# global alertBox(after) - destroy alert box after n seconds
# global alertBox(anchor) - anchor for message box
# global alertBox(background) - background color
# global alertBox(font) - message font
# global alertBox(foreground) - foreground color
# global alertBox(justify) - justify for message box
# global alertBox(toplevelName) - the toplevel name

  global alertBox

  # check file existance
  if {"$alertBoxFile" == ""} {
    puts stderr "No filename specified"
    return
  }

  if {[catch "open $alertBoxFile r" alertBoxInFile]} {
    puts stderr "$alertBoxInFile"
    return
  }

  set alertBoxMessage [read $alertBoxInFile]
  close $alertBoxInFile

  # show alert box
  if {[llength $args] > 0} {
    eval AlertBoxInternal "\{$alertBoxMessage\}" "\{$alertBoxCommand\}" "\{$alertBoxGeometry\}" "\{$alertBoxTitle\}" $args
  } {
    AlertBoxInternal $alertBoxMessage $alertBoxCommand $alertBoxGeometry $alertBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $alertBox(toplevelName)
    tkwait window $alertBox(toplevelName)

    return $alertBox(button)
  }
}


# Procedure: AlertBoxInternal
proc AlertBoxInternal { alertBoxMessage alertBoxCommand alertBoxGeometry alertBoxTitle args} {
# xf ignore me 6
  global alertBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  if {"$alertBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$alertBox(activeBackground)\" "
  }
  if {"$alertBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$alertBox(activeForeground)\" "
  }
  if {"$alertBox(background)" != ""} {
    append tmpButtonOpt "-background \"$alertBox(background)\" "
    append tmpFrameOpt "-background \"$alertBox(background)\" "
    append tmpMessageOpt "-background \"$alertBox(background)\" "
  }
  if {"$alertBox(font)" != ""} {
    append tmpButtonOpt "-font \"$alertBox(font)\" "
    append tmpMessageOpt "-font \"$alertBox(font)\" "
  }
  if {"$alertBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$alertBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$alertBox(foreground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy $alertBox(toplevelName)}
  } {
    catch {destroy $alertBox(toplevelName)}
  }
  toplevel $alertBox(toplevelName)  -borderwidth 0
  catch "$alertBox(toplevelName) config $tmpFrameOpt"
  if {[catch "wm geometry $alertBox(toplevelName) $alertBoxGeometry"]} {
    wm geometry $alertBox(toplevelName) 350x150
  }
  wm title $alertBox(toplevelName) $alertBoxTitle
  wm maxsize $alertBox(toplevelName) 1000 1000
  wm minsize $alertBox(toplevelName) 100 100
  # end build of toplevel

  message $alertBox(toplevelName).message1  -anchor "$alertBox(anchor)"  -justify "$alertBox(justify)"  -relief raised  -text "$alertBoxMessage"
  catch "$alertBox(toplevelName).message1 config $tmpMessageOpt"

  set xfTmpWidth  [string range $alertBoxGeometry 0 [expr [string first x $alertBoxGeometry]-1]]
  if {"$xfTmpWidth" != ""} {
    # set message size
    catch "$alertBox(toplevelName).message1 configure  -width [expr $xfTmpWidth-10]"
  } {
    $alertBox(toplevelName).message1 configure  -aspect 1500
  }

  frame $alertBox(toplevelName).frame1  -borderwidth 0  -relief raised
  catch "$alertBox(toplevelName).frame1 config $tmpFrameOpt"

  set alertBoxCounter 0
  set buttonNum [llength $args]
  if {$buttonNum > 0} {
    while {$alertBoxCounter < $buttonNum} {
      button $alertBox(toplevelName).frame1.button$alertBoxCounter  -text "[lindex $args $alertBoxCounter]"  -command "
          global alertBox
          set alertBox(button) $alertBoxCounter
          if {\"\[info commands XFDestroy\]\" != \"\"} {
            catch {XFDestroy $alertBox(toplevelName)}
          } {
            catch {destroy $alertBox(toplevelName)}
          }"
      catch "$alertBox(toplevelName).frame1.button$alertBoxCounter config $tmpButtonOpt"

      pack append $alertBox(toplevelName).frame1  $alertBox(toplevelName).frame1.button$alertBoxCounter {left fillx expand}

      incr alertBoxCounter
    }
  } {
    button $alertBox(toplevelName).frame1.button0  -text "OK"  -command "
        global alertBox
        set alertBox(button) 0
        if {\"\[info commands XFDestroy\]\" != \"\"} {
          catch {XFDestroy $alertBox(toplevelName)}
        } {
          catch {destroy $alertBox(toplevelName)}
        }
        $alertBoxCommand"
    catch "$alertBox(toplevelName).frame1.button0 config $tmpButtonOpt"

    pack append $alertBox(toplevelName).frame1  $alertBox(toplevelName).frame1.button0 {left fillx expand}
  }

  # packing
  pack append $alertBox(toplevelName)  $alertBox(toplevelName).frame1 {bottom fill}  $alertBox(toplevelName).message1 {top fill expand}

  if {$alertBox(after) != 0} {
    after [expr $alertBox(after)*1000]  "catch \"$alertBox(toplevelName).frame1.button0 invoke\""
  }
}


# Procedure: CloseLibr
proc CloseLibr {} {
  global CurrentLibrary
  if {$CurrentLibrary != {}} {
    $CurrentLibrary delete
    set CurrentLibrary {}
    wm title . "Edit Library: (No Open File)"
    DisableEditor
  }
}

# Procedure: CopyingProc
proc CopyingProc {} {
  global CopyingMessage
  if {$CopyingMessage != ""} {
    AlertBoxFile $CopyingMessage "" {500x300}
  }
}

# Procedure: CreateLibr
proc CreateLibr {} {
  global CurrentLibrary
  if {$CurrentLibrary != {}} {
    if {[YesNoBox "Library file already open, close and continue?"]} {
      $CurrentLibrary delete
      set CurrentLibrary {}
      wm title . "Edit Library: (No Open File)"
      DisableEditor
    } else {
      return
    }
  }
  global inputBox
  set inputBox($inputBox(toplevelName),inputOne) {Newlibrary.libr}
  set inputBox(erase) 0
  set lfile [InputBoxOne "File to create:"]
  if {$lfile == {}} {
    return
  }
  set inputBox($inputBox(toplevelName),inputOne) {50}
  set inputBox(erase) 0
  set nfree [InputBoxOne "Initial number of free pages:"]
  if {$nfree == {}} {set nfree 0}
  set CurrentLibrary [TkvBTree $lfile ReadWrite|Create $nfree]
  if {[$CurrentLibrary openstat] == {failure}} {
    AlertBox "Error opening $lfile"
    $CurrentLibrary delete
    set CurrentLibrary {}
    return
  }
  wm title . "Edit Library: $lfile"
  EnableEditor
}

# Procedure: DeleteByAuthor
proc DeleteByAuthor {key} {
  global CurrentLibrary
  foreach a [$CurrentLibrary searchauthors $key] {
    foreach c [$CurrentLibrary readauthorlist $a] {
      set card [$CurrentLibrary readid $c]
      if {$card == {}} {continue}
      set question "Delete $c ([$card title])?"
      $card delete
      if {[YesNoBox $question]} {
	DeleteACard $c
      }
    }
  }  
}


# Procedure: DeleteBySubject
proc DeleteBySubject {key} {
  global CurrentLibrary
  foreach s [$CurrentLibrary searchsubjects $key] {
    foreach c [$CurrentLibrary readsubjectlist $s] {
      set card [$CurrentLibrary readid $c]
      if {$card == {}} {continue}
      set question "Delete $c ([$card title])?"
      $card delete
      if {[YesNoBox $question]} {
	DeleteACard $c
      }
    }
  }  
}


# Procedure: DeleteByTitle
proc DeleteByTitle {key} {
  global CurrentLibrary
  foreach t [$CurrentLibrary searchtitles $key] {
    foreach c [$CurrentLibrary readtitlelist $t] {
      set card [$CurrentLibrary readid $c]
      if {$card == {}} {continue}
      set question "Delete $c ([$card title])?"
      $card delete
      if {[YesNoBox $question]} {
	DeleteACard $c
      }
    }
  }  
}

# Procedure: DeleteCard
proc DeleteCard {key} {
  global CurrentLibrary
  set card [$CurrentLibrary readid $key]
  if {$card == {}} {
    AlertBox "No such card: $key"
    return
  }
  set question "Delete $key ([$card title])?"
  $card delete
  if {[YesNoBox $question]} {
    DeleteACard $key
  }
}

# Procedure: DeleteACard
proc DeleteACard {key} {
  global CurrentLibrary
  set card [$CurrentLibrary readid "$key"]
  if {$card == {}} {
    return
  }
  set author "[$card author]"
  set title  "[$card title]"
  set subjs   [$CurrentLibrary fetchsubjs "$key"]
  $CurrentLibrary updatetitle {} "$title" "$key"
  $CurrentLibrary updateauthor {} "$author" "$key"
  $CurrentLibrary updatesubjs {} "$subjs" "$key"
  $CurrentLibrary deleteid "$key"
} 

# Procedure: DisableEditor
proc DisableEditor {} {
  foreach e {deleteByAuthor deleteBySubject deleteByTitle deleteCard  editCard listAuthors listCards listSubjects listTitles} {
    [join [list . $e Frame. $e] {}] configure -state disabled
  }
  .buttons.close configure -state disabled
  .buttons.create configure -state normal
  .buttons.open configure -state normal
  .frame0.menubutton1.m entryconfigure Create -state normal
  .frame0.menubutton1.m entryconfigure Open -state normal
  .frame0.menubutton1.m entryconfigure Close -state disabled
  .frame0.menubutton1.m entryconfigure PrintLabels -state disabled
  .frame0.menubutton1.m entryconfigure PrintCards -state disabled
}


# Procedure: DismisEditCard
proc DismisEditCard { origcard key filehandle editcard origsubj newsubjlb} {
  $editcard author "[.edit$origcard.main.ay.author get]"
  $editcard year "[.edit$origcard.main.ay.year get]"
  $editcard description "[.edit$origcard.main.m2.m3.descr.description get 1.0 end]"
  $editcard city "[.edit$origcard.main.m2.m3.pubframe.city get]"
  $editcard publisher "[.edit$origcard.main.m2.m3.pubframe.publisher get]"
  $editcard title "[.edit$origcard.main.m2.m3.titleframe.title get]"
#  $editcard cardtype "[EditCardTypeMenuTypeFromLabel \"[.edit$origcard.main.m2.m3.typeframe.type cget -text]\"]"
  $editcard vol "[.edit$origcard.main.m2.m3.volframe.volume get]"
  set newsubj {}
  set elemns [$newsubjlb size]
  for {set i 0} {$i < $elemns} {incr i} {lappend newsubj [$newsubjlb get $i]}
  set origsubj [lsort $origsubj]
  set newsubj [lsort $newsubj]
  if {$origsubj != $newsubj || [$origcard] != [$editcard]} {
    if {[YesNoBox "Card is modified, save changes?"]} {
      UpdateCard $origcard "$key" $filehandle $editcard "$origsubj" $newsubjlb
      return
    }
  }
  catch "$origcard delete"
  catch "$editcard delete"
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .edit$origcard"
  } {
    catch "destroy .edit$origcard"
  }
}


# Procedure: DismisList
proc DismisList { handle} {
  if {"[info commands XFDestroy]" != ""} {
    catch "XFDestroy .$handle"
  } else {
    catch "destroy .$handle"
  }
}


# Procedure: EMBackwardCharacter
proc EMBackwardCharacter { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert insert-1c
  $W yview -pickplace insert
}


# Procedure: EMBackwardWord
proc EMBackwardWord { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  set cur [$W index insert]
  $W mark set insert "insert wordstart"
  if {[$W index insert] == $cur} {
    $W mark set insert insert-1c
    $W mark set insert "insert wordstart"
  }
  $W yview -pickplace insert
}


# Procedure: EMBeginFile
proc EMBeginFile { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert 1.0
  $W yview -pickplace insert
}


# Procedure: EMBeginLine
proc EMBeginLine { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert "insert linestart"
  $W yview -pickplace insert
}


# Procedure: EMCopyRegion
proc EMCopyRegion { W} {
  global EMMark
  if {$EMMark != {}} {
    if {[$W compare insert < $EMMark]} {
      set newcut [$W get insert $EMMark]
    } else {
      set newcut [$W get $EMMark insert]
    }
    global {EMCutBufferFlag}
    global {EMCutBuffer}
    if {$EMCutBufferFlag == 0} {
      set EMCutBuffer "$newcut"
      set EMCutBufferFlag 1
    } else {
      set EMCutBuffer "$EMCutBuffer$newcut"
    }
  }
}


# Procedure: EMDeleteNextChar
proc EMDeleteNextChar { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W delete insert insert+1c
  $W yview -pickplace insert
}


# Procedure: EMDeleteNextWord
proc EMDeleteNextWord { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W delete insert "insert wordend"
  $W yview -pickplace insert
}


# Procedure: EMDeletePrevChar
proc EMDeletePrevChar { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W delete insert-1c insert
  $W yview -pickplace insert
}


# Procedure: EMDeletePrevWord
proc EMDeletePrevWord { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W delete insert "insert wordstart"
  $W yview -pickplace insert
}


# Procedure: EMEndFile
proc EMEndFile { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert end
  $W yview -pickplace insert
}


# Procedure: EMEndLine
proc EMEndLine { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert "insert lineend"
  $W yview -pickplace insert
}


# Procedure: EMForwardCharacter
proc EMForwardCharacter { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert insert+1c
  $W yview -pickplace insert
}


# Procedure: EMForwardWord
proc EMForwardWord { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  set cur [$W index insert]
  $W mark set insert "insert wordend"
  if {[$W index insert] == $cur} {
    $W mark set insert insert+1c
    $W mark set insert "insert wordend"
  }
  $W yview -pickplace insert
}


# Procedure: EMGotoMark
proc EMGotoMark { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  global EMMark
  if {$EMMark != {}} {
    $W mark set insert $EMMark
    $W yview -pickplace insert
  }
}


# Procedure: EMHandleTab
proc EMHandleTab { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W insert insert \t
  $W yview -pickplace insert
}


# Procedure: EMKill
proc EMKill { W} {
  if {[$W compare insert == "insert lineend"]} {
    set newcut [$W get insert "insert lineend +1c"]
    $W delete insert "insert lineend +1c"
  } else {
    set newcut [$W get insert "insert lineend"]
    $W delete insert "insert lineend"
  }
  global {EMCutBufferFlag}
  global {EMCutBuffer}
  if {$EMCutBufferFlag == 0} {
    set EMCutBuffer "$newcut"
    set EMCutBufferFlag 1
  } else {
    set EMCutBuffer "$EMCutBuffer$newcut"
  }
  $W yview -pickplace insert
}


# Procedure: EMKillRegion
proc EMKillRegion { W} {
  global EMMark
  if {$EMMark != {}} {
    if {[$W compare insert < $EMMark]} {
      set newcut [$W get insert $EMMark]
      $W delete insert $EMMark
    } else {
      set newcut [$W get $EMMark insert]
      $W delete $EMMark insert
    }
    global {EMCutBufferFlag}
    global {EMCutBuffer}
    if {$EMCutBufferFlag == 0} {
      set EMCutBuffer "$newcut"
      set EMCutBufferFlag 1
    } else {
      set EMCutBuffer "$EMCutBuffer$newcut"
    }
  }
  $W yview -pickplace insert
}


# Procedure: EMNewLine
proc EMNewLine { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W inser insert \n
  $W yview -pickplace insert
}


# Procedure: EMNewLineAndIndent
proc EMNewLineAndIndent { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  set index [$W index "insert linestart"]
  for {set i 0} {[$W get "$index+$i c"] == " " ||  [$W get "$index+$i c"] == "\t"} {incr i} {}
  set prefix [$W get $index "$index+$i c"]
  $W insert insert "\n$prefix"  
  $W yview -pickplace insert
}


# Procedure: EMNextLine
proc EMNextLine { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert insert+1l
  $W yview -pickplace insert
}


# Procedure: EMNextPage
proc EMNextPage { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  set counter [lindex [$W config -height] 4]
  while {$counter > 0} {
    $W mark set insert insert+1l
    incr counter -1
  }
  $W yview -pickplace insert
}


# Procedure: EMNop
proc EMNop { W} {

}


# Procedure: EMOpenLine
proc EMOpenLine { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W inser insert \n
  $W mark set insert insert-1c
  $W yview -pickplace insert
}


# Procedure: EMPrevLine
proc EMPrevLine { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  $W mark set insert insert-1l
  $W yview -pickplace insert
}


# Procedure: EMPrevPage
proc EMPrevPage { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  set counter [lindex [$W config -height] 4]
  while {$counter > 0} {
    $W mark set insert insert-1l
    incr counter -1
  }
  $W yview -pickplace insert
}


# Procedure: EMPutSelection
proc EMPutSelection { W} {
  $W insert insert "[GetSelection]"
  $W yview -pickplace insert
}


# Procedure: EMRefresh
proc EMRefresh { W} {
  $W yview -pickplace insert
}


# Procedure: EMRemoveMark
proc EMRemoveMark { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  global EMMark
  set EMMark {}
}


# Procedure: EMScrollLine
proc EMScrollLine { W} {
  $W yview @0,0+1l
}


# Procedure: EMScrollLineBack
proc EMScrollLineBack { W} {
  $W yview @0,0-1l
}


# Procedure: EMSelfInsert
proc EMSelfInsert { W K} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  if {$K != ""} {
    $W inser insert $K
    $W yview -pickplace insert
  }
}


# Procedure: EMSetMark
proc EMSetMark { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  global EMMark
  set EMMark [$W index insert]
}


# Procedure: EMSwap
proc EMSwap { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  global EMMark
  if {$EMMark != {}} {
    set temp [$W index insert]
    $W mark set insert $EMMark
    set $EMMark $temp
    $W yview -pickplace insert
  }
}


# Procedure: EMTextBind
proc EMTextBind { W args} {
  bind $W <Any-Key>   {EMSelfInsert %W %A}
  bind $W <Left>      {EMBackwardCharacter %W}
  bind $W <Right>     {EMForwardCharacter %W}
  bind $W <Up>        {EMPrevLine %W}
  bind $W <Down>      {EMNextLine %W}
  bind $W <Delete>    {EMDeletePrevChar %W}
  bind $W <Control-a> {EMBeginLine %W}
  bind $W <Control-b> {EMBackwardCharacter %W}
  bind $W <Control-c> {EMNop %W}
  bind $W <Control-d> {EMDeleteNextChar %W}
  bind $W <Control-e> {EMEndLine %W}
  bind $W <Control-f> {EMForwardCharacter %W}
  bind $W <Control-g> {EMNop %W}
  bind $W <Control-h> {EMDeletePrevChar %W}
  bind $W <Control-i> {EMHandleTab %W}
  bind $W <Control-j> {EMNewLineAndIndent %W}
  bind $W <Control-k> {EMKill %W}
  bind $W <Control-l> {EMRefresh %W}
  bind $W <Control-m> {EMNewLine %W}
  bind $W <Return>    {EMNewLine %W}
  bind $W <Control-n> {EMNextLine %W}
  bind $W <Control-o> {EMOpenLine %W}
  bind $W <Control-p> {EMPrevLine %W}
  bind $W <Control-q> {EMNop %W}
  bind $W <Control-r> {EMNop %W}
  bind $W <Control-s> {EMNop %W}
  bind $W <Control-t> {EMTransposeCharacters %W}
  bind $W <Control-u> {EMNop %W}
  bind $W <Control-v> {EMNextPage %W}
  bind $W <Control-w> {EMKillRegion %W}
  bind $W <Control-x> {EMRemoveMark %W}
  bind $W <Control-y> {EMYank %W}
  bind $W <Control-z> {EMScrollLine %W}

  bind $W <Meta-a>    {EMNop %W}
  bind $W <Meta-b>    {EMBackwardWord %W}
  bind $W <Meta-c>    {EMNop %W}
  bind $W <Meta-d>    {EMDeleteNextWord %W}
  bind $W <Meta-e>    {EMNop %W}
  bind $W <Meta-f>    {EMForwardWord %W}
  bind $W <Meta-g>    {EMNop %W}
  bind $W <Meta-h>    {EMDeletePrevWord %W}
  bind $W <Meta-i>    {EMNop %W}
  bind $W <Meta-j>    {EMNop %W}
  bind $W <Meta-k>    {EMNop %W}
  bind $W <Meta-l>    {EMNop %W}
  bind $W <Meta-m>    {EMNop %W}
  bind $W <Meta-n>    {EMNop %W}
  bind $W <Meta-o>    {EMNop %W}
  bind $W <Meta-p>    {EMNop %W}
  bind $W <Meta-q>    {EMNop %W}
  bind $W <Meta-r>    {EMNop %W}
  bind $W <Meta-s>    {EMNop %W}
  bind $W <Meta-t>    {EMNop %W}
  bind $W <Meta-u>    {EMNop %W}
  bind $W <Meta-v>    {EMPrevPage %W}
  bind $W <Meta-w>    {EMCopyRegion %W}
  bind $W <Meta-x>    {EMNop %W}
  bind $W <Meta-y>    {EMNop %W}
  bind $W <Meta-z>    {EMScrollLineBack %W}

  bind $W <Meta-space> {EMSetMark %W}
  bind $W <Meta-Control-g> {EMGotoMark %W}
  bind $W <Meta-Escape> {EMSwap %W}

  bind $W <ButtonRelease-2> {EMPutSelection %W}

  foreach ibind $args {
    if {[catch [list bind $W [lindex $ibind 0] [lindex $ibind 1]] result] != 0} {
	tkerror "$result"
    }
  }
}


# Procedure: EMTransposeCharacters
proc EMTransposeCharacters { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  set temp [$W get insert insert+1c]
  $W delete insert insert+1c
  $W insert insert-1c $temp
  $W yview -pickplace insert
}


# Procedure: EMYank
proc EMYank { W} {
  global {EMCutBufferFlag}
  set {EMCutBufferFlag} {0}
  global {EMCutBuffer}
  $W inser insert "$EMCutBuffer"
  $W yview -pickplace insert
}

# Procedure: EditAAuth
proc EditAAuth { handle selection} {
  global CurrentLibrary
  set authorid "$selection"
  set ids [$CurrentLibrary readauthorlist "$authorid"]
  if {[llength $ids] == 0} {
    return
  } elseif {[llength $ids] == 1} {
    EditACard {} $ids
  } else {
    set title "List of all ids for author $authorid"
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" EditACard $lines
  }
}


# Procedure: EditACard
proc EditACard { handle selection} {
  global CurrentLibrary
  set cardid [lindex $selection 0]
  set card [$CurrentLibrary readid "$cardid"]
  EditCard $card "$cardid" $CurrentLibrary [$CurrentLibrary fetchsubjs "$cardid"]
}


# Procedure: EditASubj
proc EditASubj { handle selection} {
  global CurrentLibrary
  set subjid "$selection"
  set ids [$CurrentLibrary readsubjectlist "$subjid"]
  if {[llength $ids] == 0} {
    return
  } elseif {[llength $ids] == 1} {
    EditACard {} $ids
  } else {
    set title "List of all ids for subject $subjid"
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" EditACard $lines
  }
}


# Procedure: EditATitle
proc EditATitle { handle selection} {
  global CurrentLibrary
  set titleid "$selection"
  set ids [$CurrentLibrary readtitlelist "$titleid"]
  if {[llength $ids] == 0} {
    return
  } elseif {[llength $ids] == 1} {
    EditACard {} $ids
  } else {
    set title "List of all ids for title $titleid"
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" EditACard $lines
  }
}



# Procedure: EditCard
proc EditCard { handle key filehandle subjectlist} {

  set editcard [TkCardRecord [$handle cardtype] [$handle author]  [$handle title] [$handle publisher] [$handle city]  [$handle description] [$handle vol] [$handle year]]
  # build widget .edit$handle
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .edit$handle"
  } {
    catch "destroy .edit$handle"
  }
  toplevel .edit$handle  -relief {raised}

  # Window manager configurations
  global tk_version
  wm sizefrom .edit$handle ""
  wm maxsize .edit$handle 1000 768
  wm minsize .edit$handle 10 10
  wm title .edit$handle "[$handle title]"


  # build widget .edit$handle.main
  frame .edit$handle.main  -borderwidth {2}

  # build widget .edit$handle.main.id
  entry .edit$handle.main.id  -relief {sunken} -takefocus 0
  # bindings
  bind .edit$handle.main.id <Any-Key> {break}

  # build widget .edit$handle.main.ay
  frame .edit$handle.main.ay 

  # build widget .edit$handle.main.ay.label14
  label .edit$handle.main.ay.label114 -text {Author: }

  # build widget .edit$handle.main.ay.author
  entry .edit$handle.main.ay.author  -relief {sunken}
  # bindings
  bind .edit$handle.main.ay.author <Return> "$editcard author \"\[%W get\]\""

  # build widget .edit$handle.main.ay.label15
  label .edit$handle.main.ay.label15  -text {, Year:}

  # build widget .edit$handle.main.ay.year
  entry .edit$handle.main.ay.year  -relief {sunken}
  # bindings
  bind .edit$handle.main.ay.year <Return> "$editcard year \"\[%W get\]\""

  # pack widget .edit$handle.main.ay
  pack append .edit$handle.main.ay  \
	.edit$handle.main.ay.label114 {left frame center}  \
	.edit$handle.main.ay.author {left frame center expand fillx} \
	.edit$handle.main.ay.label15 {left frame center}  \
	.edit$handle.main.ay.year {left frame center fillx} 

  # build widget .edit$handle.main.label12
  label .edit$handle.main.label12  -text {}

  # build widget .edit$handle.main.m2
  frame .edit$handle.main.m2 

  # build widget .edit$handle.main.m2.label18
  label .edit$handle.main.m2.label18  -text {     }

  # build widget .edit$handle.main.m2.m3
  frame .edit$handle.main.m2.m3  -borderwidth {2}

  # build widget .edit$handle.main.m2.m3.titleframe
  frame .edit$handle.main.m2.m3.titleframe

  # build widget .edit$handle.main.m2.m3.titleframe.label23
  label .edit$handle.main.m2.m3.titleframe.label23 -text {Title: }

  # build widget .edit$handle.main.m2.m3.titleframe.title
  entry .edit$handle.main.m2.m3.titleframe.title  -relief {sunken}
  # bindings
  bind .edit$handle.main.m2.m3.titleframe.title <Return> "$editcard title \"\[%W get\]\""

  # pack widget .edit$handle.main.m2.m3.titleframe
  pack append .edit$handle.main.m2.m3.titleframe \
	.edit$handle.main.m2.m3.titleframe.label23 {left frame center}  \
	.edit$handle.main.m2.m3.titleframe.title {left frame center expand fillx}

  # build widget .edit$handle.main.m2.m3.typeframe
  frame .edit$handle.main.m2.m3.typeframe

  # build widget .edit$handle.main.m2.m3.typeframe.label23
  label .edit$handle.main.m2.m3.typeframe.label23 -text {Type: }

  # build widget .edit$handle.main.m2.m3.typeframe.type
  menubutton .edit$handle.main.m2.m3.typeframe.type \
	-menu .edit$handle.main.m2.m3.typeframe.type.m \
	-text {Book} \
	-justify left \
	-anchor w \
	-relief {sunken} \
	-takefocus 0
  menu .edit$handle.main.m2.m3.typeframe.type.m -tearoff 0
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu book .edit$handle.main.m2.m3.typeframe.type Book $editcard" \
	-label {Book}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu magazine .edit$handle.main.m2.m3.typeframe.type Magazine $editcard" \
	-label {Magazine}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu cd .edit$handle.main.m2.m3.typeframe.type CD $editcard" \
	-label {CD}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu audiocassette .edit$handle.main.m2.m3.typeframe.type {Audio Cassette} $editcard" \
	-label {Audio Cassette}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu album .edit$handle.main.m2.m3.typeframe.type Album $editcard" \
	-label {Album}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu laserdisk .edit$handle.main.m2.m3.typeframe.type {Laser Disk} $editcard" \
	-label {Laser Disk}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu vhsvideo .edit$handle.main.m2.m3.typeframe.type {VHS Video Tape} $editcard" \
	-label {VHS Video Tape}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu betavideo .edit$handle.main.m2.m3.typeframe.type {Beta Video Tape} $editcard" \
	-label {Beta Video Tape}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu eightmm .edit$handle.main.m2.m3.typeframe.type {8mm Video Tape} $editcard" \
	-label {8mm Video Tape}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu eighttrack .edit$handle.main.m2.m3.typeframe.type {8 Track Tape} $editcard" \
	-label {8 Track Tape}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu dat .edit$handle.main.m2.m3.typeframe.type DAT $editcard" \
	-label {DAT}
  .edit$handle.main.m2.m3.typeframe.type.m add command \
	-command "EditCardTypeMenu other .edit$handle.main.m2.m3.typeframe.type {Other} $editcard" \
	-label {Other}

  # pack widget .edit$handle.main.m2.m3.typeframe
  pack append .edit$handle.main.m2.m3.typeframe \
	.edit$handle.main.m2.m3.typeframe.label23 {left frame center}  \
	.edit$handle.main.m2.m3.typeframe.type {left frame center expand fillx}

  # build widget .edit$handle.main.m2.m3.pubframe
  frame .edit$handle.main.m2.m3.pubframe 

  # build widget .edit$handle.main.m2.m3.pubframe.label23
  label .edit$handle.main.m2.m3.pubframe.label23  -text {Published by }

  # build widget .edit$handle.main.m2.m3.pubframe.publisher
  entry .edit$handle.main.m2.m3.pubframe.publisher  -relief {sunken}
  # bindings
  bind .edit$handle.main.m2.m3.pubframe.publisher <Return> "$editcard publisher  \"\[%W get\]\""

  # build widget .edit$handle.main.m2.m3.pubframe.label24
  label .edit$handle.main.m2.m3.pubframe.label24  -text { in city: }

  # build widget .edit$handle.main.m2.m3.pubframe.city
  entry .edit$handle.main.m2.m3.pubframe.city  -relief {sunken}
  # bindings
  bind .edit$handle.main.m2.m3.pubframe.city <Return> "$editcard city \"\[%W get\]\""

  # pack widget .edit$handle.main.m2.m3.pubframe
  pack append .edit$handle.main.m2.m3.pubframe  \
	.edit$handle.main.m2.m3.pubframe.label23 {left frame center}  \
	.edit$handle.main.m2.m3.pubframe.publisher {left frame center expand fillx}  \
	.edit$handle.main.m2.m3.pubframe.label24 {left frame center}  \
	.edit$handle.main.m2.m3.pubframe.city {left frame center} 

  # build widget .edit$handle.main.m2.m3.volframe
  frame .edit$handle.main.m2.m3.volframe 

  # build widget .edit$handle.main.m2.m3.volframe.label27
  label .edit$handle.main.m2.m3.volframe.label27  -text {Volume: }

  # build widget .edit$handle.main.m2.m3.volframe.volume
  entry .edit$handle.main.m2.m3.volframe.volume  -relief {sunken}
  # bindings
  bind .edit$handle.main.m2.m3.volframe.volume <Return> "$editcard vol \"\[%W get\]\""

  # pack widget .edit$handle.main.m2.m3.volframe
  pack append .edit$handle.main.m2.m3.volframe  .edit$handle.main.m2.m3.volframe.label27 {left frame center}  .edit$handle.main.m2.m3.volframe.volume {left frame center expand fillx} 

  # build widget .edit$handle.main.m2.m3.label19
  label .edit$handle.main.m2.m3.label19 -text {Description:}

  # build widget .edit$handle.main.m2.m3.descr
  frame .edit$handle.main.m2.m3.descr  -relief {raised}

  # build widget .edit$handle.main.m2.m3.descr.scrollbar1
  scrollbar .edit$handle.main.m2.m3.descr.scrollbar1 -takefocus 0 -command ".edit$handle.main.m2.m3.descr.description yview" -relief {raised}

  # build widget .edit$handle.main.m2.m3.descr.description
  text .edit$handle.main.m2.m3.descr.description  \
	-height 20 \
	-borderwidth {2} -relief {sunken} -wrap {word} \
	-yscrollcommand ".edit$handle.main.m2.m3.descr.scrollbar1 set"
  # bindings
  bind <Meta-Return> "$editcard description \"\[%W get 1.0 end-1char\]\";break"
  bind <Alt-Return> "$editcard description \"\[%W get 1.0 end-1char\]\";break"
  bind <Control-Return> "$editcard description \"\[%W get 1.0 end-1char\]\";break"

  # pack widget .edit$handle.main.m2.m3.descr
  pack append .edit$handle.main.m2.m3.descr  .edit$handle.main.m2.m3.descr.scrollbar1 {right frame center filly}  .edit$handle.main.m2.m3.descr.description {top frame center expand fill} 

  # pack widget .edit$handle.main.m2.m3
  pack append .edit$handle.main.m2.m3  \
	.edit$handle.main.m2.m3.titleframe {top frame center fillx}  \
	.edit$handle.main.m2.m3.typeframe {top frame center fillx}  \
	.edit$handle.main.m2.m3.pubframe {top frame center fillx}  \
	.edit$handle.main.m2.m3.volframe {top frame center fillx}  \
	.edit$handle.main.m2.m3.label19 {top frame w expand}  \
	.edit$handle.main.m2.m3.descr {top frame center fill} 

  # pack widget .edit$handle.main.m2
  pack append .edit$handle.main.m2  \
	.edit$handle.main.m2.label18 {left frame center fill}  \
	.edit$handle.main.m2.m3 {left frame center expand fill} 

  # pack widget .edit$handle.main
  pack append .edit$handle.main  \
	.edit$handle.main.id {top frame center fillx}  \
	.edit$handle.main.label12 {top frame center fillx}  \
	.edit$handle.main.ay {top frame center fillx}  \
	.edit$handle.main.m2 {top frame center fillx} 

  # build widget .edit$handle.subjlabel
  label .edit$handle.subjlabel -text {Subject List:}

  # build widget .edit$handle.subjframe
  frame .edit$handle.subjframe  -relief {raised}

  # build widget .edit$handle.subjframe.frame
  frame .edit$handle.subjframe.frame 

  # build widget .edit$handle.subjframe.frame.scrollbar2
  scrollbar .edit$handle.subjframe.frame.scrollbar2 -takefocus 0  -command ".edit$handle.subjframe.frame.listbox1 yview" -relief {raised}

  # build widget .edit$handle.subjframe.frame.scrollbar3
  scrollbar .edit$handle.subjframe.frame.scrollbar3 -takefocus 0 -command ".edit$handle.subjframe.frame.listbox1 xview" -orient {horizontal} -relief {raised}

  # build widget .edit$handle.subjframe.frame.listbox1
  listbox .edit$handle.subjframe.frame.listbox1  \
	-width 36 -height 4 -selectmode single -takefocus 0\
	-relief {raised} -xscrollcommand ".edit$handle.subjframe.frame.scrollbar3 set" -yscrollcommand ".edit$handle.subjframe.frame.scrollbar2 set"


  # pack widget .edit$handle.subjframe.frame
  pack append .edit$handle.subjframe.frame  .edit$handle.subjframe.frame.scrollbar2 {right frame center filly}  .edit$handle.subjframe.frame.listbox1 {top frame center expand fill}  .edit$handle.subjframe.frame.scrollbar3 {bottom frame center fillx} 

  # build widget .edit$handle.subjframe.subjbuttons
  frame .edit$handle.subjframe.subjbuttons  -relief {raised}

  # build widget .edit$handle.subjframe.subjbuttons.label3
  label .edit$handle.subjframe.subjbuttons.label3  -text {Add Subject:}

  # build widget .edit$handle.subjframe.subjbuttons.remove
  button .edit$handle.subjframe.subjbuttons.remove -takefocus 0 -text {Remove} -command "EditCardRemoveSubject $handle .edit$handle.subjframe.frame.listbox1"

  # build widget .edit$handle.subjframe.subjbuttons.edit
  button .edit$handle.subjframe.subjbuttons.edit -takefocus 0 -text {Edit} -command "EditCardEditSubject $handle .edit$handle.subjframe.frame.listbox1 .edit$handle.subjframe.subjbuttons.subject"

  # build widget .edit$handle.subjframe.subjbuttons.subject
  entry .edit$handle.subjframe.subjbuttons.subject  -relief {sunken}
  # bindings
  bind .edit$handle.subjframe.subjbuttons.subject <Return>  "EditCardAddSubject %W $handle .edit$handle.subjframe.frame.listbox1"

  # pack widget .edit$handle.subjframe.subjbuttons
  pack append .edit$handle.subjframe.subjbuttons  .edit$handle.subjframe.subjbuttons.remove {left frame center}  .edit$handle.subjframe.subjbuttons.edit {left frame center}  .edit$handle.subjframe.subjbuttons.label3 {left frame center}  .edit$handle.subjframe.subjbuttons.subject {left frame center expand fillx} 

  # pack widget .edit$handle.subjframe
  pack append .edit$handle.subjframe  .edit$handle.subjframe.frame {top frame center fill}  .edit$handle.subjframe.subjbuttons {top frame center fill} 

  # build widget .edit$handle.buttons
  frame .edit$handle.buttons  -borderwidth {2}

  # build widget .edit$handle.buttons.dismis
  button .edit$handle.buttons.dismis  -takefocus 0\
	-text {Dismis}  \
	-command "DismisEditCard $handle \"$key\" $filehandle $editcard \"$subjectlist\" .edit$handle.subjframe.frame.listbox1"

  # build widget .edit$handle.buttons.update
  button .edit$handle.buttons.update -takefocus 0\
    -text {Update}  -command "UpdateCard $handle \"$key\" $filehandle $editcard \"$subjectlist\" .edit$handle.subjframe.frame.listbox1"

  # build widget .edit$handle.buttons.help
  button .edit$handle.buttons.help  -takefocus 0 -text {Help}  -command {HelpEditCard}

  # pack widget .edit$handle.buttons
  pack append .edit$handle.buttons  .edit$handle.buttons.dismis {left frame center expand fillx}  .edit$handle.buttons.update {left frame center expand fillx}  .edit$handle.buttons.help {left frame center expand fillx} 

  # pack widget .edit$handle
  pack append .edit$handle  \
	.edit$handle.main {top frame center fill}  \
	.edit$handle.subjlabel {top frame w expand}  \
	.edit$handle.subjframe {top frame center fill}  \
	.edit$handle.buttons {top frame center fill} 

  .edit$handle.main.ay.author insert end "[$handle author]"
  .edit$handle.main.ay.year insert end "[$handle year]"
  .edit$handle.main.id insert end "$key"
  .edit$handle.main.m2.m3.descr.description insert end "[$handle description]"
  .edit$handle.main.m2.m3.pubframe.city insert end "[$handle city]"
  .edit$handle.main.m2.m3.pubframe.publisher insert end "[$handle publisher]"
  .edit$handle.main.m2.m3.titleframe.title insert end "[$handle title]"
  .edit$handle.main.m2.m3.typeframe.type configure -text "[EditCardTypeMenuLabelFromType [$handle cardtype]]"
  .edit$handle.main.m2.m3.volframe.volume insert end "[$handle vol]"
  .edit$handle.subjframe.subjbuttons.subject insert end {}
  foreach s $subjectlist {
    .edit$handle.subjframe.frame.listbox1 insert end "$s"
  }
  focus .edit$handle.main.ay.author
}

# Procedure EditCardTypeMenu
proc EditCardTypeMenu {newvalue mbut mblabel cardhandle} {
  $cardhandle cardtype $newvalue
  $mbut configure -text "$mblabel"
}

# Procedure EditCardTypeMenuTypeFromLabel
proc EditCardTypeMenuTypeFromLabel {label} {
#  puts stderr "*** EditCardTypeMenuTypeFromLabel: label = \"$label\""
  switch -exact "$label" {
    Book {return book}
    Magazine {return magazine}
    CD {return cd}
    {Audio Cassette} {return audiocassette}
    Album {return album}
    {Laser Disk} {return laserdisk}
    {VHS Video Tape} {return vhsvideo}
    {Beta Video Tape} {return betavideo}
    {8mm Video Tape} {return eightmm}
    {8 Track Tape} {return eighttrack}
    DAT {return dat}
    Other {return other}
  }
  return other
}

# Procedure EditCardTypeMenuLabelFromType
proc EditCardTypeMenuLabelFromType {type} {
  set type [string tolower $type]
#  puts stderr "*** EditCardTypeMenuLabelFromType: \"$type\""
  switch -exact -- "$type" {
    book {return Book}
    magazine {return Magazine}
    cd {return CD}
    AudioCassette {return {Audio Cassete}} 
    album {retrun Album}
    laserdisk {return {Laser Disk}}
    vhsvideo {return {VHS Video Tape}}
    betavideo {return {Beta Video Tape}}
    eightmm {return {8mm Video Tape}}
    eighttrack {return {8 Track Tape}}
    dat {return DAT}
    other {return Other}
  }
  return Book
}

# Procedure: EditCardAddSubject
proc EditCardAddSubject { entry origcard lb} {
  set subj "[$entry get]"
  if {$subj != {}} {$lb insert end "$subj"}
}

# Procedure: EditCardByKey
proc EditCardByKey {key} {
  global CurrentLibrary
  set card [$CurrentLibrary readid "$key"]
  if {$card == {}} {
    if {[YesNoBox "Card $key does not exist, create it?"]} {
      set card [TkCardRecord]
      $CurrentLibrary insertid "$key" $card
    } else {
      return
    }
  }
  EditACard $card $key
}

# Procedure: EditCardEditSubject
proc EditCardEditSubject {origcard lb entry} {
  if {[selection own] == "$lb"} {
    set selected [$lb curselection]
    set selection [$lb get [lindex $selected 0]]
    $lb delete [lindex $selected 0]
    $entry delete 0 end
    $entry insert end "$selection"
  }
}


# Procedure: EditCardRemoveSubject
proc EditCardRemoveSubject { origcard lb} {
  if {[selection own] == "$lb"} {
    set selected [$lb curselection]
    $lb delete [lindex $selected 0]
  }
}


# Procedure: EnableEditor
proc EnableEditor {} {
  foreach e {deleteByAuthor deleteBySubject deleteByTitle deleteCard  editCard listAuthors listCards listSubjects listTitles} {
    [join [list . $e Frame. $e] {}] configure -state normal
  }
  .buttons.close configure -state normal
  .buttons.create configure -state disabled
  .buttons.open configure -state disabled
  .frame0.menubutton1.m entryconfigure Create -state disabled
  .frame0.menubutton1.m entryconfigure Open -state disabled
  .frame0.menubutton1.m entryconfigure Close -state normal
  .frame0.menubutton1.m entryconfigure PrintLabels -state normal
  .frame0.menubutton1.m entryconfigure PrintCards -state normal
}


# Procedure: Exit
proc Exit {} {
  if {[YesNoBox "Really Exit?"]} {
    global {CurrentLibrary}
    if {$CurrentLibrary != {}} {
      $CurrentLibrary delete
    }
    exit
  }
}

# Procedure: FindFileFromPath
proc FindFileFromPath { basename} {
  global xfLoadPath
  set loadpathlist [split $xfLoadPath ":"]
  foreach i $loadpathlist {
    set testfile [join [list $i $basename] ""]
    if {[file exists $testfile]} {
      return $testfile
    }
  }
  return {}
}


global fsBox
set fsBox(activeBackground) ""
set fsBox(activeForeground) ""
set fsBox(background) ""
set fsBox(font) ""
set fsBox(foreground) ""
set fsBox(scrollActiveForeground) ""
set fsBox(scrollBackground) ""
set fsBox(scrollForeground) ""
set fsBox(scrollSide) left
set fsBox(showPixmap) 0
set fsBox(name) ""
set fsBox(path) [pwd]
set fsBox(pattern) *
set fsBox(typeMask) Regular
set fsBox(button) 0
set fsBox(extensions) 0
set fsBox(internalPath) [pwd]

proc FSBox {{fsBoxMessage "Select file:"} {fsBoxFileName ""} {fsBoxActionOk ""} {fsBoxActionCancel ""}} {# xf ignore me 5
##########
# Procedure: FSBox
# Description: show file selector box
# Arguments: fsBoxMessage - the text to display
#            fsBoxFileName - a file name that should be selected
#            fsBoxActionOk - the action that should be performed on ok
#            fsBoxActionCancel - the action that should be performed on cancel
# Returns: the filename that was selected, or nothing
# Sideeffects: none
##########
# 
# global fsBox(activeBackground) - active background color
# global fsBox(activeForeground) - active foreground color
# global fsBox(background) - background color
# global fsBox(font) - text font
# global fsBox(foreground) - foreground color
# global fsBox(extensions) - scan directory for extensions
# global fsBox(scrollActiveForeground) - scrollbar active background color
# global fsBox(scrollBackground) - scrollbar background color
# global fsBox(scrollForeground) - scrollbar foreground color
# global fsBox(scrollSide) - side where scrollbar is located

  global fsBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScaleOpt ""
  set tmpScrollOpt ""
  if {"$fsBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$fsBox(activeBackground)\" "
  }
  if {"$fsBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$fsBox(activeForeground)\" "
  }
  if {"$fsBox(background)" != ""} {
    append tmpButtonOpt "-background \"$fsBox(background)\" "
    append tmpFrameOpt "-background \"$fsBox(background)\" "
    append tmpMessageOpt "-background \"$fsBox(background)\" "
  }
  if {"$fsBox(font)" != ""} {
    append tmpButtonOpt "-font \"$fsBox(font)\" "
    append tmpMessageOpt "-font \"$fsBox(font)\" "
  }
  if {"$fsBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$fsBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$fsBox(foreground)\" "
  }
  if {"$fsBox(scrollActiveForeground)" != ""} {
    append tmpScrollOpt "-activeforeground \"$fsBox(scrollActiveForeground)\" "
  }
  if {"$fsBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$fsBox(scrollBackground)\" "
  }
  if {"$fsBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$fsBox(scrollForeground)\" "
  }

  if {[file exists [file tail $fsBoxFileName]] &&
      [IsAFile [file tail $fsBoxFileName]]} {
    set fsBox(name) [file tail $fsBoxFileName]
  } {
    set fsBox(name) ""
  }
  if {[file exists $fsBoxFileName] && [IsADir $fsBoxFileName]} {
    set fsBox(path) $fsBoxFileName
  } {
    if {"[file rootname $fsBoxFileName]" != "."} {
      set fsBox(path) [file rootname $fsBoxFileName]
    }
  }
  if {$fsBox(showPixmap)} {
    set fsBox(path) [string trimleft $fsBox(path) @]
  }
  if {"$fsBox(path)" != "" && [file exists $fsBox(path)] &&
      [IsADir $fsBox(path)]} {
    set fsBox(internalPath) $fsBox(path)
  } {
    if {"$fsBox(internalPath)" == "" ||
        ![file exists $fsBox(internalPath)]} {
      set fsBox(internalPath) [pwd]
    }
  }
  # build widget structure

  # build widget .fsbox
  catch "destroy .fsbox"

  toplevel .fsbox
  catch ".fsBox config $tmpFrameOpt"
  # Window manager configurations
  global tk_version
  wm sizefrom .fsbox program
  wm maxsize .fsbox 1000 1000
  wm minsize .fsbox 100 100
  wm title .fsbox {File Select Box}


  # build widget .fsbox.filter
  entry .fsbox.filter -relief {sunken}
  catch ".fsbox.filter config $tmpMessageOpt"

  # build widget .fsbox.selection
  entry .fsbox.selection -relief {sunken}
  catch ".fsbox.selection config $tmpMessageOpt"

  # build widget .fsbox.frame3
  frame .fsbox.frame3 -relief {raised}
  catch ".fsbox.frame3 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7
  frame .fsbox.frame3.frame7 -borderwidth {2}
  catch ".fsbox.frame3.frame7 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0
  frame .fsbox.frame3.frame7.frame0 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1
  frame .fsbox.frame3.frame7.frame0.frame1 
  catch ".fsbox.frame3.frame7.frame0.frame1 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame3
  frame .fsbox.frame3.frame7.frame0.frame1.frame3 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame3 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8
  listbox .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 \
    -width 20 -height 10 \
    -relief {sunken}\
    -selectmode single\
    -xscrollcommand {.fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 set}\
    -yscrollcommand {.fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 set}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame1.frame3
  pack append .fsbox.frame3.frame7.frame0.frame1.frame3 \
    .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 {left frame center expand fill} 

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame4
  frame .fsbox.frame3.frame7.frame0.frame1.frame4 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame4 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9
  scrollbar .fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 \
    -command {.fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 yview}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame1.frame4
  pack append .fsbox.frame3.frame7.frame0.frame1.frame4 \
    .fsbox.frame3.frame7.frame0.frame1.frame4.scrollbar9 {top frame center expand filly} 

  # pack widget .fsbox.frame3.frame7.frame0.frame1
  pack append .fsbox.frame3.frame7.frame0.frame1 \
    .fsbox.frame3.frame7.frame0.frame1.frame3 {left frame center expand fill} \
    .fsbox.frame3.frame7.frame0.frame1.frame4 {right frame center filly} 

  # build widget .fsbox.frame3.frame7.frame0.frame2
  frame .fsbox.frame3.frame7.frame0.frame2 -borderwidth {1}
  catch ".fsbox.frame3.frame7.frame0.frame2 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame5
  frame .fsbox.frame3.frame7.frame0.frame2.frame5  -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame5 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10
  scrollbar .fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 \
    -command {.fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 xview}\
    -orient {horizontal}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame2.frame5
  pack append .fsbox.frame3.frame7.frame0.frame2.frame5 \
    .fsbox.frame3.frame7.frame0.frame2.frame5.scrollbar10 {left frame center expand fillx} 

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame6
  frame .fsbox.frame3.frame7.frame0.frame2.frame6 -borderwidth {2}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame6 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame7.frame0.frame2.frame6.frame11
  frame .fsbox.frame3.frame7.frame0.frame2.frame6.frame11 \
    -borderwidth {2}\
    -height {13}\
    -width {16}
  catch ".fsbox.frame3.frame7.frame0.frame2.frame6.frame11 config $tmpFrameOpt"

  # pack widget .fsbox.frame3.frame7.frame0.frame2.frame6
  pack append .fsbox.frame3.frame7.frame0.frame2.frame6 \
    .fsbox.frame3.frame7.frame0.frame2.frame6.frame11 {top frame center expand fill} 

  # pack widget .fsbox.frame3.frame7.frame0.frame2
  pack append .fsbox.frame3.frame7.frame0.frame2 \
    .fsbox.frame3.frame7.frame0.frame2.frame5 {left frame center expand fill} \
    .fsbox.frame3.frame7.frame0.frame2.frame6 {right frame center filly} 

  # pack widget .fsbox.frame3.frame7.frame0
  pack append .fsbox.frame3.frame7.frame0 \
    .fsbox.frame3.frame7.frame0.frame1 {top frame center expand fill} \
    .fsbox.frame3.frame7.frame0.frame2 {bottom frame center fillx} 

  # build widget .fsbox.frame3.frame7.label9
  label .fsbox.frame3.frame7.label9 \
    -text {Directories:}
  catch ".fsbox.frame3.frame7.label9 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame7
  pack append .fsbox.frame3.frame7 \
    .fsbox.frame3.frame7.label9 {top frame w} \
    .fsbox.frame3.frame7.frame0 {top frame center expand fill} 

  # build widget .fsbox.frame3.frame8
  frame .fsbox.frame3.frame8 -borderwidth {2}
  catch ".fsbox.frame3.frame8 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0
  frame .fsbox.frame3.frame8.frame0 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1
  frame .fsbox.frame3.frame8.frame0.frame1 
  catch ".fsbox.frame3.frame8.frame0.frame1 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame3
  frame .fsbox.frame3.frame8.frame0.frame1.frame3 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame3 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8
  listbox .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 \
    -width 20 -height 10 \
    -relief {sunken}\
    -selectmode single \
    -xscrollcommand {.fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 set}\
    -yscrollcommand {.fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 set}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame1.frame3
  pack append .fsbox.frame3.frame8.frame0.frame1.frame3 \
    .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 {left frame center expand fill} 

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame4
  frame .fsbox.frame3.frame8.frame0.frame1.frame4 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame4 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9
  scrollbar .fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 \
    -command {.fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 yview}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame1.frame4
  pack append .fsbox.frame3.frame8.frame0.frame1.frame4 \
    .fsbox.frame3.frame8.frame0.frame1.frame4.scrollbar9 {top frame center expand filly} 

  # pack widget .fsbox.frame3.frame8.frame0.frame1
  pack append .fsbox.frame3.frame8.frame0.frame1 \
    .fsbox.frame3.frame8.frame0.frame1.frame3 {left frame center expand fill} \
    .fsbox.frame3.frame8.frame0.frame1.frame4 {right frame center filly} 

  # build widget .fsbox.frame3.frame8.frame0.frame2
  frame .fsbox.frame3.frame8.frame0.frame2 -borderwidth {1}
  catch ".fsbox.frame3.frame8.frame0.frame2 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame5
  frame .fsbox.frame3.frame8.frame0.frame2.frame5 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame5 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10
  scrollbar .fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 \
    -command {.fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 xview}\
    -orient {horizontal}\
    -relief {sunken}\
    -width {13}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 config $tmpScrollOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame2.frame5
  pack append .fsbox.frame3.frame8.frame0.frame2.frame5 \
    .fsbox.frame3.frame8.frame0.frame2.frame5.scrollbar10 {left frame center expand fillx} 

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame6
  frame .fsbox.frame3.frame8.frame0.frame2.frame6 -borderwidth {2}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame6 config $tmpFrameOpt"

  # build widget .fsbox.frame3.frame8.frame0.frame2.frame6.frame11
  frame .fsbox.frame3.frame8.frame0.frame2.frame6.frame11 \
    -borderwidth {2}\
    -height {13}\
    -width {16}
  catch ".fsbox.frame3.frame8.frame0.frame2.frame6.frame11 config $tmpFrameOpt"

  # pack widget .fsbox.frame3.frame8.frame0.frame2.frame6
  pack append .fsbox.frame3.frame8.frame0.frame2.frame6 \
    .fsbox.frame3.frame8.frame0.frame2.frame6.frame11 {top frame center expand fill} 

  # pack widget .fsbox.frame3.frame8.frame0.frame2
  pack append .fsbox.frame3.frame8.frame0.frame2 \
    .fsbox.frame3.frame8.frame0.frame2.frame5 {left frame center expand fill} \
    .fsbox.frame3.frame8.frame0.frame2.frame6 {right frame center filly} 

  # pack widget .fsbox.frame3.frame8.frame0
  pack append .fsbox.frame3.frame8.frame0 \
    .fsbox.frame3.frame8.frame0.frame1 {top frame center expand fill} \
    .fsbox.frame3.frame8.frame0.frame2 {bottom frame center fillx} 

  # build widget .fsbox.frame3.frame8.label10
  label .fsbox.frame3.frame8.label10 -text {Files:}
  catch ".fsbox.frame3.frame8.label10 config $tmpMessageOpt"

  # pack widget .fsbox.frame3.frame8
  pack append .fsbox.frame3.frame8 \
    .fsbox.frame3.frame8.label10 {top frame w} \
    .fsbox.frame3.frame8.frame0 {top frame center expand fill} 

  if {$fsBox(showPixmap)} {
    # build widget .fsbox.frame3.frame9
    frame .fsbox.frame3.frame9 -borderwidth {2}
    catch ".fsbox.frame3.frame9 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0
    frame .fsbox.frame3.frame9.frame0 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1
    frame .fsbox.frame3.frame9.frame0.frame1 
    catch ".fsbox.frame3.frame9.frame0.frame1 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame3
    frame .fsbox.frame3.frame9.frame0.frame1.frame3 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame3 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame3.canvas
    canvas .fsbox.frame3.frame9.frame0.frame1.frame3.canvas \
      -confine {true} \
      -width {100} \
      -relief {sunken}\
      -borderwidth 2 \
      -scrollregion {0c 0c 20c 20c} \
      -xscrollcommand {.fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 set}\
      -yscrollcommand {.fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 set}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame3.canvas config $tmpFrameOpt"
    .fsbox.frame3.frame9.frame0.frame1.frame3.canvas addtag currentBitmap withtag [.fsbox.frame3.frame9.frame0.frame1.frame3.canvas create bitmap 5 5 -anchor nw]

    # pack widget .fsbox.frame3.frame9.frame0.frame1.frame3
    pack append .fsbox.frame3.frame9.frame0.frame1.frame3 \
      .fsbox.frame3.frame9.frame0.frame1.frame3.canvas {left frame center expand fill} 

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame4
    frame .fsbox.frame3.frame9.frame0.frame1.frame4 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame4 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9
    scrollbar .fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 \
      -command {.fsbox.frame3.frame9.frame0.frame1.frame3.canvas yview}\
      -relief {sunken}\
      -width {13}
    catch ".fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 config $tmpScrollOpt"

    # pack widget .fsbox.frame3.frame9.frame0.frame1.frame4
    pack append .fsbox.frame3.frame9.frame0.frame1.frame4 \
      .fsbox.frame3.frame9.frame0.frame1.frame4.scrollbar9 {top frame center expand filly} 

    # pack widget .fsbox.frame3.frame9.frame0.frame1
    pack append .fsbox.frame3.frame9.frame0.frame1 \
      .fsbox.frame3.frame9.frame0.frame1.frame3 {left frame center expand fill} \
      .fsbox.frame3.frame9.frame0.frame1.frame4 {right frame center filly} 

    # build widget .fsbox.frame3.frame9.frame0.frame2
    frame .fsbox.frame3.frame9.frame0.frame2 -borderwidth {1}
    catch ".fsbox.frame3.frame9.frame0.frame2 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame5
    frame .fsbox.frame3.frame9.frame0.frame2.frame5 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame5 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10
    scrollbar .fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 \
      -command {.fsbox.frame3.frame9.frame0.frame1.frame3.canvas xview}\
      -orient {horizontal}\
      -relief {sunken}\
      -width {13}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 config $tmpScrollOpt"

    # pack widget .fsbox.frame3.frame9.frame0.frame2.frame5
    pack append .fsbox.frame3.frame9.frame0.frame2.frame5 \
      .fsbox.frame3.frame9.frame0.frame2.frame5.scrollbar10 {left frame center expand fillx} 

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame6
    frame .fsbox.frame3.frame9.frame0.frame2.frame6 -borderwidth {2}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame6 config $tmpFrameOpt"

    # build widget .fsbox.frame3.frame9.frame0.frame2.frame6.frame11
    frame .fsbox.frame3.frame9.frame0.frame2.frame6.frame11 \
      -borderwidth {2}\
      -height {13}\
      -width {16}
    catch ".fsbox.frame3.frame9.frame0.frame2.frame6.frame11 config $tmpFrameOpt"

    # pack widget .fsbox.frame3.frame9.frame0.frame2.frame6
    pack append .fsbox.frame3.frame9.frame0.frame2.frame6 \
      .fsbox.frame3.frame9.frame0.frame2.frame6.frame11 {top frame center expand fill} 

    # pack widget .fsbox.frame3.frame9.frame0.frame2
    pack append .fsbox.frame3.frame9.frame0.frame2 \
      .fsbox.frame3.frame9.frame0.frame2.frame5 {left frame center expand fill} \
      .fsbox.frame3.frame9.frame0.frame2.frame6 {right frame center filly} 

    # pack widget .fsbox.frame3.frame9.frame0
    pack append .fsbox.frame3.frame9.frame0 \
      .fsbox.frame3.frame9.frame0.frame1 {top frame center expand fill} \
      .fsbox.frame3.frame9.frame0.frame2 {bottom frame center fillx} 

    # build widget .fsbox.frame3.frame9.label10
    label .fsbox.frame3.frame9.label10 -text {Pixmap:}
    catch ".fsbox.frame3.frame9.label10 config $tmpMessageOpt"

    # pack widget .fsbox.frame3.frame9
    pack append .fsbox.frame3.frame9 \
      .fsbox.frame3.frame9.label10 {top frame w} \
      .fsbox.frame3.frame9.frame0 {top frame center expand fill} 

    # pack widget .fsbox.frame3
    pack append .fsbox.frame3 \
      .fsbox.frame3.frame7 {left frame center expand fill} \
      .fsbox.frame3.frame8 {left frame center expand fill} \
      .fsbox.frame3.frame9 {right frame center expand fill} 
  } else {
    # pack widget .fsbox.frame3
    pack append .fsbox.frame3 \
      .fsbox.frame3.frame7 {left frame center expand fill} \
      .fsbox.frame3.frame8 {right frame center expand fill} 
  }

  # build widget .fsbox.buttons
  frame .fsbox.buttons -relief {raised}
  catch ".fsbox.buttons config $tmpFrameOpt"

  # build widget .fsbox.buttons.filter
  button .fsbox.buttons.filter -text {Filter} -command {FSBoxFilter .fsbox}
  catch ".fsbox.buttons.filter config $tmpButtonOpt"

  # build widget .fsbox.buttons.ok
  button .fsbox.buttons.ok -text {OK} -command {FSBoxOk .fsbox}
  catch ".fsbox.buttons.ok config $tmpButtonOpt"

  # build widget .fsbox.buttons.cancel
  button .fsbox.buttons.cancel -text {Cancel} -command {FSBoxCancel .fsbox}
  catch ".fsbox.buttons.cancel config $tmpButtonOpt"

  # build widget .fsbox.buttons.help
  button .fsbox.buttons.help -text {Help} -command {FSBoxHelp .fsbox}
  catch ".fsbox.buttons.help config $tmpButtonOpt"

  # pack widget .fsbox.buttons
  pack append .fsbox.buttons \
    .fsbox.buttons.filter {left frame center expand} \
    .fsbox.buttons.ok {left frame center expand} \
    .fsbox.buttons.cancel {left frame center expand} \
    .fsbox.buttons.help {right frame center expand} 

  # build widget .fsbox.label1
  label .fsbox.label1 -text {Filter:}
  catch ".fsbox.label1 config $tmpMessageOpt"

  # build widget .fsbox.label4
  label .fsbox.label4 -text {Selection:}
  catch ".fsbox.label4 config $tmpMessageOpt"

  # pack widget .fsbox
  pack append .fsbox \
    .fsbox.label1 {top frame w} \
    .fsbox.filter {top frame center expand fillx} \
    .fsbox.frame3 {top frame center expand fill} \
    .fsbox.label4 {top frame w expand} \
    .fsbox.selection {top frame center expand fillx} \
    .fsbox.buttons {top frame center expand fill} 

  .fsbox.filter insert end "$fsBox(internalPath)/$fsBox(pattern)"

  FSBoxFilter .fsbox
  bindtags .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 {Listbox .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8}
  bind .fsbox.frame3.frame7.frame0.frame1.frame3.listbox8 <ButtonRelease-1> {FSBoxSingle1Directories .fsbox %W}
  bindtags .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 {Listbox .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8}
  bind .fsbox.frame3.frame8.frame0.frame1.frame3.listbox8 <ButtonRelease-1> {FSBoxSingle1Files .fsbox %W}

  bind .fsbox.filter <Return> {FSBoxFilter .fsbox;break}
  bind .fsbox.selection <Return> {.fsbox.buttons.ok invoke;break}

# end of widget tree

  update idletask
  grab .fsbox
  tkwait window .fsbox
  if {"[string trim $fsBox(path)]" != "" ||
      "[string trim $fsBox(name)]" != ""} {
    if {"[string trimleft [string trim $fsBox(name)] /]" == ""} {
      return [string trimright [string trim $fsBox(path)] /]
    } {
      return [string trimright [string trim $fsBox(path)] /]/[string trimleft [string trim $fsBox(name)] /]
    }
  }


}

proc FSBoxFilter {toplevel} {
  global fsBox
  set filter "[$toplevel.filter get]"
  set fsBox(internalPath) [file dirname $filter]
  set fsBox(pattern) [file tail $filter]
  set files "[lsort [glob -nocomplain -- $filter]]"
  $toplevel.frame3.frame7.frame0.frame1.frame3.listbox8 delete 0 end
  $toplevel.frame3.frame8.frame0.frame1.frame3.listbox8 delete 0 end
  foreach f "$files" {
    set tail "[file tail $f]"
    set isdir "[file isdir $f]"
    if {$isdir} {
      if {$fsBox(typeMask) != "Regular"} {
	$toplevel.frame3.frame8.frame0.frame1.frame3.listbox8 insert end "$tail"
      }
    } else {
      if {$fsBox(typeMask) != "Directory"} {
	$toplevel.frame3.frame8.frame0.frame1.frame3.listbox8 insert end "$tail"
      }
    }
  }
  set dirs "$fsBox(internalPath)/.. [lsort [glob -nocomplain -- $fsBox(internalPath)/*]]"
  foreach d "$dirs" {
    set tail "[file tail $d]"
    set isdir "[file isdir $d]"
    if {$isdir} {
      $toplevel.frame3.frame7.frame0.frame1.frame3.listbox8 insert end "$tail/"
    }
  }
  $toplevel.selection delete 0 end
  $toplevel.selection insert end "$fsBox(internalPath)/$fsBox(name)"
}

proc FSBoxSingle1Directories {toplevel listbox} {
  global fsBox
  set selection "[string trimright [$listbox get active] {/}]"
  if {[string compare {..} "$selection"] == 0} {
    set temp "[file dirname $fsBox(internalPath)]/$fsBox(pattern)"
    $toplevel.filter delete 0 end
    $toplevel.filter insert end "$temp"
  } else {
    set temp "$fsBox(internalPath)/$selection/$fsBox(pattern)"
    $toplevel.filter delete 0 end
    $toplevel.filter insert end "$temp"
  }
}

proc FSBoxSingle1Files {toplevel listbox} {
  global fsBox
  set selection "[$listbox get active]"
  set temp "$fsBox(internalPath)/$selection"
  $toplevel.selection delete 0 end
  $toplevel.selection insert end "$temp"
  if {$fsBox(showPixmap) && ![file isdir $temp]} {
    catch "$toplevel.frame3.frame9.frame0.frame1.frame3.canvas itemconfigure currentBitmap -bitmap \"@$temp\""
  }
}

proc FSBoxOk {toplevel} {
  global fsBox
  set result "[$toplevel.selection get]"
  set fsBox(path) "[file dirname $result]"
  set fsBox(name) "[file tail $result]"
  catch "destroy $toplevel"
}

proc FSBoxCancel {toplevel} {
  global fsBox
  set fsBox(name) ""
  catch "destroy $toplevel"
}

proc FSBoxHelp {toplevel} {
  global fsBox
}


# Procedure: HelpEditCard
proc HelpEditCard {} {
  global {EditCardHelpFile}
  if {$EditCardHelpFile != ""} {
    TextBoxFile $EditCardHelpFile "" 550x300 "Help for Edit Card popup"
  }
}

# Procedure: HelpProc
proc HelpProc {} {
  global HelpFile
  if {$HelpFile != ""} {
    TextBoxFile $HelpFile "" 550x300 "Help for TkEditLibr"
  }
}

# Procedure: InputBoxInternal
proc InputBoxInternal { inputBoxMessage inputBoxCommandOk inputBoxCommandCancel inputBoxGeometry inputBoxTitle lineNum} {
# xf ignore me 6
  global inputBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScaleOpt ""
  set tmpScrollOpt ""
  if {"$inputBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$inputBox(activeBackground)\" "
  }
  if {"$inputBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$inputBox(activeForeground)\" "
  }
  if {"$inputBox(background)" != ""} {
    append tmpButtonOpt "-background \"$inputBox(background)\" "
    append tmpFrameOpt "-background \"$inputBox(background)\" "
    append tmpMessageOpt "-background \"$inputBox(background)\" "
  }
  if {"$inputBox(font)" != ""} {
    append tmpButtonOpt "-font \"$inputBox(font)\" "
    append tmpMessageOpt "-font \"$inputBox(font)\" "
  }
  if {"$inputBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$inputBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$inputBox(foreground)\" "
  }
  if {"$inputBox(scrollActiveForeground)" != ""} {
    append tmpScrollOpt "-activeforeground \"$inputBox(scrollActiveForeground)\" "
  }
  if {"$inputBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$inputBox(scrollBackground)\" "
  }
  if {"$inputBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$inputBox(scrollForeground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy $inputBox(toplevelName)}
  } {
    catch {destroy $inputBox(toplevelName)}
  }
  toplevel $inputBox(toplevelName)  -borderwidth 0
  catch "$inputBox(toplevelName) config $tmpFrameOpt"
  if {[catch "wm geometry $inputBox(toplevelName) $inputBoxGeometry"]} {
    wm geometry $inputBox(toplevelName) 350x150
  }
  wm title $inputBox(toplevelName) $inputBoxTitle
  wm maxsize $inputBox(toplevelName) 1000 1000
  wm minsize $inputBox(toplevelName) 100 100
  # end build of toplevel

  message $inputBox(toplevelName).message1  -anchor "$inputBox(anchor)"  -justify "$inputBox(justify)"  -relief raised  -text "$inputBoxMessage"
  catch "$inputBox(toplevelName).message1 config $tmpMessageOpt"

  set xfTmpWidth  [string range $inputBoxGeometry 0 [expr [string first x $inputBoxGeometry]-1]]
  if {"$xfTmpWidth" != ""} {
    # set message size
    catch "$inputBox(toplevelName).message1 configure  -width [expr $xfTmpWidth-10]"
  } {
    $inputBox(toplevelName).message1 configure  -aspect 1500
  }

  frame $inputBox(toplevelName).frame0  -borderwidth 0  -relief raised
  catch "$inputBox(toplevelName).frame0 config $tmpFrameOpt"

  frame $inputBox(toplevelName).frame1  -borderwidth 0  -relief raised
  catch "$inputBox(toplevelName).frame1 config $tmpFrameOpt"

  if {$lineNum == 1} {
    scrollbar $inputBox(toplevelName).frame1.hscroll  -orient "horizontal"  -relief raised  -command "$inputBox(toplevelName).frame1.input view"
    catch "$inputBox(toplevelName).frame1.hscroll config $tmpScrollOpt"

    entry $inputBox(toplevelName).frame1.input  -relief raised  -xscrollcommand "$inputBox(toplevelName).frame1.hscroll set"
    catch "$inputBox(toplevelName).frame1.input config $tmpMessageOpt"

    $inputBox(toplevelName).frame1.input insert 0  $inputBox($inputBox(toplevelName),inputOne)
    
    # bindings
    bind $inputBox(toplevelName).frame1.input <Return> "
      global inputBox
      set inputBox($inputBox(toplevelName),inputOne) \[$inputBox(toplevelName).frame1.input get\]
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy $inputBox(toplevelName)}
      } {
        catch {destroy $inputBox(toplevelName)}
      }
      $inputBoxCommandOk"
    
    # packing
    pack append $inputBox(toplevelName).frame1  $inputBox(toplevelName).frame1.hscroll {bottom fill}  $inputBox(toplevelName).frame1.input {top fill expand}
  } {
    text $inputBox(toplevelName).frame1.input  -relief raised  -wrap none  -borderwidth 2  -yscrollcommand "$inputBox(toplevelName).frame1.vscroll set"
    catch "$inputBox(toplevelName).frame1.input config $tmpMessageOpt"

    scrollbar $inputBox(toplevelName).frame1.vscroll  -relief raised  -command "$inputBox(toplevelName).frame1.input yview"
    catch "$inputBox(toplevelName).frame1.vscroll config $tmpScrollOpt"

    $inputBox(toplevelName).frame1.input insert 1.0  $inputBox($inputBox(toplevelName),inputMulti)

    # bindings
    bind $inputBox(toplevelName).frame1.input <Control-Return> "
      global inputBox
      set inputBox($inputBox(toplevelName),inputMulti) \[$inputBox(toplevelName).frame1.input get 1.0 end\]
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy $inputBox(toplevelName)}
      } {
        catch {destroy $inputBox(toplevelName)}
      }
      $inputBoxCommandOk"
    bind $inputBox(toplevelName).frame1.input <Meta-Return> "
      global inputBox
      set inputBox($inputBox(toplevelName),inputMulti) \[$inputBox(toplevelName).frame1.input get 1.0 end\]
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy $inputBox(toplevelName)}
      } {
        catch {destroy $inputBox(toplevelName)}
      }
      $inputBoxCommandOk"

    # packing
    pack append $inputBox(toplevelName).frame1  $inputBox(toplevelName).frame1.vscroll "$inputBox(scrollSide) filly"  $inputBox(toplevelName).frame1.input {left fill expand}
  }
  
  button $inputBox(toplevelName).frame0.button0  -text "OK"  -command "
      global inputBox
      if {$lineNum == 1} {
        set inputBox($inputBox(toplevelName),inputOne) \[$inputBox(toplevelName).frame1.input get\]
      } {
        set inputBox($inputBox(toplevelName),inputMulti) \[$inputBox(toplevelName).frame1.input get 1.0 end\]
      }
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy $inputBox(toplevelName)}
      } {
        catch {destroy $inputBox(toplevelName)}
      }
      $inputBoxCommandOk"
  catch "$inputBox(toplevelName).frame0.button0 config $tmpButtonOpt"

  button $inputBox(toplevelName).frame0.button1  -text "Cancel"  -command "
      global inputBox
      if {$lineNum == 1} {
        set inputBox($inputBox(toplevelName),inputOne) \"\"
      } {
        set inputBox($inputBox(toplevelName),inputMulti) \"\"
      }
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy $inputBox(toplevelName)}
      } {
        catch {destroy $inputBox(toplevelName)}
      }
      $inputBoxCommandCancel"
  catch "$inputBox(toplevelName).frame0.button1 config $tmpButtonOpt"

  pack append $inputBox(toplevelName).frame0  $inputBox(toplevelName).frame0.button0 {left fill expand}  $inputBox(toplevelName).frame0.button1 {left fill expand}

  pack append $inputBox(toplevelName)  $inputBox(toplevelName).frame0 {bottom fill}  $inputBox(toplevelName).frame1 {bottom fill expand}  $inputBox(toplevelName).message1 {top fill}
}


# Procedure: InputBoxMulti
proc InputBoxMulti { {inputBoxMessage "Input box:"} {inputBoxCommandOk ""} {inputBoxCommandCancel ""} {inputBoxGeometry "350x150"} {inputBoxTitle "Input box"}} {
# xf ignore me 5
##########
# Procedure: InputBoxMulti
# Description: show input box with one text line
# Arguments: {inputBoxMessage} - message to display
#            {inputBoxCommandOk} - the command to call after ok
#            {inputBoxCommandCancel} - the command to call after cancel
#            {inputBoxGeometry} - the geometry for the window
#            {inputBoxTitle} - the title for the window
# Returns: The entered text
# Sideeffects: none
# Notes: there exist also a function called:
#          InputBoxOne - to enter one line text
##########
#
# global inputBox(activeBackground) - active background color
# global inputBox(activeForeground) - active foreground color
# global inputBox(anchor) - anchor for message box
# global inputBox(background) - background color
# global inputBox(erase) - erase previous text
# global inputBox(font) - message font
# global inputBox(foreground) - foreground color
# global inputBox(justify) - justify for message box
# global inputBox(scrollActiveForeground) - scrollbar active background color
# global inputBox(scrollBackground) - scrollbar background color
# global inputBox(scrollForeground) - scrollbar foreground color
# global inputBox(scrollSide) - side where scrollbar is located
# global inputBox(toplevelName) - the toplevel name
# global inputBox(toplevelName,inputMulti) - the text in the text widget

  global inputBox

  if {"$inputBoxGeometry" == ""} {
    set inputBoxGeometry 350x150
  }
  if {$inputBox(erase)} {
    set inputBox($inputBox(toplevelName),inputMulti) ""
  } {
    if {![info exists inputBox($inputBox(toplevelName),inputMulti)]} {
      set inputBox($inputBox(toplevelName),inputMulti) ""
    }
  }
  InputBoxInternal $inputBoxMessage $inputBoxCommandOk $inputBoxCommandCancel $inputBoxGeometry $inputBoxTitle 2

  # wait for the box to be destroyed
  update idletask
  grab $inputBox(toplevelName)
  tkwait window $inputBox(toplevelName)

  return $inputBox($inputBox(toplevelName),inputMulti)
}


# Procedure: InputBoxOne
proc InputBoxOne { {inputBoxMessage "Input box:"} {inputBoxCommandOk ""} {inputBoxCommandCancel ""} {inputBoxGeometry "350x150"} {inputBoxTitle "Input box"}} {
# xf ignore me 5
##########
# Procedure: InputBoxOne
# Description: show input box with one text line
# Arguments: {inputBoxMessage} - message to display
#            {inputBoxCommandOk} - the command to call after ok
#            {inputBoxCommandCancel} - the command to call after cancel
#            {inputBoxGeometry} - the geometry for the window
#            {inputBoxTitle} - the title for the window
# Returns: The entered text
# Sideeffects: none
# Notes: there exist also a function called:
#          InputBoxMulti - to enter multiline text
##########
#
# global inputBox(activeBackground) - active background color
# global inputBox(activeForeground) - active foreground color
# global inputBox(anchor) - anchor for message box
# global inputBox(background) - background color
# global inputBox(erase) - erase previous text
# global inputBox(font) - message font
# global inputBox(foreground) - foreground color
# global inputBox(justify) - justify for message box
# global inputBox(scrollActiveForeground) - scrollbar active background color
# global inputBox(scrollBackground) - scrollbar background color
# global inputBox(scrollForeground) - scrollbar foreground color
# global inputBox(scrollSide) - side where scrollbar is located
# global inputBox(toplevelName) - the toplevel name
# global inputBox(toplevelName,inputOne) - the text in the entry widget

  global inputBox

  if {$inputBox(erase)} {
    set inputBox($inputBox(toplevelName),inputOne) ""
  } {
    if {![info exists inputBox($inputBox(toplevelName),inputOne)]} {
      set inputBox($inputBox(toplevelName),inputOne) ""
    }
  }
  InputBoxInternal $inputBoxMessage $inputBoxCommandOk $inputBoxCommandCancel $inputBoxGeometry $inputBoxTitle 1

  # wait for the box to be destroyed
  update idletask
  grab $inputBox(toplevelName)
  tkwait window $inputBox(toplevelName)

  return $inputBox($inputBox(toplevelName),inputOne)
}


# Procedure: IsADir
proc IsADir { pathName} {
# xf ignore me 5
##########
# Procedure: IsADir
# Description: check if name is a directory (including symbolic links)
# Arguments: pathName - the path to check
# Returns: 1 if its a directory, otherwise 0
# Sideeffects: none
##########

  if {[file isdirectory $pathName]} {
    return 1
  } {
    catch "file type $pathName" fileType
    if {"$fileType" == "link"} {
      if {[catch "file readlink $pathName" linkName]} {
        return 0
      }
      catch "file type $linkName" fileType
      while {"$fileType" == "link"} {
        if {[catch "file readlink $linkName" linkName]} {
          return 0
        }
        catch "file type $linkName" fileType
      }
      return [file isdirectory $linkName]
    }
  }
  return 0
}


# Procedure: IsAFile
proc IsAFile { fileName} {
# xf ignore me 5
##########
# Procedure: IsAFile
# Description: check if filename is a file (including symbolic links)
# Arguments: fileName - the filename to check
# Returns: 1 if its a file, otherwise 0
# Sideeffects: none
##########

  if {[file isfile $fileName]} {
    return 1
  } {
    catch "file type $fileName" fileType
    if {"$fileType" == "link"} {
      if {[catch "file readlink $fileName" linkName]} {
        return 0
      }
      catch "file type $linkName" fileType
      while {"$fileType" == "link"} {
        if {[catch "file readlink $linkName" linkName]} {
          return 0
        }
        catch "file type $linkName" fileType
      }
      return [file isfile $linkName]
    }
  }
  return 0
}


# Procedure: IsASymlink
proc IsASymlink { fileName} {
# xf ignore me 5
##########
# Procedure: IsASymlink
# Description: check if filename is a symbolic link
# Arguments: fileName - the path/filename to check
# Returns: none
# Sideeffects: none
##########

  catch "file type $fileName" fileType
  if {"$fileType" == "link"} {
    return 1
  }
  return 0
}


# Procedure: ListAuthors
proc ListAuthors { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchauthors $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for author prefix $key"
  } elseif {[llength $ids] == 1} {
    EditAAuth {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all authors"
    } else {
      set title "List of authors with prefix $key"
    }
    ListItems [NewListHandle xAuthors] "$title" EditAAuth $ids
  }
}


# Procedure: ListCards
proc ListCards { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchids $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for id prefix $key"
  } elseif {[llength $ids] == 1} {
    EditACard {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all ids"
    } else {
      set title "List of ids with prefix $key"
    }
    set lines {}
    foreach id $ids {
      set tempcard [$CurrentLibrary readid $id]
      lappend lines "$id [$tempcard title]"
      $tempcard delete
    }
    ListItems [NewListHandle xCards] "$title" EditACard $lines
  }
}


# Procedure: ListItems
proc ListItems { handle title selectfunction items} {

  # build widget .$handle
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .$handle"
  } {
    catch "destroy .$handle"
  }
  toplevel .$handle  -relief {raised}

  # Window manager configurations
  global tk_version
  wm sizefrom .$handle ""
  wm maxsize .$handle 1000 768
  wm minsize .$handle 10 10
  wm title .$handle "$title"


  # build widget .$handle.buttons
  frame .$handle.buttons  -borderwidth {2}

  # build widget .$handle.buttons.dismis
  button .$handle.buttons.dismis  -text {Dismis}  -command "DismisList $handle"

  # build widget .$handle.buttons.help
  button .$handle.buttons.help  -text {Help} -command {ListItemsHelp}

  # build widget .$handle.buttons.select
  button .$handle.buttons.select  -text {Select} -command "ListItemsSelect $handle \"$selectfunction\""

  # pack widget .$handle.buttons
  pack append .$handle.buttons  .$handle.buttons.select {left frame center expand fillx}  .$handle.buttons.dismis {left frame center expand fillx}  .$handle.buttons.help {right frame center expand fillx} 

  # build widget .$handle.listframe
  frame .$handle.listframe 

  # build widget .$handle.listframe.scrollbar2
  scrollbar .$handle.listframe.scrollbar2  -command ".$handle.listframe.list yview" -relief {raised}

  # build widget .$handle.listframe.scrollbar3
  scrollbar .$handle.listframe.scrollbar3  -command ".$handle.listframe.list xview" -orient {horizontal} -relief {raised}

  # build widget .$handle.listframe.list
  listbox .$handle.listframe.list  \
	-width 72 -height 19 \
	-relief {raised} -xscrollcommand ".$handle.listframe.scrollbar3 set" -yscrollcommand ".$handle.listframe.scrollbar2 set"

  # pack widget .$handle.listframe
  pack append .$handle.listframe  .$handle.listframe.scrollbar2 {right frame center filly}  .$handle.listframe.list {top frame center expand fill}  .$handle.listframe.scrollbar3 {bottom frame center fillx} 

  # pack widget .$handle
  pack append .$handle  .$handle.listframe {top frame center fill}  .$handle.buttons {top frame center fill} 

  foreach i $items {
    .$handle.listframe.list insert end "$i"
  }
}


# Procedure: ListItemsHelp
proc ListItemsHelp {} {
  global ListItemsHelpFile
  if {$ListItemsHelpFile != ""} {
    TextBoxFile $ListItemsHelpFile "" 550x300 "Help for list display popup"
  }
}


# Procedure: ListItemsSelect
proc ListItemsSelect { handle function} {
  if {[selection own] == ".$handle.listframe.list"} {
    catch [list $function $handle "[selection get]"]
  }
}


# Procedure: ListSubjects
proc ListSubjects { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchsubjects $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for subject prefix $key"
  } elseif {[llength $ids] == 1} {
    EditASubj {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all subjects"
    } else {
      set title "List of subjects with prefix $key"
    }
    ListItems [NewListHandle xSubjects] "$title" EditASubj $ids
  }
}


# Procedure: ListTitles
proc ListTitles { key} {
  global CurrentLibrary
  if {$CurrentLibrary == {}} {
    return
  }
  set ids [$CurrentLibrary searchtitles $key]
  if {[llength $ids] == 0} {
    AlertBox "No items found for title prefix $key"
  } elseif {[llength $ids] == 1} {
    EditATitle {} "[lindex $ids 0]"
  } else {
    if {$key == {}} {
      set title "List of all titles"
    } else {
      set title "List of titles with prefix $key"
    }
    ListItems [NewListHandle xTitles] "$title" EditATitle $ids 
  }
}


# Procedure: NewListHandle
proc NewListHandle { prefix} {
  for {set i 0} {[winfo exists .$prefix$i]} {incr i} {
  }
  return "$prefix$i"
}


# Procedure: OpenLibr
proc OpenLibr {} {
  global CurrentLibrary
  if {$CurrentLibrary != {}} {
    if {[YesNoBox "Library file already open, close and continue?"]} {
      $CurrentLibrary delete
      set CurrentLibrary {}
      wm title . "Edit Library: (No Open File)"
      DisableEditor
    } else {
      return
    }
  }
  global fsBox
  set fsBox(pattern) {*.libr}
  set lfile [FSBox "Select Library"]
  if {$lfile == {}} {
    return
  }
  set CurrentLibrary [TkvBTree $lfile ReadWrite]
  if {[$CurrentLibrary openstat] == {failure}} {
    AlertBox "Error opening $lfile"
    $CurrentLibrary delete
    set CurrentLibrary {}
    return
  }
  wm title . "Edit Library: $lfile"
  EnableEditor
}

# Procedure PrintLabels
proc PrintLabels {} {

  # build widget .printLabels
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .printLabels"
  } {
    catch "destroy .printLabels"
  }
  toplevel .printLabels 

  # Window manager configurations
  global tk_version
  wm sizefrom .printLabels ""
  wm maxsize .printLabels 1000 768
  wm minsize .printLabels 10 10
  wm title .printLabels {Print Labels}


  # build widget .printLabels.buttons
  frame .printLabels.buttons \
    -borderwidth {2}

  # build widget .printLabels.buttons.cancel
  button .printLabels.buttons.cancel \
    -command {PrintCancel .printLabels}\
    -text {Cancel}

  # build widget .printLabels.buttons.help
  button .printLabels.buttons.help \
    -command {PrintLabelsHelp}\
    -text {Help}

  # build widget .printLabels.buttons.print
  button .printLabels.buttons.print \
    -command {DoPrintLabels .printLabels}\
    -text {Print}

  # pack widget .printLabels.buttons
  pack append .printLabels.buttons \
    .printLabels.buttons.print {left frame center expand} \
    .printLabels.buttons.cancel {left frame center expand} \
    .printLabels.buttons.help {right frame center expand} 

  # build widget .printLabels.devFrame
  frame .printLabels.devFrame \
    -borderwidth {2}

  # build widget .printLabels.devFrame.file
  radiobutton .printLabels.devFrame.file \
    -command {PrintDisablePrinter .printLabels}\
    -text {File}\
    -value {File}\
    -variable {PrintDevice}

  # build widget .printLabels.devFrame.printer
  radiobutton .printLabels.devFrame.printer \
    -command {PrintDisableFile .printLabels}\
    -text {Printer}\
    -value {Printer}\
    -variable {PrintDevice}

  # pack widget .printLabels.devFrame
  pack append .printLabels.devFrame \
    .printLabels.devFrame.printer {left frame center expand} \
    .printLabels.devFrame.file {left frame center expand} 

  # build widget .printLabels.fileNameFrame
  frame .printLabels.fileNameFrame \
    -borderwidth {2}

  # build widget .printLabels.fileNameFrame.browse
  button .printLabels.fileNameFrame.browse \
    -command {global fsBox
set fsBox(pattern) {*.text}
set newfile [FSBox "File to print to:" "[.printLabels.fileNameFrame.filename get]"]
if {$newfile != {}} {
  .printLabels.fileNameFrame.filename delete 0 end
  .printLabels.fileNameFrame.filename insert end "$newfile"
}}\
    -state {disabled}\
    -text {Browse}

  # build widget .printLabels.fileNameFrame.filename
  entry .printLabels.fileNameFrame.filename \
    -relief {sunken}

  # build widget .printLabels.fileNameFrame.label13
  label .printLabels.fileNameFrame.label13 \
    -text {Filename:}

  # pack widget .printLabels.fileNameFrame
  pack append .printLabels.fileNameFrame \
    .printLabels.fileNameFrame.label13 {left frame center} \
    .printLabels.fileNameFrame.filename {left frame center expand fillx} \
    .printLabels.fileNameFrame.browse {right frame center} 

  # build widget .printLabels.label1
  label .printLabels.label1 \
    -font {-Adobe-Helvetica-Bold-R-Normal--*-240-*}\
    -text {Print Labels}

  # build widget .printLabels.onlyFrame
  frame .printLabels.onlyFrame \
    -borderwidth {2}

  # build widget .printLabels.onlyFrame.label16
  label .printLabels.onlyFrame.label16 \
    -text {Only expression:}

  # build widget .printLabels.onlyFrame.onlyExpression
  entry .printLabels.onlyFrame.onlyExpression \
    -relief {sunken}

  # pack widget .printLabels.onlyFrame
  pack append .printLabels.onlyFrame \
    .printLabels.onlyFrame.label16 {left frame center} \
    .printLabels.onlyFrame.onlyExpression {left frame center expand fillx} 

  # build widget .printLabels.printCommandFrame
  frame .printLabels.printCommandFrame \
    -borderwidth {2}

  # build widget .printLabels.printCommandFrame.label11
  label .printLabels.printCommandFrame.label11 \
    -text {Print Command}

  # build widget .printLabels.printCommandFrame.printCommand
  entry .printLabels.printCommandFrame.printCommand \
    -relief {sunken}

  # pack widget .printLabels.printCommandFrame
  pack append .printLabels.printCommandFrame \
    .printLabels.printCommandFrame.label11 {left frame center} \
    .printLabels.printCommandFrame.printCommand {left frame center expand fillx} 

  # build widget .printLabels.templateFrame
  frame .printLabels.templateFrame \
    -borderwidth {2}

  # build widget .printLabels.templateFrame.browse
  button .printLabels.templateFrame.browse \
    -command {global fsBox
set fsBox(pattern) {*.tmpl}
set newfile [FSBox "Select a template file" "[.printLabels.templateFrame.template get]"]
if {$newfile != {}} {
  .printLabels.templateFrame.template delete 0 end
  .printLabels.templateFrame.template insert end "$newfile"
}}\
    -text {Browse}

  # build widget .printLabels.templateFrame.label18
  label .printLabels.templateFrame.label18 \
    -text {Template file:}

  # build widget .printLabels.templateFrame.template
  entry .printLabels.templateFrame.template \
    -relief {sunken}

  # pack widget .printLabels.templateFrame
  pack append .printLabels.templateFrame \
    .printLabels.templateFrame.label18 {left frame center} \
    .printLabels.templateFrame.template {left frame center expand fillx} \
    .printLabels.templateFrame.browse {left frame center} 

  # build widget .printLabels.byFrame
  frame .printLabels.byFrame \
    -borderwidth {2}

  # build widget .printLabels.byFrame.author
  radiobutton .printLabels.byFrame.author \
    -text {Author}\
    -value {author}\
    -variable {PrintBy}

  # build widget .printLabels.byFrame.id
  radiobutton .printLabels.byFrame.id \
    -text {Id}\
    -value {id}\
    -variable {PrintBy}

  # build widget .printLabels.byFrame.subject
  radiobutton .printLabels.byFrame.subject \
    -text {Subject}\
    -value {subject}\
    -variable {PrintBy}

  # build widget .printLabels.byFrame.title
  radiobutton .printLabels.byFrame.title \
    -text {Title}\
    -value {title}\
    -variable {PrintBy}

  # pack widget .printLabels.byFrame
  pack append .printLabels.byFrame \
    .printLabels.byFrame.id {left frame center expand} \
    .printLabels.byFrame.title {left frame center expand} \
    .printLabels.byFrame.author {left frame center expand} \
    .printLabels.byFrame.subject {left frame center expand} 

  # pack widget .printLabels
  pack append .printLabels \
    .printLabels.label1 {top frame center} \
    .printLabels.devFrame {top frame center fillx} \
    .printLabels.printCommandFrame {top frame center fillx} \
    .printLabels.fileNameFrame {top frame center fillx} \
    .printLabels.byFrame {top frame center fillx} \
    .printLabels.onlyFrame {top frame center fillx} \
    .printLabels.templateFrame {top frame center fillx} \
    .printLabels.buttons {top frame center fillx} 

  .printLabels.fileNameFrame.filename insert end {print.text}
  .printLabels.fileNameFrame.filename configure -state {disabled}
  .printLabels.onlyFrame.onlyExpression insert end {}
  .printLabels.printCommandFrame.printCommand insert end {|lpr}
  .printLabels.templateFrame.template insert end {template.tmpl}

  global {PrintDevice}
  set {PrintDevice} {Printer}
  global {PrintBy}
  set {PrintBy} {id}

  update idletask
  grab .printLabels
  tkwait window .printLabels

}

# Procedure PrintCards
proc PrintCards {} {


  # build widget .printCards
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .printCards"
  } {
    catch "destroy .printCards"
  }
  toplevel .printCards 

  # Window manager configurations
  global tk_version
  wm sizefrom .printCards ""
  wm maxsize .printCards 1000 768
  wm minsize .printCards 10 10
  wm title .printCards {Print Cards}


  # build widget .printCards.buttons
  frame .printCards.buttons \
    -borderwidth {2}

  # build widget .printCards.buttons.cancel
  button .printCards.buttons.cancel \
    -command {PrintCancel .printCards}\
    -text {Cancel}

  # build widget .printCards.buttons.help
  button .printCards.buttons.help \
    -command {PrintCardsHelp}\
    -text {Help}

  # build widget .printCards.buttons.print
  button .printCards.buttons.print \
    -command {DoPrintCards .printCards}\
    -text {Print}

  # pack widget .printCards.buttons
  pack append .printCards.buttons \
    .printCards.buttons.print {left frame center expand} \
    .printCards.buttons.cancel {left frame center expand} \
    .printCards.buttons.help {right frame center expand} 

  # build widget .printCards.cardSizeFrame
  frame .printCards.cardSizeFrame \
    -borderwidth {2}

  # build widget .printCards.cardSizeFrame.large
  radiobutton .printCards.cardSizeFrame.large \
    -text {Large}\
    -value {1}\
    -variable {PrintLargeCards}

  # build widget .printCards.cardSizeFrame.small
  radiobutton .printCards.cardSizeFrame.small \
    -text {Small}\
    -value {0}\
    -variable {PrintLargeCards}

  # pack widget .printCards.cardSizeFrame
  pack append .printCards.cardSizeFrame \
    .printCards.cardSizeFrame.large {left frame center expand} \
    .printCards.cardSizeFrame.small {right frame center expand} 

  # build widget .printCards.devFrame
  frame .printCards.devFrame \
    -borderwidth {2}

  # build widget .printCards.devFrame.file
  radiobutton .printCards.devFrame.file \
    -command {PrintDisablePrinter .printCards}\
    -text {File}\
    -value {File}\
    -variable {PrintDevice}

  # build widget .printCards.devFrame.printer
  radiobutton .printCards.devFrame.printer \
    -command {PrintDisableFile .printCards}\
    -text {Printer}\
    -value {Printer}\
    -variable {PrintDevice}

  # pack widget .printCards.devFrame
  pack append .printCards.devFrame \
    .printCards.devFrame.printer {left frame center expand} \
    .printCards.devFrame.file {left frame center expand} 

  # build widget .printCards.fileNameFrame
  frame .printCards.fileNameFrame \
    -borderwidth {2}

  # build widget .printCards.fileNameFrame.browse
  button .printCards.fileNameFrame.browse \
    -command {global fsBox
set fsBox(pattern) {*.text}
set newfile [FSBox "File to print to:" "[.printCards.fileNameFrame.filename get]"]
if {$newfile != {}} {
  .printCards.fileNameFrame.filename delete 0 end
  .printCards.fileNameFrame.filename insert end "$newfile"
}}\
    -state {disabled}\
    -text {Browse}

  # build widget .printCards.fileNameFrame.filename
  entry .printCards.fileNameFrame.filename \
    -relief {sunken}

  # build widget .printCards.fileNameFrame.label13
  label .printCards.fileNameFrame.label13 \
    -text {Filename:}

  # pack widget .printCards.fileNameFrame
  pack append .printCards.fileNameFrame \
    .printCards.fileNameFrame.label13 {left frame center} \
    .printCards.fileNameFrame.filename {left frame center expand fillx} \
    .printCards.fileNameFrame.browse {right frame center} 

  # build widget .printCards.label1
  label .printCards.label1 \
    -font {-Adobe-Helvetica-Bold-R-Normal--*-240-*}\
    -text {Print Cards}

  # build widget .printCards.onlyFrame
  frame .printCards.onlyFrame \
    -borderwidth {2}

  # build widget .printCards.onlyFrame.label16
  label .printCards.onlyFrame.label16 \
    -text {Only expression:}

  # build widget .printCards.onlyFrame.onlyExpression
  entry .printCards.onlyFrame.onlyExpression \
    -relief {sunken}

  # pack widget .printCards.onlyFrame
  pack append .printCards.onlyFrame \
    .printCards.onlyFrame.label16 {left frame center} \
    .printCards.onlyFrame.onlyExpression {left frame center expand fillx} 

  # build widget .printCards.printCommandFrame
  frame .printCards.printCommandFrame \
    -borderwidth {2}

  # build widget .printCards.printCommandFrame.label11
  label .printCards.printCommandFrame.label11 \
    -text {Print Command}

  # build widget .printCards.printCommandFrame.printCommand
  entry .printCards.printCommandFrame.printCommand \
    -relief {sunken}

  # pack widget .printCards.printCommandFrame
  pack append .printCards.printCommandFrame \
    .printCards.printCommandFrame.label11 {left frame center} \
    .printCards.printCommandFrame.printCommand {left frame center expand fillx} 

  # build widget .printCards.byFrame
  frame .printCards.byFrame \
    -borderwidth {2}

  # build widget .printCards.byFrame.author
  radiobutton .printCards.byFrame.author \
    -text {Author}\
    -value {author}\
    -variable {PrintBy}

  # build widget .printCards.byFrame.id
  radiobutton .printCards.byFrame.id \
    -text {Id}\
    -value {id}\
    -variable {PrintBy}

  # build widget .printCards.byFrame.subject
  radiobutton .printCards.byFrame.subject \
    -text {Subject}\
    -value {subject}\
    -variable {PrintBy}

  # build widget .printCards.byFrame.title
  radiobutton .printCards.byFrame.title \
    -text {Title}\
    -value {title}\
    -variable {PrintBy}

  # pack widget .printCards.byFrame
  pack append .printCards.byFrame \
    .printCards.byFrame.id {left frame center expand} \
    .printCards.byFrame.title {left frame center expand} \
    .printCards.byFrame.author {left frame center expand} \
    .printCards.byFrame.subject {left frame center expand} 

  # pack widget .printCards
  pack append .printCards \
    .printCards.label1 {top frame center} \
    .printCards.devFrame {top frame center fillx} \
    .printCards.printCommandFrame {top frame center fillx} \
    .printCards.fileNameFrame {top frame center fillx} \
    .printCards.byFrame {top frame center fillx} \
    .printCards.onlyFrame {top frame center fillx} \
    .printCards.cardSizeFrame {top frame center fillx} \
    .printCards.buttons {top frame center fillx} 

  .printCards.fileNameFrame.filename insert end {print.text}
  .printCards.fileNameFrame.filename configure -state {disabled}
  .printCards.onlyFrame.onlyExpression insert end {}
  .printCards.printCommandFrame.printCommand insert end {|lpr}
  global {PrintDevice}
  set {PrintDevice} {Printer}
  global {PrintLargeCards}
  set {PrintLargeCards} {1}
  global {PrintBy}
  set {PrintBy} {id}

  update idletask
  grab .printCards
  tkwait window .printCards

}


# Procedure: PrintDisableFile
proc PrintDisableFile { toplevel} {
  $toplevel.fileNameFrame.filename configure -state disabled
  $toplevel.fileNameFrame.browse configure -state disabled
  $toplevel.printCommandFrame.printCommand configure -state normal
  focus $toplevel.printCommandFrame.printCommand
}


# Procedure: PrintDisablePrinter
proc PrintDisablePrinter { toplevel} {
  $toplevel.fileNameFrame.filename configure -state normal
  focus $toplevel.fileNameFrame.filename
  $toplevel.fileNameFrame.browse configure -state normal
  $toplevel.printCommandFrame.printCommand configure -state disabled
}

# Procedure: PrintCancel
proc PrintCancel { toplevel} {
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy $toplevel"
  } {
    catch "destroy $toplevel"
  }
}

# Procedure: PrintLabelsHelp
proc PrintLabelsHelp {} {
  global PrintLabelsHelpFile
  if {$PrintLabelsHelpFile != ""} {
    TextBoxFile $PrintLabelsHelpFile "" 550x300 "Help for PrintLabels popup"
  }
}

# Procedure: PrintCardsHelp
proc PrintCardsHelp {} {
  global PrintCardsHelpFile
  if {$PrintCardsHelpFile != ""} {
    TextBoxFile $PrintCardsHelpFile "" 550x300 "Help for PrintCards popup"
  }
}

# Procedure: QuoteQuote
proc QuoteQuote {string} {
  set result {}
  foreach c [split $string {}] {
    if {[string first $c "<>'|& \t\""] != -1} {
      lappend result "\\"
    }
    lappend result "$c"
  }
  return [join "$result" {}]
}

# Procedure: DoPrintLabels
proc DoPrintLabels {toplevel} {
  global CurrentLibrary
  set filename [$CurrentLibrary filename]
  $CurrentLibrary delete
  global PrintBy
  global PrintDevice
#  set argv [list PRINTLAB \
  set argv [list /home/heller/Deepwoods/HomeLibrarian/bin/PrintLabels \
  	         -infile $filename \
		 -templatefile "[$toplevel.templateFrame.template get]" \
		 -by $PrintBy]
  set oexp "[$toplevel.onlyFrame.onlyExpression get]"
  if {$oexp != {}} {
    lappend argv -only [QuoteQuote "$oexp"]
  }
  if {$PrintDevice == "Printer"} {
    lappend argv "[$toplevel.printCommandFrame.printCommand get]"
  } else {
    lappend argv ">[$toplevel.fileNameFrame.filename get]"
  }
  set cmd "[join "$argv" { }]"
  if {[catch "exec csh -c \{$argv\}" error]} {
    AlertBox "Error in exec: $error"
  }
  set CurrentLibrary [TkvBTree $filename ReadWrite]
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy $toplevel"
  } {
    catch "destroy $toplevel"
  }
}

# Procedure: DoPrintCards
proc DoPrintCards {toplevel} {
  global CurrentLibrary
  set filename [$CurrentLibrary filename]
  $CurrentLibrary delete
  global PrintBy
  global PrintDevice
  global PrintLargeCards
#  set argv [list PRINTCARD \
  set argv [list /home/heller/Deepwoods/HomeLibrarian/bin/PrintCards \
  	         -infile $filename -largep $PrintLargeCards \
		 -by $PrintBy]
  set oexp "[$toplevel.onlyFrame.onlyExpression get]"
  if {$oexp != {}} {
    lappend argv -only [QuoteQuote "$oexp"]
  }
  if {$PrintDevice == "Printer"} {
    lappend argv "[$toplevel.printCommandFrame.printCommand get]"
  } else {
    lappend argv ">[$toplevel.fileNameFrame.filename get]"
  }
  set cmd "[join "$argv" { }]"
  if {[catch "exec csh -c \{$cmd\}" error]} {
    AlertBox "Error in exec: $error"
  }
  set CurrentLibrary [TkvBTree $filename ReadWrite]
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy $toplevel"
  } {
    catch "destroy $toplevel"
  }
}

# Procedure: TextBox
proc TextBox { {textBoxMessage "Text message"} {textBoxCommand ""} {textBoxGeometry "350x150"} {textBoxTitle "Text box"} args} {
# xf ignore me 5
##########
# Procedure: TextBox
# Description: show text box
# Arguments: {textBoxMessage} - the text to display
#            {textBoxCommand} - the command to call after ok
#            {textBoxGeometry} - the geometry for the window
#            {textBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, or nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          TextBoxFile - to open and read a file automatically
#          TextBoxFd - to read from an already opened filedescriptor
##########
#
# global textBox(activeBackground) - active background color
# global textBox(activeForeground) - active foreground color
# global textBox(background) - background color
# global textBox(font) - text font
# global textBox(foreground) - foreground color
# global textBox(scrollActiveForeground) - scrollbar active background color
# global textBox(scrollBackground) - scrollbar background color
# global textBox(scrollForeground) - scrollbar foreground color
# global textBox(scrollSide) - side where scrollbar is located

  global textBox

  # show text box
  if {[llength $args] > 0} {
    eval TextBoxInternal "\{$textBoxMessage\}" "\{$textBoxCommand\}" "\{$textBoxGeometry\}" "\{$textBoxTitle\}" $args
  } {
    TextBoxInternal $textBoxMessage $textBoxCommand $textBoxGeometry $textBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $textBox(toplevelName)
    tkwait window $textBox(toplevelName)

    return $textBox(button)
  }
}


# Procedure: TextBoxFd
proc TextBoxFd { {textBoxInFile ""} {textBoxCommand ""} {textBoxGeometry "350x150"} {textBoxTitle "Text box"} args} {
# xf ignore me 5
##########
# Procedure: TextBoxFd
# Description: show text box containing a filedescriptor
# Arguments: {textBoxInFile} - a filedescriptor to read. The descriptor
#                              is closed after reading
#            {textBoxCommand} - the command to call after ok
#            {textBoxGeometry} - the geometry for the window
#            {textBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          TextBox - to display a passed string
#          TextBoxFile - to open and read a file automatically
##########
#
# global textBox(activeBackground) - active background color
# global textBox(activeForeground) - active foreground color
# global textBox(background) - background color
# global textBox(font) - text font
# global textBox(foreground) - foreground color
# global textBox(scrollActiveForeground) - scrollbar active background color
# global textBox(scrollBackground) - scrollbar background color
# global textBox(scrollForeground) - scrollbar foreground color
# global textBox(scrollSide) - side where scrollbar is located

  global textBox

  # check file existance
  if {"$textBoxInFile" == ""} {
    puts stderr "No filedescriptor specified"
    return
  }

  set textBoxMessage [read $textBoxInFile]
  close $textBoxInFile

  # show text box
  if {[llength $args] > 0} {
    eval TextBoxInternal "\{$textBoxMessage\}" "\{$textBoxCommand\}" "\{$textBoxGeometry\}" "\{$textBoxTitle\}" $args
  } {
    TextBoxInternal $textBoxMessage $textBoxCommand $textBoxGeometry $textBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $textBox(toplevelName)
    tkwait window $textBox(toplevelName)

    return $textBox(button)
  }
}


# Procedure: TextBoxFile
proc TextBoxFile { {textBoxFile ""} {textBoxCommand ""} {textBoxGeometry "350x150"} {textBoxTitle "Text box"} args} {
# xf ignore me 5
##########
# Procedure: TextBoxFile
# Description: show text box containing a file
# Arguments: {textBoxFile} - filename to read
#            {textBoxCommand} - the command to call after ok
#            {textBoxGeometry} - the geometry for the window
#            {textBoxTitle} - the title for the window
#            {args} - labels of buttons
# Returns: The number of the selected button, ot nothing
# Sideeffects: none
# Notes: there exist also functions called:
#          TextBox - to display a passed string
#          TextBoxFd - to read from an already opened filedescriptor
##########
#
# global textBox(activeBackground) - active background color
# global textBox(activeForeground) - active foreground color
# global textBox(background) - background color
# global textBox(font) - text font
# global textBox(foreground) - foreground color
# global textBox(scrollActiveForeground) - scrollbar active background color
# global textBox(scrollBackground) - scrollbar background color
# global textBox(scrollForeground) - scrollbar foreground color
# global textBox(scrollSide) - side where scrollbar is located

  global textBox

  # check file existance
  if {"$textBoxFile" == ""} {
    puts stderr "No filename specified"
    return
  }

  if {[catch "open $textBoxFile r" textBoxInFile]} {
    puts stderr "$textBoxInFile"
    return
  }

  set textBoxMessage [read $textBoxInFile]
  close $textBoxInFile

  # show text box
  if {[llength $args] > 0} {
    eval TextBoxInternal "\{$textBoxMessage\}" "\{$textBoxCommand\}" "\{$textBoxGeometry\}" "\{$textBoxTitle\}" $args
  } {
    TextBoxInternal $textBoxMessage $textBoxCommand $textBoxGeometry $textBoxTitle
  }

  if {[llength $args] > 0} {
    # wait for the box to be destroyed
    update idletask
    grab $textBox(toplevelName)
    tkwait window $textBox(toplevelName)

    return $textBox(button)
  }
}


# Procedure: TextBoxInternal
proc TextBoxInternal { textBoxMessage textBoxCommand textBoxGeometry textBoxTitle args} {
# xf ignore me 6
  global textBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  set tmpScrollOpt ""
  if {"$textBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$textBox(activeBackground)\" "
  }
  if {"$textBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$textBox(activeForeground)\" "
  }
  if {"$textBox(background)" != ""} {
    append tmpButtonOpt "-background \"$textBox(background)\" "
    append tmpFrameOpt "-background \"$textBox(background)\" "
    append tmpMessageOpt "-background \"$textBox(background)\" "
  }
  if {"$textBox(font)" != ""} {
    append tmpButtonOpt "-font \"$textBox(font)\" "
    append tmpMessageOpt "-font \"$textBox(font)\" "
  }
  if {"$textBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$textBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$textBox(foreground)\" "
  }
  if {"$textBox(scrollActiveForeground)" != ""} {
    append tmpScrollOpt "-activeforeground \"$textBox(scrollActiveForeground)\" "
  }
  if {"$textBox(scrollBackground)" != ""} {
    append tmpScrollOpt "-background \"$textBox(scrollBackground)\" "
  }
  if {"$textBox(scrollForeground)" != ""} {
    append tmpScrollOpt "-foreground \"$textBox(scrollForeground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy $textBox(toplevelName)}
  } {
    catch {destroy $textBox(toplevelName)}
  }
  toplevel $textBox(toplevelName)  -borderwidth 0
  catch "$textBox(toplevelName) config $tmpFrameOpt"
  if {[catch "wm geometry $textBox(toplevelName) $textBoxGeometry"]} {
    wm geometry $textBox(toplevelName) 350x150
  }
  wm title $textBox(toplevelName) $textBoxTitle
  wm maxsize $textBox(toplevelName) 1000 1000
  wm minsize $textBox(toplevelName) 100 100
  # end build of toplevel

  frame $textBox(toplevelName).frame0  -borderwidth 0  -relief raised
  catch "$textBox(toplevelName).frame0 config $tmpFrameOpt"

  text $textBox(toplevelName).frame0.text1  -relief raised  -wrap none  -borderwidth 2  -yscrollcommand "$textBox(toplevelName).frame0.vscroll set"
  catch "$textBox(toplevelName).frame0.text1 config $tmpMessageOpt"

  scrollbar $textBox(toplevelName).frame0.vscroll  -relief raised  -command "$textBox(toplevelName).frame0.text1 yview"
  catch "$textBox(toplevelName).frame0.vscroll config $tmpScrollOpt"

  frame $textBox(toplevelName).frame1  -borderwidth 0  -relief raised
  catch "$textBox(toplevelName).frame1 config $tmpFrameOpt"

  set textBoxCounter 0
  set buttonNum [llength $args]

  if {$buttonNum > 0} {
    while {$textBoxCounter < $buttonNum} {
      button $textBox(toplevelName).frame1.button$textBoxCounter  -text "[lindex $args $textBoxCounter]"  -command "
          global textBox
          set textBox(button) $textBoxCounter
          set textBox(contents) \[$textBox(toplevelName).frame0.text1 get 1.0 end\]
          if {\"\[info commands XFDestroy\]\" != \"\"} {
            catch {XFDestroy $textBox(toplevelName)}
          } {
            catch {destroy $textBox(toplevelName)}
          }"
      catch "$textBox(toplevelName).frame1.button$textBoxCounter config $tmpButtonOpt"

      pack append $textBox(toplevelName).frame1  $textBox(toplevelName).frame1.button$textBoxCounter {left fillx expand}

      incr textBoxCounter
    }
  } {
    button $textBox(toplevelName).frame1.button0  -text "OK"  -command "
        global textBox
        set textBox(button) 0
        set textBox(contents) \[$textBox(toplevelName).frame0.text1 get 1.0 end\]
        if {\"\[info commands XFDestroy\]\" != \"\"} {
          catch {XFDestroy $textBox(toplevelName)}
        } {
          catch {destroy $textBox(toplevelName)}
        }
        $textBoxCommand"
    catch "$textBox(toplevelName).frame1.button0 config $tmpButtonOpt"

    pack append $textBox(toplevelName).frame1  $textBox(toplevelName).frame1.button0 {left fillx expand}
  }

  $textBox(toplevelName).frame0.text1 insert end "$textBoxMessage"

  $textBox(toplevelName).frame0.text1 config  -state $textBox(state)

  # packing
  pack append $textBox(toplevelName).frame0  $textBox(toplevelName).frame0.vscroll "$textBox(scrollSide) filly"  $textBox(toplevelName).frame0.text1 {left fill expand}
  pack append $textBox(toplevelName)  $textBox(toplevelName).frame1 {bottom fill}  $textBox(toplevelName).frame0 {top fill expand}
}


# Procedure: UpdateCard
proc UpdateCard { origcard key filehandle editcard origsubj newsubjlb} {
  $editcard author "[.edit$origcard.main.ay.author get]"
  $editcard year "[.edit$origcard.main.ay.year get]"
  $editcard description "[.edit$origcard.main.m2.m3.descr.description get 1.0 end]"
  $editcard city "[.edit$origcard.main.m2.m3.pubframe.city get]"
  $editcard publisher "[.edit$origcard.main.m2.m3.pubframe.publisher get]"
  $editcard title "[.edit$origcard.main.m2.m3.titleframe.title get]"
#  $editcard cardtype "[EditCardTypeMenuTypeFromLabel \"[.edit$origcard.main.m2.m3.typeframe.type cget -text]\"]"
  $editcard vol "[.edit$origcard.main.m2.m3.volframe.volume get]"
  set newsubj {}
  set elemns [$newsubjlb size]
  for {set i 0} {$i < $elemns} {incr i} {lappend newsubj [$newsubjlb get $i]}
  set origsubj [lsort $origsubj]
  set newsubj [lsort $newsubj]
  if {"$origsubj" != "$newsubj" || [$origcard] != [$editcard]} {
    $filehandle insertid "$key" $editcard
    if {[string tolower "[$origcard title]"] != [string tolower "[$editcard title]"]} {
      $filehandle updatetitle "[$editcard title]" "[$origcard title]" "$key"
    }
    if {[string tolower "[$origcard author]"] != [string tolower "[$editcard author]"]} {
      $filehandle updateauthor "[$editcard author]" "[$origcard author]" "$key"
    }
    $filehandle updatesubjs "$newsubj" "$origsubj" "$key"
  }
  catch "$origcard delete"
  catch "$editcard delete"
  if {"[info procs XFEdit]" != ""} {
    catch "XFDestroy .edit$origcard"
  } {
    catch "destroy .edit$origcard"
  }
}

# Procedure: VersionProc
proc VersionProc {} {
  AlertBox {TkEditLibr Version 1.0} "" {180x50}
}

# Procedure: WarrantyProc
proc WarrantyProc {} {
  global WarrantyMessage
  if {$WarrantyMessage != ""} {
    AlertBoxFile $WarrantyMessage "" {600x350}
  }
}

# Procedure: YesNoBox
proc YesNoBox { {yesNoBoxMessage "Yes/no message"} {yesNoBoxGeometry "350x150"}} {
# xf ignore me 5
##########
# Procedure: YesNoBox
# Description: show yesno box
# Arguments: {yesNoBoxMessage} - the text to display
#            {yesNoBoxGeometry} - the geometry for the window
# Returns: none
# Sideeffects: none
##########
#
# global yesNoBox(activeBackground) - active background color
# global yesNoBox(activeForeground) - active foreground color
# global yesNoBox(anchor) - anchor for message box
# global yesNoBox(background) - background color
# global yesNoBox(font) - message font
# global yesNoBox(foreground) - foreground color
# global yesNoBox(justify) - justify for message box
# global yesNoBox(afterNo) - destroy yes-no box after n seconds.
#                            The no button is activated
# global yesNoBox(afterYes) - destroy yes-no box after n seconds.
#                             The yes button is activated

  global yesNoBox

  set tmpButtonOpt ""
  set tmpFrameOpt ""
  set tmpMessageOpt ""
  if {"$yesNoBox(activeBackground)" != ""} {
    append tmpButtonOpt "-activebackground \"$yesNoBox(activeBackground)\" "
  }
  if {"$yesNoBox(activeForeground)" != ""} {
    append tmpButtonOpt "-activeforeground \"$yesNoBox(activeForeground)\" "
  }
  if {"$yesNoBox(background)" != ""} {
    append tmpButtonOpt "-background \"$yesNoBox(background)\" "
    append tmpFrameOpt "-background \"$yesNoBox(background)\" "
    append tmpMessageOpt "-background \"$yesNoBox(background)\" "
  }
  if {"$yesNoBox(font)" != ""} {
    append tmpButtonOpt "-font \"$yesNoBox(font)\" "
    append tmpMessageOpt "-font \"$yesNoBox(font)\" "
  }
  if {"$yesNoBox(foreground)" != ""} {
    append tmpButtonOpt "-foreground \"$yesNoBox(foreground)\" "
    append tmpMessageOpt "-foreground \"$yesNoBox(foreground)\" "
  }

  # start build of toplevel
  if {"[info commands XFDestroy]" != ""} {
    catch {XFDestroy .yesNoBox}
  } {
    catch {destroy .yesNoBox}
  }
  toplevel .yesNoBox  -borderwidth 0
  catch ".yesNoBox config $tmpFrameOpt"
  if {[catch "wm geometry .yesNoBox $yesNoBoxGeometry"]} {
    wm geometry .yesNoBox 350x150
  }
  wm title .yesNoBox {Alert box}
  wm maxsize .yesNoBox 1000 1000
  wm minsize .yesNoBox 100 100
  # end build of toplevel

  message .yesNoBox.message1  -anchor "$yesNoBox(anchor)"  -justify "$yesNoBox(justify)"  -relief raised  -text "$yesNoBoxMessage"
  catch ".yesNoBox.message1 config $tmpMessageOpt"

  set xfTmpWidth  [string range $yesNoBoxGeometry 0 [expr [string first x $yesNoBoxGeometry]-1]]
  if {"$xfTmpWidth" != ""} {
    # set message size
    catch ".yesNoBox.message1 configure  -width [expr $xfTmpWidth-10]"
  } {
    .yesNoBox.message1 configure  -aspect 1500
  }

  frame .yesNoBox.frame1  -borderwidth 0  -relief raised
  catch ".yesNoBox.frame1 config $tmpFrameOpt"

  button .yesNoBox.frame1.button0  -text "Yes"  -command "
      global yesNoBox
      set yesNoBox(button) 1
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .yesNoBox}
      } {
        catch {destroy .yesNoBox}
      }"
  catch ".yesNoBox.frame1.button0 config $tmpButtonOpt"

  button .yesNoBox.frame1.button1  -text "No"  -command "
      global yesNoBox
      set yesNoBox(button) 0
      if {\"\[info commands XFDestroy\]\" != \"\"} {
        catch {XFDestroy .yesNoBox}
      } {
        catch {destroy .yesNoBox}
      }"
  catch ".yesNoBox.frame1.button1 config $tmpButtonOpt"

  pack append .yesNoBox.frame1  .yesNoBox.frame1.button0 {left fillx expand}  .yesNoBox.frame1.button1 {left fillx expand}

  # packing
  pack append .yesNoBox  .yesNoBox.frame1 {bottom fill}  .yesNoBox.message1 {top fill expand}

  if {$yesNoBox(afterYes) != 0} {
    after [expr $yesNoBox(afterYes)*1000]  "catch \".yesNoBox.frame1.button0 invoke\""
  }
  if {$yesNoBox(afterNo) != 0} {
    after [expr $yesNoBox(afterNo)*1000]  "catch \".yesNoBox.frame1.button1 invoke\""
  }

  # wait for the box to be destroyed
  update idletask
  grab .yesNoBox
  tkwait window .yesNoBox

  return $yesNoBox(button)
}


# Procedure: auto_load_ouster_index
proc auto_load_ouster_index { fn} {
    global auto_index
    set dir [file dirname $fn]

    if [catch {set f [open $dir/tclIndex]}] {
        return
    }
    set error [catch {
        set id [gets $f]
        if {$id == "# Tcl autoload index file, version 2.0"} {
            eval [read $f]
        } elseif {$id == "# Tcl autoload index file: each line identifies a Tcl"} {
            while {[gets $f line] >= 0} {
                if {([string index $line 0] == "#")
                        || ([llength $line] != 2)} {
                    continue
                }
                set name [lindex $line 0]
                if {![info exists auto_index($name)]} {
                    set auto_index($name) "source $dir/[lindex $line 1]"
                }
            }
        } else {
            error "$dir/tclIndex isn't a proper Tcl index file"
        }
    } msg]
    if {$f != ""} {
        close $f
    }
    if $error {
        global errorInfo errorCode
        error $msg $errorInfo $errorCode
    }
}


# Internal procedures


# Procedure: Alias
proc Alias { args} {
# xf ignore me 7
##########
# Procedure: Alias
# Description: establish an alias for a procedure
# Arguments: args - no argument means that a list of all aliases
#                   is returned. Otherwise the first parameter is
#                   the alias name, and the second parameter is
#                   the procedure that is aliased.
# Returns: nothing, the command that is bound to the alias or a
#          list of all aliases - command pairs. 
# Sideeffects: internalAliasList is updated, and the alias
#              proc is inserted
##########
  global internalAliasList

  if {[llength $args] == 0} {
    return $internalAliasList
  } {
    if {[llength $args] == 1} {
      set xfTmpIndex [lsearch $internalAliasList "[lindex $args 0] *"]
      if {$xfTmpIndex != -1} {
        return [lindex [lindex $internalAliasList $xfTmpIndex] 1]
      }
    } {
      if {[llength $args] == 2} {
        eval "proc [lindex $args 0] {args} {#xf ignore me 4
return \[eval \"[lindex $args 1] \$args\"\]}"
        set xfTmpIndex [lsearch $internalAliasList "[lindex $args 0] *"]
        if {$xfTmpIndex != -1} {
          set internalAliasList [lreplace $internalAliasList $xfTmpIndex $xfTmpIndex "[lindex $args 0] [lindex $args 1]"]
        } {
          lappend internalAliasList "[lindex $args 0] [lindex $args 1]"
        }
      } {
        error "Alias: wrong number or args: $args"
      }
    }
  }
}


# Procedure: GetSelection
if {"[info procs GetSelection]" == ""} {
proc GetSelection {} {
# xf ignore me 7
##########
# Procedure: GetSelection
# Description: get current selection
# Arguments: none
# Returns: none
# Sideeffects: none
##########

  # the save way
  set xfSelection ""
  catch "selection get" xfSelection
  if {"$xfSelection" == "selection doesn't exist or form \"STRING\" not defined"} {
    return ""
  } {
    return $xfSelection
  }
}
}


# Procedure: MenuPopupAdd
if {"[info procs MenuPopupAdd]" == ""} {
proc MenuPopupAdd { xfW xfButton xfMenu {xfModifier ""} {xfCanvasTag ""}} {
# xf ignore me 7
# the popup menu handling is from (I already gave up with popup handling :-):
#
# Copyright 1991,1992 by James Noble.
# Everyone is granted permission to copy, modify and redistribute.
# This notice must be preserved on all copies or derivates.
#
##########
# Procedure: MenuPopupAdd
# Description: attach a popup menu to widget
# Arguments: xfW - the widget
#            xfButton - the button we use
#            xfMenu - the menu to attach
#            {xfModifier} - a optional modifier
#            {xfCanvasTag} - a canvas tagOrId
# Returns: none
# Sideeffects: none
##########

  if {"$xfModifier" != ""} {
    set xfPressModifier "$xfModifier-"
    set xfMoveModifier "$xfModifier-"
    set xfReleaseModifier "Any-"
  } {
    set xfPressModifier ""
    set xfMoveModifier ""
    set xfReleaseModifier ""
  }

  if {"$xfCanvasTag" == ""} {
    if {[catch "bind $xfW \"<${xfPressModifier}ButtonPress-$xfButton>\"  \"$xfMenu post %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    if {[catch "bind $xfW \"<${xfMoveModifier}B$xfButton-Motion>\"  \"MenuPopupHandle $xfMenu %W %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    # we need these to counteract the effects of passive grabs :-(
    if {[catch "bind $xfW \"<${xfReleaseModifier}ButtonRelease-$xfButton>\"  \"$xfMenu invoke active; $xfMenu unpost\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
  } {
    if {[catch "$xfW bind $xfCanvasTag \"<${xfPressModifier}ButtonPress-$xfButton>\"  \"$xfMenu post %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    if {[catch "$xfW bind $xfCanvasTag \"<${xfMoveModifier}B$xfButton-Motion>\"  \"MenuPopupHandle $xfMenu %W %X %Y\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
    # we need these to counteract the effects of passive grabs :-(
    if {[catch "$xfW bind $xfCanvasTag \"<${xfReleaseModifier}ButtonRelease-$xfButton>\"  \"$xfMenu invoke active; $xfMenu unpost\"" xfResult]} {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "$xfResult"
      } {
        puts stdout "$xfResult"
      }
      return
    }
  }
}
}


# Procedure: MenuPopupHandle
if {"[info procs MenuPopupHandle]" == ""} {
proc MenuPopupHandle { xfMenu xfW xfX xfY} {
# xf ignore me 7
##########
# Procedure: MenuPopupHandle
# Description: handle the popup menus
# Arguments: xfMenu - the menu to attach
#            xfW - the widget
#            xfX - the root x coordinate
#            xfY - the root x coordinate
# Returns: none
# Sideeffects: none
##########

  if {"[info commands $xfMenu]" != "" && [winfo ismapped $xfMenu]} {
    set xfPopMinX [winfo rootx $xfMenu]
    set xfPopMaxX [expr $xfPopMinX+[winfo width $xfMenu]]
    if {($xfX >= $xfPopMinX) &&  ($xfX <= $xfPopMaxX)} {
      $xfMenu activate @[expr $xfY-[winfo rooty $xfMenu]]
    } {
      $xfMenu activate none
    }
  }
}
}


# Procedure: NoFunction
if {"[info procs NoFunction]" == ""} {
proc NoFunction { args} {
# xf ignore me 7
##########
# Procedure: NoFunction
# Description: do nothing (especially with scales and scrollbars)
# Arguments: args - a number of ignored parameters
# Returns: none
# Sideeffects: none
##########
}
}


# Procedure: SN
if {"[info procs SN]" == ""} {
proc SN { {xfName ""}} {
# xf ignore me 7
##########
# Procedure: SN
# Description: map a symbolic name to the widget path
# Arguments: xfName
# Returns: the symbolic name
# Sideeffects: none
##########

  SymbolicName $xfName
}
}


# Procedure: SymbolicName
if {"[info procs SymbolicName]" == ""} {
proc SymbolicName { {xfName ""}} {
# xf ignore me 7
##########
# Procedure: SymbolicName
# Description: map a symbolic name to the widget path
# Arguments: xfName
# Returns: the symbolic name
# Sideeffects: none
##########

  global symbolicName

  if {"$xfName" != ""} {
    set xfArrayName ""
    append xfArrayName symbolicName ( $xfName )
    if {![catch "set \"$xfArrayName\"" xfValue]} {
      return $xfValue
    } {
      if {"[info commands XFProcError]" != ""} {
        XFProcError "Unknown symbolic name:\n$xfName"
      } {
        puts stderr "XF error: unknown symbolic name:\n$xfName"
      }
    }
  }
  return ""
}
}


# Procedure: Unalias
proc Unalias { aliasName} {
# xf ignore me 7
##########
# Procedure: Unalias
# Description: remove an alias for a procedure
# Arguments: aliasName - the alias name to remove
# Returns: none
# Sideeffects: internalAliasList is updated, and the alias
#              proc is removed
##########
  global internalAliasList

  set xfIndex [lsearch $internalAliasList "$aliasName *"]
  if {$xfIndex != -1} {
    rename $aliasName ""
    set internalAliasList [lreplace $internalAliasList $xfIndex $xfIndex]
  }
}



# application parsing procedure
proc XFLocalParseAppDefs {xfAppDefFile} {
  global xfAppDefaults

  # basically from: Michael Moore
  if {[file exists $xfAppDefFile] &&
      [file readable $xfAppDefFile] &&
      "[file type $xfAppDefFile]" == "link"} {
    catch "file type $xfAppDefFile" xfType
    while {"$xfType" == "link"} {
      if {[catch "file readlink $xfAppDefFile" xfAppDefFile]} {
        return
      }
      catch "file type $xfAppDefFile" xfType
    }
  }
  if {!("$xfAppDefFile" != "" &&
        [file exists $xfAppDefFile] &&
        [file readable $xfAppDefFile] &&
        "[file type $xfAppDefFile]" == "file")} {
    return
  }
  if {![catch "open $xfAppDefFile r" xfResult]} {
    set xfAppFileContents [read $xfResult]
    close $xfResult
    foreach line [split $xfAppFileContents "\n"] {
      # backup indicates how far to backup.  It applies to the
      # situation where a resource name ends in . and when it
      # ends in *.  In the second case you want to keep the *
      # in the widget name for pattern matching, but you want
      # to get rid of the . if it is the end of the name. 
      set backup -2  
      set line [string trim $line]
      if {[string index $line 0] == "#" || "$line" == ""} {
        # skip comments and empty lines
        continue
      }
      set list [split $line ":"]
      set resource [string trim [lindex $list 0]]
      set i [string last "." $resource]
      set j [string last "*" $resource]
      if {$j > $i} { 
        set i $j
        set backup -1
      }
      incr i
      set name [string range $resource $i end]
      incr i $backup
      set widname [string range $resource 0 $i]
      set value [string trim [lindex $list 1]]
      if {"$widname" != "" && "$widname" != "*"} {
        # insert the widget and resourcename to the application
        # defaults list.
        set xfAppDefaults($widname:[string tolower $name]) $value
      }
    }
  }
}

# application loading procedure
proc XFLocalLoadAppDefs {xfClasses {xfPriority "startupFile"} {xfAppDefFile ""}} {
  global env

  if {"$xfAppDefFile" == ""} {
    set xfFileList ""
    if {[info exists env(XUSERFILESEARCHPATH)]} {
      append xfFileList [split $env(XUSERFILESEARCHPATH) :]
    }
    if {[info exists env(XAPPLRESDIR)]} {
      append xfFileList [split $env(XAPPLRESDIR) :]
    }
    if {[info exists env(XFILESEARCHPATH)]} {
      append xfFileList [split $env(XFILESEARCHPATH) :]
    }
    append xfFileList " /usr/lib/X11/app-defaults"
    append xfFileList " /usr/X11/lib/X11/app-defaults"

    foreach xfCounter1 $xfClasses {
      foreach xfCounter2 $xfFileList {
        set xfPathName $xfCounter2
        if {[regsub -all "%N" "$xfPathName" "$xfCounter1" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%T" "$xfPathName" "app-defaults" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%S" "$xfPathName" "" xfResult]} {
          set xfPathName $xfResult
        }
        if {[regsub -all "%C" "$xfPathName" "" xfResult]} {
          set xfPathName $xfResult
        }
        if {[file exists $xfPathName] &&
            [file readable $xfPathName] &&
            ("[file type $xfPathName]" == "file" ||
             "[file type $xfPathName]" == "link")} {
          catch "option readfile $xfPathName $xfPriority"
          if {"[info commands XFParseAppDefs]" != ""} {
            XFParseAppDefs $xfPathName
          } {
            if {"[info commands XFLocalParseAppDefs]" != ""} {
              XFLocalParseAppDefs $xfPathName
            }
          }
        } {
          if {[file exists $xfCounter2/$xfCounter1] &&
              [file readable $xfCounter2/$xfCounter1] &&
              ("[file type $xfCounter2/$xfCounter1]" == "file" ||
               "[file type $xfCounter2/$xfCounter1]" == "link")} {
            catch "option readfile $xfCounter2/$xfCounter1 $xfPriority"
            if {"[info commands XFParseAppDefs]" != ""} {
              XFParseAppDefs $xfCounter2/$xfCounter1
            } {
              if {"[info commands XFLocalParseAppDefs]" != ""} {
                XFLocalParseAppDefs $xfCounter2/$xfCounter1
              }
            }
          }
        }
      }
    }
  } {
    # load a specific application defaults file
    if {[file exists $xfAppDefFile] &&
        [file readable $xfAppDefFile] &&
        ("[file type $xfAppDefFile]" == "file" ||
         "[file type $xfAppDefFile]" == "link")} {
      catch "option readfile $xfAppDefFile $xfPriority"
      if {"[info commands XFParseAppDefs]" != ""} {
        XFParseAppDefs $xfAppDefFile
      } {
        if {"[info commands XFLocalParseAppDefs]" != ""} {
          XFLocalParseAppDefs $xfAppDefFile
        }
      }
    }
  }
}

# application setting procedure
proc XFLocalSetAppDefs {{xfWidgetPath "."}} {
  global xfAppDefaults

  if {![info exists xfAppDefaults]} {
    return
  }
  foreach xfCounter [array names xfAppDefaults] {
    if {[string match "${xfWidgetPath}*" $xfCounter]} {
      set widname [string range $xfCounter 0 [expr [string first : $xfCounter]-1]]
      set name [string range $xfCounter [expr [string first : $xfCounter]+1] end]
      # Now lets see how many tcl commands match the name
      # pattern specified.
      set widlist [info command $widname]
      if {"$widlist" != ""} {
        foreach widget $widlist {
          # make sure this command is a widget.
          if {![catch "winfo id $widget"]} {
            catch "$widget configure -[string tolower $name] $xfAppDefaults($xfCounter)" 
          }
        }
      }
    }
  }
}



# end source
proc EndSrc {} {
  # bindings
  EMTextBind Text
  bind Text <Alt-Tab> {focus [tk_focusNext %W]}
  bind Text <Meta-Tab> {focus [tk_focusNext %W]}
  bind Text <Alt-Shift-Tab> {focus [tk_focusPrev %W]}
  bind Text <Alt-Shift-Return> {focus [tk_focusPrev %W]}
  bind Text <Meta-Shift-Tab> {focus [tk_focusPrev %W]}
  bind Text <Meta-Shift-Return> {focus [tk_focusPrev %W]}
  bind Entry <Return> {focus [tk_focusNext %W]}
  bind Entry <Shift-Return> {focus [tk_focusPrev %W]}

  global CopyingMessage
  set CopyingMessage [FindFileFromPath tkedit.copying.message]
  global WarrantyMessage
  set WarrantyMessage [FindFileFromPath Warranty.message]
  global HelpFile
  set HelpFile [FindFileFromPath TkEditLibr.help]
  global ListItemsHelpFile
  set ListItemsHelpFile [FindFileFromPath ListItems.help]
  global {PrintCardsHelpFile}
  set {PrintCardsHelpFile} [FindFileFromPath PrintCards.help]
  global {PrintLabelsHelpFile}
  set {PrintLabelsHelpFile} [FindFileFromPath PrintLabels.help]
  global {EditCardHelpFile}
  set {EditCardHelpFile} [FindFileFromPath EditCard.help]
}

# prepare auto loading
global auto_path
global tk_library
global xfLoadPath
set auto_path "[split $xfLoadPath :] $tk_library [info library]"

# initialize global variables
proc InitGlobals {} {
  global {CopyingMessage}
  set {CopyingMessage} {}
  global {CurrentLibrary}
  set {CurrentLibrary} {}
  global {EditCardHelpFile}
  set {EditCardHelpFile} {}
  global {PrintCardsHelpFile}
  set {PrintCardsHelpFile} {}
  global {PrintLabelsHelpFile}
  set {PrintLabelsHelpFile} {}
  global {HelpFile}
  set {HelpFile} {}
  global {ListItemsHelpFile}
  set {ListItemsHelpFile} {}
  global {WarrantyMessage}
  set {WarrantyMessage} {}
  global {PrintDevice}
  set {PrintDevice} {Printer}
  global {PrintLargeCards}
  set {PrintLargeCards} {1}
  global {PrintBy}
  set {PrintBy} {id}
  global {alertBox}
  set {alertBox(activeBackground)} {}
  set {alertBox(activeForeground)} {}
  set {alertBox(after)} {0}
  set {alertBox(anchor)} {nw}
  set {alertBox(background)} {}
  set {alertBox(button)} {0}
  set {alertBox(font)} {}
  set {alertBox(foreground)} {}
  set {alertBox(justify)} {center}
  set {alertBox(toplevelName)} {.alertBox}
  global fsBox
  set fsBox(activeBackground) ""
  set fsBox(activeForeground) ""
  set fsBox(background) ""
  set fsBox(font) ""
  set fsBox(foreground) ""
  set fsBox(scrollActiveForeground) ""
  set fsBox(scrollBackground) ""
  set fsBox(scrollForeground) ""
  set fsBox(scrollSide) left
  set fsBox(showPixmap) 0
  set fsBox(name) ""
  set fsBox(path) [pwd]
  set fsBox(pattern) *
  set fsBox(typeMask) Regular
  set fsBox(button) 0
  set fsBox(extensions) 0
  set fsBox(internalPath) [pwd]
  global {inputBox}
  set {inputBox(activeBackground)} {}
  set {inputBox(activeForeground)} {}
  set {inputBox(anchor)} {n}
  set {inputBox(background)} {}
  set {inputBox(erase)} {1}
  set {inputBox(font)} {}
  set {inputBox(foreground)} {}
  set {inputBox(justify)} {center}
  set {inputBox(scrollActiveForeground)} {}
  set {inputBox(scrollBackground)} {}
  set {inputBox(scrollForeground)} {}
  set {inputBox(scrollSide)} {left}
  set {inputBox(toplevelName)} {.inputBox}
  global {textBox}
  set {textBox(activeBackground)} {}
  set {textBox(activeForeground)} {}
  set {textBox(background)} {}
  set {textBox(button)} {0}
  set {textBox(contents)} {}
  set {textBox(font)} {}
  set {textBox(foreground)} {}
  set {textBox(scrollActiveForeground)} {}
  set {textBox(scrollBackground)} {}
  set {textBox(scrollForeground)} {}
  set {textBox(scrollSide)} {left}
  set {textBox(state)} {disabled}
  set {textBox(toplevelName)} {.textBox}
  global {yesNoBox}
  set {yesNoBox(activeBackground)} {}
  set {yesNoBox(activeForeground)} {}
  set {yesNoBox(afterNo)} {0}
  set {yesNoBox(afterYes)} {0}
  set {yesNoBox(anchor)} {n}
  set {yesNoBox(background)} {}
  set {yesNoBox(button)} {0}
  set {yesNoBox(font)} {*times-bold-r-normal*24*}
  set {yesNoBox(foreground)} {}
  set {yesNoBox(justify)} {center}

  # please don't modify the following
  # variables. They are needed by xf.
  global {autoLoadList}
  set {autoLoadList(TkEditLibr)} {0}
  set {autoLoadList(main.tcl)} {0}
  global {internalAliasList}
  set {internalAliasList} {}
  global {moduleList}
  set {moduleList(TkEditLibr)} {}
  global {preloadList}
  set {preloadList(xfInternal)} {}
  global {symbolicName}
  set {symbolicName(root)} {.}
  global {xfWmSetPosition}
  set {xfWmSetPosition} {}
  global {xfWmSetSize}
  set {xfWmSetSize} {}
  global {xfAppDefToplevels}
  set {xfAppDefToplevels} {}
}

# initialize global variables
InitGlobals

# display/remove toplevel windows.
ShowWindow.

# load default bindings.
if {[info exists env(XF_BIND_FILE)] &&
    "[info procs XFShowHelp]" == ""} {
  source $env(XF_BIND_FILE)
}

# parse and apply application defaults.
XFLocalLoadAppDefs TkEditLibr
XFLocalSetAppDefs

# end source
EndSrc

# eof
#

