Annotation of capa/capa51/GUITools/quizzer.tcl, revision 1.5

1.1       albertel    1: ###########################################################
                      2: # quizzer.tcl - 
                      3: # Copyright Guy Albertelli II 1996
                      4: ###########################################################
                      5: set gTclVer 4.0
                      6: 
                      7: ###########################################################
                      8: # createControlWindow
                      9: ###########################################################
                     10: # Creates the menu window 
                     11: ###########################################################
                     12: # Arguments: none
                     13: # Returns: nothing
                     14: ###########################################################
                     15: proc createControlWindow {} {
                     16:     global gPrefs gDate gFind gChanged gWindowMenu gStudentSelection gFile \
                     17: 	   gUniqueNumber gXdviOpt gHeaderQCount gDir gHintVal gTryVal gProbVal \
                     18:            gPutLine gQuizTemp gCapaConfig gStopPrinting gFindList gFirstTime \
                     19:            gRefChanged gChangedLast gCreateImportLinks gFasterParsing
                     20:     
                     21:     after 500 { dateUpdate }
                     22:     after 1000 { cleanWindowList }
                     23: 
                     24:     set gFasterParsing 1
                     25:     set gFirstTime 1
                     26:     set gPrefs(info) "Problem"
                     27:     set gPrefs(TeXHeader) ""
                     28:     set gPrefs(TeXFooter) ""
                     29:     set gFind(find) ""
                     30:     set gFind(replace) ""
                     31:     set gFind(findOption) "-nocase"
                     32:     set gFind(scope) File
                     33:     set gChanged 0
                     34:     set gChangedLast 0
                     35:     trace variable gChanged w updateChangeStatus
                     36:     trace variable gRefChanged w updateChangeStatus
                     37:     set gStudentSelection(type) "Random"
                     38:     set gStudentSelection(random) "1"
                     39:     set gStudentSelection(studentNumber) ""
                     40:     set gStudentSelection(studentName) ""
                     41:     set gFile ""
                     42:     set gUniqueNumber 1
                     43:     set gXdviOpt "-geometry 800x650" 
                     44:     set gHeaderQCount 0
                     45:     set gPutLine 1
                     46:     set gTryVal 99
                     47:     set gHintVal 1
                     48:     set gProbVal 1
                     49:     set gStopPrinting 0
                     50:     set gDir(class) [pwd]
                     51:     set gDir(import) [pwd]
                     52:     set gDir(include) [pwd]
                     53:     set gDir(reference) [pwd]
                     54:     set gQuizTemp "true"
                     55:     set gFindList(files) ""
                     56:     set gFindList(refNum) ""
                     57:     set gCreateImportLinks 1
                     58:     set gCapaConfig(IMP_color) #0000ff
                     59:     set gCapaConfig(comment_color) #008400
                     60:     set gCapaConfig(Printer_selected) "0"
                     61:     set gCapaConfig(latex_command) "latex"
                     62:     set gCapaConfig(qzparse_command) "qzparse"
                     63:     set gCapaConfig(dvips_command) "dvips"
                     64:     set gCapaConfig(xdvi_command) "xdvi"
                     65:     set gCapaConfig(lprOneSided_command) "lpr "
                     66:     set gCapaConfig(lprTwoSided_command) ""
                     67:     set gCapaConfig(printer_option) ""
                     68:     set gCapaConfig(standardQuizzerHeader) "//CAPA system software is copyrighted by Michigan State University.\n//By using these materials, the User agrees to:\n//1) Protect the source code files  from unauthorized copying.\n//2) Limit  access  of the source material to teaching staff.\n//3) The User is free to mix, cut and paste, modify, adapt, delete,\n//   improve, etc. the problems and graphics for his/her own use.\n//\n/IMP \"../Tools/StdMacros\"\n/IMP \"../Tools/StdUnits\"\n/IMP \"../Tools/StdConst\"\n/IMP \"HWTop\"\n"
                     69:     
                     70: 
                     71:     wm withdraw .
                     72: 
                     73:     # there is code later on that depends upon .main existing and being visable
                     74:     set menuFrame [menu .main -tearoff 0 -type tearoff ]
                     75: 
                     76:     wm title $menuFrame "Quizzer"
                     77: 
                     78:     $menuFrame post 0 0
                     79: 
                     80:     wm geometry $menuFrame "+0+20"
                     81:     $menuFrame add command -label "Quizzer" -foreground grey85 -background \
                     82: 	    black -state disabled 
                     83:     $menuFrame add command -label "Info" -command { createInfoWindow }
                     84:     $menuFrame add cascade -label "File" -menu $menuFrame.file
                     85:     #$menuFrame add cascade -label "Edit .qz" -menu $menuFrame.edit
                     86:     #$menuFrame add cascade -label "Find" -menu $menuFrame.find
                     87:     $menuFrame add command -label "Prefs" -command { createPrefsWindow }
                     88:     $menuFrame add cascade -label "Windows" -menu $menuFrame.windows
                     89:     $menuFrame add command -label "Create .dvi" -command { 
                     90: 	studentSelectWindow createDvi } -accelerator "Alt+D"
                     91:     bind all <Alt-Shift-D> "studentSelectWindow createDvi"
                     92:     $menuFrame add command -label "Analyze Set" -command { 
                     93: 	analyzeSet } -accelerator "Alt+A"
                     94:     bind all <Alt-Shift-A> "analyzeSet"
                     95:     $menuFrame add command -label "Print" -command { printWindow }
                     96:     $menuFrame add command -label "Remap" -command { createRemapWindow }
                     97:     $menuFrame add command -label "Xdvi Options" -command { createXdviOpt }
                     98:     #$menuFrame add command -label "Change font" -command { changeFont }
                     99:     $menuFrame add command -label "Quit" -command { quit } \
                    100: 	    -accelerator "Alt+q"
                    101:     bind all <Alt-q> quit
                    102:     bind $menuFrame <Destroy> "quit 1"
                    103: 
                    104:     set file  [menu $menuFrame.file -tearoff 1  ]
                    105:     set edit    [menu $menuFrame.edit -tearoff 1 ]
                    106:     #set find    [menu $menuFrame.find -tearoff 1 ]
                    107:     set windows [menu $menuFrame.windows -tearoff 1 ]
                    108:     set gWindowMenu $windows
                    109:     
                    110:     $file add command -label "Set.qz File" -foreground grey50 -background \
                    111: 	    black -state disabled     
                    112:     $file add command -label "New" -command { 
                    113: 	createEditingWindow 
                    114: 	pickCapaConfig
                    115:     } -accelerator "Alt+n"
                    116:     bind all <Alt-n> { 
                    117: 	createEditingWindow 
                    118: 	pickCapaConfig
                    119:     }
                    120:     $file add command -label "Open" -command { openDocument } -accelerator "Alt+o"
                    121:     bind all <Alt-o> openDocument
                    122:     $file add command -label "Save" -command { saveDocument } -accelerator "Alt+s"
                    123:   #  binding moved to the creation of the editwindow
                    124:   #  bind $menuFrame <Alt-s> saveDocument
                    125:     $file add command -label "Save As..." -command { saveDocument 1 } \
                    126: 	-accelerator "Alt+S"
                    127:   #  binding moved to the creation of the editwindow
                    128:   #  bind $menuFrame <Alt-Shift-s> { saveDocument 1 }
                    129:     $file add command -label "Delete" -command { deleteFile 0 } 
                    130:     $file add command -label "Close" -command { closeDocument } -accelerator "Alt+w"
                    131:   #  binding moved to the creation of the editwindow
                    132:   #  bind .main <Alt-w> closeDocument
                    133:     $file add command -label "Reference File" -foreground grey90 -background \
                    134: 	    black -state disabled     
                    135:     $file add command -label "New Reference File..." \
                    136: 	-command { newReferenceFile } -accelerator "Alt+t"
                    137:     bind all <Alt-t> openReferenceFile
                    138:     $file add command -label "Open Reference File..." \
                    139: 	-command { openReferenceFile } -accelerator "Alt+r"
                    140:     bind all <Alt-r> openReferenceFile
                    141:     $file add command -label "Open capa.config" \
                    142: 	-command { openReferenceFile capa.config } 
                    143:     
                    144:     $edit add command -label "Cut" -command { cut } -accelerator "Alt+x"
                    145:   #  binding moved to the creation of the editwindow
                    146:   #  bind $menuFrame <Alt-x> cut 
                    147:     $edit add command -label "Copy" -command { copy } -accelerator "Alt+c"
                    148:   #  binding moved to the creation of the editwindow
                    149:   #  bind $menuFrame <Alt-c> copy
                    150:     $edit add command -label "Paste" -command { paste } -accelerator "Alt+v"
                    151:   #  binding moved to the creation of the editwindow
                    152:   #  bind .main <Alt-v> paste
                    153:     $edit add command -label "Select All " -command { selectAll } \
                    154: 	    -accelerator "Alt+a"
                    155:   #  binding moved to the creation of the editwindow
                    156:   #  bind $menuFrame <Alt-a> selectAll 
                    157:     $edit add separator
                    158:     $edit add command -label "Undo" -command "undo 0" \
                    159: 	    -accelerator "Alt+u"
                    160: #    $edit add command -label "Redo" -command "redo $num"
                    161:     $edit add separator
                    162:     $edit add command -label "Find" -command { createFindWindow } \
                    163: 	-accelerator "Alt+f"
                    164:     bind all <Alt-f> createFindWindow
                    165: 
                    166: #    $find add command -label "Find Panel.." -command { createFindWindow } \
                    167: 	    -accelerator "Alt+f"
                    168: #    bind all <Alt-f> createFindWindow
                    169: #    $find add command -label "Find Next" -command { next }
                    170: #    $find add command -label "Find Previous" -command { previous }
                    171: #    $find add command -label "Enter Selecton" -command { enterSelection }
                    172: #    $find add command -label "Jump to Selection" -command { jumpToSelection }
                    173: #    $find add command -label "Line Range..." -command { createLineWindow } \
                    174: 	    -accelerator "Alt+l"
                    175: #    bind all <Alt-l> createLineWindow
                    176: 
                    177:     bind all <Alt-0> printInfo
                    178:     bind all <Alt-KeyPress> { #unbind tkTraverseToMenu 
                    179:     } 
                    180:     bind all <Control-Tab> {tkTabToWindow [tk_focusPrev %W]}
                    181:     catch {bind all <ISO_Left_Tab> {tkTabToWindow [tk_focusPrev %W]}}
                    182:     catch {bind all <KP_Tab> {tkTabToWindow [tk_focusPrev %W]}}
                    183:     trace variable gQuizTemp w "changeMenuStatus $menuFrame"
                    184: }
                    185: 
                    186: ###########################################################
                    187: # changeMenuStatus
                    188: ###########################################################
                    189: # either enables or disable printing or creation of Dvi files
                    190: # based on the value of the gQuizTemp global
                    191: ###########################################################
                    192: # Argument: menuFrame (path name of the menu window)
                    193: #           name1 (name of traced varaiable, gQuizTemp)
                    194: #           name2 (empty argument from trace)
                    195: #           op (tracing on writes so this should be "w")
                    196: # Returns : nothing
                    197: # Globals : gQuizTemp (r)
                    198: ###########################################################
                    199: proc changeMenuStatus { menuFrame name1 name2 op } {
                    200:     global gQuizTemp
                    201:     if { $gQuizTemp } {
                    202: 	$menuFrame entryconfigure  5 -state normal
                    203: 	$menuFrame entryconfigure  6 -state normal 
                    204:     } else {
                    205: 	$menuFrame entryconfigure  5 -state disabled 
                    206: 	$menuFrame entryconfigure  6 -state disabled 
                    207:     }
                    208: }
                    209: 
                    210: ###########################################################
                    211: # printInfo
                    212: ###########################################################
                    213: # gets called by Alt-0, used to print out variable while
                    214: # still running
                    215: ###########################################################
                    216: # Argument: none
                    217: # Returns : nothing
                    218: # Globals : auto_path
                    219: ###########################################################
                    220: proc printInfo { } {
                    221:     global auto_path gUndo gRefText
                    222:     set num [lindex [array names gRefText] 0]
                    223:     set a "updateLocation 0"
                    224:     puts [list Main2: [time $a 20000]]
                    225:     set a "updateLocation $num"
                    226:     puts [list Ref  : [time $a 20000]]
                    227: }
                    228: 
                    229: ###########################################################
                    230: # createXdviOpt
                    231: ###########################################################
                    232: ###########################################################
                    233: ###########################################################
                    234: proc createXdviOpt {} {
                    235:     global gXdviOpt gWindowMenu
                    236: 
                    237:     if { [winfo exists .xdviOpt] } { 
                    238: 	capaRaise .xdviOpt 
                    239: 	return
                    240:     }
                    241: 
                    242:     set xdviOpt [toplevel .xdviOpt]
                    243:     $gWindowMenu add command -label "XdviOptions" -command "capaRaise $xdviOpt"
                    244:     wm title $xdviOpt "Options for Xdvi"
                    245: 
                    246:     set messageFrame [frame $xdviOpt.msg]
                    247:     message $xdviOpt.msg2 -text "Example: -geometry 800x700" -aspect 5000
                    248:     set buttonFrame [frame $xdviOpt.buttons -bd 10]
                    249:     pack $messageFrame $xdviOpt.msg2 $buttonFrame -side top -fill x
                    250: 
                    251:     message $messageFrame.msg -text "Options to xdvi:" -aspect 5000
                    252:     entry $messageFrame.entry -textvariable gXdviOpt
                    253: 
                    254:     pack $messageFrame.msg $messageFrame.entry -side left -fill x
                    255:     
                    256:     button $buttonFrame.ok -text Dismiss -command "destroy $xdviOpt
                    257:             removeWindowEntry XdviOptions" -underline 0
                    258:     pack $buttonFrame.ok -side left
                    259:     bind $xdviOpt <Destroy> "removeWindowEntry XdviOptions"
                    260: }
                    261: 
                    262: ###########################################################
                    263: # createInfoWindow
                    264: ###########################################################
                    265: # creates the Information window
                    266: ###########################################################
                    267: # Arguments: None
                    268: # Returns: Nothing
                    269: # Globals: gDate - the variable containg the current date 
                    270: #          gWindowMenu - used to register the new window in the
                    271: #                        windows menu
                    272: #          gVer - Stores the current version of Quizzer (set in 
                    273: #                 C init code
                    274: ###########################################################
                    275: proc createInfoWindow {} {
                    276:     global gDate gWindowMenu gVer gTclVer gCmd gCompileDate gUndoSize gUniqueNumber
                    277: 
                    278:     if { [winfo exists .about] } { 
                    279: 	capaRaise .about
                    280: 	return 
                    281:     }
                    282: 
                    283:     set about [toplevel .about]
                    284:     $gWindowMenu add command -label "About" -command "capaRaise $about"
                    285:     wm title $about "About" 
                    286:     
                    287:     label $about.l1  -font 12x24 -text "Quizzer $gVer" -pady 20
                    288:     label $about.l4  -font 8x13 -text "Quizzer.tcl version $gTclVer" -pady 20
                    289:     label $about.l6  -font 8x13 -text "$gCompileDate" 
                    290:     message $about.l2 -font 8x13 -text "Code by: Y. Tsai, G. Albertelli II Copyright Michigan State University Board of Trustees, 1992-1999, No Unauthorized Commercial Use" \
                    291: 	-pady 20 -aspect 300
                    292:     label $about.l3  -font 8x13 -textvariable gDate 
                    293:     label $about.l5  -font 8x13 -textvariable gCmd
                    294:     label $about.l7  -font 8x13 -textvariable gUndoSize
                    295:     label $about.l8  -font 8x13 -textvariable gUniqueNumber
                    296:    
                    297:     button $about.close -text "Close" -command "destroy $about
                    298:                                                 removeWindowEntry About"
                    299:     
                    300:     pack $about.l1 $about.l4 $about.l6 $about.l2 $about.l3 $about.l5 $about.l7 $about.l8\
                    301: 	    $about.close -side top 
                    302:     bind $about <Destroy> "removeWindowEntry About"
                    303:     Centre_Dialog $about default
                    304: }
                    305: 
                    306: ###########################################################
                    307: # enterSelection 
                    308: ###########################################################
                    309: ###########################################################
                    310: ###########################################################
                    311: proc enterSelection {} {
                    312:     global gTextWindow gFind
                    313:     if { [catch {set gTextWindow}] } { return }
                    314:     if { ![winfo exists $gTextWindow] } { return }
                    315: 
                    316:     createFindWindow
                    317:     catch {set gFind(find) [$gTextWindow get sel.first sel.last]}
                    318: }
                    319: 
                    320: ###########################################################
                    321: # jumpToSelection 
                    322: ###########################################################
                    323: ###########################################################
                    324: ###########################################################
                    325: proc jumpToSelection {} {
                    326:     global gTextWindow
                    327:     catch {$gTextWindow see sel.first}
                    328: }
                    329: 
                    330: proc cut {} {global gTextWindow;tk_textCut $gTextWindow}
                    331: proc copy {} {global gTextWindow;tk_textCopy $gTextWindow}
                    332: proc paste {} {global gTextWindow;tk_textPaste $gTextWindow}
                    333: 
                    334: ###########################################################
                    335: # selectAll 
                    336: ###########################################################
                    337: ###########################################################
                    338: ###########################################################
                    339: proc selectAll { { refNum 0 } } {
                    340:     global gTextWindow gRefText
                    341: 
                    342:     if { $refNum } { set window $gRefText($refNum) } else {
                    343: 	catch {set window $gTextWindow}
                    344:     } 
                    345:     if { ![winfo exists $window] } { return }
                    346:     $window tag add sel 0.0 end
                    347: }
                    348: 
                    349: ###########################################################
                    350: # creatEditingWindow
                    351: ###########################################################
                    352: ###########################################################
                    353: # Arguments: none
                    354: # Returns: a one if the Editing window existed and a zero
                    355: #          if it created a new window
                    356: # Globals:
                    357: ###########################################################
                    358: proc createEditingWindow { {setupUndo 1} } {
                    359:     global gEditWindow gPreviewMode gTextWindow gSetNumberText gFile \
                    360: 	gWindowMenu gNumberParsedText gLineNumberGoto gUndo \
                    361: 	gCharacterNumberGoto gLineNumberGoto gClosedDocument \
                    362: 	gPreviewButton gFirstTime
                    363: 
                    364:     if { [winfo exists .editwindow] } { 
                    365: 	capaRaise .editwindow
                    366: 	return 1 
                    367:     }
                    368:     set gFirstTime 1
                    369: 
                    370:     set gEditWindow [toplevel .editwindow]
                    371:     $gWindowMenu add command -label "$gFile" -command "capaRaise $gEditWindow"
                    372:     wm title $gEditWindow $gFile
                    373:     set gClosedDocument 0
                    374:     set editWindow [frame $gEditWindow.frame -borderwidth 10]
                    375:     
                    376:     pack $editWindow -expand 1 -fill both
                    377:    
                    378:     set editTop [frame $editWindow.editTop]
                    379:     set editBottom [frame $editWindow.editBottom]
                    380: 
                    381:     pack $editTop $editBottom -side top
                    382:     pack configure $editBottom -expand 1 -fill both
                    383: 
                    384:     set menuFrame [frame $editTop.menu -borderwidth 2 -relief raised]
                    385:     set assignInfo [frame $editTop.assignInfo -borderwidth 4 -relief groove]
                    386:     set mode [frame $editTop.mode -borderwidth 4 -relief groove]
                    387:     set buttonAndGoto [frame $editTop.buttonAndGoto ]
                    388:     pack $menuFrame $assignInfo $mode $buttonAndGoto -side left
                    389:     pack configure $menuFrame -anchor n
                    390: 
                    391:     menubutton $menuFrame.edit -text Edit -menu $menuFrame.edit.m
                    392:     pack $menuFrame.edit -side left
                    393: 
                    394:     set edit [ menu $menuFrame.edit.m ]
                    395:     $edit add command -label "Cut" -command { cut } -accelerator "Alt+x"
                    396:     $edit add command -label "Copy" -command { copy } -accelerator "Alt+c"
                    397:     $edit add command -label "Paste" -command { paste } -accelerator "Alt+v"
                    398:     $edit add command -label "Select All " -command { selectAll } -accelerator "Alt+a"
                    399:     $edit add separator
                    400:     $edit add command -label "Undo" -command "undo 0" -accelerator "Alt+u"
                    401:     $edit add separator
                    402:     $edit add command -label "Find" -command { createFindWindow } -accelerator "Alt+f"
                    403:     bind all <Alt-f> createFindWindow
                    404: 
                    405:     set buttons [frame $buttonAndGoto.buttons ]
                    406:     set gotoFrame [ frame $buttonAndGoto.gotoFrame ]
                    407:     pack $buttons $gotoFrame -side top
                    408: 
                    409:     set button1 [frame $buttons.button1]
                    410:     set button2 [frame $buttons.button2]
                    411:     pack $button1 $button2 -side top
                    412: 
                    413:     set gPreviewButton [button $button1.preview -text "Preview"  -command \
                    414: 			    { studentSelectWindow createPreviewWindow }]
                    415:     button $button1.dbHeader -text "DB Header"  -command createDBHeader
                    416:     button $button1.include -text "Include"  -command includeFile
                    417:     pack $button1.preview $button1.dbHeader $button1.include -side left
                    418:     
                    419:     button $button2.header -text "Std. Header" \
                    420:  	    -command insertStandardHeader
                    421:     button $button2.import -text "Import" -command importFile
                    422:     button $button2.end -text "Endline" -command insertEndline
                    423:     pack $button2.header $button2.import $button2.end -side left
                    424:         
                    425:     label $gotoFrame.msg -text "Current Line:"
                    426:     label $gotoFrame.current -textvariable gLineNumber
                    427:     entry $gotoFrame.line -width 8 -textvariable gLineNumberGoto
                    428:     bind $gotoFrame.line <KeyPress-Return> "gotoLine"
                    429:     button $gotoFrame.button -text "Goto" -command "gotoLine"
                    430:     pack $gotoFrame.msg $gotoFrame.current $gotoFrame.line \
                    431: 	    $gotoFrame.button -side left
                    432:     # variable used by gotoLine, needs to be set if it doesn't exist
                    433:     if { [ catch { set gCharacterNumberGoto } ] } {
                    434: 	set gCharacterNumberGoto ""
                    435:     }
                    436: 
                    437:     label $assignInfo.time -textvariable gDate 
                    438:     set setNum [frame $assignInfo.setNum -borderwidth 2]
                    439:     set probsParsed [frame $assignInfo.probsParsed -borderwidth 2]
                    440:     
                    441:     pack $assignInfo.time $setNum $probsParsed -side top
                    442:     pack configure $setNum $probsParsed -anchor e
                    443: 
                    444:     message $setNum.msg -text "Problem Set Number" -aspect 10000 
                    445:     set setNumberWindow [message $setNum.num  -relief sunken  -width 70 \
                    446: 	    -textvariable gSetNumberText]
                    447:     
                    448:     pack $setNum.num $setNum.msg -side right -anchor e
                    449: 
                    450:     label $probsParsed.msg -text "Number of Questions Parsed"  
                    451:     set numberParsedWindow [label $probsParsed.num -relief sunken  \
                    452: 	    -textvariable gNumberParsedText]
                    453:     
                    454:     pack $probsParsed.num $probsParsed.msg -side right -anchor e
                    455:     
                    456:     message $mode.msg -text "Mode" -aspect 10000 
                    457:     radiobutton $mode.enscript -text "Enscript" -value "Enscript" \
                    458: 	    -variable gPreviewMode 
                    459:     radiobutton $mode.tex -text "TeX" -value "TeX" -variable gPreviewMode
                    460:     radiobutton $mode.web -text "Web" -value "Web" -variable gPreviewMode
                    461:     
                    462:     pack $mode.msg $mode.enscript $mode.tex $mode.web -side top
                    463:     pack configure $mode.enscript $mode.tex $mode.web -anchor w 
                    464:     set gPreviewMode Enscript
                    465: 
                    466:     scrollbar $editBottom.scroll -orient vertical -command \
                    467: 	    "$editBottom.text yview"
                    468:     set gTextWindow [text $editBottom.text -yscrollcommand \
                    469: 	    "$editBottom.scroll set" -wrap char -height 40]
                    470: 
                    471:     pack $editBottom.scroll $editBottom.text -side left -expand 0
                    472:     pack configure $editBottom.scroll -expand 0 -fill y
                    473:     pack configure $editBottom.text -expand true -fill both
                    474: 
                    475:     if { $setupUndo} {
                    476: 	rename $gTextWindow .$gTextWindow
                    477: 	trackChanges $gTextWindow 0
                    478: 	set gUndo(0) 0
                    479: 	set gUndo(0.cur) 0
                    480:     }
                    481: 
                    482:     bind $gTextWindow <Alt-s> saveDocument
                    483:     bind $gTextWindow <Alt-Shift-s> { saveDocument 1 }
                    484:     bind $gEditWindow <Alt-w> closeDocument
                    485: #    bind $gEditWindow <Destroy> "closeDocument 1"
                    486:     wm protocol $gEditWindow WM_DELETE_WINDOW "closeDocument 1"
                    487:     bind $gTextWindow <Alt-x> "tk_textCut %W"
                    488:     bind $gTextWindow <Alt-c> "tk_textCopy %W"
                    489:     bind $gTextWindow <Alt-v> "tk_textPaste %W"
                    490:     bind $gTextWindow <Alt-a> selectAll 
                    491:     bind $gTextWindow <Alt-u> "undo 0" 
                    492:     addFindList
                    493:     Centre_Dialog $gEditWindow default
                    494: 
                    495:     createImportLinks 0 0.0 end
                    496:     return 0
                    497: }
                    498: 
                    499: ###########################################################
                    500: # includeFile 
                    501: ###########################################################
                    502: ###########################################################
                    503: ###########################################################
                    504: proc includeFile {} {
                    505:     global gTextWindow gDir
                    506:     
                    507:     if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
                    508: 	return
                    509:     }
                    510:     
                    511: #    if { $gDir(include) == "." } { set gDir(include) [pwd] }
                    512:     set file [tk_getOpenFile -filetypes \
                    513: 	    { { {All Files} {"*"} } { {Quizzer} {"*.qz"} } } \
                    514: 	    -title "Select the proper file" \
                    515: 	    -initialdir "$gDir(include)" ]
                    516:     if { $file == "" } { return }
                    517:     set gDir(include) [file dirname $file]
                    518: 
                    519:     if { $file == "" } { return }
                    520: 
                    521:     set fileId [open $file "r"]
                    522:     
                    523:     $gTextWindow insert insert [read $fileId [file size $file]]
                    524: }
                    525: 
                    526: ###########################################################
                    527: # insertStandardHeader 
                    528: ###########################################################
                    529: ###########################################################
                    530: ###########################################################
                    531: proc insertStandardHeader {} {
                    532:     global gTextWindow gCapaConfig
                    533:     
                    534:     if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
                    535:  	return
                    536:     }
                    537:     $gTextWindow insert insert $gCapaConfig(standardQuizzerHeader)
                    538: }
                    539: 
                    540: ###########################################################
                    541: # importFile 
                    542: ###########################################################
                    543: ###########################################################
                    544: ###########################################################
                    545: proc importFile {} {
                    546:     global gTextWindow gDir gProbVal gTryVal gHintVal gPutLine
                    547:     
                    548:     if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
                    549:  	return
                    550:     }
                    551:     
                    552: #    if { $gDir(import) == "." } { set gDir(import) [pwd] }
                    553:     set file [tk_getOpenFile -filetypes \
                    554: 	    { { {All Files} {"*"} } { {Quizzer} {"*.qz"} } } \
                    555: 	    -title "Select the proper file" -initialdir "$gDir(import)" ]
                    556:     if { $file == "" } { return }
                    557:     set gDir(import) [file dirname $file]
                    558: 
                    559:     
                    560:     if { [getProbValTryVal] == "Cancel" } { return }
                    561:     
                    562:     $gTextWindow insert insert "//\n/BEG prob_val=$gProbVal\n/LET try_val=$gTryVal\n/LET hint_val=$gHintVal\n/DIS(\"$file\")\n/IMP \"$file\"\n"
                    563:     if { $gPutLine } {
                    564: 	$gTextWindow insert insert "/DIS(stdline)\n"
                    565:     } else {
                    566:  	$gTextWindow insert insert "/DIS(webonlyline)\n"
                    567:     }
                    568:     $gTextWindow see insert
                    569: }
                    570: 
                    571: ###########################################################
                    572: # insertEndline 
                    573: ###########################################################
                    574: ###########################################################
                    575: ###########################################################
                    576: proc insertEndline {} {
                    577:     global gTextWindow
                    578:     
                    579:     if { [makeSure "Is the cursor in the correct position?"] == "Cancel" } {
                    580:  	return
                    581:     }
                    582:     $gTextWindow insert insert "/END(stdendline)\n"
                    583: }
                    584: 
                    585: ###########################################################
                    586: # getProbValTryVal
                    587: ###########################################################
                    588: ###########################################################
                    589: ###########################################################
                    590: proc getProbValTryVal {} {
                    591:     global gPrompt gProbVal gTryVal gHintVal gPutLine
                    592:     
                    593:     set dialog [toplevel .getProbValTryVal -borderwidth 10]
                    594:     wm title $dialog "Getting Problem Value and Try Value"
                    595:     wm geo $dialog "+200+200"
                    596:     message $dialog.msg -text "Set the weight of the problem and the number of tries allowed." -aspect 700
                    597:     
                    598:     set gPrompt(result) ""
                    599:     scale $dialog.probVal -orient horizontal -variable gProbVal \
                    600:  	    -from 0 -to 9 -label "Problem Value" -length 150
                    601:     scale $dialog.tryVal -orient horizontal -variable gTryVal \
                    602:  	    -from 0 -to 99 -label "Try Value" -length 150
                    603:     scale $dialog.hintVal -orient horizontal -variable gHintVal \
                    604:  	    -from 1 -to 99 -label "Number of Tries Before Showing Hint" -length 150
                    605:     set gPrompt(stdline.1) "Put a stdline after this problem."
                    606:     set gPrompt(stdline.0) "Put a webonlyline after this problem."
                    607:     checkbutton $dialog.putLine -variable gPutLine \
                    608: 	    -width 38 \
                    609: 	    -textvariable gPrompt(displayLine) \
                    610: 	    -command { set gPrompt(displayLine) $gPrompt(stdline.$gPutLine) }
                    611:     set gPrompt(displayLine) $gPrompt(stdline.$gPutLine) 
                    612:     set buttonFrame [frame $dialog.buttons -bd 10]
                    613:     pack $dialog.msg $dialog.probVal $dialog.tryVal $dialog.hintVal $dialog.putLine \
                    614:  	    $buttonFrame -side top -fill x
                    615:     
                    616:     button $buttonFrame.yes -text Import -command {set gPrompt(yes) 1} \
                    617:  	    -underline 0
                    618:     button $buttonFrame.cancel -text Cancel -command { set gPrompt(yes) 0 } \
                    619:  	    -underline 0
                    620:     pack $buttonFrame.yes $buttonFrame.cancel -side left
                    621:     
                    622:     bind $dialog <Alt-Key> break
                    623:     bind $dialog <Destroy> "set gPrompt(yes) 0"
                    624:     Centre_Dialog $dialog default
                    625:     update
                    626:     
                    627:     focus $dialog
                    628:     capaRaise $dialog
                    629:     capaGrab $dialog
                    630:     vwait gPrompt(yes)
                    631:     capaGrab release $dialog
                    632:     bind $dialog <Destroy> ""
                    633:     destroy $dialog
                    634:     if {$gPrompt(yes)} {
                    635:  	return Done
                    636:     } else {
                    637:  	return Cancel
                    638:     }
                    639: }
                    640: 
                    641: ###########################################################
                    642: # updateDateBox 
                    643: ###########################################################
                    644: ###########################################################
                    645: ###########################################################
                    646: proc updateDateBox { listbox } {
                    647:     global gControlDates
                    648:     $listbox delete 0 end
                    649:     for {set i 0} {$i < [llength $gControlDates]} {incr i } {
                    650: 	set date [lindex $gControlDates $i]
                    651: 	if { $i != 0 } {
                    652: 	    $listbox insert end [eval format {"%4d %4d   %s %s %s"} $date]
                    653: 	} else {
                    654: 	    $listbox insert end [eval format {"  DEFAULT   %s %s %s"} [lrange $date 2 end]]
                    655: 	}
                    656:     }
                    657: }
                    658: 
                    659: ###########################################################
                    660: # loadDates 
                    661: ###########################################################
                    662: ###########################################################
                    663: ###########################################################
                    664: proc loadDates { listbox } {
                    665:     global gControlDates
                    666:     if { [catch {getHeaderInfo}]} { 
                    667: 	displayError "That set.db does not exist"
                    668:     } 
                    669:     updateDateBox $listbox
                    670: }
                    671: 
                    672: ###########################################################
                    673: # deleteDate 
                    674: ###########################################################
                    675: ###########################################################
                    676: ###########################################################
                    677: proc deleteDate { listbox } {
                    678:     global gControlDates
                    679:     if { [set a [$listbox index anchor]] != 0 } {
                    680: 	catch {$listbox delete anchor}
                    681: 	set gControlDates [lreplace $gControlDates $a $a]
                    682:     } else {
                    683: 	displayError "You can not delete the default setting, only change it."
                    684:     }
                    685: }
                    686: 
                    687: ###########################################################
                    688: # checkHeaderForDefault 
                    689: ###########################################################
                    690: ###########################################################
                    691: ###########################################################
                    692: proc checkHeaderForDefault { } {
                    693:     global gControlDates
                    694:     if { [lindex [lindex $gControlDates 0] 0] == 0 && \
                    695: 	     [lindex [lindex $gControlDates 0] 1] == 0 } {
                    696: 	return 1
                    697:     }
                    698:     return 0
                    699: }
                    700: 
                    701: ###########################################################
                    702: # dueAnswerOrder 
                    703: ###########################################################
                    704: ###########################################################
                    705: ###########################################################
                    706: proc dueAnswerOrder { } {
                    707:     global gDates
                    708:     set duetime [clock scan "$gDates(duemonth)/$gDates(dueday)/$gDates(dueyear) $gDates(duehour):$gDates(dueminute)"]
                    709:     set answertime [clock scan "$gDates(answermonth)/$gDates(answerday)/$gDates(answeryear) $gDates(answerhour):$gDates(answerminute)"]
                    710:     if { $duetime > $answertime } { return 1 } { return 0 }
                    711: }
                    712: 
                    713: ###########################################################
                    714: # checkDateFields 
                    715: ###########################################################
                    716: ###########################################################
                    717: ###########################################################
                    718: proc checkDateFields { } {
                    719:     global gDates
                    720: 
                    721:     set result 1
                    722:     foreach kind { open due answer } {
                    723: 	foreach type { year month day hour minute } {
                    724: 	    if { [validate $kind $type] != 1 } {
                    725: 		return $kind$type
                    726: 	    }
                    727: 	}
                    728:     }
                    729:     if { [validate "" durationhour] != 1 } { return durationhour }
                    730:     if { [validate  duration minute] != 1 } { return durationminute }
                    731:     if { [catch { expr $gDates(sectionstart) }] } { return sectionstart } else {
                    732: 	if {[string length $gDates(sectionstart)] <1} { return sectionstart } else {
                    733: 	    if { [catch { expr $gDates(sectionend) }] } { return sectionend } else {
                    734: 		if {[string length $gDates(sectionend)] <1} { return sectionend } 
                    735: 	    }
                    736: 	}
                    737:     }    
                    738:     return $result
                    739: }
                    740: 
                    741: ###########################################################
                    742: # validate
                    743: ###########################################################
                    744: ###########################################################
                    745: ###########################################################
                    746: proc validate { kind type {newvalue novalue} } {
                    747:     global gDates
                    748:     #tcl interprets all strings of digits with 0 as the first number as being 
                    749:     #in octal, need to prevent this from causing an error
                    750:     if { $newvalue == "novalue" } { 
                    751: 	set temp $gDates($kind$type)
                    752: 	set lowfail -1
                    753:     } else {
                    754: 	if { $newvalue == "" } { return 1 }
                    755: 	set temp $newvalue
                    756: 	set lowfail 1
                    757:     }
                    758:     if { [string length $temp] > 1  && [string index $temp 0] == 0 } {
                    759: 	set test [string range $temp 1 end]
                    760:     } else {
                    761: 	set test $temp
                    762:     }
                    763:     if { [catch { expr $test }] } { return 0 } else {
                    764: 	switch $type {
                    765: 	    year { 
                    766: 		if { $test < 1990 } { return $lowfail } 
                    767: 		if { $test > 9999 } { return 0 } 
                    768: 		if { [string length $temp] > 4 } { return 0 }
                    769: 	    }
                    770: 	    month { 
                    771: 		if { $test < 1 } { return $lowfail } 
                    772: 		if { $test > 12 } { return 0 } 
                    773: 		if { [string length $temp] > 2 } { return 0 }
                    774: 	    }
                    775: 	    day { 
                    776: 		if { $test < 1 } { return $lowfail } 
                    777: 		if { $test > 31 } { return 0 } 
                    778: 		if { [string length $temp] > 2 } { return 0 }
                    779: 	    }
                    780: 	    hour {
                    781: 		if { $test < 0 } { return 0 }
                    782: 		if { $test > 23 } { return 0 }
                    783: 		if { [string length $temp] > 2 } { return 0 }
                    784: 	    }
                    785: 	    minute {
                    786: 		if { $test < 0 } { return 0 }
                    787: 		if { $test > 59 } { return 0 }
                    788: 		if { [string length $temp] > 2 } { return 0 }
                    789: 	    }
                    790: 	    durationhour {
                    791: 		if { $test < 0 } { return 0 }
                    792: 		if { [string length $temp] > 4 } { return 0 }
                    793: 	    }
                    794: 	}
                    795:     }
                    796:     return 1
                    797: }
                    798: 
                    799: ###########################################################
                    800: # getday
                    801: ###########################################################
                    802: ###########################################################
                    803: ###########################################################
                    804: proc getday { kind } {
                    805:     global gDates
                    806:     if { [set day $gDates([set kind]day)] != ""} {
                    807: 	if { [set month $gDates([set kind]month)] != ""} {
                    808: 	    if { [set year $gDates([set kind]year)] != ""} {
                    809: 		if { [ catch { set gDates($kind.dayoweek) \
                    810: 				   [clock format [clock scan "$month/$day/$year"] \
                    811: 					-format %a] } error ] } {
                    812: 		    set gDates($kind.dayoweek) ""
                    813: 		}
                    814: 		return
                    815: 	    }
                    816: 	}
                    817:     }
                    818:     set gDates($kind.dayoweek) ""
                    819: }
                    820: 
                    821: ###########################################################
                    822: # enableDateValidation
                    823: ###########################################################
                    824: ###########################################################
                    825: ###########################################################
                    826: proc  enableDateValidation { toplevel } {
                    827:     global gDates
                    828:     set dateFrame $toplevel.dateFrame
                    829:     foreach type { open due answer } {
                    830: 	$dateFrame.[set type]date.year configure -validate key \
                    831: 	    -validatecommand "validate $type year %P"
                    832: 	$dateFrame.[set type]date.month configure -validate key \
                    833: 	    -validatecommand "validate $type month %P"
                    834: 	$dateFrame.[set type]date.day configure -validate key \
                    835: 	    -validatecommand "validate $type day %P"
                    836: 	$dateFrame.[set type]time.hour configure -validate key \
                    837: 	    -validatecommand "validate $type hour %P"
                    838: 	$dateFrame.[set type]time.minute configure -validate key \
                    839: 	    -validatecommand "validate $type minute %P"
                    840:     }
                    841:     $gDates(optFrame).duration.hour configure -validate key \
                    842: 	-validatecommand "validate {} durationhour %P"
                    843:     $gDates(optFrame).duration.minute configure -validate key \
                    844: 	-validatecommand "validate duration minute %P"
                    845: 
                    846: }
                    847: 
                    848: ###########################################################
                    849: # addDateOptions
                    850: ###########################################################
                    851: ###########################################################
                    852: ###########################################################
                    853: proc addDateOptions {} {
                    854:     global gDates
                    855:     pack $gDates(optFrame2)
                    856:     $gDates(optBut) configure -text "Less Options" -command "removeDateOptions"
                    857: }
                    858: 
                    859: ###########################################################
                    860: # removeDateOptions
                    861: ###########################################################
                    862: ###########################################################
                    863: ###########################################################
                    864: proc removeDateOptions {} {
                    865:     global gDates
                    866:     pack forget $gDates(optFrame2)
                    867:     $gDates(optBut) configure -text "More Options" -command "addDateOptions"
                    868: }
                    869: 
                    870: ###########################################################
                    871: # createDateDialog
                    872: ###########################################################
                    873: ###########################################################
                    874: ###########################################################
                    875: proc createDateDialog { toplevel makedefault } {
                    876:     global gDates gPrompt2
                    877: 
                    878:     catch [unset gDates]
                    879: 
                    880:     set infoFrame [frame $toplevel.infoFrame]
                    881:     set sectionFrame [frame $toplevel.sectionFrame -borderwidth 4]
                    882:     set dateFrame [frame $toplevel.dateFrame]
                    883:     set optionsFrame [frame $toplevel.optionsFrame]
                    884:     set buttonFrame [frame $toplevel.buttonFrame]
                    885:     pack $infoFrame $sectionFrame $dateFrame $buttonFrame -side top
                    886:     
                    887:     if { $makedefault } {
                    888: 	label $sectionFrame.sectionl -text "Default value for all sections:"
                    889: 	pack $sectionFrame.sectionl
                    890: 	set gDates(sectionstart) 0
                    891: 	set gDates(sectionend) 0
                    892:     } else {
                    893: 	grid [label $sectionFrame.sectionl -text "Dates and times are for"] \
                    894: 	    -column 0 -columnspan 4 -row 0
                    895: 	grid [label $sectionFrame.section12 -text "section:"] -column 0 -row 1
                    896: 	grid [entry $sectionFrame.start -width 3 -textvariable gDates(sectionstart)] \
                    897: 	    -column 1 -row 1
                    898: 	grid [label $sectionFrame.sectionl3 -text "through section: "] -column 2 -row 1
                    899: 	grid [entry $sectionFrame.end -width 3 -textvariable gDates(sectionend)] \
                    900: 	    -column 3 -row 1
                    901: 	button $buttonFrame.getdefaults -text "Get Defaults" -command \
                    902: 	    "setValues 0 0;enableDateValidation $toplevel"
                    903: 	pack $buttonFrame.getdefaults -side left
                    904:     }
                    905: 
                    906:     grid [label $dateFrame.datel -text "Date"] -column 1 -row 0
                    907:     grid [label $dateFrame.timel -text "Time"] -column 2 -row 0
                    908:     grid [label $dateFrame.helpd -text "yyyy/mm/dd"] -column 1 -row 1
                    909:     grid [label $dateFrame.helpt -text "hh:mm"] -column 2 -row 1
                    910:     grid [label $dateFrame.openl -text "Open"] -column 0 -row 2
                    911:     grid [set openDate [frame $dateFrame.opendate -borderwidth 2 -relief sunken]] -column 1 -row 2
                    912:     grid [set openTime [frame $dateFrame.opentime -borderwidth 2 -relief sunken]] -column 2 -row 2
                    913:     grid [label $dateFrame.openday -textvariable gDates(open.dayoweek)] -column 3 -row 2
                    914:     grid [label $dateFrame.duel -text "Due"] -column 0 -row 3
                    915:     grid [set dueDate [frame $dateFrame.duedate -borderwidth 2 -relief sunken]] -column 1 -row 3
                    916:     grid [set dueTime [frame $dateFrame.duetime -borderwidth 2 -relief sunken]] -column 2 -row 3
                    917:     grid [label $dateFrame.dueday -textvariable gDates(due.dayoweek)] -column 3 -row 3
                    918:     grid [label $dateFrame.answerl -text "Answer"] -column 0 -row 4
                    919:     grid [set answerDate [frame $dateFrame.answerdate -borderwidth 2 -relief sunken]] -column 1 -row 4
                    920:     grid [set answerTime [frame $dateFrame.answertime -borderwidth 2 -relief sunken]] -column 2 -row 4		
                    921:     grid [label $dateFrame.ansday -textvariable gDates(answer.dayoweek)] -column 3 -row 4
                    922:     
                    923:     
                    924:     foreach type { open due answer } {
                    925: 	entry [set [set type]Date].year -width 4 -textvariable gDates([set type]year) 
                    926: 	label [set [set type]Date].sl1 -text "/"
                    927: 	entry [set [set type]Date].month -width 2 -textvariable gDates([set type]month) 
                    928: 	label [set [set type]Date].sl2 -text "/"
                    929: 	entry [set [set type]Date].day -width 2 -textvariable gDates([set type]day) 
                    930: 	entry [set [set type]Time].hour -width 2 -textvariable gDates([set type]hour) 
                    931: 	label [set [set type]Time].colon -text ":"
                    932: 	entry [set [set type]Time].minute -width 2 -textvariable gDates([set type]minute)
                    933: 	pack [set [set type]Date].year [set [set type]Date].sl1 \
                    934: 	    [set [set type]Date].month [set [set type]Date].sl2 \
                    935: 	    [set [set type]Date].day -side left
                    936: 	pack [set [set type]Time].hour [set [set type]Time].colon \
                    937: 	    [set [set type]Time].minute -side left
                    938:     }
                    939: 
                    940:     set optionsFrame3 [frame $optionsFrame.options]
                    941:     set gDates(optFrame) [ set optionsFrame2 [frame $optionsFrame3.options ] ]
                    942:     pack $gDates(optFrame) $optionsFrame3
                    943:     set gDates(optFrame2) $optionsFrame
                    944: 
                    945:     set durationFrame [frame $optionsFrame2.duration]
                    946:     checkbutton $optionsFrame2.view -variable gDates(viewbetween) \
                    947: 	-text "Allow Viewing between Due and Answer dates" 
                    948:     checkbutton $optionsFrame2.response -variable gDates(inhibitresponse) \
                    949: 	-text "Inhibit Correct/Incorrect response \n(normally only for exams/quizzes)"
                    950:     pack $durationFrame $optionsFrame2.view $optionsFrame2.response -side top
                    951:     set gDates(viewbetween) 1
                    952:     set gDates(inhibitresponse) 0
                    953: 
                    954:     label $durationFrame.label -text "Duration"
                    955:     entry $durationFrame.hour  -width 4 -textvariable gDates(durationhour)
                    956:     label $durationFrame.colon -text ":"
                    957:     entry $durationFrame.minute -width 2 -textvariable gDates(durationminute) 
                    958:     pack $durationFrame.label $durationFrame.hour $durationFrame.colon \
                    959: 	$durationFrame.minute -side left
                    960:     set gDates(durationhour) 0
                    961:     set gDates(durationminute) 0
                    962: 
                    963:     button $buttonFrame.help -text "Help" -command "showHelp dateEntry"
                    964:     button $buttonFrame.set -text "Ok" -command "set gPrompt2(ok) 1"
                    965:     button $buttonFrame.cancel -text "Cancel" -command "set gPrompt2(ok) 0"
                    966:     set gDates(optBut) [ button $buttonFrame.options -text "More Options" \
                    967: 			     -command "addDateOptions"]
                    968:     pack $buttonFrame.help $buttonFrame.set $buttonFrame.cancel $buttonFrame.options \
                    969: 	-side left
                    970:     bind $toplevel <Destroy> "set gPrompt2(ok) 0"
                    971:     bind $toplevel <KeyPress> "getday open;getday due;getday answer"
                    972:     bind $toplevel <Return> {tkTabToWindow [tk_focusNext %W]}
                    973: }
                    974: 
                    975: ###########################################################
                    976: # addCurrentDates
                    977: ###########################################################
                    978: ###########################################################
                    979: ###########################################################
                    980: proc addCurrentDates { listbox makedefault {which -1} } {
                    981:     global gControlDates gDates
                    982:     foreach kind { open due answer } {
                    983: 	foreach type { year month day hour minute } {
                    984: 	    #tcl interprets all strings of digits with 0 as the first number as 
                    985: 	    #being in octal, need to prevent this from causing an error
                    986: 	    if { [string length $gDates($kind$type)] > 1  && \
                    987: 		     [string index $gDates($kind$type) 0] == 0 } {
                    988: 		set gDates($kind$type) [string range $gDates($kind$type) 1 end]
                    989: 	    }
                    990: 	}
                    991:     }
                    992:     set datestring [list $gDates(sectionstart) $gDates(sectionend) \
                    993: 			[format "%04d/%02d/%02d %02d:%02d" $gDates(openyear) \
                    994: 			     $gDates(openmonth) $gDates(openday) \
                    995: 			     $gDates(openhour) $gDates(openminute) ] \
                    996: 			[format "%04d/%02d/%02d %02d:%02d" $gDates(dueyear) \
                    997: 			     $gDates(duemonth) $gDates(dueday) \
                    998: 			     $gDates(duehour) $gDates(dueminute) ] \
                    999: 			[format "%04d/%02d/%02d %02d:%02d" $gDates(answeryear) \
                   1000: 			     $gDates(answermonth) $gDates(answerday) \
                   1001: 			     $gDates(answerhour) $gDates(answerminute) ] \
                   1002: 		        [format "%d:%d" $gDates(durationhour) $gDates(durationminute)] \
                   1003: 			$gDates(inhibitresponse) $gDates(viewbetween) ]
                   1004:     if { $makedefault } {
                   1005: 	if { ([info globals gControlDates] == "") || ($gControlDates == "") } {
                   1006: 	    set gControlDates [list $datestring]
                   1007: 	} else { 
                   1008: 	    set gControlDates [lreplace $gControlDates 0 0 $datestring]
                   1009: 	}
                   1010:     } else {
                   1011: 	if { $which > -1 } {
                   1012: #	    puts "$gControlDates=$which=$which=$datestring"
                   1013: 	    set gControlDates [lreplace $gControlDates $which $which $datestring]
                   1014: 	} else {
                   1015: 	    lappend gControlDates $datestring
                   1016: 	}
                   1017:     }
                   1018:     updateDateBox $listbox
                   1019: }
                   1020: 
                   1021: ###########################################################
                   1022: # setValues
                   1023: ###########################################################
                   1024: ###########################################################
                   1025: ###########################################################
                   1026: proc setValues { which {doSections 1} } {
                   1027:     global gControlDates gDates
                   1028:     set datestring [lindex $gControlDates $which]
                   1029:     if { $doSections } {
                   1030: 	set gDates(sectionstart) [lindex $datestring 0]
                   1031: 	set gDates(sectionend) [lindex $datestring 1]
                   1032:     }
                   1033:     foreach type {open due answer} element {2 3 4} {
                   1034: 	set gDates([set type]year) [lindex [split [lindex $datestring $element] "/" ] 0]
                   1035: 	set gDates([set type]month) [lindex [split [lindex $datestring $element] "/" ] 1]
                   1036: 	set gDates([set type]day) [lindex [split [lindex [lindex $datestring $element] 0] "/" ] 2]
                   1037: 	set gDates([set type]hour) [lindex [split [lindex [lindex $datestring $element] 1] ":" ] 0]
                   1038: 	set gDates([set type]minute) [lindex [split [lindex [lindex $datestring $element] 1] ":" ] 1]
                   1039:     }
                   1040:     set gDates(durationhour) [lindex [split [lindex $datestring 5] ":" ] 0]
                   1041:     set gDates(durationminute) [lindex [split [lindex $datestring 5] ":" ] 1]
                   1042:     set gDates(inhibitresponse) [lindex $datestring 6]
                   1043:     set gDates(viewbetween) [lindex $datestring 7]
                   1044:     getday open
                   1045:     getday due
                   1046:     getday answer
                   1047: }
                   1048: 
                   1049: ###########################################################
                   1050: # changeDate
                   1051: ###########################################################
                   1052: ###########################################################
                   1053: ###########################################################
                   1054: proc changeDate { listbox } {
                   1055:     global gDates gPrompt2 gControlDates
                   1056: 
                   1057:     if { ![winfo exists $listbox] } { return }
                   1058:     if { [winfo exists .adddate] } { return }
                   1059:     if { [set which [$listbox index anchor]] == 0 } { set makedefault 1 } else { 
                   1060: 	set makedefault 0 }
                   1061:     if { $which == [$listbox index end] } {addDate $listbox;return}
                   1062:     set changeDate [toplevel .changeDate]
                   1063:     createDateDialog $changeDate $makedefault
                   1064:     setValues $which
                   1065:     enableDateValidation $changeDate
                   1066: 
                   1067:     if { $makedefault } {
                   1068: 	set gDates(sectionstart) 0
                   1069: 	set gDates(sectionend) 0
                   1070:     }
                   1071: 
                   1072:     Centre_Dialog $changeDate default
                   1073:     update
                   1074: 
                   1075:     focus $changeDate
                   1076:     capaRaise $changeDate
                   1077:     capaGrab $changeDate
                   1078:     set done 0
                   1079:     while { $done != 1 } {
                   1080: 	vwait gPrompt2(ok)
                   1081: 	if { $gPrompt2(ok) == 1 } {
                   1082: 	    if { 1 != [set done [checkDateFields]] } {
                   1083: 		displayError "Please correct field: $done"
                   1084: 		set done 0
                   1085: 	    } else {
                   1086: 		if { [dueAnswerOrder] } {
                   1087: 		    if { "Yes" == [makeSure "Right now answers are available before an assignment is due. Would you like to change this?."]} {
                   1088: 		    set done 0
                   1089: 		    } else {
                   1090: 			set done 1
                   1091: 		    }
                   1092: 		}
                   1093: 	    }
                   1094: 	} else {
                   1095: 	    set done 1
                   1096: 	}
                   1097:     }
                   1098:     capaGrab release $changeDate
                   1099:     bind $changeDate <Destroy> ""
                   1100:     destroy $changeDate
                   1101:     if {$gPrompt2(ok) == 1 } {
                   1102: 	addCurrentDates $listbox $makedefault $which
                   1103:     }    
                   1104:     return 
                   1105: }
                   1106: 
                   1107: ###########################################################
                   1108: # addDate 
                   1109: ###########################################################
                   1110: ###########################################################
                   1111: ###########################################################
                   1112: proc addDate { listbox } {
                   1113:     global gDates gPrompt2
                   1114: 
                   1115:     if { ![winfo exists $listbox ] } { return }
                   1116:     if { [winfo exists .adddate ] } { return }
                   1117:     if { [$listbox index end] == 0 } { set makedefault 1 } else { set makedefault 0 }
                   1118:     set addDate [toplevel .adddate]
                   1119: 
                   1120:     createDateDialog $addDate $makedefault
                   1121:     enableDateValidation $addDate
                   1122: 
                   1123:     Centre_Dialog $addDate default
                   1124:     update
                   1125: 
                   1126:     focus $addDate
                   1127:     capaRaise $addDate
                   1128:     capaGrab $addDate
                   1129:     set done 0
                   1130:     while { $done != 1 } {
                   1131: 	vwait gPrompt2(ok)
                   1132: 	if { $gPrompt2(ok) == 1 } {
                   1133: 	    if { 1 != [set done [checkDateFields]] } {
                   1134: 		displayError "Please correct field: $done"
                   1135: 		set done 0
                   1136: 	    } else {
                   1137: 		if { [dueAnswerOrder] } {
                   1138: 		    if { "Yes" == [makeSure "Right now answers are available before an assignment is due. Would you like to change this?."]} {
                   1139: 		    set done 0
                   1140: 		    } else {
                   1141: 			set done 1
                   1142: 		    }
                   1143: 		}
                   1144: 	    }
                   1145: 	} else {
                   1146: 	    set done 1
                   1147: 	}
                   1148:     }
                   1149:     capaGrab release $addDate
                   1150:     bind $addDate <Destroy> ""
                   1151:     destroy $addDate
                   1152:     if {$gPrompt2(ok) == 1 } {
                   1153: 	addCurrentDates $listbox $makedefault
                   1154:     }    
                   1155:     return 
                   1156: }
                   1157: 
                   1158: ###########################################################
                   1159: # createDBHeader
                   1160: ###########################################################
                   1161: ###########################################################
                   1162: ###########################################################
                   1163: proc createDBHeader {} {
                   1164:     global gNumberParsedText gPrompt gLoadHeaderSet gControlDates \
1.2       albertel 1165: 	    gSetNumberText  gHeaderQCount gEnableDiscussion gFile
1.1       albertel 1166: 
                   1167:     if { $gNumberParsedText == "" } {
                   1168: 	displayError "You must first preview the file before creating the \
                   1169: 		DB header."
                   1170: 	return
                   1171:     }
                   1172: 
                   1173:     if { [winfo exists .headerPrompt] } {
                   1174: 	capaRaise .headerPrompt
                   1175: 	return
                   1176:     }
                   1177: 
                   1178:     set dialog [toplevel .headerPrompt -borderwidth 10]
                   1179:     wm geo $dialog "+200+200"
                   1180:     wm title $dialog "Creating DB Header"
                   1181: 
                   1182:     message $dialog.msg -text "Header Information" -aspect 1000
                   1183:     set loadFrame [frame $dialog.loadFrame -borderwidth 4 -relief sunken]
                   1184:     set infoFrame [frame $dialog.infoFrame -borderwidth 4 -relief sunken]
1.2       albertel 1185:     set optionFrame [frame $dialog.options]
1.1       albertel 1186:     set buttonFrame [frame $dialog.buttons -bd 10]
1.2       albertel 1187:     pack $dialog.msg $loadFrame $infoFrame $optionFrame $buttonFrame -side top -fill x
1.1       albertel 1188: 
                   1189:     set legendFrame [frame $infoFrame.legendFrame]
                   1190:     set listFrame [frame $infoFrame.listFrame]
                   1191:     set commandFrame [frame $infoFrame.commandFrame]
                   1192:     pack $legendFrame $listFrame $commandFrame -side top
                   1193:  
                   1194:     label $legendFrame.legend1 -text " Section# |     Open       |     Due        |     Answer         "
                   1195:     label $legendFrame.legend2 -text "Start  End| Date      Time | Date     Time  | Date      Time     "
                   1196:     pack $legendFrame.legend1 $legendFrame.legend2 -side top
                   1197: 
                   1198:     set listbox [listbox $listFrame.list -width 63 -yscrollcommand "$listFrame.scroll set" ]
                   1199:     scrollbar $listFrame.scroll -command "$listbox yview"
                   1200:     pack $listFrame.list $listFrame.scroll -side left
                   1201:     updateDateBox $listbox
                   1202:     
                   1203:     button $commandFrame.add -text "Add" -command "addDate $listbox"
                   1204:     button $commandFrame.change -text "Change" -command "changeDate $listbox"
                   1205:     button $commandFrame.delete -text "Delete" -command "deleteDate $listbox"
                   1206:     pack $commandFrame.add $commandFrame.change $commandFrame.delete -side left
                   1207:     bind $listbox <Double-ButtonPress-1> "changeDate $listbox"
                   1208: 
                   1209:     message $loadFrame.msg -text "Load header information from set:"  \
                   1210: 	    -aspect 1000
                   1211:     set gLoadHeaderSet $gSetNumberText
                   1212:     entry $loadFrame.entry -textvariable gLoadHeaderSet  -width 2
                   1213:     button $loadFrame.load -text "load" -command "loadDates $listbox"
                   1214:     pack $loadFrame.msg $loadFrame.entry $loadFrame.load -side left
                   1215: 
1.2       albertel 1216:     if { [file exists [file join [file dirname $gFile] discussion $gSetNumberText]] } {
                   1217: 	set gEnableDiscussion 1
                   1218:     } else {
                   1219: 	set gEnableDiscussion 0
                   1220:     }
                   1221:     checkbutton $optionFrame.discuss -text "Enable Discussion Forum" \
                   1222: 	-variable gEnableDiscussion
                   1223:     pack $optionFrame.discuss
                   1224: 
1.1       albertel 1225:     button $buttonFrame.ok -text Set -command { set gPrompt(ok) 1 } \
                   1226: 	    -underline 0 
                   1227:     button $buttonFrame.cancel -text Cancel -command { set gPrompt(ok) 0 } \
                   1228: 	    -underline 0 
                   1229:     pack $buttonFrame.ok $buttonFrame.cancel -side left
                   1230:     
                   1231:     bind $dialog <Destroy> "set gPrompt(ok) 0"
                   1232:     Centre_Dialog $dialog default
                   1233:     update
                   1234: 
                   1235:     focus $dialog
                   1236:     capaRaise $dialog
                   1237:     capaGrab $dialog
                   1238:     bind $dialog <Destroy> ""
                   1239:     set done 0
                   1240:     while { $done != 1 } {
                   1241: 	vwait gPrompt(ok)
                   1242: 	if { $gPrompt(ok) == 1 } {
                   1243: 	    set done [checkHeaderForDefault]
                   1244: 	    if { $done == 0 } {
                   1245: 		displayError "Must have a Default setting."
                   1246: 	    }
                   1247: 	} else {
                   1248: 	    set done 1
                   1249: 	}
                   1250:     }
                   1251:     capaGrab release $dialog
                   1252:     destroy $dialog
                   1253:     if {$gPrompt(ok) == 1 } {
1.2       albertel 1254: 	updateDiscussion
1.1       albertel 1255: 	eval updateHeader [ eval concat $gControlDates ]
                   1256:     }
                   1257:     
                   1258:     return    
                   1259: 
                   1260: }
                   1261: 
                   1262: ###########################################################
