home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
messagehdl.tcl
< prev
next >
Wrap
Text File
|
1996-11-11
|
6KB
|
244 lines
#---------------------------------------------------------------------------
#
# (c) Westmount Technology 1994
#
# File: @(#)messagehdl.tcl /main/hindenburg/4
# Author: frmo
# Description: Generic Message Handling.
#---------------------------------------------------------------------------
# SccsId = @(#)messagehdl.tcl /main/hindenburg/4 11 Nov 1996 Copyright 1994 Westmount Technology
# Start user added include file section
require procs.tcl
# End user added include file section
# Format a message stack.
#
proc formatMessage {msgVarName} {
global errorCode
upvar $msgVarName msg
if {[lindex [get errorCode] 0] != "ErrorStack"} {
return
}
set errorStack [lindex $errorCode 1]
set msg ""
set nl ""
foreach error $errorStack {
append msg "$nl[lindex $error 1] [lindex $error 2]"
set nl "\n"
}
}
# Reset error variables. This prevents "old" errors from showing up in
# "new" errors when wmtkerror is called directly.
#
proc resetErrorVars {} {
global errorInfo errorCode
if [info exists errorInfo] {
unset errorInfo
}
if [info exists errorCode] {
unset errorCode
}
}
# Display a fatal error. Exits on "ok".
#
proc wmtkfatal {msg} {
formatMessage msg
if [isCommand .main.fatal] {
.main.fatal message "$msg\n[.main.fatal message]"
return
}
if {(! [isCommand MainWindow]) || (! [isCommand ErrorDialog])} {
puts "$msg"
exit
}
if {![isCommand .main]} {
MainWindow new .main -closed exit
}
ErrorDialog new .main.fatal \
-message $msg \
-title "Fatal" \
-okPressed {exit}
.main.fatal delHelpButton
.main.fatal popUp
}
# Give details of the error.
#
proc errorHelp {} {
if [isCommand .main.errorInfo] {
return
}
interface TemplateDialog .main.errorInfo {
modal 1
okPressed {
%this delete
}
title "Error Info"
DlgColumn c {
Label l {
text "Tcl Traceback:"
}
MultiLineText text {
editable 0
rowCount 24
columnCount 80
}
}
PushButton print {
label "Print"
default 0
activated printErrorInfo
}
PushButton save {
label "Save..."
default 0
activated saveErrorInfo
}
}
.main.errorInfo.c.text text $errorInfo
.main.errorInfo delCancelButton
.main.errorInfo delHelpButton
.main.errorInfo popUp
}
proc printErrorInfo {} {
set printer [m4_var get M4_a_printer]
set printfile [args_file [list [.main.errorInfo.c.text text]]]
.main startCommand extern \
"$printer $printfile" [list BasicFS::removeFile $printfile] \
"Sending output to $printer..." \
{0 0} 0
}
proc saveErrorInfo {} {
set box .main.saveErrorInfo
if {! [isCommand $box]} {
EntryDialog new $box \
-title "Save Error Info" \
-message "File:" \
-modal yes \
-entry "[path_name concat [pwd] errorInfo.[pid]]" \
-okPressed {
set logFile [%this entry]
if [catch {set fid [open $logFile w]} msg] {
set box .main.saveErrorInfoError
ErrorDialog new $box \
-message $msg \
-title "Save Error Info Error" \
-okPressed "$box delete"
$box delHelpButton
$box popUp
return
}
puts $fid "[.main.errorInfo.c.text text]"
close $fid
}
$box delHelpButton
}
$box popUp
}
# Display an error message. Exits if the interface was not yet set-up properly.
#
proc wmtkerror {msg} {
if {[lindex [get errorCode] 0] == "ErrorStack"} {
set msgStack [lindex $errorCode 1]
if {[llength $msgStack] == 1 &&
[lindex [lindex $msgStack 0] 0] == "MESSAGE"} {
wmtkmessage [lindex [lindex $msgStack 0] 2]
return
}
}
formatMessage msg
if [isCommand .main.error] {
global errorInfo
set errorInfo "First Error:\n$errorInfo\n\nSecond Error:\n$oldErrorInfo"
.main.error message "$msg\n[.main.error message]"
return
}
if {(! [isCommand MainWindow]) || (! [isCommand ErrorDialog])} {
puts "$msg"
return
}
if {![isCommand .main]} {
MainWindow new .main -closed exit
}
# Exit on "ok" if the interface has not been set up properly.
# We use the existence of the menubar as a test for that.
if {[.main menuBar] == ""} {
set exitCmd exit
} else {
set exitCmd resetErrorVars
}
global errorInfo
if {![info exists errorInfo]} {
set errorInfo $msg
}
global oldErrorInfo
set oldErrorInfo $errorInfo
ErrorDialog new .main.error \
-message $msg \
-title "Error" \
-okPressed "%this delete; $exitCmd" \
-helpPressed errorHelp
.main.error popUp
}
# Display a warning.
#
proc wmtkwarning {msg} {
formatMessage msg
if [isCommand .main.warning] {
.main.warning message "$msg\n[.main.warning message]"
return
}
if {(! [isCommand MainWindow]) || (! [isCommand WarningDialog])} {
puts "$msg"
return
}
if {![isCommand .main]} {
MainWindow new .main -closed exit
}
WarningDialog new .main.warning \
-message $msg \
-title "Warning" \
-okPressed {%this delete; resetErrorVars}
.main.warning delCancelButton
.main.warning delHelpButton
.main.warning popUp
}
# Display a message, if there is a message area. Else the message is ignored.
#
proc wmtkmessage {msg} {
if {![isCommand .main]} {
return
}
set messageArea [.main messageArea]
if {$messageArea != ""} {
$messageArea message $msg
}
}
# Display info in an InfoDialog
#
proc wmtkinfo {msg} {
if {![isCommand .main]} {
return
}
set box .main.wmtkinfo
InfoDialog new $box \
-title "Info" \
-message $msg \
-okPressed {%this delete}
$box delHelpButton
$box popUp
}