1.2       albertel 1263: # updateDiscussion
                   1264: ###########################################################
                   1265: ###########################################################
                   1266: ###########################################################
                   1267: proc updateDiscussion {} {
                   1268:     global gFile gSetNumberText gEnableDiscussion
                   1269:     set dir [file dirname $gFile]
                   1270:     set disDir [file join $dir discussion $gSetNumberText]
                   1271:     set logDir [file join $dir discussion logs]
                   1272:     if { $gEnableDiscussion } {
                   1273: 	if { ![file exists $disDir] } {
                   1274: 	    if { [file exists $disDir.unavailable] } {
                   1275: 		exec mv $disDir.unavailable $disDir
                   1276: 	    } else {
                   1277: 		file mkdir $disDir
                   1278: 		file attributes $disDir -permissions 0777
                   1279: 	    }
                   1280: 	}
                   1281: 	if { ![file exists $logDir] } {
                   1282: 	    file mkdir [file join $dir discussion logs]
                   1283: 	    file attributes [file join $dir discussion logs] -permissions 0777
                   1284: 	}
                   1285:     } else { 
                   1286: 	if { [file exists $disDir] } { exec mv $disDir $disDir.unavailable } 
                   1287:     }
                   1288: }
                   1289: 
                   1290: ###########################################################
1.1       albertel 1291: # allFieldsComplete2 
                   1292: ###########################################################
                   1293: ###########################################################
                   1294: ###########################################################
                   1295: proc allFieldsComplete2 {} {
1.2       albertel 1296:     global gLoadHeaderSet gControlDates 
1.1       albertel 1297:     
                   1298:     if { [string length $gOpenDate] != 8 } {
                   1299: 	return 0
                   1300:     } elseif { [string length $gOpenTime] != 5 } {
                   1301: 	return 0
                   1302:     } elseif { [string length $gDueDate] != 8 } {
                   1303: 	return 0
                   1304:     } elseif { [string length $gDueTime] != 5 } {
                   1305: 	return 0
                   1306:     } elseif { [string length $gAnswerDate] != 8 } {
                   1307: 	return 0
                   1308:     } elseif { [string length $gAnswerTime] != 5 } {
                   1309: 	return 0
                   1310:     } else {
                   1311: 	return 1
                   1312:     }
                   1313: }
                   1314: 
                   1315: ###########################################################
                   1316: # createFindWindow
                   1317: ###########################################################
                   1318: ###########################################################
                   1319: ###########################################################
                   1320: proc createFindWindow { {num 0} } {
                   1321:     global gFind gWindowMenu gFindListbox
                   1322: 
                   1323:     if { [winfo exists .find] } { 
                   1324: 	capaRaise .find
                   1325: 	pickFindFile $num
                   1326: 	return 
                   1327:     }
                   1328: 
                   1329:     set find [toplevel .find]
                   1330:     $gWindowMenu add command -label "Find" -command "capaRaise $find"
                   1331:     wm title $find "Find"
                   1332: 
                   1333:     set findFrame [frame $find.findFrame -width 5i]
                   1334:     set replaceFrame [frame $find.replaceFrame ]
                   1335:     set optionsFrame [frame $find.optionsFrame ]
                   1336:     set buttonFrame [frame $find.buttonsFrame ]
                   1337:     pack $findFrame $replaceFrame $optionsFrame $buttonFrame -side top \
                   1338: 	    -anchor e
                   1339:     pack configure $buttonFrame -anchor center
                   1340: 
                   1341:     message $findFrame.msg -text "Find:" -aspect 10000 
                   1342:     entry $findFrame.entry -width 50  -textvariable gFind(find)
                   1343:     pack $findFrame.msg $findFrame.entry -side left
                   1344: 
                   1345:     message $replaceFrame.msg -text "Replace with:" -aspect 10000 
                   1346:     entry $replaceFrame.entry -width 50  -textvariable gFind(replace)
                   1347:     pack $replaceFrame.msg $replaceFrame.entry -side left
                   1348: 
                   1349:     set fileFrame [frame $optionsFrame.file]
                   1350:     set scopeFrame [frame $optionsFrame.scope -relief groove -borderwidth 4]
                   1351:     set findOptionsFrame [frame $optionsFrame.findOptionsFrame -relief \
                   1352: 	    groove -borderwidth 4]
                   1353:     pack $fileFrame $scopeFrame $findOptionsFrame -side left
                   1354: 
                   1355:     set fileList [ frame $fileFrame.list ]
                   1356:     set fileScroll [frame $fileFrame.scroll ]
                   1357:     pack $fileList $fileScroll -side left
                   1358:     pack configure $fileScroll -fill y
                   1359: 
                   1360:     set gFindListbox [listbox $fileList.list -width 35 -height 4 \
                   1361: 	    -xscrollcommand "$fileList.scroll set" \
                   1362: 	    -yscrollcommand "$fileScroll.scroll set" \
                   1363: 	    -exportselection no]
                   1364:     scrollbar $fileList.scroll -orient h -command "$fileList.list xview"
                   1365:     pack $fileList.list $fileList.scroll -side top
                   1366:     pack configure $fileList.scroll -fill x
                   1367:     pack configure $fileList.list -fill both -expand 1
                   1368:     $fileList.list xview moveto 1
                   1369: 
                   1370:     scrollbar $fileScroll.scroll -orient v \
                   1371: 	    -command "$fileList.list yview"
                   1372:     pack $fileScroll.scroll -fill y -expand 1
                   1373: 
                   1374:     message $scopeFrame.msg -text "Replace All Scope" -aspect 10000 
                   1375:     radiobutton $scopeFrame.file -value "File" -variable gFind(scope) -text \
                   1376: 	    "Entire File" \
                   1377: 	    
                   1378:     radiobutton $scopeFrame.selection -value "Selection" -variable \
                   1379: 	    gFind(scope) -text "Selection" 
                   1380:     pack $scopeFrame.msg $scopeFrame.file $scopeFrame.selection 
                   1381:     pack configure $scopeFrame.file $scopeFrame.selection -anchor w
                   1382:     set gFind(scope) File
                   1383: 
                   1384:     message $findOptionsFrame.msg -text "Find Options" -aspect 10000 
                   1385:     radiobutton $findOptionsFrame.ignoreCase -variable gFind(findOption) \
                   1386: 	    -text "Ignore Case" -value "-nocase"
                   1387:     radiobutton $findOptionsFrame.exactCase -variable gFind(findOption) \
                   1388: 	    -text "Exact Case" -value "-exact"
                   1389:     radiobutton $findOptionsFrame.regexp -variable gFind(findOption) \
                   1390: 	    -text "Regular Expression" -value "-regexp"
                   1391:     pack $findOptionsFrame.msg $findOptionsFrame.ignoreCase \
                   1392: 	    $findOptionsFrame.exactCase $findOptionsFrame.regexp 
                   1393:     pack $findOptionsFrame.ignoreCase $findOptionsFrame.exactCase \
                   1394: 	    $findOptionsFrame.regexp -anchor w
                   1395:     set gFind(findOption) "-nocase"
                   1396: 
                   1397:     button $buttonFrame.replaceAll -text "Replace All" -command "replaceAll" 
                   1398:     button $buttonFrame.replace -text "Replace" -command "replace" 
                   1399:     button $buttonFrame.replaceFind -text "Replace and Find" -command \
                   1400: 	    "replaceFind" 
                   1401:     button $buttonFrame.previous -text "Previous" -command "previous" 
                   1402:     button $buttonFrame.next -text "Next <Return>" -command "next" 
                   1403:     bind $find <KeyPress-Return> next
                   1404:     button $buttonFrame.close -text "Close" -command "removeWindowEntry Find
                   1405:                                                       destroy $find"
                   1406:     bind $find <Destroy> "removeWindowEntry Find"
                   1407:     pack $buttonFrame.replaceAll $buttonFrame.replace \
                   1408: 	    $buttonFrame.replaceFind $buttonFrame.previous \
                   1409: 	    $buttonFrame.next $buttonFrame.close -side left
                   1410: 
                   1411:     Centre_Dialog $find default
                   1412:     updateFindList
                   1413:     pickFindFile $num
                   1414: }
                   1415: 
                   1416: ###########################################################
                   1417: # pickFindFile
                   1418: ###########################################################
                   1419: ###########################################################
                   1420: ###########################################################
                   1421: proc pickFindFile { num } {
                   1422:     global gFindListbox gFindList gRefFile gFile
                   1423:     if { [catch {set gFindListbox}] } { return }
                   1424:     if { ![winfo exists $gFindListbox] } { return }
                   1425:     if { $num == 0 } {
                   1426: 	set newfile $gFile
                   1427:     } else {
                   1428: 	set newfile $gRefFile($num)
                   1429:     }
                   1430:     for {set i 0} {$i<[llength $gFindList(files)]} {incr i} {
                   1431: 	set file [lindex $gFindList(files) $i]
                   1432: 	if { $file == $newfile } { break }
                   1433:     }
                   1434:     if { $i < [llength $gFindList(files)] } { 
                   1435: 	$gFindListbox selection clear 0 end 
                   1436: 	$gFindListbox selection set $i 
                   1437:     }
                   1438: }
                   1439: 
                   1440: ###########################################################
                   1441: # updateFindList 
                   1442: ###########################################################
                   1443: ###########################################################
                   1444: ###########################################################
                   1445: proc updateFindList {} {
                   1446:     global gFindListbox gFindList
                   1447:     if { [catch {set gFindListbox}] } { return }
                   1448:     if { ![winfo exists $gFindListbox] } { return }
                   1449:     $gFindListbox delete 0 end
                   1450:     eval "$gFindListbox insert end $gFindList(files)"
                   1451:     $gFindListbox xview moveto 1
                   1452: }
                   1453: 
                   1454: ###########################################################
                   1455: # whichFile 
                   1456: ###########################################################
                   1457: ###########################################################
                   1458: ###########################################################
                   1459: proc whichFile { refNum } {
                   1460:     global gRefFile gFile
                   1461:     if { $refNum > 0 } {
                   1462: 	return $gRefFile($refNum)
                   1463:     } else {
                   1464: 	if { $refNum < 0 } {
                   1465: 	    switch -- $refNum {
                   1466: 		-1 { return "Preview Window" }
                   1467: 		-2 { return "Parse Errors Window" }
                   1468: 		-3 { return "LaTeX Output Window" }
                   1469: 	    }
                   1470: 	} else {
                   1471: 	    return $gFile
                   1472: 	}
                   1473:     }
                   1474: }
                   1475: ###########################################################
                   1476: # addFindList 
                   1477: ###########################################################
                   1478: ###########################################################
                   1479: ###########################################################
                   1480: proc addFindList { {refNum 0} } {
                   1481:     global gFindList gRefFile gFile
                   1482: 
                   1483:     set file [whichFile $refNum]
                   1484:     lappend gFindList(files) $file
                   1485:     lappend gFindList(refNum) $refNum
                   1486:     updateFindList
                   1487: }
                   1488: 
                   1489: ###########################################################
                   1490: # removeFindList 
                   1491: ###########################################################
                   1492: ###########################################################
                   1493: ###########################################################
                   1494: proc removeFindList { {refNum 0} } {
                   1495:     global gFindList gRefFile gFile
                   1496: 
                   1497:     set file [whichFile $refNum]
                   1498:     set k [llength $gFindList(refNum)]
                   1499:     for {set i 0} {$i < $k } { incr i } {
                   1500: 	if { $refNum == [lindex $gFindList(refNum) $i] } { break } 
                   1501:     }
                   1502:     if { $i != $k } {
                   1503: 	set gFindList(refNum) [lreplace $gFindList(refNum) $i $i]
                   1504: 	set gFindList(files) [lreplace $gFindList(files) $i $i]
                   1505:     } 
                   1506:     updateFindList
                   1507: }
                   1508: 
                   1509: ###########################################################
                   1510: # getFindWindow 
                   1511: ###########################################################
                   1512: ###########################################################
                   1513: ###########################################################
                   1514: proc getFindWindow { {refNumVar none} } {
                   1515:     global gFindListbox gFindList gRefText gTextWindow \
                   1516: 	gPreviewText gParseErrorsText gCreateDviText
                   1517: 
                   1518:     set current [$gFindListbox curselection]
                   1519:     if { $current == "" } { set current 0 }
                   1520:     if { [set refNum [lindex $gFindList(refNum) $current] ] } {
                   1521: 	if { $refNum < 0 } {
                   1522: 	    switch -- $refNum {
                   1523: 		-1 { set window $gPreviewText }
                   1524: 		-2 { set window $gParseErrorsText }
                   1525: 		-3 { set window $gCreateDviText }
                   1526: 	    }
                   1527: 	} else {
                   1528: 	    set window $gRefText($refNum)
                   1529: 	}
                   1530:     } else {
                   1531: 	set window $gTextWindow
                   1532:     }
                   1533:     if { $refNumVar != "none" } {
                   1534: 	upvar $refNumVar refNumUp
                   1535: 	set refNumUp $refNum
                   1536:     }
                   1537:     return $window
                   1538: }
                   1539: 
                   1540: ###########################################################
                   1541: # replaceAll 
                   1542: ###########################################################
                   1543: ###########################################################
                   1544: ###########################################################
                   1545: proc replaceAll {} {
                   1546:     global gFind gCreateImportLinks 
                   1547:     
                   1548:     set window [getFindWindow]
                   1549:     if { ![winfo exists $window] } { return }
                   1550: 
                   1551:     set gCreateImportLinks 0
                   1552:     set num 0
                   1553:     switch $gFind(scope) {
                   1554: 	File 
                   1555: 	{
                   1556: 	    $window mark set insert 0.0
                   1557: 	    set begin 0.0
                   1558: 	    while { [nextRegion $begin end] != "" } {
                   1559: 		incr num
                   1560: 		replace
                   1561: 		if { ! ($num%10) } { update idletasks }
                   1562: 		set begin sel.last
                   1563: 	    }
                   1564: 	}
                   1565: 	Selection
                   1566: 	{
                   1567: 	    set error [ catch {$window mark set replace sel.first}]
                   1568: 	    if { $error != 0 } { return }
                   1569: 	    $window mark set capaBegin sel.first
                   1570: 	    $window mark set capaEnd   sel.last
                   1571: 	    while { [set begin [nextRegion capaBegin capaEnd]] != "" } {
                   1572: 		incr num
                   1573: 		replace
                   1574: 		$window mark set capaBegin $begin
                   1575: 	    }
                   1576: 	}
                   1577:     }
                   1578:     if { $num == 1 } { set s {} } { set s s }    
                   1579:     update idletasks
                   1580:     set gCreateImportLinks 1
                   1581:     getFindWindow refNum
                   1582:     if { $refNum >= 0 } { registerCreateImportLinks $refNum 0.0 end }
                   1583:     displayMessage "Replaced $num occurance$s"
                   1584: }
                   1585: 
                   1586: ###########################################################
                   1587: ###########################################################
                   1588: ###########################################################
                   1589: ###########################################################
                   1590: proc replace {} {
                   1591:     global gFind 
                   1592: 
                   1593:     set refNum 0
                   1594:     set window [getFindWindow refNum]
                   1595:     if { ![winfo exist $window] } { return }
                   1596: 
                   1597:     set error [ catch {$window mark set replace sel.first}]
                   1598:     if { $error == 0 } {
                   1599: 	$window delete sel.first sel.last
                   1600:     } else {
                   1601: 	$window mark set replace insert
                   1602:     }
                   1603: 
                   1604:     $window insert replace "$gFind(replace)"
                   1605:  
                   1606:     catch {$window tag remove sel sel.first sel.last}
                   1607: 
                   1608:     $window tag add sel "replace - [string length "$gFind(replace)"] \
                   1609: 	    chars " replace
                   1610:     $window see replace
                   1611: 
                   1612:     $window mark unset replace
                   1613: }
                   1614: 
                   1615: ###########################################################
                   1616: ###########################################################
                   1617: ###########################################################
                   1618: ###########################################################
                   1619: proc replaceFind {} {
                   1620:     set window [getFindWindow]
                   1621:     if { ![winfo exists $window] } { return }
                   1622:     replace
                   1623:     next
                   1624: }
                   1625: 
                   1626: ###########################################################
                   1627: ###########################################################
                   1628: ###########################################################
                   1629: ###########################################################
                   1630: proc searchBody { found } {
                   1631:     global gFind 
                   1632: 
                   1633:     set window [getFindWindow refNum]
                   1634:     if { ![winfo exists $window] } { return }
                   1635: 
                   1636:     catch {$window tag remove sel sel.first sel.last}
                   1637:     $window tag add sel $found "$found + [string length $gFind(find)] \
                   1638: 	    chars"
                   1639:     $window see $found
                   1640:     $window mark set insert "$found + [string length $gFind(find)] chars"
                   1641: }
                   1642: 
                   1643: ###########################################################
                   1644: ###########################################################
                   1645: ###########################################################
                   1646: ###########################################################
                   1647: proc previous {} {
                   1648:     global gFind
                   1649: 
                   1650:     set window [getFindWindow]
                   1651:     if { ![winfo exists $window] } { return }
                   1652: 
                   1653:     if { [catch { set found [$window search $gFind(findOption) -backwards -- \
                   1654: 	    $gFind(find) "sel.first - 1 c" ] } ] } {
                   1655: 	set found [ $window search $gFind(findOption) -backwards -- \
                   1656: 		$gFind(find) "insert - 1 c" ]
                   1657:     }
                   1658:     if { $found != "" } { searchBody $found }
                   1659:     return $found    
                   1660: }
                   1661: 
                   1662: ###########################################################
                   1663: ###########################################################
                   1664: ###########################################################
                   1665: ###########################################################
                   1666: proc next {} {
                   1667:     global gFind 
                   1668: 
                   1669:     set window [getFindWindow]
                   1670:     if { ![winfo exists $window] } { return }
                   1671: 
                   1672:     set found [ $window search $gFind(findOption) -forwards -- \
                   1673: 	    $gFind(find) "insert + 1 c" ]
                   1674:     if { $found != "" } { 
                   1675: 	searchBody $found 
                   1676:     } else { 
                   1677: 	displayMessage "Search String Not Found" 
                   1678:     }
                   1679:     return $found    
                   1680: }
                   1681: 
                   1682: ###########################################################
                   1683: ###########################################################
                   1684: ###########################################################
                   1685: ###########################################################
                   1686: proc nextRegion { begin end } {
                   1687:     global gFind 
                   1688: 
                   1689:     set window [getFindWindow]
                   1690:     if { ![winfo exists $window] } { return }
                   1691: 
                   1692:     set error [ catch {set found [ $window search $gFind(findOption) \
                   1693: 	    -forwards -- $gFind(find) $begin $end ] } ]
                   1694:     if { $error != 0 } { set found "" }
                   1695:     if { $found != "" } { 
                   1696: 	searchBody $found 
                   1697: 	set found "$found + [string length $gFind(find)] chars"
                   1698:     }
                   1699:     return $found
                   1700: }
                   1701: 
                   1702: ###########################################################
                   1703: ###########################################################
                   1704: ###########################################################
                   1705: ###########################################################
                   1706: proc createLineWindow {} {
                   1707:     global gLineNumber gCharacterNumber gLineNumberGoto gCharacterNumberGoto
                   1708:     global gWindowMenu
                   1709: 
                   1710:     if { [winfo exists .lineWindow] } { 
                   1711: 	capaRaise .lineWindow
                   1712: 	return 
                   1713:     }
                   1714: 
                   1715:     set lineWindow [toplevel .lineWindow]
                   1716:     $gWindowMenu add command -label "LineSelect" -command \
                   1717: 	    "capaRaise $lineWindow"
                   1718:     wm title $lineWindow "Select Line"
                   1719: 
                   1720:     label $lineWindow.line -text "Line:"
                   1721:     grid $lineWindow.line -column 1 -row 0
                   1722:     label $lineWindow.character -text "Character:"
                   1723:     grid $lineWindow.character -column 2 -row 0
                   1724:     label $lineWindow.current -text "Current:"
                   1725:     grid $lineWindow.current -column 0 -row 1
                   1726:     label $lineWindow.lineNumber -textvariable gLineNumber
                   1727:     grid $lineWindow.lineNumber -column 1 -row 1
                   1728:     label $lineWindow.characterNumber -textvariable gCharacterNumber
                   1729:     grid $lineWindow.characterNumber -column 2 -row 1
                   1730:     label $lineWindow.goto -text "Goto:"
                   1731:     grid $lineWindow.goto -column 0 -row 2
                   1732:     entry $lineWindow.lineEntry -textvariable gLineNumberGoto
                   1733:     grid $lineWindow.lineEntry -column 1 -row 2
                   1734:     set gLineNumberGoto ""
                   1735:     entry $lineWindow.characterEntry -textvariable gCharacterNumberGoto
                   1736:     grid $lineWindow.characterEntry -column 2 -row 2
                   1737:     set gCharacterNumberGoto ""
                   1738:     button $lineWindow.close -text "Close" -command "destroy $lineWindow 
                   1739: 	                                       removeWindowEntry LineSelect"
                   1740:     bind $lineWindow <Destroy> "removeWindowEntry LineSelect"
                   1741:     grid $lineWindow.close -column 1 -row 3
                   1742:     button $lineWindow.gotoButton -text "Goto<Return>" -command "gotoLine"
                   1743:     grid $lineWindow.gotoButton -column 2 -row 3    
                   1744:     
                   1745:     bind $lineWindow <KeyPress-Return> gotoLine
                   1746: 
                   1747:     Centre_Dialog $lineWindow default
                   1748: }
                   1749: 
                   1750: ###########################################################
                   1751: ###########################################################
                   1752: ###########################################################
                   1753: ###########################################################
                   1754: proc gotoLine {} {
                   1755:     global gTextWindow gLineNumberGoto gCharacterNumberGoto
                   1756:     if { [catch {set gTextWindow}] } { return }
                   1757:     if { ![winfo exists $gTextWindow] } { return }
                   1758: 
                   1759:     if { $gCharacterNumberGoto == "" } {
                   1760: 	if { $gLineNumberGoto == "" } {
                   1761: 	    return
                   1762: 	} else {
                   1763: 	    $gTextWindow mark set insert $gLineNumberGoto.0
                   1764: 	    catch {$gTextWindow tag remove sel sel.first sel.last}
                   1765: 	    $gTextWindow tag add sel "insert linestart" "insert lineend"
                   1766: 	    $gTextWindow see insert
                   1767: 	} 
                   1768:     } else {
                   1769: 	if { $gLineNumberGoto == "" } {
                   1770: 	    $gTextWindow mark set insert "insert linestart + \
                   1771: 		    $gCharacterNumberGoto chars"
                   1772: 	    catch {$gTextWindow tag remove sel sel.first sel.last}
                   1773: 	    $gTextWindow tag add sel "insert - 1 chars " insert
                   1774: 	    $gTextWindow see insert
                   1775: 	} else {
                   1776: 	    $gTextWindow mark set insert $gLineNumberGoto.$gCharacterNumberGoto
                   1777: 	    catch {$gTextWindow tag remove sel sel.first sel.last}
                   1778: 	    $gTextWindow tag add sel "$gLineNumberGoto.$gCharacterNumberGoto \
                   1779: 		    - 1 chars " "$gLineNumberGoto.$gCharacterNumberGoto"
                   1780: 	    $gTextWindow see insert
                   1781: 	} 
                   1782:     }
                   1783: }
                   1784: 
                   1785: proc faster {} {
                   1786:     global gFasterParsing
                   1787:     puts $gFasterParsing
                   1788: }
                   1789: 
                   1790: ###########################################################
                   1791: # createPrefsWindow
                   1792: ###########################################################
                   1793: ###########################################################
                   1794: ###########################################################
                   1795: proc createPrefsWindow {} {
                   1796:     global gPrefs gWindowMenu gEditWindow gFile gWhichFile gPrefsEditWindow \
                   1797: 	gFasterParsing
                   1798:     if { [catch {set gEditWindow}] } { return }
                   1799:     if { ![winfo exists $gEditWindow] } { return }
                   1800:     if { [winfo exists .prefs] } { capaRaise .prefs; return }
                   1801: 
                   1802:     set prefs [toplevel .prefs]
                   1803:     $gWindowMenu add command -label "Prefrences" -command "capaRaise $prefs"
                   1804:     wm title $prefs "Preferences"
                   1805: 
                   1806:     set frameAll [frame $prefs.frameAll -relief groove -borderwidth 4]
                   1807:     pack $frameAll -expand true -fill both
                   1808: 
                   1809:     set frameFile [frame $frameAll.file]
                   1810:     set frameInfo [frame $frameAll.info -relief groove -borderwidth 4 ]
                   1811:     set frameButton [frame $frameAll.button ]
                   1812:     pack $frameButton $frameInfo $frameFile -side top -expand false
                   1813:     pack configure $frameButton -expand false -anchor center
                   1814: 
                   1815:     message $frameInfo.msg -text "Print Out"
                   1816:     radiobutton $frameInfo.problem -text "Problems Only" -value "Problem" \
                   1817: 	    -variable gPrefs(info) 
                   1818:     radiobutton $frameInfo.problemandanswer -text "Problems and Answers" \
                   1819: 	    -value "ProblemAnswer" -variable gPrefs(info) 
                   1820:     radiobutton $frameInfo.answer -text "Answers Only" -value "Answer" \
                   1821: 	    -variable gPrefs(info) 
                   1822:     pack $frameInfo.msg $frameInfo.problem $frameInfo.problemandanswer \
                   1823: 	    $frameInfo.answer -side left -expand false -anchor w
                   1824: 
                   1825:     
                   1826:     set selectMenu [tk_optionMenu $frameFile.menu gWhichFile HTMLheader HTMLfooter \
                   1827: 			TeXheader TeXfooter]
                   1828:     set frameEdit [frame $frameFile.edit]
                   1829:     pack $frameFile.menu $frameEdit
                   1830:     pack configure $frameEdit -expand true -fill both
                   1831:     trace variable gWhichFile w changePrefFile
                   1832: 
                   1833:     scrollbar $frameEdit.scroll -orient vertical -command "$frameEdit.text yview"
                   1834:     set gPrefsEditWindow [text $frameEdit.text -yscrollcommand \
                   1835: 	    "$frameEdit.scroll set" -wrap char -height 20 -width 80]
                   1836:     pack $frameEdit.scroll $frameEdit.text -side left
                   1837:     pack configure $frameEdit.scroll -expand false -fill y
                   1838:     pack configure $frameEdit.text -expand true -fill both
                   1839: 
                   1840:     checkbutton $frameButton.faster -text "Faster Parsing" -command faster \
                   1841: 	-variable gFasterParsing
                   1842:     button $frameButton.impcolor -text "/IMP color" -command "getColor IMP_color"
                   1843:     button $frameButton.commentcolor -text "// color" -command "getColor comment_color"
                   1844:     button $frameButton.config -text "Reread capa.config" -command "rereadCapaConfig"
                   1845:     button $frameButton.ok -text "Dismiss" -command "destroy $prefs
                   1846:                                                 trace vdelete gWhichFile w changePrefFile
                   1847:                                                 removeWindowEntry Prefrences"
                   1848:     bind $prefs <Destroy> "removeWindowEntry Preferences"
                   1849:     button $frameButton.save -text "Save All" -command "savePrefs"
                   1850:     pack $frameButton.impcolor $frameButton.commentcolor $frameButton.config \
                   1851: 	$frameButton.ok $frameButton.save $frameButton.faster -side left
                   1852: 
                   1853:     foreach file {HTMLheader HTMLfooter TeXheader TeXfooter} {
                   1854: 	if { [ catch {
                   1855: 	    set filename [file join [file dirname $gFile] $file ]
                   1856: 	    set fileId [open $filename r]
                   1857: 	    set gPrefs($file) [read $fileId [file size $filename ]]
                   1858: 	    close $fileId } errors ] } { 
                   1859: 	    set gPrefs($file) ""
                   1860: 	}
                   1861:     }
                   1862:     set gPrefs(currentFile) ""
                   1863:     set gWhichFile HTMLheader
                   1864: 
                   1865: 
                   1866:     Centre_Dialog $prefs default
                   1867: }
                   1868: 
                   1869: ###########################################################
                   1870: # getColor
                   1871: ###########################################################
                   1872: ###########################################################
                   1873: ###########################################################
                   1874: proc getColor { whatfor } {
                   1875:     global gCapaConfig gUniqueNumber gRefText
                   1876:     set color [tk_chooseColor -initialcolor $gCapaConfig($whatfor)]
                   1877:     set gCapaConfig($whatfor) $color 
                   1878:     if { $color != "" } { updateColors }
                   1879:     displayMessage "To keep this color, put \"$whatfor = $color\" in the capa.config file."
                   1880: }
                   1881: 
                   1882: ###########################################################
                   1883: # updateColors
                   1884: ###########################################################
                   1885: ###########################################################
                   1886: ###########################################################
                   1887: proc updateColors {} {
                   1888:     global gCapaConfig gUniqueNumber gRefText
                   1889:     set todo [array names gRefText]
                   1890:     lappend todo 0
                   1891:     displayStatus "Updating Colors . . ." both
                   1892:     set num 0
                   1893:     foreach win $todo {
                   1894: 	createImportLinks $win 0.0 end
                   1895: 	incr num
                   1896: 	updateStatusBar [expr $num/double([llength $todo])]
                   1897:     }
                   1898:     removeStatus
                   1899: }
                   1900: 
                   1901: ###########################################################
                   1902: # changePrefFile
                   1903: ###########################################################
                   1904: ###########################################################
                   1905: ###########################################################
                   1906: proc changePrefFile { var1 var2 op } {
                   1907:     global gPrefs gPrefsEditWindow gFile gWhichFile
                   1908: 
                   1909:     if { $gPrefs(currentFile) != "" } {
                   1910: 	set  gPrefs($gPrefs(currentFile)) [$gPrefsEditWindow get 0.0 end-1c]
                   1911:     }
                   1912:     set gPrefs(currentFile) $gWhichFile
                   1913:     $gPrefsEditWindow delete 0.0 end
                   1914:     $gPrefsEditWindow insert 0.0 $gPrefs($gWhichFile)
                   1915: }
                   1916: 
                   1917: ###########################################################
                   1918: # updatePrefsWindow 
                   1919: ###########################################################
                   1920: ###########################################################
                   1921: ###########################################################
                   1922: proc updatePrefsWindow {} {
                   1923:     global gPrefs gPrefsEditWindow gFile gWhichFile
                   1924:     if { [catch {set gPrefsEditWindow}] } { return }
                   1925:     if { ![winfo exists $gPrefsEditWindow] } { return }
                   1926: 
                   1927:     foreach file {HTMLheader HTMLfooter TeXheader TeXfooter} {
                   1928: 	if { [ catch {
                   1929: 	    set filename [file join [file dirname $gFile] $file ]
                   1930: 	    set fileId [open $filename r]
                   1931: 	    set gPrefs($file) [read $fileId [file size $filename]]
                   1932: 	    close $fileId } ] } { 
                   1933: 	    set gPrefs($file) ""
                   1934: 	}
                   1935:     }
                   1936:     $gPrefsEditWindow delete 0.0 end
                   1937:     $gPrefsEditWindow insert 0.0 $gPrefs($gWhichFile)
                   1938: }
                   1939: 
                   1940: ###########################################################
                   1941: ###########################################################
                   1942: ###########################################################
                   1943: ###########################################################
                   1944: proc savePrefs {} {
                   1945:     global gPrefsEditWindow gFile gPrefs 
                   1946:     if { [catch {set gPrefsEditWindow}] } { return }
                   1947:     if { ![winfo exists $gPrefsEditWindow] } { return }
                   1948:     if { $gPrefs(currentFile) != "" } {
                   1949: 	set  gPrefs($gPrefs(currentFile)) [$gPrefsEditWindow get 0.0 end-1c]
                   1950:     }
                   1951:     foreach file {HTMLheader HTMLfooter TeXheader TeXfooter} {
                   1952: 	if { $gPrefs($file) != "" } {
                   1953: 	    set fileId [open [file join [file dirname $gFile] $file ] w]
                   1954: 	    puts -nonewline $fileId $gPrefs($file)
                   1955: 	    close $fileId
                   1956: 	} else {
                   1957: 	    exec rm -f [file join [file dirname $gFile] $file ]
                   1958: 	}
                   1959:     }
                   1960: }
                   1961: 
                   1962: ###########################################################
                   1963: # checkHeader
                   1964: ###########################################################
                   1965: ###########################################################
                   1966: ###########################################################
                   1967: proc checkHeader { numberParsed } {
                   1968:     global gWeightsDiffer gPartialDiffer gSetNumberText gHeaderQCount \
                   1969: 	gControlDates gLoadHeaderSet gFirstTime
                   1970: 
                   1971: #    if { $gFirstTime } { set gFirstTime 0; return }
                   1972:     set gLoadHeaderSet $gSetNumberText
                   1973:     set error [catch {getHeaderInfo}]
                   1974:     if { $error == 1 } {
                   1975: 	set gHeaderQCount "0"
                   1976: 	set gControlDates ""
                   1977: 	displayError "The db file for this set does not yet exist."
                   1978:     } else {
                   1979: 	set errortext ""
                   1980: 	if { ( $numberParsed != $gHeaderQCount ) } {
                   1981: 	    set error 1
                   1982: 	    append errortext "Number of questions ($numberParsed) is different from the number in setX.db ($gHeaderQCount). "    
                   1983: 	} 
                   1984: 	if { $gWeightsDiffer } {
                   1985: 	    set error 1
                   1986: 	    append errortext "The problem weights specified in the QZ file are different from the ones in the DB file. "
                   1987: 	} 
                   1988: 	if { $gPartialDiffer } {
                   1989: 	    set error 1
                   1990: 	    append errortext "Whether or not a problem is hand graded as specified in the QZ file is different from the DB file. "
                   1991: 	}
                   1992: 	if { $error } {
                   1993: 	    displayError "The curent DB Header does not match what the set file says it should be: $errortext. Set the DB Header!" red
                   1994: 	}
                   1995:     }
                   1996:     return $error
                   1997: }
                   1998: 
                   1999: ###########################################################
                   2000: # fillInStudentName
                   2001: ###########################################################
                   2002: ###########################################################
                   2003: ###########################################################
                   2004: #proc notherefillInStudentName { v } {
                   2005: #    global $v
                   2006: 
                   2007: #    set student [capaGetStudent [set ${v}(studentNumber)]]
                   2008: #    set ${v}(studentName) [lindex $student [expr [llength $student] - 1] ]
                   2009: #}
                   2010: 
                   2011: ###########################################################
                   2012: # studentSelectWindow
                   2013: ###########################################################
                   2014: ###########################################################
                   2015: ###########################################################
                   2016: proc studentSelectWindow { followupCommand } {
                   2017:     global gStudentSelection gChanged gWindowMenu gEditWindow
                   2018:     if { [catch {set gEditWindow}] } { return }
                   2019:     if { ![winfo exists $gEditWindow] } { return }
                   2020:     if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
                   2021: 
                   2022:     if { [winfo exists .studentSelect] } { 
                   2023: 	capaRaise .studentSelect
                   2024: 	return
                   2025:     }
                   2026:     set student [toplevel .studentSelect]
                   2027:     $gWindowMenu add command -label "SelectStudent" \
                   2028: 	    -command "capaRaise $student"
                   2029:     wm title $student "Select Student"
                   2030: 
                   2031:     message $student.msg -text "Please specify a student to preview" \
                   2032: 	    -aspect 10000
                   2033:     set infoFrame [frame $student.frame -relief groove -borderwidth 4]
                   2034:     set buttonFrame [frame $student.buttonFrame ]
                   2035:     pack $student.msg $infoFrame $buttonFrame -side top 
                   2036: 
                   2037:     button $buttonFrame.ok -text "Preview" -command \
                   2038: 	"selectStudentPreview $student $followupCommand"
                   2039:     button $buttonFrame.cancel -text "Cancel" -command \
                   2040: 	    "destroy $student
                   2041:              trace vdelete gStudentSelection(studentNumber) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
                   2042:              trace vdelete gStudentSelection(studentName) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
                   2043:              removeWindowEntry SelectStudent"
                   2044:     bind $student <Destroy> \
                   2045: 	    "trace vdelete gStudentSelection(studentNumber) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
                   2046:              trace vdelete gStudentSelection(studentName) w \"global gStudentSelection; set gStudentSelection(type) Specific ;#\"
                   2047:              removeWindowEntry SelectStudent"
                   2048:     pack $buttonFrame.ok $buttonFrame.cancel -side left
                   2049: 
                   2050:     set randomAnyFrame [frame $infoFrame.randomany]
                   2051:     set randomFrame [frame $infoFrame.random]
                   2052:     set specificFrame [frame $infoFrame.specific]
                   2053:     set sectionFrame [frame $infoFrame.section]
                   2054: #    pack $randomAnyFrame  $randomFrame $specificFrame $sectionFrame -side top
                   2055:     pack $randomFrame $specificFrame -side top
                   2056:     pack configure $specificFrame -expand true -fill both
                   2057: 
                   2058:     radiobutton $randomAnyFrame.random -text "Randomly select a student" \
                   2059: 	-value "RandomAny" -variable gStudentSelection(type) 
                   2060:     pack $randomAnyFrame.random
                   2061: 
                   2062:     radiobutton $randomFrame.random -text "Randomly select one student \
                   2063: 	    from section:" -value "Random" -variable gStudentSelection(type) 
                   2064:     entry $randomFrame.entry -textvariable gStudentSelection(random)  -width 3
                   2065:     pack $randomFrame.random $randomFrame.entry -side left 
                   2066: 
                   2067:     radiobutton $specificFrame.specific -text "Specify the student by:" \
                   2068: 	    -value "Specific" -variable gStudentSelection(type) 
                   2069:     set studentNumber [frame $specificFrame.studentNumber]
                   2070:     set fullName [frame $specificFrame.fullName]
                   2071:     pack $specificFrame.specific $studentNumber $fullName -side top
                   2072:     pack configure $specificFrame.specific -anchor w
                   2073:     pack configure $studentNumber $fullName -anchor e
                   2074: 
                   2075:     radiobutton $sectionFrame.section 
                   2076:     message $studentNumber.msg -text "Student Number: "  -aspect 10000
                   2077:     entry $studentNumber.entry -textvariable gStudentSelection(studentNumber) \
                   2078: 	    -width 9 -validate key -validatecommand "limitEntry %W 9 any %P"
                   2079:     pack $studentNumber.msg $studentNumber.entry -side left
                   2080: 
                   2081:     message $fullName.msg -text "Student Name: "  -aspect 10000 
                   2082:     entry $fullName.msg2 -textvariable gStudentSelection(studentName) -width 35 \
                   2083: 	-validate key -validatecommand "limitEntry %W 35 any %P"
                   2084:     pack $fullName.msg $fullName.msg2 -side left
                   2085:     
                   2086:     trace variable gStudentSelection(studentNumber) w \
                   2087: 	"global gStudentSelection; set gStudentSelection(type) Specific ;#"
                   2088:     trace variable gStudentSelection(studentName) w \
                   2089: 	"global gStudentSelection; set gStudentSelection(type) Specific ;#"
                   2090: 
                   2091:     bind $studentNumber.entry <KeyPress-Return> \
                   2092: 	"fillInStudent gStudentSelection(studentName) gStudentSelection(studentNumber) 0"
                   2093:     bind $fullName.msg2 <KeyPress-Return> \
                   2094: 	"fillInStudent gStudentSelection(studentName) gStudentSelection(studentNumber) 1"
                   2095: #    $specificFrame.specific configure -command \
                   2096: 	"$studentNumber.entry configure -state normal"
                   2097: #    $randomFrame.random configure -command \
                   2098: 	"$studentNumber.entry configure -state disabled"
                   2099: 
                   2100:     Centre_Dialog $student default
                   2101: }
                   2102: 
                   2103: ###########################################################
                   2104: # selectStudentPreview
                   2105: ###########################################################
                   2106: ###########################################################
                   2107: ###########################################################
                   2108: proc selectStudentPreview { student followupCommand} {
                   2109:     global gStudentSelection
                   2110:     destroy $student
                   2111:     if { $gStudentSelection(type) == "Specific" } { 
                   2112: 	if {$gStudentSelection(studentNumber) == ""} {
                   2113: 	    fillInStudent gStudentSelection(studentName) \
                   2114: 		gStudentSelection(studentNumber) 1
                   2115: 	} else {
                   2116: 	    fillInStudent gStudentSelection(studentName) \
                   2117: 		gStudentSelection(studentNumber) 0
                   2118: 	}
                   2119: 	if {$gStudentSelection(studentNumber) == ""} { return }
                   2120:     }
                   2121:     removeWindowEntry SelectStudent
                   2122:     $followupCommand
                   2123: }
                   2124: 
                   2125: ###########################################################
                   2126: # createPreviewWindow
                   2127: ###########################################################
                   2128: ###########################################################
                   2129: ###########################################################
                   2130: proc createPreviewWindow {} {
                   2131:     global gPreviewMode gPreviewText gPrefs gSetNumberText gStudentSelection
                   2132:     global gWindowMenu gNumberParsedText    gNumber    
                   2133:     global gLoadHeaderSet gHeaderQCount gControlDates
                   2134:     
                   2135:     if { ![winfo exists .preview] } {
                   2136: 	
                   2137: 	set previewWindow [toplevel .preview]
                   2138:         $gWindowMenu add command -label "Preview" -command \
                   2139: 		"capaRaise $previewWindow"
                   2140: 	wm title $previewWindow "Preview"
                   2141: 	addFindList -1
                   2142: 
                   2143: 	set windowFrame [frame $previewWindow.windowFrame]
                   2144: 	set buttonFrame [frame $previewWindow.buttonFrame]
                   2145: 	
                   2146: 	pack $windowFrame $buttonFrame -side bottom 
                   2147: 	pack configure $windowFrame -expand true -fill both
                   2148: 	pack configure $buttonFrame -anchor e
                   2149: 
                   2150: 	scrollbar $windowFrame.scroll -orient vertical -command \
                   2151: 		"$windowFrame.text yview"
                   2152: 	set gPreviewText [text $windowFrame.text -yscrollcommand \
                   2153: 		"$windowFrame.scroll set" -wrap char -height 40]
                   2154: 	
                   2155: 	pack $windowFrame.scroll $gPreviewText -side left -expand 0
                   2156: 	pack configure $windowFrame.scroll -expand 0 -fill y
                   2157: 	pack configure $gPreviewText -expand true -fill both
                   2158: 	
                   2159: 	button $buttonFrame.ok -text Dismiss -command "destroy $previewWindow
                   2160: 	                                          removeWindowEntry Preview
                   2161:                                                   removeFindList -1"
                   2162: 	bind $previewWindow <Destroy> "removeWindowEntry Preview
                   2163:                                        removeFindList -1"
                   2164: 	button $buttonFrame.save -text "Save Output" -command "saveText $gPreviewText"
                   2165: 	button $buttonFrame.stop -text "Stop Parser" -command "stopParser"
                   2166: 	button $buttonFrame.print -text "Print Output" -command "printText $gPreviewText"
                   2167: 	pack $buttonFrame.print $buttonFrame.save $buttonFrame.stop \
                   2168: 	    $buttonFrame.ok -side left
                   2169: 	
                   2170: 	Centre_Dialog $previewWindow default
                   2171: 	wm withdraw $previewWindow
                   2172: 	update idletasks
                   2173: 	set win_width [winfo reqwidth $previewWindow]
                   2174: 	set win_height [winfo reqheight $previewWindow]
                   2175: 	wm geometry $previewWindow +[expr [winfo rootx $previewWindow] - \
                   2176: 		100]+[winfo rooty $previewWindow]
                   2177: 	wm deiconify $previewWindow
                   2178: 	update
                   2179:     } else {
                   2180: 	set previewWindow .preview
                   2181: 	$gPreviewText delete 0.0 end
                   2182: 	update
                   2183:     }
                   2184: 
                   2185:     switch $gPrefs(info) {
                   2186: 	Problem { set type 0 }
                   2187: 	ProblemAnswer { set type 1 }
                   2188: 	Answer { set type 2 }
                   2189:     }
                   2190:     grab .preview
                   2191:     if { [catch {
                   2192: 	switch $gPreviewMode {
                   2193: 	    Enscript
                   2194: 	    {
                   2195: 		set numberParsed [enscriptParse $type $gSetNumberText \
                   2196: 				  $gStudentSelection(type) $gStudentSelection(random) \
                   2197: 				  $gStudentSelection(studentNumber) \
                   2198: 				  $gStudentSelection(studentName) gPreviewText]
                   2199: 	    }
                   2200: 	    TeX
                   2201: 	    {
                   2202: 		set numberParsed [texParse $type $gSetNumberText \
                   2203: 				  $gStudentSelection(type) $gStudentSelection(random) \
                   2204: 				  $gStudentSelection(studentNumber) \
                   2205: 				  $gStudentSelection(studentName) gPreviewText]
                   2206: 	    }
                   2207: 	    Web
                   2208: 	    {
                   2209: 		set numberParsed [webParse $type $gSetNumberText \
                   2210: 				  $gStudentSelection(type) $gStudentSelection(random) \
                   2211: 				  $gStudentSelection(studentNumber) \
                   2212: 				  $gStudentSelection(studentName) gPreviewText]
                   2213: 	    }
                   2214: 	} }]} { return }
                   2215:     grab release .preview
                   2216:     if { $numberParsed == -1 } {
                   2217: 	destroy $previewWindow
                   2218: 	removeWindowEntry Preview
                   2219: 	return
                   2220:     }
                   2221:     checkHeader $numberParsed
                   2222:     $gPreviewText tag configure problem 
                   2223:     $gPreviewText tag configure answer 
                   2224:     capaRaise $previewWindow
                   2225: 
                   2226:     set gNumberParsedText $numberParsed
                   2227:     showParseErrors 
                   2228: }
                   2229: 
                   2230: ###########################################################
                   2231: ###########################################################
                   2232: ###########################################################
                   2233: ###########################################################
                   2234: proc showParseErrors {} {
                   2235:     global gParseErrorsText gWindowMenu
                   2236: 
                   2237:     set parseErrors [getParseErrors]
                   2238:     
                   2239:     if { $parseErrors != "" } {
                   2240: 
                   2241: 	if { ![winfo exists .parseErrors] } {
                   2242: 	    
                   2243: 	    set parseErrorsWindow [toplevel .parseErrors]
                   2244: 	    $gWindowMenu add command -label "ParseErrors" -command "capaRaise \
                   2245: 		    $parseErrorsWindow"
                   2246: 	    wm title $parseErrorsWindow "Parse Errors"
                   2247: 	    addFindList -2
                   2248: 
                   2249: 	    set windowFrame [frame $parseErrorsWindow.windowFrame]
                   2250: 	    set buttonFrame [frame $parseErrorsWindow.buttonFrame]
                   2251: 	    
                   2252: 	    pack $windowFrame $buttonFrame -side bottom 
                   2253: 	    pack configure $windowFrame -expand true -fill both
                   2254: 	    pack configure $buttonFrame -anchor e
                   2255: 
                   2256: 	    scrollbar $windowFrame.scroll -orient vertical -command \
                   2257: 		    "$windowFrame.text yview"
                   2258: 	    set gParseErrorsText [text $windowFrame.text -yscrollcommand \
                   2259: 		    "$windowFrame.scroll set" -wrap char -height 40]
                   2260: 	    
                   2261: 	    pack $windowFrame.scroll $gParseErrorsText -side left -expand 0
                   2262: 	    pack configure $windowFrame.scroll -expand 0 -fill y
                   2263: 	    pack configure $gParseErrorsText -expand true -fill both
                   2264: 	    
                   2265: 	    button $buttonFrame.ok -text Dismiss -command \
                   2266: 		    "destroy $parseErrorsWindow
                   2267: 	             removeWindowEntry ParseErrors
                   2268:                      removeFindList -2"
                   2269: 	    bind $parseErrorsWindow <Destroy> "removeWindowEntry ParseErrors
                   2270:                                                removeFindList -2"
                   2271: 	    button $buttonFrame.save -text "Save Output" \
                   2272: 		    -command "saveText $gParseErrorsText"
                   2273: 	    button $buttonFrame.print -text "Print Output" \
                   2274: 		    -command "printText $gParseErrorsText"
                   2275: 	    pack $buttonFrame.print $buttonFrame.save \
                   2276: 		    $buttonFrame.ok -side left
                   2277: 	
                   2278: 	    Centre_Dialog $parseErrorsWindow default
                   2279: 	    update
                   2280: 	    capaRaise $parseErrorsWindow
                   2281: 	} else {
                   2282: 	    $gParseErrorsText delete 0.0 end
                   2283: 	    capaRaise .parseErrors
                   2284: 	}
1.5     ! albertel 2285: 	foreach line [split $parseErrors "\n"] {
        !          2286: 	    if { [regexp {File:.+->(.+), Line ([0-9]+): ERROR:} $line a one two three four five]} {
        !          2287: 		puts a:$a
        !          2288: 		puts one:$one
        !          2289: 		puts two:$two
        !          2290: 		puts three:$three
        !          2291: 		puts four:$four
        !          2292: 		puts five:$five
        !          2293: 	    } else {
        !          2294: 		if { [regexp {File:(.+), Line ([0-9]+): ERROR:} $line a one two three four five]} {
        !          2295: 		    puts a:$a
        !          2296: 		    puts one:$one
        !          2297: 		    puts two:$two
        !          2298: 		    puts three:$three
        !          2299: 		    puts four:$four
        !          2300: 		    puts five:$five
        !          2301: 		}
        !          2302: 	    }
        !          2303: 	}
1.1       albertel 2304: 	$gParseErrorsText insert end $parseErrors
                   2305:     } else {
                   2306: 	if { [winfo exists .parseErrors] } { $gParseErrorsText delete 0.0 end }
                   2307:     }
                   2308: 
                   2309:     return $parseErrors
                   2310: }
                   2311: 
                   2312: ###########################################################
                   2313: # printText
                   2314: ###########################################################
                   2315: # prints the contents of the text window, creates a temp file named
                   2316: # quiztemp.txt
                   2317: ###########################################################
                   2318: # Arguments: window (name of text window to print the contents of.
                   2319: # Returns  : nothing
                   2320: # Globals  :
                   2321: ###########################################################
                   2322: proc printText { window } {
                   2323: 
                   2324:     if { ![winfo exists $window] } {
                   2325: 	return
                   2326:     }
                   2327:     set lprCommand [getLprCommand quiztemp.txt]
                   2328: 
                   2329:     if {$lprCommand == "Cancel"} { 
                   2330: 	return
                   2331:     }
                   2332:   
                   2333:     set fileId [open "quiztemp.txt" w]
                   2334:     puts -nonewline $fileId "[ $window get 0.0 end ]"
                   2335:     close $fileId
                   2336: 
                   2337:     set errorMsg ""
                   2338:     set error [catch {set output [ eval "exec $lprCommand" ] } errorMsg ]
                   2339:     
                   2340:     if { $error == 1 } {
                   2341:         displayError "An error occurred while printing: $errorMsg"
                   2342:     } else {
                   2343: 	displayMessage "Print job sent to the printer.\n $output"
                   2344:     }
                   2345:     exec rm -f quiztemp.txt
                   2346: }
                   2347: 
                   2348: ###########################################################
                   2349: # saveText
                   2350: ###########################################################
                   2351: # saves the contents of the text window
                   2352: ###########################################################
                   2353: # Arguments: window (name of text window to save the contents of.
                   2354: #            saveAs (whether to ask to save)
                   2355: #            refNum (if supplied reference file unique number
                   2356: #                    that is being saved)
                   2357: # Returns  : name of the file saved
                   2358: # Globals  :
                   2359: ###########################################################
                   2360: proc saveText { window {saveAs 1} {refNum 0} } {
                   2361:     global gWindowMenu gRefFile gRefChanged gCapaConfig gFile
                   2362: 
                   2363:     if { ![winfo exists $window] } {return}
                   2364:     if { $refNum } {
                   2365: 	if {$saveAs} { 
                   2366: 	    set dir [file dirname $gRefFile($refNum)]
                   2367: 	    set file ""
                   2368: 	} else {
                   2369: 	    set dir [file dirname $gRefFile($refNum)]
                   2370: 	    set file [file tail $gRefFile($refNum)]
                   2371: 	}
                   2372:     } else { set dir [ set file "" ] }
                   2373: #    if { $dir == "" || $dir == "."} { set dir [pwd] }
                   2374:     if { $file == "" } {
                   2375: 	set file [tk_getSaveFile -title "Enter the name to Save As" \
                   2376: 		-initialdir "$dir" ]
                   2377: 	if { $file == "" } {
                   2378: 	    displayError "File not saved"
                   2379: 	    return
                   2380: 	}
                   2381:     } else {
                   2382: 	set file [file join $dir $file]
                   2383:     }
                   2384: 
                   2385:     if { $refNum } { 
                   2386: 	catch {removeWindowEntry  "Reference $gRefFile($refNum)*" }
                   2387: 	catch {removeFindList $refNum}
                   2388: 	set gRefFile($refNum) $file
                   2389: 	addFindList $refNum
                   2390: 	wm title [winfo toplevel $window] $file 
                   2391: 	$gWindowMenu add command -label "Reference $file" \
                   2392: 		-command "capaRaise [winfo toplevel $window]"
                   2393: 	if { !$saveAs } {
                   2394: 	    if { ([array name gCapaConfig quizzerBackupRef] == "") ||
                   2395: 		 ($gCapaConfig(quizzerBackupRef)!="off") } {
                   2396: 		if { [catch {file copy -force $file $file.bak} ] } {
                   2397: 		    displayError "Unable to create backup for $file"
                   2398: 		}
                   2399: 	    }
                   2400: 	}
                   2401:     }
                   2402:     set fileId [open $file w]
                   2403:     puts -nonewline $fileId [$window get 0.0 end]
                   2404:     close $fileId
                   2405:     if { $refNum } { set gRefChanged($refNum) 0 }
                   2406:     if { ([file tail $file] == "capa.config") && ($dir == [file dirname $gFile]) } {
                   2407: 	if { [makeSure "Reread capa.config settings into Quizzer?"] != "Cancel" } {
                   2408: 	    rereadCapaConfig
                   2409: 	}
                   2410:     }
                   2411: 
                   2412:     return $file
                   2413: }
                   2414: 
                   2415: ###########################################################
                   2416: # deleteFile
                   2417: ###########################################################
                   2418: ###########################################################
                   2419: ###########################################################
                   2420: proc deleteFile { which } {
                   2421:     global gFile gRefFile
                   2422:     if { $which } { set file $gRefFile($which) } else { set file $gFile }
                   2423:     if { [makeSure "Do you wish to Delete $file"] == "Cancel" } { return } 
                   2424:     if { $which } { closeRefFile $which 1 0 } else { closeDocument 1 0 }
                   2425:     file delete -- $file
                   2426: }
                   2427: 
                   2428: ###########################################################
                   2429: ###########################################################
                   2430: ###########################################################
                   2431: ###########################################################
                   2432: proc rereadCapaConfig { } {
                   2433:     global gCapaConfig
                   2434:     set printer_option $gCapaConfig(printer_option)
                   2435:     unset gCapaConfig(printer_option)
                   2436:     set error [parseCapaConfig]
                   2437:     if { $error != "OK" } { 
                   2438: 	displayError "Invalid capa.config file" 
                   2439: 	set gCapaConfig(printer_option) $printer_option
                   2440:     } 
1.5     ! albertel 2441:     setDefaultValues
1.1       albertel 2442:     updateColors
                   2443: }
                   2444: 
                   2445: ###########################################################
                   2446: ###########################################################
                   2447: ###########################################################
                   2448: ###########################################################
                   2449: proc pickCapaConfig { } {
                   2450:     set error NOTOK
                   2451:     while { $error != "OK" } {
                   2452: 	set file [tk_getOpenFile -title "Pick a capa.config file" \
                   2453: 		      -filetypes { { {CAPA configuration}  {capa.config} } \
                   2454: 				       { {All Files} {*} } }]
                   2455: 	if { $file == "" } { break }
                   2456: 	set oldDir [pwd]
                   2457: 	cd [file dirname $file]	
                   2458: 	set error [parseCapaConfig]
                   2459: 	if { $error != "OK" } { displayError "Invalid capa.config file"; cd $oldDir } 
1.5     ! albertel 2460: 	setDefaultValues
1.1       albertel 2461:     } 
                   2462: }
                   2463: 
1.5     ! albertel 2464: proc setDefaultValues {} {
        !          2465:     global gProbVal gTryVal gHintVal gCapaConfig
        !          2466:     catch {set gProbVal $gCapaConfig(default_prob_val)}
        !          2467:     catch {set gTryVal $gCapaConfig(default_try_val)}
        !          2468:     catch {set gHintVal $gCapaConfig(default_hint_val)}
        !          2469: }
        !          2470: 
1.1       albertel 2471: ###########################################################
                   2472: # openDocument
                   2473: ###########################################################
                   2474: ###########################################################
                   2475: ###########################################################
                   2476: proc openDocument {} {
1.5     ! albertel 2477:     global gFile gTextWindow gSetNumberText gPrefs gChanged gQuizTemp gUndo 
1.1       albertel 2478: 
                   2479:     if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
                   2480:     if { ![catch {set gTextWindow}] } { 
                   2481: 	if { [winfo exists $gTextWindow] } { return }
                   2482:     }
                   2483: 
                   2484:     # the event generation is because of a bug in tk_getOpenFile
                   2485:     # After double cliking the mouse Button one is thought to be left down.
                   2486:     # this only seems to happen when a toplevel window is created
                   2487:     # after getting the file
                   2488:     set gFile [tk_getOpenFile -filetypes \
                   2489: 	    { { {Quizzer} {"*.qz"} } { {All Files} {"*"} } } \
                   2490: 	    -title "Select the proper file" -initialdir "[pwd]" ]
                   2491: #    event generate .main <ButtonRelease-1>
                   2492:     if { $gFile == "" } { return }
                   2493:     if { [file isdirectory $gFile] } {
                   2494: 	displayError "You attempted to open $gFile which is a directory not a file."
                   2495: 	return
                   2496:     }
                   2497: 
                   2498:     set error [ catch {set fileId [open $gFile r] } ]
                   2499: 
                   2500:     if { $error } {
                   2501: 	displayError "Unable to read $gFile"
                   2502: 	return
                   2503:     } 
                   2504:     
                   2505:     set oldDir [pwd]
                   2506:     
                   2507:     cd [file dirname $gFile]
                   2508: 
                   2509:     set tempfiles ""
                   2510:     catch {set tempfiles [glob quiztemp.*]}
                   2511:     if { $tempfiles == "" } { 
                   2512: 	set gQuizTemp true 
                   2513:     }     
                   2514:     foreach quiztempFile $tempfiles {
                   2515: 	if { ! ( [file isfile $quiztempFile] && 
                   2516: 	[file writable $quiztempFile] ) } {
                   2517: 	    if { [makeSure "There are old quiztemp files in this directory that can not be overwritten. If you continue editing you will be unable to print or Create .dvi. You can still preview and save."] == "Cancel" } {
                   2518:                 cd $oldDir
                   2519:                 set gQuizTemp true
                   2520:                 return
                   2521: 	    } else {
                   2522:                 set gQuizTemp false
                   2523: 		break
                   2524: 	    }
                   2525: 	}
                   2526:     }
                   2527: 
                   2528:     if { $tempfiles == "" } {
                   2529: 	if { ! [file writable $gFile] } {
                   2530: 	    if { [makeSure "You do not have permission to write to this directory. If you continue editing you will be unable to save, print, or create .dvi"] == "Cancel" } {
                   2531: 		cd $oldDir
                   2532:                 set gQuizTemp true
                   2533:                 return
                   2534: 	    } else {
                   2535:                 set gQuizTemp false
                   2536: 	    }
                   2537: 	}
                   2538:     }
                   2539: 
                   2540:     set error [parseCapaConfig]
                   2541:     
                   2542:     if { $error != "OK" } {
                   2543: 	cd $oldDir
                   2544: 	set gQuizTemp true
                   2545:         return
                   2546:     }
1.5     ! albertel 2547:     setDefaultValues
        !          2548: 
1.1       albertel 2549:     createEditingWindow 0
                   2550:     $gTextWindow delete 0.0 end
                   2551:     $gTextWindow insert 0.0 [read $fileId [file size $gFile]]
                   2552:     $gTextWindow delete end-1c
                   2553: 
                   2554:     rename $gTextWindow .$gTextWindow
                   2555:     trackChanges $gTextWindow 0
                   2556:     set gUndo(0) 0
                   2557:     set gUndo(0.cur) 0
                   2558: 
                   2559:     createImportLinks 0 0.0 end
                   2560:     focus -force $gTextWindow 
                   2561:     set coord [$gTextWindow bbox 0.0]
                   2562:     event generate $gTextWindow <1> -x [lindex $coord 0] -y [lindex $coord 1]
                   2563:     event generate $gTextWindow <ButtonRelease-1>
                   2564:     update
                   2565:     close $fileId
                   2566: 
                   2567:     updatePrefsWindow 
                   2568: 
                   2569:     set gSetNumberText [string range [file rootname [file tail $gFile]] 3 end ]
                   2570:     checkIfValidFilename
                   2571:     set gChanged 0
                   2572: }
                   2573: 
                   2574: ###########################################################
                   2575: # includeReferenceFile
                   2576: ###########################################################
                   2577: ###########################################################
                   2578: ###########################################################
                   2579: proc includeReferenceFile { file num window } {
                   2580:     set index [$window index "file.$num.first linestart"]
                   2581:     if { ![file readable $file] } {
                   2582: 	displayError "Unable to read file $file"
                   2583: 	return
                   2584:     }
                   2585:     set impline [$window get $index "$index lineend"]
                   2586:     set fileId [open $file r]
                   2587:     $window insert $index /
                   2588:     update idletasks
                   2589:     if { [$window index end] == [$window index "$index + 1 lines"] } {
                   2590: 	$window insert "$index + 1 lines" "\n[read $fileId [file size $file]]"
                   2591:     } else {
                   2592: 	$window insert "$index + 1 lines" [read $fileId [file size $file]]
                   2593:     }
                   2594:     close $fileId
                   2595: }
                   2596: 
                   2597: ###########################################################
                   2598: # impMenuSaveAs
                   2599: ###########################################################
                   2600: ###########################################################
                   2601: ###########################################################
                   2602: proc impMenuSaveAs { file num window } {
                   2603:     set index [$window index "file.$num.first linestart"]
                   2604:     if { ![file readable $file] } {
                   2605: 	displayError "Unable to read file $file"
                   2606: 	return
                   2607:     }
                   2608:     set dir [file dirname $file]
                   2609:     if { $dir != "." } {
                   2610: 	set dest [tk_getSaveFile -title "Enter the name to Save As" -initialdir $dir]
                   2611:     } else {
                   2612: 	set dest [tk_getSaveFile -title "Enter the name to Save As" -initialdir [pwd]]
                   2613:     }
                   2614:     if { $dest == "" } {
                   2615: 	displayError "File not saved"
                   2616: 	return
                   2617:     }
                   2618:     if { [catch {file copy -force -- $file $dest} errorMsg ] } {
                   2619: 	displayError "Unable to copy $file to $dest: $errorMsg"
                   2620: 	return
                   2621:     }
                   2622:     $window delete $index "$index lineend"
                   2623:     if { $dir != "." } {
                   2624: 	$window insert $index "/IMP \"$dest\""
                   2625:     } else {
                   2626: 	$window insert $index "/IMP \"[file tail $dest]\""
                   2627:     }
                   2628: }
                   2629: 
                   2630: ###########################################################
                   2631: # createImpMenu
                   2632: ###########################################################
                   2633: ###########################################################
                   2634: ###########################################################
                   2635: proc createImpMenu { file num window } {
                   2636:     set menuFrame [menu .impmenu -tearoff 0 -type tearoff ]
                   2637: 
                   2638: #    wm title $menuFrame "Quizzer"
                   2639:     wm overrideredirect $menuFrame 1
                   2640:     wm positionfrom $menuFrame program
                   2641:     $menuFrame post [winfo pointerx .] [winfo pointery .]
                   2642:     $menuFrame add command -label "Open" -command "openReferenceFile $file"
                   2643:     $menuFrame add command -label "Include" -command \
                   2644: 	"includeReferenceFile $file $num $window"
                   2645:     $menuFrame add command -label "saveAs" -command "impMenuSaveAs $file $num $window"
                   2646:     grab $menuFrame
                   2647:     bind all <ButtonRelease> "grab release $menuFrame;destroy $menuFrame"
                   2648: }
                   2649: 
                   2650: ###########################################################
                   2651: # registerCreateImportLinks
                   2652: ###########################################################
                   2653: ###########################################################
                   2654: ###########################################################
                   2655: proc registerCreateImportLinks { num start end} {
                   2656:     global gDoCreateImportLinks gCreateImportLinks
                   2657: 
                   2658:     if { $gCreateImportLinks && !$gDoCreateImportLinks($num) } {
                   2659: 	after idle "createImportLinks $num $start $end"
                   2660: 	set gDoCreateImportLinks($num) 1
                   2661:     }
                   2662: }
                   2663: 
                   2664: ###########################################################
                   2665: # createImportLinks
                   2666: ###########################################################
                   2667: ###########################################################
                   2668: ###########################################################
                   2669: proc createImportLinks { num start end } {
                   2670:     global gTextWindow gUniqueNumber gDoCreateImportLinks gRefText gCapaConfig 
                   2671:     
                   2672:     set gDoCreateImportLinks($num) 0
                   2673:     if { $num } { set window $gRefText($num) } else { set window $gTextWindow }
                   2674:     if { ![winfo exists $window] } { return }
                   2675:     set end [$window index $end]
                   2676:     set start [$window index $start]
                   2677:     set lastline [lindex [split $end .] 0]
                   2678:     set startline [lindex [split $start .] 0]
                   2679:     foreach tag [$window tag names] {
                   2680: 	if { [regexp {file\..+} $tag ] } {
                   2681: 	    if { [$window tag nextrange $tag "$start linestart" "$end lineend"] != "" } {
                   2682: 		$window tag delete $tag
                   2683: 	    }
                   2684: 	}
                   2685:     }
                   2686:     for { set i $startline } { $i <= $lastline } { incr i } {
                   2687: 	set aline [$window get $i.0 "$i.0 lineend"]
                   2688: 	if { [regexp -nocase {(^[ 	]*)(//.*)} $aline matchVar match1 match2] } {
                   2689: 	    set tagnum [incr gUniqueNumber]
                   2690: 	    set start [string length $match1]
                   2691: 	    set end [expr $start + [string length $match2]]
                   2692: 	    $window tag add file.$tagnum $i.$start $i.$end
                   2693: 	    $window tag configure file.$tagnum -foreground $gCapaConfig(comment_color)
                   2694: 	} elseif { [regexp -nocase {(^.*/let.*[ 	]+)(//.*)} $aline matchVar \
                   2695: 			match1 match2] } {
                   2696: 	    set tagnum [incr gUniqueNumber]
                   2697: 	    set start [string length $match1]
                   2698: 	    set end [expr $start + [string length $match2]]
                   2699: 	    $window tag add file.$tagnum $i.$start $i.$end
                   2700: 	    $window tag configure file.$tagnum -foreground $gCapaConfig(comment_color)
                   2701: 	} 
                   2702: 	if { [regexp -nocase "(.*/imp +)(\"\[^\"\]+\")(.*)" $aline matchVar \
                   2703: 		  match1 match2 match3] } {
                   2704: 	    set tagnum [incr gUniqueNumber]
                   2705: 	    set start [string length $match1]
                   2706: 	    set end [expr $start + [string length $match2]]
                   2707: 	    $window tag add file.$tagnum $i.$start $i.$end
                   2708: 	    $window tag configure file.$tagnum -foreground $gCapaConfig(IMP_color)
                   2709: 	    $window tag bind file.$tagnum <Double-ButtonPress> \
                   2710: 		"eval openReferenceFile $match2"
                   2711: 	    $window tag bind file.$tagnum <ButtonPress-3> \
                   2712: 		"eval createImpMenu $match2 $tagnum $window"
                   2713: 	} 
                   2714:     }
                   2715: }
                   2716: 
                   2717: ###########################################################
                   2718: # isReferenceFileOpen
                   2719: ###########################################################
                   2720: ###########################################################
                   2721: ###########################################################
                   2722: proc isReferenceFileOpen { file } {
                   2723:     global gWindowMenu
                   2724: #    if { [catch {set index [$gWindowMenu index "Reference $file"]} ] } { return "" }
                   2725:     set last [$gWindowMenu index end]
                   2726: #    puts $last
                   2727:     for { set index 1 } { $index <= $last } { incr index } {
                   2728: #	puts $index
                   2729: 	catch {set entry [$gWindowMenu entrycget $index -label]}
                   2730: 	if { "Reference" == [set entryfile [lindex $entry 0]] } {
                   2731: 	    set entryfile [lindex $entry 1]
                   2732: 	}
                   2733: #	puts $entryfile
                   2734: 	if { [catch {file stat $entryfile a1}] } { puts skipped;continue }
                   2735: 	file stat $file a2
                   2736: #	puts "$a2(ino) == $a1(ino)"
                   2737: 	if { $a2(ino) == $a1(ino) } {
                   2738: #	    puts "seems right"
                   2739: 	    return [lindex [$gWindowMenu entrycget $index -command] 1]
                   2740: 	}
                   2741:     }
                   2742: #    puts "failed $index"
                   2743:     return ""
                   2744: #    puts $index
                   2745: #    puts [$gWindowMenu entrycget $index -command]
                   2746: #    return [lindex [$gWindowMenu entrycget $index -command] 1]
                   2747: }
                   2748: 
                   2749: ###########################################################
                   2750: # newReferenceFile
                   2751: ###########################################################
                   2752: ###########################################################
                   2753: ###########################################################
                   2754: proc newReferenceFile { } {
                   2755:     global gDir
                   2756: #    if { $gDir(reference) == "." } { set gDir(reference) [pwd] }
                   2757:     set file [tk_getSaveFile -title "Enter the name of the New reference file" \
                   2758: 		  -initialdir "$gDir(reference)" ]
                   2759:     event generate .main <ButtonRelease-1>
                   2760:     if { $file == "" } { return }
                   2761:     set gDir(reference) [file dirname $file]
                   2762:     if { [file isdirectory $file] } {
                   2763: 	displayError "You attempted to create $file which is already a directory."
                   2764: 	return
                   2765:     }
                   2766:     openReferenceFile $file 1
                   2767: }
                   2768: 
                   2769: ###########################################################
                   2770: # openReferenceFile
                   2771: ###########################################################
                   2772: ###########################################################
                   2773: ###########################################################
                   2774: proc openReferenceFile { {file ""} {new 0}} {
                   2775:     global gUniqueNumber gWindowMenu gDir
                   2776: 
                   2777:     set num [incr gUniqueNumber]
                   2778:     global gRefCurLine gRefLine gRefText gRefChanged gRefFile gRefClosed \
                   2779: 	gUndo gRefChangedLast
                   2780:     # the event generation is because of a bug in tk_getOpenFile
                   2781:     # After double cliking the mouse Button one is thought to be left down.
                   2782:     # this only seems to happen when a toplevel window is created
                   2783:     # after getting the file
                   2784:     if { $file == "" } {
                   2785: #	if { $gDir(reference) == "." } { set gDir(reference) [pwd] }
                   2786: 	set file [tk_getOpenFile -filetypes \
                   2787: 		      { { {All Files} {"*"} } { {Quizzer} {"*.qz"} } } \
                   2788: 		      -title "Select the proper file" \
                   2789: 		      -initialdir "$gDir(reference)" ]
                   2790: 	event generate .main <ButtonRelease-1>
                   2791: 	if { $file == "" } { return }
                   2792: 	set gDir(reference) [file dirname $file]
                   2793: 	
                   2794: 	if { [file isdirectory $file] } {
                   2795: 	    displayError "You attempted to open $file which is a directory not a file."
                   2796: 	    return
                   2797: 	}
                   2798:     } else {
                   2799: 	if { !$new } {
                   2800: 	    if { [set window [isReferenceFileOpen $file] ] != "" } { 
                   2801: 		capaRaise $window
                   2802: 		return 
                   2803: 	    }
                   2804: 	    # specifically opening the capa.config file
                   2805: 	    if { $file == "capa.config" } {
                   2806: 		global gTextWindow gFile
                   2807: 		if { [catch {set gTextWindow}] } { 
                   2808: 		    set file [tk_getOpenFile -filetypes \
                   2809: 				  {{{Capa.config file} {"capa.config"}} 
                   2810: 				      { {All Files} {"*"} } } \
                   2811: 				  -title "Select the proper file" \
                   2812: 				  -initialdir "$gDir(reference)" ]
                   2813: 		    if { $file == "" } { return }
                   2814: 		} else {
                   2815: 		    set file [file join [file dirname $gFile] capa.config]
                   2816: 		}
                   2817: 	    } else {
                   2818: 		if { ![file isfile $file] && ![file readable $file] } {
                   2819: 		    displayError "Unable to find $file"
                   2820: 		    return
                   2821: 		}
                   2822: 		if { [file isdirectory $file] } {
                   2823: 		    displayError "You attempted to open $file which is a directory not a file."
                   2824: 		    return
                   2825: 		}
                   2826: 	    }
                   2827: 	}
                   2828:     }
                   2829: 
                   2830:     set gRefFile($num) $file
                   2831:     set referenceFile [toplevel .reference$num]
                   2832:     wm title $referenceFile "$file"
                   2833: 
                   2834:     $gWindowMenu add command -label "Reference $file" \
                   2835: 	-command "capaRaise $referenceFile"
                   2836: 
                   2837:     set menuFrame [frame $referenceFile.menu -borderwidth 3 -relief raised]
                   2838:     set lineFrame [frame $referenceFile.lineFrame]
                   2839:     set windowFrame [frame $referenceFile.windowFrame]
                   2840:     pack $menuFrame $lineFrame $windowFrame
                   2841:     pack configure $windowFrame -expand 1 -fill both
                   2842:     pack configure $menuFrame -fill x
                   2843: 
                   2844:     label $lineFrame.msg -text "Current Line:"
                   2845:     label $lineFrame.current -textvariable gRefCurLine($num)
                   2846:     entry $lineFrame.line -width 8 -textvariable gRefLine($num)
                   2847:     bind $lineFrame.line <KeyPress-Return> "+gotoRefLine $num"
                   2848:     button $lineFrame.button -text "Goto" -command \
                   2849: 	    "gotoRefLine $num"
                   2850:     pack $lineFrame.msg $lineFrame.current $lineFrame.line \
                   2851: 	    $lineFrame.button -side left
                   2852:     
                   2853:     set infoFrame [frame $windowFrame.infoFrame]
                   2854:     set textFrame [frame $windowFrame.textFrame]
                   2855:     pack $infoFrame $textFrame -side top
                   2856:     pack configure $textFrame -expand 1 -fill both
                   2857: 
                   2858:     scrollbar $textFrame.scroll -orient vertical -command \
                   2859: 	    "$textFrame.text yview"
                   2860:     set textWindow [text $textFrame.text -yscrollcommand \
                   2861: 	    "$textFrame.scroll set" -wrap char]
                   2862:     pack $textFrame.scroll $textWindow -side left -expand 0
                   2863:     pack configure $textFrame.scroll -expand 0 -fill y
                   2864:     pack configure $textWindow -expand true -fill both
                   2865: 
                   2866: #    label $infoFrame.label -textvariable gRefFile($num)
                   2867: #    pack $infoFrame.label -side left
                   2868: 
                   2869:     menubutton $menuFrame.file -text File -menu $menuFrame.file.m
                   2870:     menubutton $menuFrame.edit -text Edit -menu $menuFrame.edit.m
                   2871:     pack $menuFrame.file $menuFrame.edit -side left
                   2872:     
                   2873:     set fileMenu [ menu $menuFrame.file.m ]
                   2874:     set editMenu [ menu $menuFrame.edit.m ]
                   2875: 
                   2876:     $fileMenu add command -label Save -command \
                   2877: 	    "saveText $textWindow 0 $num" -accelerator "Alt+s"
                   2878:     bind $referenceFile <Alt-s> \
                   2879: 	    "saveText $textWindow 0 $num"
                   2880:     $fileMenu add command -label "Save As" -command \
                   2881: 	    "saveText $textWindow 1 $num" -accelerator "Alt+S"
                   2882:     bind $referenceFile <Alt-Shift-s> "saveText $textWindow 1 $num" 
                   2883:     $fileMenu add command -label Delete -command "deleteFile $num"
                   2884:     $fileMenu add command -label Print -command "printText $textWindow"
                   2885:     $fileMenu add command -label Close -command "closeRefFile $num" \
                   2886: 	    -accelerator "Alt+w"
                   2887:     bind $referenceFile <Alt-w> "closeRefFile $num"
                   2888: #    bind $referenceFile <Destroy> "closeRefFile $num 1"
                   2889:     wm protocol $referenceFile WM_DELETE_WINDOW "closeRefFile $num 1"
                   2890:     $editMenu add command -label "Cut" -command "tk_textCut $textWindow" \
                   2891: 	    -accelerator "Alt+x"
                   2892:     bind $referenceFile <Alt-x> "tk_textCut $textWindow"
                   2893:     $editMenu add command -label "Copy" -command "tk_textCopy $textWindow" \
                   2894: 	    -accelerator "Alt+c"
                   2895:     bind $referenceFile <Alt-c> "tk_textCopy $textWindow"
                   2896:     $editMenu add command -label "Paste" -command "tk_textPaste $textWindow" \
                   2897: 	    -accelerator "Alt+v"
                   2898:     bind $referenceFile <Alt-v> "tk_textPaste $textWindow"
                   2899:     $editMenu add command -label "Select All " -command \
                   2900: 	    "selectAll $num "  -accelerator "Alt+a"
                   2901:     bind $referenceFile <Alt-a> "selectAll $num" 
                   2902:     $editMenu add separator
                   2903:     $editMenu add command -label "Undo" -command "undo $num" \
                   2904: 	    -accelerator "Alt+u"
                   2905:     bind $referenceFile <Alt-u> "undo $num" 
                   2906: #    $editMenu add command -label "Redo" -command "redo $num"
                   2907:     $editMenu add separator
                   2908:     $editMenu add command -label "Find" -command "createFindWindow $num" \
                   2909: 	-accelerator "Alt+f"
                   2910: 
                   2911:     
                   2912:     if { !$new } {
                   2913: 	set fileId [open $file r]
                   2914: 	$textWindow insert 0.0 [read $fileId [file size $file]]
                   2915: 	$textWindow delete end-1c
                   2916: 	close $fileId
                   2917:     }
                   2918:     
                   2919:     set gRefText($num) $textWindow
                   2920:     rename $textWindow .$textWindow
                   2921:     trackChanges $textWindow $num
                   2922:     set gUndo($num) 0
                   2923:     set gUndo($num.cur) 0
                   2924: 
                   2925:     createImportLinks $num 0.0 end
                   2926:     focus -force $textWindow 
                   2927: #    update
                   2928:     set coord [$textWindow bbox 0.0]
                   2929:     event generate $textWindow <1> -x [lindex $coord 0] -y [lindex $coord 1]
                   2930: #    update
                   2931:     event generate $textWindow <ButtonRelease-1>
                   2932: #    update
                   2933: #    capaRaise $referenceFile
                   2934:     after 1 "catch \{focus $textWindow;raise $referenceFile\}"
                   2935:     selection clear
                   2936: #order is important here since gRefChanged has a trace on it the references 
                   2937: #gRefChangedLast
                   2938:     set gRefChangedLast($num) 0
                   2939:     set gRefChanged($num) 0
                   2940:     set gRefClosed($num) 0
                   2941:     addFindList $num
                   2942: }
                   2943: 
                   2944: ###########################################################
                   2945: ###########################################################
                   2946: ###########################################################
                   2947: ###########################################################
                   2948: proc trackChanges { procName num } {
                   2949:     eval "proc $procName args {
                   2950: 	global gUndo gRefChanged gChanged
                   2951: 	if {\[regexp {^(ins|del).*} \[lindex \$args 0\]\]} { 
                   2952: 	    #puts \"\$args\"
                   2953: 	    if { \$gUndo($num.cur) != \$gUndo($num) } {
                   2954: 		set i \[expr \$gUndo($num.cur) + 1 \]
                   2955: 		while { \[ info exists gUndo($num.\$i) \] } {
                   2956: 		    unset gUndo($num.\$i)
                   2957: 		    incr i
                   2958: 		}
                   2959: 		set gUndo($num) \$gUndo($num.cur)
                   2960: 	    }
                   2961: 	    set gUndo($num.cur) \$gUndo($num)
                   2962: 	    set insertindex \[.$procName index \[lindex \$args 1 \] \]
                   2963: 	    set numChange \[set gUndo($num.cur) \[incr gUndo($num) \] \]
                   2964: 	    if { $num == 0 } { set gChanged 1 } else { set gRefChanged($num) 1 }
                   2965: 	}
                   2966: 	if {\[regexp {^(ins).*} \[lindex \$args 0\]\]} {
                   2967: 	    set index2 \$insertindex+\[string length \[lindex \$args 2 \] \]chars
                   2968: 	    set gUndo($num.\$numChange) \"delete \$insertindex \$index2 \"
                   2969:             if {\[regexp {.*\[\"/\].*} \$args\] || \
                   2970:                 \[regexp {.*\[\"/\].*} \[.$procName get \"\$insertindex linestart\" \"\$index2 lineend\"\]\]} { 
                   2971:                 registerCreateImportLinks $num \$insertindex \$index2
                   2972:             }
                   2973: 	} elseif {\[regexp {^(del).*} \[lindex \$args 0\]\]} { 
                   2974: 	    if { \[catch { set insertindex2 \[.$procName index \
                   2975: 		    \[lindex \$args 2 \] \] } \] } {
                   2976: 		set chars \[ .$procName get \$insertindex \]
                   2977:                 set insertindex2 \$insertindex+1c
                   2978: 	    } else {
                   2979: 		set chars \[ .$procName get \$insertindex \$insertindex2 \]
                   2980: 	    }
                   2981: 	    set gUndo($num.\$numChange) \"insert \$insertindex \[list \$chars\] \"
                   2982:             if {\[regexp \{.*\[\"/\].*\} \$chars\] || \
                   2983:                 \[regexp \{.*\[\"/\].*\} \[.$procName get \"\$insertindex linestart\" \"\$insertindex2 lineend\"\]\]} { 
                   2984:                registerCreateImportLinks $num \$insertindex \$insertindex2
                   2985:             }
                   2986: 	}
                   2987: 	set result \[uplevel .$procName \$args\]
                   2988:         updateLocation $num
                   2989:         return \$result
                   2990:     }"
                   2991: }
                   2992: 
                   2993: ###########################################################
                   2994: ###########################################################
                   2995: ###########################################################
                   2996: ###########################################################
                   2997: proc undo { num } {
                   2998:     global gUndo gRefText gTextWindow
                   2999:     if { $gUndo($num.cur) == 0 } { return }
                   3000:     set undoInfo $gUndo($num.$gUndo($num.cur))
                   3001:     if { [regexp {.*[\"/].*} $undoInfo] } {
                   3002: 	registerCreateImportLinks $num [lindex $undoInfo 1] end
                   3003:     }
                   3004:     if { [regexp {.*delete.*} $undoInfo] } {
                   3005: 	registerCreateImportLinks $num [lindex $undoInfo 1] [lindex $undoInfo 2]
                   3006:     }
                   3007:     if { $num == 0 } {
                   3008: 	if {[catch {eval ".$gTextWindow $gUndo($num.$gUndo($num.cur))"}]} { return }
                   3009:     } else {
                   3010: 	if {[catch {eval ".$gRefText($num) $gUndo($num.$gUndo($num.cur))"}]} { return }
                   3011:     }
                   3012:     incr gUndo($num.cur) -1
                   3013: }
                   3014: 
                   3015: ###########################################################
                   3016: ###########################################################
                   3017: ###########################################################
                   3018: ###########################################################
                   3019: proc redo { num } {
                   3020:     global gUndo gRefText
                   3021: }
                   3022: 
                   3023: ###########################################################
                   3024: ###########################################################
                   3025: ###########################################################
                   3026: ###########################################################
                   3027: proc gotoRefLine { number } {
                   3028:     global gRefLine gRefText
                   3029:     if { [catch {set gRefText($number)}] } { return }
                   3030:     if { ![winfo exists $gRefText($number)] } { return }
                   3031: 
                   3032:     if { $gRefLine($number) == "" } {
                   3033: 	return
                   3034:     } else {
                   3035: 	$gRefText($number) mark set insert $gRefLine($number).0
                   3036: 	catch {$gRefText($number) tag remove sel sel.first sel.last}
                   3037: 	$gRefText($number) tag add sel "insert linestart" "insert lineend"
                   3038: 	$gRefText($number) see insert
                   3039:     } 
                   3040: }
                   3041: 
                   3042: ###########################################################
                   3043: # updateLocation
                   3044: ###########################################################
                   3045: ###########################################################
                   3046: ###########################################################
                   3047: proc updateLocation { number } {
                   3048:     global gRefCurLine gRefText gTextWindow gLineNumber gCharacterNumber
                   3049: 
                   3050:     if {$number} {set window $gRefText($number)} {set window $gTextWindow} 
                   3051: #    if {![winfo exists $gRefText($number)]} {return};#do I need this
                   3052:     set spot [split [.$window index insert] "."]
                   3053:     if { $number } {
                   3054: 	set gRefCurLine($number) [lindex $spot 0 ]
                   3055:     } else {
                   3056: 	set gLineNumber [lindex $spot 0]
                   3057: 	set gCharacterNumber [lindex $spot 0]
                   3058:     }
                   3059: }
                   3060: 
                   3061: ###########################################################
                   3062: ###########################################################
                   3063: ###########################################################
                   3064: ###########################################################
                   3065: proc askToSave { refNum mustClose } {
                   3066:     global gPrompt
                   3067:     
                   3068:     set dialog [toplevel .askToSavePrompt -borderwidth 10]
                   3069:     wm title $dialog "Do you wish to Save"
                   3070:     wm geo $dialog "+200+200"
                   3071:     if { $refNum } {
                   3072: 	global gRefFile
                   3073: 	set msg "Reference File: $gRefFile($refNum) has changed. Do you wish to save?"
                   3074:     } else {
                   3075: 	set msg "Source has changed do you wish to save?"
                   3076:     }
                   3077:     message $dialog.msg -text $msg -aspect 800
                   3078:     
                   3079:     set gPrompt(result) ""
                   3080:     set buttonFrame [frame $dialog.buttons -bd 10]
                   3081:     pack $dialog.msg $buttonFrame -side top -fill x
                   3082:     
                   3083:     bind $dialog <Destroy> { 
                   3084: 	set gPrompt(result) Cancel
                   3085: 	set gPrompt(yes) 0
                   3086:     }
                   3087: 
                   3088:     button $buttonFrame.yes -text Yes -underline 0 -command {
                   3089: 	set gPrompt(yes) 1
                   3090:     }
                   3091:     button $buttonFrame.no -text No -underline 0 -command {
                   3092: 	set gPrompt(yes) 0
                   3093:     } 
                   3094:     if { !$mustClose } {
                   3095: 	button $buttonFrame.cancel -text Cancel  -underline 0 -command { 
                   3096: 	    set gPrompt(yes) 0 
                   3097: 	    set gPrompt(result) Cancel
                   3098: 	}
                   3099: 	pack $buttonFrame.yes $buttonFrame.no $buttonFrame.cancel -side left
                   3100:     } else {
                   3101: 	pack $buttonFrame.yes $buttonFrame.no -side left
                   3102:     }
                   3103:     bind $dialog <Alt-Key> break
                   3104: 
                   3105:     Centre_Dialog $dialog default
                   3106:     update
                   3107: 
                   3108:     focus $dialog
                   3109:     capaRaise $dialog
                   3110:     capaGrab $dialog
                   3111:     vwait gPrompt(yes)
                   3112:     capaGrab release $dialog
                   3113:     bind $dialog <Destroy> ""
                   3114:     destroy $dialog
                   3115:     if {$gPrompt(yes)} {
                   3116: 	if { $refNum } {
                   3117: 	    global gRefText 
                   3118: 	    saveText $gRefText($refNum) 0 $refNum
                   3119: 	} else {
                   3120: 	    saveDocument
                   3121: 	}
                   3122:     } else {
                   3123: 	return $gPrompt(result)
                   3124:     }
                   3125: }    
                   3126: 
                   3127: ###########################################################
                   3128: ###########################################################
                   3129: ###########################################################
                   3130: ###########################################################
                   3131: proc saveDocument { {saveAs 0} } {
                   3132:     global gFile gTextWindow gSetNumberText gChanged gEditWindow gWindowMenu \
                   3133: 	gCapaConfig
                   3134:     if { [catch {set gTextWindow}] } { return }
                   3135:     if { ![winfo exists $gTextWindow] } { return }
                   3136:     if { $gFile == "" } { set saveAs 1 }
                   3137:     if {$saveAs == 1} {
                   3138: 	set temp [tk_getSaveFile -title "Enter the name to Save As" \
                   3139: 		-initialdir "[pwd]" ]
                   3140: 	if { $temp == "" } {
                   3141: 	    displayError "File not saved"
                   3142: 	    return
                   3143: 	}
                   3144: 	
                   3145: 	catch {removeWindowEntry "$gFile*"}
                   3146: 	catch {removeFindList}	
                   3147: 	set gFile $temp
                   3148: 	addFindList
                   3149: 	cd [file dirname $gFile]
                   3150: 	set gSetNumberText [string range [file rootname [file tail $gFile]] \
                   3151: 		3 end ]
                   3152: 	checkIfValidFilename
                   3153: 	wm title [winfo toplevel $gEditWindow] $gFile 
                   3154: 
                   3155: 	$gWindowMenu add command -label "$gFile" -command \
                   3156: 		"capaRaise $gEditWindow"
                   3157:     } else {
                   3158: 	if { ([array name gCapaConfig quizzerBackupQZ] == "") ||
                   3159: 	     ($gCapaConfig(quizzerBackupQZ)!="off") } {
                   3160: 	    if { [catch {file copy -force $gFile $gFile.bak} ] } {
                   3161: 		displayError "Unable to create backup for $gFile"
                   3162: 	    }
                   3163: 	}
                   3164:     }
                   3165:     
                   3166:     set fileId [open $gFile w]
                   3167: 
                   3168:     puts -nonewline $fileId [$gTextWindow get 0.0 end]
                   3169: 
                   3170:     close $fileId
                   3171: 
                   3172:     savePrefs
                   3173:     set gChanged 0
                   3174: }
                   3175:  
                   3176: ###########################################################
                   3177: ###########################################################
                   3178: ###########################################################
                   3179: ###########################################################
                   3180: proc closeDocument { { mustClose 0 } { save 1 } } {
                   3181:     global gFile gEditWindow gChanged gPrefs \
                   3182: 	    gPutLine gTryVal gProbVal gHintVal gQuizTemp \
                   3183: 	    gNumberParsedText gSetNumberText gClosedDocument gTextWindow
                   3184:     if { [catch {set gEditWindow}] } { return }
                   3185:     if { ![winfo exists $gEditWindow] } { return }
                   3186:     if { $gClosedDocument } { return }
                   3187:     if { $save && $gChanged } {
                   3188: 	if { [askToSave 0 $mustClose] == "Cancel"  && (! $mustClose ) } { return }
                   3189:     }
                   3190:     if {(!$mustClose)&&[makeSure "Are you sure you wish to stop editing?"]=="Cancel"} {
                   3191: 	return 
                   3192:     }
                   3193:     set gClosedDocument 1
                   3194:     removeFindList
                   3195:     destroy $gEditWindow
                   3196:     removeWindowEntry "$gFile*"
                   3197:     set gFile ""
                   3198:     set gChanged 0
                   3199:     set gPrefs(info) "Problem"
                   3200:     set gPrefs(TeXHeader) ""
                   3201:     set gPrefs(TeXFooter) ""
                   3202:     set gPutLine 1
                   3203:     set gTryVal 99
                   3204:     set gHintVal 1
                   3205:     set gProbVal 1
                   3206:     set gQuizTemp "true"
                   3207:     set gNumberParsedText ""
                   3208:     set gSetNumberText ""
                   3209: }
                   3210: 
                   3211: ###########################################################
                   3212: ###########################################################
                   3213: ###########################################################
                   3214: ###########################################################
                   3215: proc closeRefFile { refNum  { mustClose 0 } { save 1 } } {
                   3216:     global gRefChanged gRefText gRefFile gRefClosed gRefCurLine gRefLine gRefChangedLast
                   3217:     if { [catch {set gRefText($refNum)}] } { return }
                   3218:     if { ![winfo exists $gRefText($refNum)] } { return }
                   3219:     if { $gRefClosed($refNum) } { return }
                   3220:     if { $save && $gRefChanged($refNum) } { 
                   3221: 	if { [askToSave $refNum $mustClose] == "Cancel" && ( ! $mustClose ) } { return }
                   3222:     }
                   3223: 
                   3224:     if { ( ! $mustClose ) && ( [makeSure "Are you sure you wish to stop editing $gRefFile($refNum)?"] == "Cancel" ) } {
                   3225: 	return 
                   3226:     }
                   3227:     set gRefClosed($refNum) 1
                   3228:     removeFindList $refNum
                   3229:     destroy [winfo toplevel $gRefText($refNum)]
                   3230:     removeWindowEntry "Reference $gRefFile($refNum)*"
                   3231:     unset gRefText($refNum) gRefChanged($refNum) gRefClosed($refNum) gRefFile($refNum) \
                   3232: 	gRefCurLine($refNum) gRefLine($refNum) gRefChangedLast($refNum)
                   3233: }
                   3234: 
                   3235: ###########################################################
                   3236: # quit
                   3237: ###########################################################
                   3238: # called when the quit option is selected on the menu, unmaps
                   3239: # all keys.
                   3240: ###########################################################
                   3241: # Arguments: None
                   3242: # Returns: Nothing
                   3243: # Globals: gChanged - whether or not the file has been modified
                   3244: ###########################################################
                   3245: proc quit { { mustClose 0 } } {
                   3246:     global gChanged gRefChanged gRefText
                   3247: 
                   3248:     if { (! $mustClose ) && [makeSure "Are you sure you wish to quit?"] == "Cancel" } {
                   3249: 	return 
                   3250:     }
                   3251: 
                   3252:     if { $gChanged } {
                   3253:  	if { [askToSave 0 $mustClose] == "Cancel" && ( ! $mustClose ) } {
                   3254: 	    return
                   3255: 	}
                   3256:     }
                   3257:     
                   3258:     foreach refNum [array names gRefChanged] {
                   3259: 	if { $gRefChanged($refNum) == 1 } {
                   3260: 	    if { [winfo exists $gRefText($refNum)] } {
                   3261: 		if { [askToSave $refNum $mustClose ] == "Cancel" && (! $mustClose ) } {
                   3262: 		    return
                   3263: 		}
                   3264: 	    }
                   3265: 	}
                   3266:     }
                   3267: 
                   3268:     exec /bin/rm -f quiztemp.ps
                   3269:     exec /bin/rm -f quiztemp.dvi
                   3270:     exec /bin/rm -f quiztemp.tex
                   3271:     exec /bin/rm -f quiztemp.log
                   3272:     exec /bin/rm -f quiztemp.aux
                   3273:     exec /bin/rm -f quiztemp.txt
                   3274: 
                   3275:     unmapAllKeys
                   3276: 
                   3277:     exit
                   3278: }
                   3279: 
                   3280: ###########################################################
                   3281: # createStopButton
                   3282: ###########################################################
                   3283: ###########################################################
                   3284: ###########################################################
                   3285: proc createStopButton {} {
                   3286:     global gStopStatus
                   3287:     if {[winfo exists .stopbutton]} {destroy .stopbutton}
                   3288:     set top [toplevel .stopbutton]
                   3289:     button $top.stop -text "Stop Parser" -command "stopParser"
1.4       albertel 3290:     label $top.status -textvariable gStopStatus -width 35 -anchor w
1.1       albertel 3291:     pack $top.stop $top.status
                   3292:     set gStopStatus ""
                   3293:     grab $top
                   3294:     Centre_Dialog $top default
                   3295:     update
                   3296: }
                   3297: 
                   3298: ###########################################################
                   3299: # destroyStopButton
                   3300: ###########################################################
                   3301: ###########################################################
                   3302: ###########################################################
                   3303: proc destroyStopButton {} {
                   3304:     grab release .stopbutton
                   3305:     destroy .stopbutton
                   3306: }
                   3307: 
                   3308: ###########################################################
                   3309: # createDvi
                   3310: ###########################################################
                   3311: ###########################################################
                   3312: ###########################################################
                   3313: proc createDvi { {showXdvi 1} {showStopButton 0} {useqzparse 0}} {
                   3314:     global gPreviewMode gCreateDviText gPrefs gSetNumberText \
                   3315: 	    gStudentSelection gFile gWindowMenu gLatexId gParseErrorsText \
                   3316: 	    gEditWindow gCreateDviTextTemp gXdviOpt  \
                   3317:             gLoadHeaderSet gCapaConfig gControlDates gNumberParsedText \
                   3318: 	    gDonePrinting
                   3319: 
                   3320:     if { [catch {set gEditWindow}] } { return }
                   3321:     if { ![winfo exists $gEditWindow] } { return }
                   3322:     
                   3323:     catch { destroy .createDviText }
                   3324:     set gCreateDviTextTemp [text .createDviText]
                   3325:     
                   3326:     switch $gPrefs(info) {
                   3327: 	Problem { set type 0 }
                   3328: 	ProblemAnswer { set type 1 }
                   3329: 	Answer { set type 2 }
                   3330:     }
                   3331: 
                   3332:     if { $useqzparse } {
                   3333: 	set gDonePrinting 0
                   3334: 	switch $gPrefs(info) {
                   3335: 	    Problem	{ set type "-T" }
                   3336: 	    Answer	{ set type "-Ta" }
                   3337: 	    ProblemAnswer { set type "-Tb" }
                   3338: 	    default	{ set type "-T"	}
                   3339: 	}
                   3340: 	createCreateDviWin
                   3341: 	grab .createDvi
                   3342: 	$gCreateDviText delete 0.0 end
                   3343: 	if { [setupSetsToPrint set start end 0] == 1 } { return 1 }
                   3344: 	if { [set gStopPrinting [expr 2 == [runLatex \
                   3345:             "echo [pwd] | $gCapaConfig(qzparse_command) \
                   3346: 	    -stu $gStudentSelection(studentNumber) -set $set \
                   3347: 	    -d [pwd] -c [pwd] $type " gCreateDviText] ] ] } {
                   3348: 	    exec rm -f $gStudentSelection(studentNumber).tex quiztemp.tex
                   3349: 	    if {$showStopping} {
                   3350: 		displayMessage "Printing has been stopped."
                   3351: 		set gDonePrinting 1
                   3352: 		set gStopPrinting 0
                   3353: 	    }
                   3354: 	    return 1
                   3355: 	}
                   3356: 	exec mv $gStudentSelection(studentNumber).tex quiztemp.tex
                   3357: 	exec /bin/rm -f quiztemp.dvi 
                   3358:     } else {
                   3359: 	createStopButton
                   3360: 	if { [catch { 
                   3361: 	    set numberParsed [ texParse $type $gSetNumberText \
                   3362: 				   $gStudentSelection(type) $gStudentSelection(random) \
                   3363: 				   $gStudentSelection(studentNumber) \
                   3364: 				   $gStudentSelection(studentName) \
                   3365: 				   gCreateDviTextTemp 1 ] }]} {
                   3366: 	    return
                   3367: 	}
                   3368: 	destroyStopButton
                   3369: 	checkHeader $numberParsed
                   3370: 	
                   3371: 	if { [showParseErrors] != "" } {
                   3372: 	    if { [makeSure "There were errors when parsing the .qz file, \
                   3373: 		continue to create the .dvi?"] =="Cancel" } {
                   3374: 		destroy $gCreateDviTextTemp
                   3375: 		return
                   3376: 	    }   
                   3377: 	}
                   3378: 	
                   3379: 	set error [catch { set fileId [open quiztemp.tex w] } ]
                   3380: 	if { $error } {
                   3381: 	    displayError "Unable to create neccessary temp files, delete all the\
                   3382:  quiztemp file from the class directory."
                   3383: 	    return
                   3384: 	}
                   3385: 
                   3386: 	set filename [file join [file dirname $gFile] TeXheader ]
                   3387: 	set texfileId [open $filename r]
                   3388: 	puts -nonewline $fileId [read $texfileId [file size $filename]]
                   3389: 	close $texfileId
                   3390:     
                   3391: 	puts -nonewline  $fileId "[$gCreateDviTextTemp get 0.0 end]"
                   3392: 	
                   3393: 	set filename [file join [file dirname $gFile] TeXfooter ]
                   3394: 	set texfileId [open $filename r]
                   3395: 	puts $fileId [read $texfileId [file size $filename]]
                   3396: 	close $texfileId
                   3397: 	
                   3398: 	close $fileId
                   3399:     }
                   3400: 
                   3401:     destroy $gCreateDviTextTemp
                   3402: 
                   3403:     if { ![winfo exists .createDvi] } {
                   3404: 	set createDviWindow [toplevel .createDvi]
                   3405: 	$gWindowMenu add command -label "CreateDvi" -command \
                   3406: 		"capaRaise $createDviWindow"
                   3407: 	wm title $createDviWindow "LaTeX Output"
                   3408: 	addFindList -3
                   3409: 
                   3410: 	set windowFrame [frame $createDviWindow.windowFrame]
                   3411: 	set buttonFrame [frame $createDviWindow.buttonFrame]
                   3412: 	
                   3413: 	pack $windowFrame $buttonFrame -side bottom
                   3414: 	pack configure $windowFrame -expand true -fill both
                   3415: 	pack configure $buttonFrame -anchor e
                   3416: 
                   3417: 	scrollbar $windowFrame.scroll -orient vertical -command \
                   3418: 		"$windowFrame.text yview"
                   3419: 	set gCreateDviText [text $windowFrame.text -yscrollcommand \
                   3420: 		"$windowFrame.scroll set" -wrap char -height 40]
                   3421: 	
                   3422: 	pack $windowFrame.scroll $gCreateDviText -side left -expand 0
                   3423: 	pack configure $windowFrame.scroll -expand 0 -fill y
                   3424: 	pack configure $gCreateDviText -expand true -fill both
                   3425: 	
                   3426: 	set appearingFrame [frame $buttonFrame.appearingFrame]
                   3427: 	button $buttonFrame.ok -text Dismiss -command \
                   3428: 		"trace vdelete gFile w updateCreateDvi
                   3429:                  destroy $createDviWindow
                   3430: 	         removeWindowEntry CreateDvi
                   3431:                  removeFindList -3"
                   3432: 	bind $createDviWindow <Destroy> \
                   3433: 		"trace vdelete gFile w updateCreateDvi
                   3434: 	         removeWindowEntry CreateDvi
                   3435:                  removeFindList -3"
                   3436: 	pack $appearingFrame $buttonFrame.ok -side left
                   3437: 
                   3438: 	button $appearingFrame.stop -text "Stop Creating Print Jobs"\
                   3439: 		-command "stopPrinting"
                   3440: 	set name [file rootname [file tail $gFile ] ].dvi
                   3441: 	button $appearingFrame.print -text \
                   3442: 		"Save.dvi file to $name" \
                   3443: 		-command saveDvi
                   3444: 	trace variable gFile w updateCreateDvi
                   3445: 
                   3446: 	if { $showStopButton } {
                   3447: 	    pack $appearingFrame.stop $appearingFrame.print -side left
                   3448: 	    pack forget $appearingFrame.print
                   3449: 	} else {
                   3450: 	    pack $appearingFrame.stop $appearingFrame.print -side left
                   3451: 	    pack forget $appearingFrame.stop
                   3452: 	}
                   3453: 
                   3454: 	Centre_Dialog $createDviWindow default
                   3455: 	update
                   3456:     } else {
                   3457: 	if { $showStopButton } {
                   3458: 	    pack forget .createDvi.buttonFrame.appearingFrame.print
                   3459: 	    pack .createDvi.buttonFrame.appearingFrame.stop
                   3460: 	} else {
                   3461: 	    pack forget .createDvi.buttonFrame.appearingFrame.stop
                   3462: 	    pack .createDvi.buttonFrame.appearingFrame.print
                   3463: 	}
                   3464: 	if { !$useqzparse } { $gCreateDviText delete 0.0 end }
                   3465:     }
                   3466:         
                   3467:     exec /bin/rm -f quiztemp.dvi 
                   3468:     $gCreateDviText insert end      "$gCapaConfig(latex_command)\n"
                   3469:     $gCreateDviText see end
                   3470:     set createdDvi [ runLatex "pwd ; $gCapaConfig(latex_command) quiztemp.tex < \
                   3471: 	    [file join / dev null ]" gCreateDviText]
                   3472: 
                   3473:     if { ($showXdvi == 1)  && ( $createdDvi == 1 ) } { 
                   3474: 	eval "exec $gCapaConfig(xdvi_command) $gXdviOpt quiztemp.dvi >& /dev/null & "
                   3475:     }
                   3476: 
                   3477:     catch { capaRaise $gParseErrorsText }
                   3478:     set gDonePrinting 1
                   3479:     return $createdDvi
                   3480: }
                   3481: 
                   3482: ###########################################################
                   3483: ###########################################################
                   3484: ###########################################################
                   3485: ###########################################################
                   3486: proc stopPrinting {} {
                   3487:     global gStopPrinting
                   3488:     set gStopPrinting 1
                   3489: }
                   3490: 
                   3491: ###########################################################
                   3492: ###########################################################
                   3493: ###########################################################
                   3494: ###########################################################
                   3495: proc saveDvi { } {
                   3496:     global gFile
                   3497: 
                   3498:     set name [file rootname [ file tail $gFile]].dvi
                   3499:     catch { exec rm -f $name }
                   3500: 
                   3501:     if { [ catch { exec cp quiztemp.dvi $name } ] } {
                   3502: 	displayMessage "Unable to create $name "
                   3503:     } else {
                   3504: 	displayMessage "Created $name "
                   3505:     }
                   3506: }
                   3507: 
                   3508: 
                   3509: ###########################################################
                   3510: ###########################################################
                   3511: ###########################################################
                   3512: ###########################################################
                   3513: proc updateCreateDvi { name1 name2 op } {
                   3514:     global gFile
                   3515: 
                   3516:     set name [file rootname [file tail $gFile ] ].dvi
                   3517:     catch { .createDvi.buttonFrame.appearingFrame.print configure \
                   3518: 	    -text "Save.dvi file to $name" }
                   3519: }
                   3520: ###########################################################
                   3521: ###########################################################
                   3522: ###########################################################
                   3523: ###########################################################
                   3524: proc printWindow {} {
                   3525:     global gPrintSelection gWindowMenu gEditWindow gStopPrinting\
                   3526: 	gSetNumberText gMaxSet gFile gChanged
                   3527: 
                   3528:     set gStopPrinting 0
                   3529:     if { [catch {set gEditWindow}] } { return }
                   3530:     if { ![winfo exists $gEditWindow] } { return }
                   3531: 
                   3532:     if { [winfo exists .print] } { 
                   3533: 	capaRaise .print
                   3534: 	return 
                   3535:     }
                   3536:     if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
                   3537: 
                   3538:     set print [toplevel .print]
                   3539:     $gWindowMenu add command -label "Print" -command "capaRaise $print"
                   3540:     wm title $print "Select a Print Method"
                   3541:     message $print.msg -text "Please specify a print method." -aspect 10000
                   3542:     set oneSetFrame [frame $print.frame1 -relief groove -borderwidth 4]
                   3543:     set moreSetFrame [frame $print.frame2 -relief groove -borderwidth 4]
                   3544:     set buttonFrame [frame $print.buttons]
                   3545:     pack $print.msg $oneSetFrame $moreSetFrame $buttonFrame -side top 
                   3546:     pack configure $oneSetFrame $moreSetFrame -anchor w -fill x
                   3547:    
                   3548:     set infoFrame [frame $moreSetFrame.frame1]
                   3549:     set setFrame [frame $moreSetFrame.frame2 -relief solid -borderwidth 1]
                   3550:     pack $infoFrame $setFrame 
                   3551:     pack configure $infoFrame $setFrame -anchor w
                   3552:     
                   3553:     if {[catch {set gPrintSelection(sets)}]} {set gPrintSelection(sets) printCur}
                   3554:     if {[catch {set gPrintSelection(type)}]} {set gPrintSelection(type) printSpecific}
                   3555:     if {[catch {set gPrintSelection(setend)}]} {set gPrintSelection(setend) $gSetNumberText}
                   3556:     radiobutton $setFrame.specific -text "Print Current Set ($gSetNumberText)" \
                   3557: 	    -value "printCur" -variable gPrintSelection(sets) 
                   3558:     set scaleFrame [frame $setFrame.scales]
                   3559:     pack $setFrame.specific $scaleFrame -anchor w
                   3560: 
                   3561:     for { set i 1 } { $i <= $gMaxSet } { incr i } {
                   3562: 	if { ! [file exists [file join [file dirname $gFile] records "set$i.db"]] } { break }
                   3563:     }
                   3564:     incr i -1
                   3565:     set gPrintSelection(setend) $gSetNumberText
                   3566:     radiobutton $scaleFrame.range -text "Print Set Range:" \
                   3567: 	    -value "printRange" -variable gPrintSelection(sets) 
                   3568:     scale $scaleFrame.start -from 1 -to $i -variable gPrintSelection(setstart) \
                   3569: 	-orient h 
                   3570:     label $scaleFrame.msg -text "to"
                   3571:     scale $scaleFrame.end -from 1 -to $i -variable gPrintSelection(setend) \
                   3572: 	-orient h 
                   3573:     pack $scaleFrame.range $scaleFrame.start $scaleFrame.msg \
                   3574: 	$scaleFrame.end -side left
                   3575: 
                   3576:     button $buttonFrame.ok -text "Select" -command selectedPrintMethod
                   3577:     button $buttonFrame.cancel -text "Cancel" -command \
                   3578: 	    "destroy .print
                   3579:              removeWindowEntry Print"
                   3580:     bind $print <Destroy> "removeWindowEntry Print"
                   3581:     pack $buttonFrame.ok $buttonFrame.cancel -side left
                   3582:     
                   3583:     set currentDviFrame [frame $oneSetFrame.currentDvi]
                   3584:     set currentPreviewFrame [frame $oneSetFrame.currentPreview]
                   3585:     set randomFrame [frame $oneSetFrame.random]
                   3586:     set specificFrame [frame $infoFrame.specific]
                   3587:     set sectionFrame [frame $infoFrame.section]
                   3588:     set multSectionFrame [frame $infoFrame.multsection]
                   3589:     set wholeClassFrame [frame $infoFrame.wholeClass]
                   3590:     pack $currentDviFrame $currentPreviewFrame $randomFrame $specificFrame \
                   3591: 	    $sectionFrame $multSectionFrame $wholeClassFrame -anchor w \
                   3592: 	    -side top
                   3593:     pack configure $specificFrame -expand true -fill both
                   3594: 
                   3595:     radiobutton $currentDviFrame.currentDvi -text "Print current .dvi" \
                   3596: 	    -value "printCurrentDvi" -variable gPrintSelection(type) 
                   3597:     pack $currentDviFrame.currentDvi -side left 
                   3598: 
                   3599:     radiobutton $randomFrame.random -text \
                   3600: 	    "Randomly select one student from section:" \
                   3601: 	    -value "printRandom" -variable gPrintSelection(type) 
                   3602:     entry $randomFrame.entry -textvariable gPrintSelection(random)  -width 3 \
                   3603: 	-validate key -validatecommand "limitEntry %W 3 number %P"
                   3604:     pack $randomFrame.random $randomFrame.entry -side left 
                   3605: 
                   3606:     radiobutton $specificFrame.specific -text "Specify the student by:" \
                   3607: 	-value "printSpecific" -variable gPrintSelection(type) 
                   3608:     set studentNumber [frame $specificFrame.studentNumber]
                   3609:     set fullName [frame $specificFrame.fullName]
                   3610:     pack $specificFrame.specific $studentNumber $fullName -side top
                   3611:     pack configure $specificFrame.specific -anchor w
                   3612:     pack configure $studentNumber $fullName -anchor e
                   3613: 
                   3614:     radiobutton $sectionFrame.section -text "Print section" \
                   3615: 	-value "printSection" -variable gPrintSelection(type) 
                   3616:     entry $sectionFrame.entry -textvariable gPrintSelection(section)  -width 3 \
                   3617: 	-validate key -validatecommand "limitEntry %W 3 number %P"
                   3618:     pack $sectionFrame.section $sectionFrame.entry -side left
                   3619: 
                   3620:     radiobutton $multSectionFrame.section -text "Print multiple sections" \
                   3621: 	-value "printMultipleSections" -variable gPrintSelection(type) 
                   3622:     pack $multSectionFrame.section -side left
                   3623: 
                   3624:     radiobutton $wholeClassFrame.wholeClass -text "Print whole class." \
                   3625: 	-value "printWholeClass" -variable gPrintSelection(type) 
                   3626:     pack $wholeClassFrame.wholeClass -side left
                   3627:     
                   3628:     message $studentNumber.msg -text "Student Number: "  -aspect 10000
                   3629:     entry $studentNumber.entry -textvariable gPrintSelection(studentNumber) -width 9 \
                   3630: 	-validate key -validatecommand "limitEntry %W 9 any %P"
                   3631:     pack $studentNumber.msg $studentNumber.entry -side left
                   3632: 
                   3633:     message $fullName.msg -text "Student Name: "  -aspect 10000 
                   3634:     entry $fullName.entry -textvariable gPrintSelection(studentName) -width 30 \
                   3635: 	-validate key -validatecommand "limitEntry %W 30 any %P"
                   3636:     pack $fullName.msg $fullName.entry -side left
                   3637: 
                   3638:     trace variable gPrintSelection(studentNumber) w \
                   3639: 	"global gPrintSelection; set gPrintSelection(type) printSpecific ;#"
                   3640:     trace variable gPrintSelection(studentName) w \
                   3641: 	"global gPrintSelection; set gPrintSelection(type) printSpecific ;#"
                   3642: 
                   3643: #    puts "trace info:[trace vinfo gPrintSelection(studentNumber)]"
                   3644: 
                   3645:     bind $studentNumber.entry <KeyPress-Return> \
                   3646: 	"fillInStudent gPrintSelection(studentName) gPrintSelection(studentNumber) 0"
                   3647:     bind $fullName.entry <KeyPress-Return> \
                   3648: 	"fillInStudent gPrintSelection(studentName) gPrintSelection(studentNumber) 1"
                   3649: 
                   3650: 
                   3651:     #Disable the entry boxes that are not selected, and enable the 
                   3652:     #ones that are
                   3653: #    $specificFrame.specific configure -command "
                   3654: #           $studentNumber.entry configure -state normal
                   3655: #           $fullName.entry configure -state normal"
                   3656: #    $randomFrame.random configure -command "
                   3657: #           $studentNumber.entry configure -state disabled
                   3658: #           $fullName.entry configure -state disabled"    
                   3659: 
                   3660:     #If the window had been called up before we need to check the state
                   3661:     #of the variable and disable/enable the correct enry boxes
                   3662: #    if { $gPrintSelection(type) == "printSpecific" } {
                   3663: #	   $studentNumber.entry configure -state normal
                   3664: #           $fullName.entry configure -state normal
                   3665: #    } 
                   3666: #    if { $gPrintSelection(type) == "printRandom" } {
                   3667: #           $studentNumber.entry configure -state disabled
                   3668: #           $fullName.entry configure -state disabled
                   3669: #    } 
                   3670:     
                   3671:     Centre_Dialog $print default
                   3672: }
                   3673: 
                   3674: proc selectedPrintMethod {} {
                   3675:     global gStopPrinting gPrintSelection gStudentSelection
                   3676:     
                   3677:     switch $gPrintSelection(type) {
                   3678: 	printSpecific {
                   3679: 	    if { $gPrintSelection(studentNumber) == "" } {
                   3680: 		displayError "You must specify a student number."
                   3681: 		return
                   3682: 	    }
                   3683: 	}
                   3684: 	printSection {
                   3685: 	    if { $gPrintSelection(section)== "" } {
                   3686: 		displayError "You must specify a section."
                   3687: 		return
                   3688: 	    }
                   3689: 	}
                   3690: 	default {}
                   3691:     }
                   3692: 	
                   3693:     destroy .print
                   3694:     removeWindowEntry Print
                   3695:     [set gPrintSelection(type)]
                   3696:     set gStopPrinting 0 
                   3697: }
                   3698: 
                   3699: ###########################################################
                   3700: # createCreateDviWin
                   3701: ###########################################################
                   3702: ###########################################################
                   3703: ###########################################################
                   3704: proc createCreateDviWin {} { 
                   3705:     global gWindowMenu gFile gCreateDviText
                   3706:     if { ![winfo exists .createDvi] } {
                   3707: 	set createDviWindow [toplevel .createDvi]
                   3708: 	$gWindowMenu add command -label "CreateDvi" -command \
                   3709: 		"capaRaise $createDviWindow"
                   3710: 	wm title $createDviWindow "LaTeX Output"
                   3711: 
                   3712: 	set windowFrame [frame $createDviWindow.windowFrame]
                   3713: 	set buttonFrame [frame $createDviWindow.buttonFrame]
                   3714: 	
                   3715: 	pack $windowFrame $buttonFrame -side bottom
                   3716: 	pack configure $windowFrame -expand true -fill both
                   3717: 	pack configure $buttonFrame -anchor e
                   3718: 
                   3719: 	scrollbar $windowFrame.scroll -orient vertical -command \
                   3720: 		"$windowFrame.text yview"
                   3721: 	set gCreateDviText [text $windowFrame.text -yscrollcommand \
                   3722: 		"$windowFrame.scroll set" -wrap char -height 40]
                   3723: 	
                   3724: 	pack $windowFrame.scroll $gCreateDviText -side left -expand 0
                   3725: 	pack configure $windowFrame.scroll -expand 0 -fill y
                   3726: 	pack configure $gCreateDviText -expand true -fill both
                   3727: 	
                   3728: 	set appearingFrame [frame $buttonFrame.appearingFrame]
                   3729: 	button $buttonFrame.ok -text Dismiss -command \
                   3730: 	    "checkDestroyPrint $createDviWindow"
                   3731: 	wm protocol $createDviWindow WM_DELETE_WINDOW \
                   3732: 	    "checkDestroyPrint $createDviWindow"
                   3733: 	pack $appearingFrame $buttonFrame.ok -side left
                   3734: 
                   3735: 	button $appearingFrame.stop -text "Stop Creating Print Jobs"\
                   3736: 		-command "stopPrinting"
                   3737: 	set name [file rootname [file tail $gFile ] ].dvi
                   3738: 	button $appearingFrame.print -text \
                   3739: 		"Save.dvi file to $name" \
                   3740: 		-command saveDvi
                   3741: 	trace variable gFile w updateCreateDvi
                   3742: 
                   3743: 	pack $appearingFrame.stop $appearingFrame.print -side left
                   3744: 	pack forget $appearingFrame.print
                   3745: 
                   3746: 	Centre_Dialog $createDviWindow default
                   3747: 	update
                   3748:     } else {
                   3749: 	pack forget .createDvi.buttonFrame.appearingFrame.print
                   3750: 	pack .createDvi.buttonFrame.appearingFrame.stop
                   3751:     }
                   3752: }
                   3753: 
                   3754: ###########################################################
                   3755: # printBody
                   3756: ###########################################################
                   3757: # sends the file quiztemp.ps to the printer through lpr using
                   3758: # the option foud in gLprCommand
                   3759: ###########################################################
                   3760: # Arguments: none
                   3761: # Returns: Nothing
                   3762: # Globals: gCapaConfig -
                   3763: #          gStopPrinting -
                   3764: # Files: quiztemp.ps - file containg info to print (removed)
                   3765: ###########################################################
                   3766: proc printBody { lprCommand { showCompletionMessage 1 } } {
                   3767:     global gCapaConfig gStopPrinting gDonePrinting
                   3768: 
                   3769:     set errorMsg ""
                   3770:     set error [ catch {exec $gCapaConfig(dvips_command) quiztemp.dvi \
                   3771: 	    -o quiztemp.ps >& /dev/null} errorMsg ]
                   3772:     if { $error } {
                   3773: 	displayError \
                   3774: 		"When attempting to run dvips an error occured : $errorMsg"
                   3775: 	return 1
                   3776:     }
                   3777: 
                   3778:     if { $gStopPrinting } {
                   3779: 	displayMessage "Printing has been stopped."
                   3780: 	set gStopPrinting 0
                   3781: 	set gDonePrinting 1
                   3782: 	return 1
                   3783:     }
                   3784: 
                   3785:     set errorMsg
                   3786:     set error [catch {set returnMessage [eval "exec $lprCommand"] } errorMsg ]
                   3787:     
                   3788:     if { $error == 1 } {
                   3789:         displayError "When attempting to print an error occured : $errorMsg"
                   3790: 	return 1
                   3791:     } else {
                   3792: 	if { $showCompletionMessage } {
                   3793: 	    displayMessage "Print job sent to the printer.\n $returnMessage"
                   3794: 	}
                   3795:     }
                   3796:     
                   3797:     return 0
                   3798: }
                   3799: 
                   3800: 
                   3801: 
                   3802: ###########################################################
                   3803: ###########################################################
                   3804: ###########################################################
                   3805: ###########################################################
                   3806: proc printCurrentDvi {} {
                   3807: 
                   3808:     set lprCommand [getLprCommand quiztemp.ps]
                   3809: 
                   3810:     if {$lprCommand == ""} { 
                   3811: 	displayError "You must at least specify a print queue for lpr. \
                   3812: 		Nothing printed."
                   3813: 	return 
                   3814:     }
                   3815: 
                   3816:     if {$lprCommand == "Cancel"} { 
                   3817: 	return
                   3818:     }
                   3819:     
                   3820:     printBody $lprCommand
                   3821:     
                   3822:     return 0
                   3823: }
                   3824: 
                   3825: ###########################################################
                   3826: ###########################################################
                   3827: ###########################################################
                   3828: ###########################################################
                   3829: proc printCurrentPreview {} {
                   3830: 
                   3831:     set lprCommand [getLprCommand quiztemp.ps]
                   3832: 
                   3833:     if {$lprCommand == ""} { 
                   3834: 	displayError "You must at least specify a print queue for lpr. \
                   3835: 		Nothing printed."
                   3836: 	return 
                   3837:     }
                   3838: 
                   3839:     if {$lprCommand == "Cancel"} { 
                   3840: 	return
                   3841:     }
                   3842: 
                   3843:     if { [createDvi 0] == 2 } {
                   3844: 	displayMessage "Printing has been stopped"
                   3845:     }
                   3846: 
                   3847:     printBody $lprCommand
                   3848: 
                   3849:     return 0
                   3850: }
                   3851: 
                   3852: ###########################################################
                   3853: ###########################################################
                   3854: ###########################################################
                   3855: ###########################################################
                   3856: proc printRandom {} {
                   3857:     global gStudentSelection gPrintSelection
                   3858:     
                   3859:     set lprCommand [getLprCommand quiztemp.ps]
                   3860: 
                   3861:     if {$lprCommand == ""} { 
                   3862: 	displayError "You must at least specify a print queue for lpr. \
                   3863: 		Nothing printed."
                   3864: 	return 
                   3865:     }
                   3866: 
                   3867:     if {$lprCommand == "Cancel"} { 
                   3868: 	return
                   3869:     }
                   3870: 
                   3871:     set type $gStudentSelection(type)
                   3872:     set random $gStudentSelection(random)
                   3873: 
                   3874:     set gStudentSelection(type) Random
                   3875:     set gStudentSelection(random) $gPrintSelection(random)
                   3876: 
                   3877:     if { [createDvi 0 1] == 2 } {
                   3878: 	displayMessage "Printing has been stopped"
                   3879:     }
                   3880: 
                   3881:     printBody $lprCommand
                   3882: 
                   3883:     set gStudentSelection(type) $type
                   3884:     set gStudentSelection(random) $random
                   3885:     
                   3886:     return 0
                   3887: }
                   3888: 
                   3889: ###########################################################
                   3890: ###########################################################
                   3891: ###########################################################
                   3892: ###########################################################
                   3893: proc printSpecific {} {
                   3894:     global gStudentSelection gPrintSelection
                   3895:     
                   3896:     set lprCommand [getLprCommand quiztemp.ps]
                   3897: 
                   3898:     if {$lprCommand == ""} { 
                   3899: 	displayError "You must at least specify a print queue for lpr. \
                   3900: 		Nothing printed."
                   3901: 	return 
                   3902:     }
                   3903: 
                   3904:     if {$lprCommand == "Cancel"} { 
                   3905: 	return
                   3906:     }
                   3907: 
                   3908:     set type $gStudentSelection(type)
                   3909:     set studentNumber $gStudentSelection(studentNumber)
                   3910: 
                   3911:     set gStudentSelection(type) Specific
                   3912:     set gStudentSelection(studentNumber) $gPrintSelection(studentNumber)
                   3913: 
                   3914:     if { [createDvi 0 1 1] == 2 } {
                   3915: 	displayMessage "Printing has been stopped"
                   3916:     }
                   3917: 
                   3918:     printBody $lprCommand
                   3919: 
                   3920:     set gStudentSelection(type) $type
                   3921:     set gStudentSelection(studentNumber) $studentNumber
                   3922:     
                   3923:     return 0
                   3924: }
                   3925: 
                   3926: ###########################################################
                   3927: ###########################################################
                   3928: ###########################################################
                   3929: ###########################################################
                   3930: proc printStudent { studentNumber } {
                   3931:     global gStudentSelection gStopPrinting gDonePrinting
                   3932:     
                   3933:     set type $gStudentSelection(type)
                   3934:     set studentNumberOld $gStudentSelection(studentNumber)
                   3935: 
                   3936:     set gStudentSelection(type) Specific
                   3937:     set gStudentSelection(studentNumber) $studentNumber
                   3938: 
                   3939:     set createdDvi [createDvi 0 1]
                   3940: 
                   3941:     if { $createdDvi == 1 } { printBody } else { 
                   3942: 	displayMessage "Printing has been stopped"
                   3943: 	set gStopPrinting 0
                   3944: 	set gDonePrinting 1
                   3945:     }
                   3946:     
                   3947:     set gStudentSelection(type) $type
                   3948:     set gStudentSelection(studentNumber) $studentNumberOld
                   3949: 
                   3950:     return 0
                   3951: }
                   3952: 
                   3953: proc checkDestroyPrint { createDviWindow } {
                   3954:     global gDonePrinting
                   3955:     if { !$gDonePrinting } {
                   3956: 	if { [makeSure "Do you really wish to stop printing?"] == "Yes" } {
                   3957: 	    global gStopPrinting 
                   3958: 	    set gStopPrinting 1
                   3959: 	    after 1000 "destroyPrint $createDviWindow"
                   3960: 	}
                   3961: 	return
                   3962:     }
                   3963:     destroyPrint $createDviWindow
                   3964: }
                   3965: 
                   3966: proc destroyPrint { createDviWindow } {
                   3967:     trace vdelete gFile w updateCreateDvi
                   3968:     destroy $createDviWindow
                   3969:     removeWindowEntry CreateDvi
                   3970: }
                   3971: 
                   3972: ###########################################################
                   3973: ###########################################################
                   3974: ###########################################################
                   3975: ###########################################################
                   3976: proc setupSetsToPrint { setVar startVar endVar {checkForHeader 1}} {
                   3977:     global gPrintSelection gSetNumberText gLoadHeaderSet 
                   3978:     upvar $setVar set $startVar start $endVar end
                   3979:     if { $gPrintSelection(sets) == "printRange" } {
                   3980: 	set start $gPrintSelection(setstart)
                   3981: 	set end $gPrintSelection(setend)
                   3982: 	set set "$start:$end"
                   3983: 	set errors ""
                   3984: 	for {set i $start}  {$i <= $end} {incr i} {
                   3985: 	    set gLoadHeaderSet $i
                   3986: 	    if {[catch {getHeaderInfo}]} { append errors ", $i" }
                   3987: 	}
                   3988: 	if { $checkForHeader && $errors != "" } {
                   3989: 	    set errors [string range $errors 1 end]
                   3990: 	    if { [llength $errors] > 1 } { 
                   3991: 		set errors "s$errors" 
                   3992: 		set errors [linsert $errors [expr [llength $errors] - 1] and]
                   3993: 	    }
                   3994: 	    displayError "DB header has not yet been set for set$errors. Please set the DB Header before printing Sections."
                   3995: 	    return 1
                   3996: 	}
                   3997:     } else {
                   3998: 	set start [set end [set set $gSetNumberText]]
                   3999: 	set gLoadHeaderSet $gSetNumberText
                   4000: 	if {$checkForHeader && [catch {getHeaderInfo}]} {
                   4001: 	    displayError "DB header has not yet been set. Please set the DB Header before printing Sections."
                   4002: 	    return 1
                   4003: 	}
                   4004:     }
                   4005: }
                   4006: 
                   4007: ###########################################################
                   4008: ###########################################################
                   4009: ###########################################################
                   4010: ###########################################################
                   4011: proc printSection { { lprCommand "" } } {
                   4012:     global gPrintSelection gCapaConfig gSetNumberText gWindowMenu \
                   4013: 	gCreateDviText gStopPrinting gPrefs gFile gDonePrinting \
                   4014: 	gLoadHeaderSet
                   4015: 
                   4016:     set gDonePrinting 0
                   4017:     set showStopping 0
                   4018: 
                   4019:     if { [setupSetsToPrint set start end] == 1 } { return 1}
                   4020:     if { $lprCommand == "" } {
                   4021: 	set showStopping 1
                   4022: 	set lprCommand [getLprCommand quiztemp.ps]
                   4023: 	if { $lprCommand == "" } {
                   4024: 	    displayError "Print command was empty, unable to print."
                   4025: 	    return 1
                   4026: 	}
                   4027: 	if {$lprCommand == "Cancel" } {
                   4028: 	    return 1
                   4029: 	}
                   4030:     }
                   4031: 
                   4032:     createCreateDviWin
                   4033:     
                   4034:     grab .createDvi
                   4035: 
                   4036:     $gCreateDviText delete 0.0 end
                   4037: 
                   4038:     switch $gPrefs(info) {
                   4039: 	Problem	{ set type "-T" }
                   4040: 	Answer	{ set type "-Ta" }
                   4041: 	ProblemAnswer { set type "-Tb" }
                   4042: 	default	{ set type "-T"	}
                   4043:     }
                   4044: 
                   4045:     if { [set gStopPrinting [expr 2 == [runLatex \
                   4046: 	    "echo [pwd] | $gCapaConfig(qzparse_command) \
                   4047: 	    -sec $gPrintSelection(section) -set $set \
                   4048: 	    -d [pwd] -c [pwd] $type " gCreateDviText] ] ] } {
                   4049: 	for {set i $start} { $i <= $end} { incr i } {
                   4050: 	    exec rm -f section$gPrintSelection(section)-set$i.tex 
                   4051: 	}
                   4052: 	if {$showStopping} {
                   4053: 	    displayMessage "Printing has been stopped."
                   4054: 	    set gDonePrinting 1
                   4055: 	    set gStopPrinting 0
                   4056: 	}
                   4057: 	return 1
                   4058:     }
                   4059:     if { $gStopPrinting } {
                   4060: 	displayMessage "Printing has been stopped."
                   4061: 	set gDonePrinting 1
                   4062: 	set gStopPrinting 0
                   4063: 	return 1
                   4064:     }
                   4065: 
                   4066:     for { set i $start} { $i <= $end } { incr i } {
                   4067: 	if { ! [file exists section$gPrintSelection(section)-set$i.tex] } {
                   4068: 	    if {$showStopping} {
                   4069: 		displayError "The qzparse command: $gCapaConfig(qzparse_command), was unable to produce the expected output. Printing stopped"
                   4070: 		set gStopPrinting 0
                   4071: 		set gDonePrinting 1
                   4072: 	    }
                   4073: 	    return 2
                   4074: 	}
                   4075: 	
                   4076: 	exec mv section$gPrintSelection(section)-set$i.tex quiztemp.tex
                   4077: 	exec /bin/rm -f quiztemp.dvi 
                   4078: 
                   4079: 	$gCreateDviText insert end "$gCapaConfig(latex_command)\n"
                   4080: 	$gCreateDviText see end 
                   4081: 	
                   4082: 	if { [set gStopPrinting [ expr 2 == [runLatex \
                   4083: 	    "pwd ; $gCapaConfig(latex_command) \
                   4084: 	    quiztemp.tex < [file join / dev null ]" gCreateDviText ] ] ] } {
                   4085: 	    if {$showStopping} {
                   4086: 		displayError "The LaTeX command: $gCapaConfig(latex_command), was unable to produce the expected output. Printing stopped"
                   4087: 		set gStopPrinting 0
                   4088: 		set gDonePrinting 1
                   4089: 	    }
                   4090: 	    return 1
                   4091: 	}
                   4092: 
                   4093: 	if { $gStopPrinting } {
                   4094: 	    displayMessage "Printing has been stopped."
                   4095: 	    set gDonePrinting 1
                   4096: 	    set gStopPrinting 0
                   4097: 	    return 1
                   4098: 	}
                   4099: 
                   4100: 	set a [expr ($showStopping) && ($end == $i)]
                   4101: 	if { [set gStopPrinting [printBody $lprCommand $a ] ] } {
                   4102: 	    if {$showStopping} {
                   4103: 		displayMessage "Printing has been stopped."
                   4104: 		set gDonePrinting 1
                   4105: 		set gStopPrinting 0
                   4106: 	    }
                   4107: 	    return 1
                   4108: 	}
                   4109: 	if { $gStopPrinting } {
                   4110: 	    displayMessage "Printing has been stopped."
                   4111: 	    set gDonePrinting 1
                   4112: 	    set gStopPrinting 0
                   4113: 	    return 1
                   4114: 	}
                   4115:     }
                   4116: 
                   4117:     set gDonePrinting 1
                   4118:     return 0
                   4119: }
                   4120: 
                   4121: ###########################################################
                   4122: ###########################################################
                   4123: ###########################################################
                   4124: ###########################################################
                   4125: proc printMultipleSections { } {
                   4126:     global gPrintSelection gCapaConfig gSetNumberText gWindowMenu \
                   4127: 	    gCreateDviText gStopPrinting gPrefs gDonePrinting
                   4128:     
                   4129:     #checks if the DB Header is set
                   4130:     if { [setupSetsToPrint set start end] == 1 } { return 1}
                   4131: 
                   4132:     set sectionList [ getExistingSections ]
                   4133:     set sectionsToPrint [ pickSections $sectionList "Select Sections to Print:" ]
                   4134: 
                   4135:     if { $sectionsToPrint == "" } {
                   4136: 	displayMessage "No sections selected, therefore nothing was printed."
                   4137: 	return 1
                   4138:     }
                   4139:     if { $sectionsToPrint == "Cancel" } {
                   4140: 	return 1
                   4141:     }
                   4142: 
                   4143:     set lprCommand [getLprCommand quiztemp.ps]
                   4144:     if { $lprCommand == "" } {
                   4145: 	displayError "Print command was empty, unable to print."
                   4146: 	return 1
                   4147:     }
                   4148:     if {$lprCommand == "Cancel" } {
                   4149: 	return 1
                   4150:     }
                   4151: 
                   4152:     if { [makeSure "You have selected to print $gPrefs(info)s for sections: [string trim $sectionsToPrint], using the print command \"$lprCommand\", continue?"] == "Cancel" } {
                   4153: 	return 1
                   4154:     }
                   4155: 
                   4156:     foreach section $sectionsToPrint {
                   4157: 	set gDonePrinting 0
                   4158: 	set gPrintSelection(section) $section
                   4159: 	if { [set gStopPrinting [printSection $lprCommand] ] } {
                   4160: 	    set gDonePrinting 0
                   4161: 	    if { $gStopPrinting == 2 } {
                   4162: 		displayError "The qzparse command: $gCapaConfig(qzparse_command), was unable to produce the expected output. Printing stopped"
                   4163: 	    } else {
                   4164: 		displayMessage "Printing has been stopped."
                   4165: 	    }
                   4166: 	    set gDonePrinting 1
                   4167: 	    return 1
                   4168: 	}
                   4169: 	if { $gStopPrinting } {
                   4170: 	    displayMessage "Printing has been stopped."
                   4171: 	    set gStopPrinting 0
                   4172: 	    set gDonePrinting 1
                   4173: 	    return 1
                   4174: 	}
                   4175:     }
                   4176:     set gDonePrinting 1
                   4177:     displayMessage "Print jobs sent to the printer."
                   4178:     return 0
                   4179: }
                   4180: 
                   4181: ###########################################################
                   4182: ###########################################################
                   4183: ###########################################################
                   4184: ###########################################################
                   4185: proc printWholeClass { } {
                   4186:     global gPrintSelection gCapaConfig gSetNumberText gWindowMenu \
                   4187: 	    gCreateDviText gStopPrinting gPrefs gDonePrinting
                   4188:     
                   4189:     if {[catch {getHeaderInfo}]} {
                   4190: 	displayError "DB header has not yet been set, Please set DB Header before printing Sections."
                   4191: 	return 1
                   4192:     }
                   4193:     set sectionsToPrint [ getExistingSections ]
                   4194: 
                   4195:     if { $sectionsToPrint == "" } {
                   4196: 	displayMessage "No sections exist, therefore nothing was printed."
                   4197: 	return 1
                   4198:     }
                   4199: 
                   4200:     set lprCommand [getLprCommand quiztemp.ps]
                   4201: 
                   4202:     if { $lprCommand == "" } {
                   4203: 	displayError "Print command was empty, unable to print."
                   4204: 	return 1
                   4205:     }
                   4206:     if {$lprCommand == "Cancel" } {
                   4207: 	return 1
                   4208:     }
                   4209: 
                   4210:     if { [makeSure "You have selected to print $gPrefs(info)s for the entire class of [llength $sectionsToPrint] sections, using the print command $lprCommand, continue?"] == "Cancel" } {
                   4211: 	return 1
                   4212:     }
                   4213: 
                   4214:     foreach section $sectionsToPrint {
                   4215: 	set section [lindex $section 0]
                   4216: 	set gPrintSelection(section) $section
                   4217: 	set gStopPrinting [printSection $lprCommand]
                   4218: 	if { $gStopPrinting } {
                   4219: 	    if { $gStopPrinting == 2 } {
                   4220: 		displayError "$gCapaConfig(qzparse_command) was unable to produce the expected output. Printing stopped"
                   4221: 	    } else {
                   4222: 		displayMessage "Printing has been stopped."
                   4223: 	    }
                   4224: 	    set gDonePrinting 1
                   4225: 	    set gStopPrinting 0
                   4226: 	    return 1
                   4227: 	}
                   4228:     }
                   4229:     set gDonePrinting 1
                   4230:     displayMessage "Print jobs sent to the printer."
                   4231:     return 0
                   4232: }
                   4233: 
                   4234: ###########################################################
                   4235: # analyzeSet
                   4236: ###########################################################
                   4237: ###########################################################
                   4238: ###########################################################
                   4239: proc analyzeSet {} {
                   4240:     global gChanged gWindowMenu gEditWindow gAnalyze gSetNumberText gNumberParsedText
                   4241: 
                   4242:     if { [catch {winfo exists $gEditWindow}] } { return }
                   4243:     if { ![ winfo exists $gEditWindow ] } { return }
                   4244:     if { $gChanged } { if { [askToSave 0 0] == "Cancel" } { return } }
                   4245:     if { [winfo exists .analyzeSet] } { 
                   4246: 	capaRaise .analyzeSet
                   4247: 	return
                   4248:     }
                   4249: 
                   4250:     set analyze [toplevel .analyzeSet]
                   4251:     $gWindowMenu add command -label "AnalyzeSet" \
                   4252: 	    -command "capaRaise $analyze"
                   4253:     wm title $analyze "Analyze Set"
                   4254:     
                   4255:     set settingsFrame [frame $analyze.settingsFrame]
                   4256:     set dataFrame [frame $analyze.dataFrame]
                   4257:     pack $settingsFrame $dataFrame -side top
                   4258: 
                   4259:     set classFrame [frame $settingsFrame.classFrame]
                   4260:     set setFrame [frame $settingsFrame.setFrame]
                   4261:     set probFrame [frame $settingsFrame.probFrame]
                   4262:     set statusFrame [frame $settingsFrame.statusFrame]
                   4263:     set statusBar [frame $settingsFrame.statusBar]
                   4264:     set buttonFrame [frame $settingsFrame.buttonFrame]
                   4265:     pack $classFrame $setFrame $probFrame $statusFrame $statusBar $buttonFrame \
                   4266: 	-side top
                   4267:     
                   4268:     set canvasFrame [frame $dataFrame.canvasFrame]
                   4269:     set numberFrame [frame $dataFrame.numberFrame]
                   4270:     pack $canvasFrame $numberFrame -side top
                   4271: 
                   4272:     set gAnalyze(class) [pwd]
                   4273:     label $classFrame.label -textvariable gAnalyze(class)
                   4274:     pack $classFrame.label
                   4275:     
                   4276:     set gAnalyze(set) $gSetNumberText
                   4277:     label $setFrame.lbl -text "Set number:"
                   4278:     label $setFrame.set -textvariable gAnalyze(set)
                   4279: #    button $setFrame.change -text "Change" -command analyzeChangeSet
                   4280:     pack $setFrame.lbl $setFrame.set -side left
                   4281: 
                   4282:     if { [set gAnalyze(maxprob) $gNumberParsedText] == "" } { set gAnalyze(maxprob) 1 }
                   4283:     
                   4284:     label $probFrame.label -text "Problem Number :"
                   4285:     set gAnalyze(scale) [scale $probFrame.problem \
                   4286: 			     -from 1 -to $gAnalyze(maxprob) \
                   4287: 			     -variable gAnalyze(prob) -command analyzeUpdate \
                   4288: 			     -orient h -length 150 -tickinterval 1]
                   4289:     pack $probFrame.label $probFrame.problem -side left
                   4290: 
                   4291:     set gAnalyze(status) ""
                   4292:     label $statusFrame.label -text "Status:" 
                   4293:     label $statusFrame.status -textvariable gAnalyze(status)
                   4294:     pack $statusFrame.label $statusFrame.status -side left
                   4295: 
                   4296:     set gAnalyze(statcanvas) [canvas $statusBar.canvas -width 200 -height 20]
                   4297:     pack $statusBar.canvas
                   4298:     $gAnalyze(statcanvas) create rectangle 1 1 199 19 -outline black
                   4299:     set gAnalyze(bar) [$gAnalyze(statcanvas) create rectangle 1 1 1 19 -fill red -outline black]
                   4300: 
                   4301:     button $buttonFrame.class -text "Run Class" -command "analyzeClass 1"
                   4302:     button $buttonFrame.random -text "Run Random" -command analyzeRandom
                   4303:     button $buttonFrame.stop -text "Stop" -command analyzeStop
                   4304:     button $buttonFrame.close -text "Dismiss" -comman analyzeClose
                   4305:     pack $buttonFrame.class $buttonFrame.random $buttonFrame.stop \
                   4306: 	$buttonFrame.close -side left
                   4307:     
                   4308:     set gAnalyze(canvaswidth) 600
                   4309:     set gAnalyze(canvas) [canvas $canvasFrame.canvas -width $gAnalyze(canvaswidth) \
                   4310: 			      -height 100]
                   4311:     pack $gAnalyze(canvas)
                   4312:     
                   4313:     set hiFrame [frame $numberFrame.hiFrame]
                   4314:     set lowFrame [frame $numberFrame.lowFrame]
                   4315:     set uniqFrame [frame $numberFrame.uniqFrame]
                   4316:     pack $lowFrame $hiFrame $uniqFrame -side left
                   4317:     pack configure $hiFrame -anchor e
                   4318:     pack configure $lowFrame -anchor w
                   4319: 
                   4320:     label $hiFrame.label -text "High End:"
                   4321:     label $hiFrame.num -textvariable gAnalyze(highnum)
                   4322:     pack $hiFrame.label $hiFrame.num -side left
                   4323: 
                   4324:     label $lowFrame.label -text "Low End:"
                   4325:     label $lowFrame.num -textvariable gAnalyze(lownum)
                   4326:     pack $lowFrame.label $lowFrame.num -side left
                   4327: 
                   4328:     label $uniqFrame.label -text "Num. Unique:"
                   4329:     label $uniqFrame.num -textvariable gAnalyze(numuniq)
                   4330:     pack $uniqFrame.label $uniqFrame.num -side left
                   4331: 
                   4332:     set gAnalyze(studentNumbers) [getStudentNumbers]
                   4333:     set gAnalyze(exit) 0
                   4334: }
                   4335: 
                   4336: ###########################################################
                   4337: # analyzeClass
                   4338: ###########################################################
                   4339: ###########################################################
                   4340: ###########################################################
                   4341: proc analyzeClass { {start 1} } {
                   4342:     global gAnalyze gCapaConfig
                   4343:     if { $gAnalyze(studentNumbers)=="" } { return }
                   4344:     if { $start } { 
                   4345: 	set gAnalyze(toprocess) $gAnalyze(studentNumbers) 
                   4346: 	set gAnalyze(stop) 0
                   4347: 	set gAnalyze(update) 1
                   4348: 	set gAnalyze(done) 0
                   4349: 	set gAnalyze(total) [expr [llength $gAnalyze(toprocess)]/3]
                   4350: 	foreach name [array names gAnalyze *.\[alhu\]*] { unset gAnalyze($name) }
                   4351:     }
                   4352:     set number [lindex $gAnalyze(toprocess) 0]
                   4353:     set name [lindex $gAnalyze(toprocess) 1]
                   4354:     set section [lindex $gAnalyze(toprocess) 2]
                   4355:     set gAnalyze(toprocess) [lrange $gAnalyze(toprocess) 3 end]
                   4356:     set command "$gCapaConfig(answers_command) $number \"$name\" $section $gAnalyze(set)"
                   4357:     set fileId [open "|$command" "r"]
                   4358:     set gAnalyze(pid) [pid $fileId]
                   4359:     fconfigure $fileId -blocking 0
                   4360:     fileevent $fileId readable "analyzeLine $fileId"
                   4361:     set gAnalyze(status) "Processing $number"
                   4362:     incr gAnalyze(done)
                   4363:     $gAnalyze(statcanvas) coords $gAnalyze(bar) 1 1 [expr 200*($gAnalyze(done)/double($gAnalyze(total)))] 19
                   4364:     update idletasks
                   4365: }
                   4366: 
                   4367: ###########################################################
                   4368: # analyzeEatQuestion
                   4369: ###########################################################
                   4370: ###########################################################
                   4371: ###########################################################
                   4372: proc analyzeEatQuestion { fileId } {
                   4373:     global gAnalyze 
                   4374:     if { $gAnalyze(exit) } { 
                   4375: 	fileevent $fileId readable ""
                   4376: 	catch {close $fileId}
                   4377: 	return
                   4378:     }
                   4379:     set aline [gets $fileId]
                   4380:     if { $aline != "" } {
                   4381: 	switch -- [lindex [split $aline :] 0] {
                   4382: 	    EQES { fileevent $fileId readable "analyzeLine $fileId" }
                   4383: 	}
                   4384:     }
                   4385:     if { [eof $fileId] } { analyzeEnd $fileId }
                   4386: }
                   4387: 
                   4388: ###########################################################
                   4389: # analyzeLine
                   4390: ###########################################################
                   4391: ###########################################################
                   4392: ###########################################################
                   4393: proc analyzeLine { fileId } {
                   4394:     global gAnalyze 
                   4395:     
                   4396:     if { $gAnalyze(exit) } { 
                   4397: 	fileevent $fileId readable ""
                   4398: 	catch {close $fileId}
                   4399: 	return
                   4400:     }
                   4401:     set aline [gets $fileId]
                   4402:     if { $aline != "" } {
                   4403: 	switch [lindex [split $aline :] 0] {
                   4404: 	    ANS { 
                   4405: 		incr gAnalyze(problemNum)
                   4406: 		set ans [string range $aline 4 end]
                   4407: 		set length [llength $ans]
                   4408: 		lappend gAnalyze($gAnalyze(problemNum).ans) \
                   4409: 		    [lindex $ans 0]
                   4410: 		if { ($length == 2) || ($length == 4)} {
                   4411: 		    lappend gAnalyze($gAnalyze(problemNum).unit) \
                   4412: 			[lindex $ans end]
                   4413: 		} 
                   4414: 		if { ($length == 3) || ($length == 4) } {
                   4415: 		    lappend gAnalyze($gAnalyze(problemNum).low) \
                   4416: 			[lindex $ans 1]
                   4417: 		    lappend gAnalyze($gAnalyze(problemNum).high) \
                   4418: 			[lindex $ans 2]
                   4419: 		}
                   4420: 	    }
                   4421: 	    SET { set gAnalyze(problemNum) 0 }
                   4422: 	    DONE { 
                   4423: 		set gAnalyze(maxprob) $gAnalyze(problemNum)
                   4424: 		$gAnalyze(scale) configure -to $gAnalyze(maxprob)
                   4425: 	    }
                   4426: 	    ERROR {
                   4427:  		fileevent $fileId readable ""
                   4428: 		displayError "Answers returned invalid message: $aline" 
                   4429: 		fileevent $fileId readable "analyzeLine $fileId"
                   4430: 	    }
                   4431: 	    BQES { fileevent $fileId readable "analyzeEatQuestion $fileId" }
                   4432: 	    default {
                   4433: 	    }
                   4434: 	}
                   4435:     }
                   4436:     if { [eof $fileId] } { analyzeEnd $fileId }
                   4437: }
                   4438: 
                   4439: ###########################################################
                   4440: # analyzeEnd
                   4441: ###########################################################
                   4442: ###########################################################
                   4443: ###########################################################
                   4444: proc analyzeEnd { fileId } {
                   4445:     global gAnalyze
                   4446:     if { [eof $fileId] } {
                   4447: 	fileevent $fileId readable ""
                   4448: 	catch {close $fileId}
                   4449: 	if { $gAnalyze(stop) } { return }
                   4450: 	if { [llength $gAnalyze(toprocess)] > 0 } { 
                   4451: 	    analyzeClass 0 
                   4452: 	} else {
                   4453: 	    analyzeUpdate
                   4454: 	    set gAnalyze(status) "Done"
                   4455: 	}
                   4456: 	if { !$gAnalyze(update) } {
                   4457: 	    incr gAnalyze(update) 
                   4458: 	    analyzeUpdate
                   4459: 	} else {
                   4460:  	    incr gAnalyze(update) 
                   4461: 	    if { $gAnalyze(update) == 10 } {
                   4462: 		set gAnalyze(update) 0
                   4463: 	    }
                   4464: 	}
                   4465:     }
                   4466: }
                   4467: 
                   4468: ###########################################################
                   4469: # analyzeRandom
                   4470: ###########################################################
                   4471: ###########################################################
                   4472: ###########################################################
                   4473: proc analyzeRandom { } {
                   4474:     global gAnalyze
                   4475:     set numToRun [getString . "How many random students should be run?"]
                   4476:     if { $numToRun == "" } { return }
                   4477:     if { [catch {incr numToRun} ] } {
                   4478: 	displayMessage "Invalid number."
                   4479:     }
                   4480:     incr numToRun -1
                   4481:     set gAnalyze(total) $numToRun
                   4482:     catch {unset gAnalyze(toprocess)}
                   4483:     for { set i 0 } { $i < $numToRun } { incr i } {
                   4484: 	append gAnalyze(toprocess) "[format "%09d" $i] Random 999 "
                   4485:     }
                   4486:     set gAnalyze(stop) 0
                   4487:     set gAnalyze(update) 1
                   4488:     set gAnalyze(done) 0
                   4489:     foreach name [array names gAnalyze *.\[alhu\]*] { unset gAnalyze($name) }    
                   4490:     analyzeClass 0
                   4491: }
                   4492: 
                   4493: ###########################################################
1.4       albertel 4494: # analyzeStrings
                   4495: ###########################################################
                   4496: ###########################################################
                   4497: ###########################################################
                   4498: proc analyzeStrings { prob window create} {
                   4499:     global gAnalyze
                   4500: 
                   4501:     if { ![winfo exists $window.analyzestrings] } { if {!$create} { return } }
                   4502:     if { ![catch {set setWin [toplevel $window.analyzestrings]}] } {
                   4503: 	set msgFrame [frame $setWin.msgFrame]
                   4504: 	set valFrame [frame $setWin.valFrame]
                   4505: 	set buttonFrame [frame $setWin.buttonFrame]
                   4506: 	pack $msgFrame $valFrame $buttonFrame
                   4507: 	pack configure $valFrame -expand 1 -fill both
                   4508: 	
                   4509: 	message $msgFrame.msg -text "Correct Answers" -aspect 3000
                   4510: 	pack $msgFrame.msg
                   4511: 	
                   4512: 	set maxWidth 1
                   4513: 	foreach choice $gAnalyze($prob.ans) {
                   4514: 	    if {[string length $choice]>$maxWidth} {set maxWidth [string length $choice]}
                   4515: 	}
                   4516: 	set maxStringWidth $maxWidth
                   4517: 	incr maxWidth 6
                   4518: 
                   4519: 	set selectMode none
                   4520: 	listbox $valFrame.val -width [expr $maxWidth + 2] \
                   4521: 	    -yscrollcommand "$valFrame.scroll set" -selectmode $selectMode
                   4522: 	scrollbar $valFrame.scroll -command "$valFrame.val yview"
                   4523: 	pack $valFrame.val $valFrame.scroll -side left
                   4524: 	pack configure $valFrame.val -expand 1 -fill both 
                   4525: 	pack configure $valFrame.scroll -expand 0 -fill y
                   4526: 	button $buttonFrame.cancel -text "Dismiss" -command "destroy $setWin"
                   4527: 	pack $buttonFrame.cancel
                   4528:     } else {
                   4529: 	set maxWidth 1
                   4530: 	set valFrame $window.analyzestrings.valFrame
                   4531: 	$valFrame.val delete 0 end
                   4532: 	foreach choice $gAnalyze($prob.ans) {
                   4533: 	    if {[string length $choice]>$maxWidth} {set maxWidth [string length $choice]}
                   4534: 	}
                   4535: 	set maxStringWidth $maxWidth
                   4536: 	incr maxWidth 6
                   4537:     }
                   4538:     set lastchoice [lindex $gAnalyze($gAnalyze(prob).ans) 0]
                   4539:     set num 1
                   4540:     foreach choice [lsort $gAnalyze($gAnalyze(prob).ans)] {    
                   4541: 	if { $lastchoice != $choice } {
                   4542: 	    $valFrame.val insert end \
                   4543: 		"[format %-[set maxStringWidth]s $lastchoice] [format %5d $num]"
                   4544: 	    set lastchoice $choice
                   4545: 	    set num 1
                   4546: 	} else {
                   4547: 	    incr num
                   4548: 	}
                   4549:     }	
                   4550:     $valFrame.val insert end \
                   4551: 	"[format %-[set maxStringWidth]s $lastchoice] [format %5d $num]"
                   4552: }
                   4553: 
                   4554: ###########################################################
1.1       albertel 4555: # analyzeUpdate
                   4556: ###########################################################
                   4557: ###########################################################
                   4558: ###########################################################
                   4559: proc analyzeUpdate { {newProbNumber 0} } {
                   4560:     global gAnalyze
                   4561: 
                   4562:     if {[catch {set gAnalyze($gAnalyze(prob).ans)}]} { return }
                   4563:     foreach problem [array names gAnalyze *.\[alh\]*] {
                   4564: 	if { [catch {set gAnalyze($problem) [lsort -real $gAnalyze($problem)]}]} {
                   4565: 	    set gAnalyze($problem) [lsort $gAnalyze($problem)]
                   4566: 	}
                   4567:     }
                   4568: 
                   4569:     set c $gAnalyze(canvas)
                   4570:     $c delete all
                   4571:     set gAnalyze(lownum) [set low [lindex $gAnalyze($gAnalyze(prob).ans) 0]]
                   4572:     set gAnalyze(highnum) [set high [lindex $gAnalyze($gAnalyze(prob).ans) end]]
                   4573:     set gAnalyze(numuniq) [llength [lunique $gAnalyze($gAnalyze(prob).ans)]]
                   4574: #don't draw anything if the answers aren't numbers
1.4       albertel 4575:     if { [catch {expr $low + 1}]} { 
                   4576: 	catch {destroy $c.button}
                   4577: 	update idletask
                   4578: 	button $c.button -text "List of strings" -command \
                   4579: 	    "analyzeStrings $gAnalyze(prob) $c 1"
                   4580: 	$c create window [expr $gAnalyze(canvaswidth)/2.0] 40 -window $c.button
                   4581: 	analyzeStrings $gAnalyze(prob) $c 0
                   4582: 	return 
                   4583:     }
1.1       albertel 4584: 
                   4585:     $c create line 25 50 [expr $gAnalyze(canvaswidth) - 25] 50
                   4586:     set diff [expr double($high-$low)]
                   4587:     if { $diff == 0 } {
                   4588: 	set center [expr $gAnalyze(canvaswidth)/2.0]
1.4       albertel 4589: 	$c create rectangle [expr $center - 2] 48 [expr $center + 2] 52 -fill green
1.1       albertel 4590: 	update idletasks
                   4591: 	return
                   4592:     }
                   4593:     set delta [format "%1.e" [expr ($diff)/15.0]]
                   4594:     set start [expr double(int($low/$delta)+1)*$delta]
                   4595:     while { $start < $high } {
                   4596: 	set center [expr ($gAnalyze(canvaswidth)-50)*(($start-$low)/$diff)]
                   4597: 	set center [expr $center+25]
                   4598: 	$c create line $center 40 $center 60
                   4599: 	set start [expr $start + $delta]
                   4600:     }
                   4601:     if { ($low < 0) && ($high > 0) } {
                   4602: 	set center [expr ($gAnalyze(canvaswidth)-50)*((0-$low)/$diff)]
                   4603: 	set center [expr $center+25]
                   4604: 	$c create rectangle [expr $center - 1] 40 [expr $center + 1] 60
                   4605:     }
1.3       albertel 4606:     set lastpoint [lindex $gAnalyze($gAnalyze(prob).ans) 0]
                   4607:     set num 0
1.1       albertel 4608:     foreach point $gAnalyze($gAnalyze(prob).ans) {    
1.3       albertel 4609: 	if { $lastpoint != $point } {
                   4610: 	    set center [expr ($gAnalyze(canvaswidth)-50)*(($lastpoint-$low)/$diff)]
                   4611: 	    set center [expr $center+25]
1.4       albertel 4612: 	    $c create rectangle [expr $center - 2] [expr 48-$num] \
                   4613: 		[expr $center + 2] [expr 52+$num] -fill green
1.3       albertel 4614: 	    set lastpoint $point
                   4615: 	    set num 0
                   4616: 	} else {
                   4617: 	    incr num
                   4618: 	}
1.1       albertel 4619:     }	
1.4       albertel 4620:     set center [expr ($gAnalyze(canvaswidth)-50)*(($lastpoint-$low)/$diff)]
                   4621:     set center [expr $center+25]
                   4622:     $c create rectangle [expr $center - 2] [expr 48-$num] \
                   4623: 	[expr $center + 2] [expr 52+$num] -fill green
1.1       albertel 4624:     
                   4625:     update idletasks
                   4626: }
                   4627: 
                   4628: ###########################################################
                   4629: # analyzeStop
                   4630: ###########################################################
                   4631: ###########################################################
                   4632: ###########################################################
                   4633: proc analyzeStop {} {
                   4634:     global gAnalyze
                   4635:     set gAnalyze(stop) 1
                   4636:     set gAnalyze(status) "Stopped"
                   4637:     exec kill -SIGKILL $gAnalyze(pid)
                   4638: }
                   4639: 
                   4640: ###########################################################
                   4641: # analyzeClose
                   4642: ###########################################################
                   4643: ###########################################################
                   4644: ###########################################################
                   4645: proc analyzeClose { } {
                   4646:     global gAnalyze
                   4647:     destroy [winfo toplevel $gAnalyze(canvas)]
                   4648:     unset gAnalyze
                   4649:     global gAnalyze
                   4650:     set gAnalyze(exit) 1
                   4651: }
                   4652: 
                   4653: ###########################################################
                   4654: # checkIfValidFilename 
                   4655: ###########################################################
                   4656: ###########################################################
                   4657: ###########################################################
                   4658: proc checkIfValidFilename {} {
                   4659:     global gSetNumberText gPreviewButton
                   4660:     if { [regexp \[^0-9\]+ $gSetNumberText] } {
                   4661: 	displayError "This file is not properly named. \n\nA main assignment file must be named setX.qz, where  X is replaced by a number between 1 and 99 inclusive. \n\nPlease do a \"Save .qz As\". \n\nUntil the file is properly named you will not be able to Preview, Create .dvi, or Print."
                   4662: 	$gPreviewButton configure -state disabled
                   4663: 	.main entryconfigure 5 -state disabled
                   4664: 	.main entryconfigure 7 -state disabled
                   4665: 	return 0
                   4666:     }
                   4667:     $gPreviewButton configure -state normal
                   4668:     .main entryconfigure 5 -state normal
                   4669:     .main entryconfigure 7 -state normal
                   4670:     return 1
                   4671: }
                   4672: 
                   4673: ###########################################################
                   4674: # updateChangeStatus
                   4675: ###########################################################
                   4676: ###########################################################
                   4677: ###########################################################
                   4678: proc updateChangeStatus { name1 name2 op } {
                   4679:     global gChanged gRefChanged gRefText gChangedLast gRefChangedLast \
                   4680: 	gEditWindow gWindowMenu gRefFile
                   4681:     if { $name1 == "gChanged" } {
                   4682: 	if { $gChanged != $gChangedLast } {
                   4683: 	    set gChangedLast $gChanged
                   4684: 	    global gFile
                   4685: 	    if { [catch {set gEditWindow}] } { return }
                   4686: 	    if { ![winfo exists $gEditWindow] } { return }
                   4687: 	    if { $gChanged } {
                   4688: 		catch {removeWindowEntry "$gFile*"}
                   4689: 		wm title [winfo toplevel $gEditWindow] "$gFile (Modified)"
                   4690: 		$gWindowMenu add command -label "$gFile (Modified)" -command \
                   4691: 		    "capaRaise $gEditWindow"
                   4692: 	    } else {
                   4693: 		catch {removeWindowEntry "$gFile*"}
                   4694: 		wm title [winfo toplevel $gEditWindow] "$gFile"
                   4695: 		$gWindowMenu add command -label "$gFile" -command \
                   4696: 		    "capaRaise $gEditWindow"
                   4697: 	    }
                   4698: 	}
                   4699:     } else {
                   4700: 	if { $gRefChanged($name2) != $gRefChangedLast($name2) } {
                   4701: 	    if { [catch {set gRefText($name2)}] } { return }
                   4702: 	    if { ![winfo exists $gRefText($name2)] } { return }
                   4703: 	    if { $gRefChanged($name2) } {
                   4704: 		catch {removeWindowEntry  "Reference $gRefFile($name2)*" }
                   4705: 	       wm title [winfo toplevel $gRefText($name2)] "$gRefFile($name2) (Modified)"
                   4706: 		$gWindowMenu add command -label "Reference $gRefFile($name2) (Modified)" \
                   4707: 		    -command "capaRaise [winfo toplevel $gRefText($name2)]"
                   4708: 	    } else {
                   4709: 		catch {removeWindowEntry  "Reference $gRefFile($name2)*" }
                   4710: 		wm title [winfo toplevel $gRefText($name2)] "$gRefFile($name2)"
                   4711: 		$gWindowMenu add command -label "Reference $gRefFile($name2)" \
                   4712: 		    -command "capaRaise [winfo toplevel $gRefText($name2)]"
                   4713: 	    }
                   4714: 	}
                   4715:     }
                   4716: }
                   4717: ###########################################################
                   4718: # main
                   4719: ###########################################################
                   4720: # sets up the auto_path variable, some globals and adds some
                   4721: # options then calls createControlWindow to give the user something
                   4722: # to do
                   4723: ###########################################################
                   4724: # Arguments: None
                   4725: # Returns: Nothing
                   4726: # Globals:
                   4727: ###########################################################
                   4728: 
                   4729: source quizzer.templates.tcl
                   4730: 
                   4731: if { [lindex $auto_path 0] == "./lib/tcl7.5" } {
                   4732:     set auto_path ""
                   4733:     lappend auto_path [pwd]/lib/tcl7.5
                   4734:     lappend auto_path [pwd]/lib/tk4.1
                   4735: }
                   4736: 
                   4737: lappend auto_path /usr/local/lib/CAPA45/Quizzer
                   4738: lappend auto_path [pwd]
                   4739: 
                   4740: set font 8x13bold
                   4741: catch {
                   4742:     if { $argc > 0 } {
                   4743: 	switch -glob -- [lindex $argv 0] {
                   4744: 	    {-[Ll]*} { set font 9x15bold }
                   4745: 	    {-[Mm]*} -
                   4746: 	    {-[Nn]*} { set font 8x13bold }
                   4747: 	    {-[Ss]*} { set font fixed }
                   4748: 	}
                   4749:     }
                   4750: }
                   4751: option add *font $font
                   4752: createControlWindow

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>