home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
messagehdl.tcl
< prev
next >
Wrap
Text File
|
1997-11-20
|
6KB
|
283 lines
#---------------------------------------------------------------------------
#
# (c) Westmount Technology 1994
#
# File: @(#)messagehdl.tcl /main/titanic/14
# Author: frmo
# Description: Generic Message Handling.
#---------------------------------------------------------------------------
# SccsId = @(#)messagehdl.tcl /main/titanic/14 20 Nov 1997 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
set nl ""
set prevErrorStr ""
if {[lindex [get errorCode] 0] != "ErrorStack"} {
set errorStack $msg
set msg ""
foreach errorStr [split $errorStack "\n"] {
if {"$errorStr" == ""} continue
if [strncmp $errorStr $prevErrorStr] {
append msg "$nl$errorStr"
set nl "\n"
set prevErrorStr $errorStr
}
}
return
}
set errorStack [lindex $errorCode 1]
set msg ""
foreach error $errorStack {
set errorStr "[lindex $error 1] [lindex $error 2]"
if [strncmp $errorStr $prevErrorStr] {
append msg "$nl$errorStr"
set nl "\n"
set prevErrorStr $errorStr
}
}
}
# 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
}
}
# Check if errorInfo exists: could be unset by resetErrorVars
if [info exists errorInfo] {
set text $errorInfo
} else {
set text [.main.error message]
}
.main.errorInfo.c.text text $text
.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]} {
set cwd [pwd]
if $win95 {
# until TCL fixes pwd
# to support native pathnames
regsub -all {/} $cwd {\\} cwd
}
EntryDialog new $box \
-title "Save Error Info" \
-message "File:" \
-modal yes \
-entry "[path_name concat $cwd errorInfo[pid].txt]" \
-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} {
global errorInfo oldErrorInfo
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]
resetErrorVars
return
}
}
formatMessage msg
if {(! [info exists errorInfo]) || "$errorInfo" == "" ||
([info exists oldErrorInfo] &&
[string first $oldErrorInfo $errorInfo] != -1)} {
set errorInfo $msg
}
if [isCommand .main.error] {
set lab1 "First Error:\n"
set lab2 "\n\nSecond Error:\n"
set newErrorInfo "$lab1$errorInfo$lab2$oldErrorInfo"
set oldErrorInfo $errorInfo
set errorInfo $newErrorInfo
.main.error message "$msg\n[.main.error message]"
return
}
set oldErrorInfo $errorInfo
if {(! [isCommand MainWindow]) || (! [isCommand ErrorDialog])} {
puts "$msg"
return
}
if {![isCommand .main]} {
MainWindow new .main -closed exit
}
ErrorDialog new .main.error \
-message $msg \
-title "Error" \
-okPressed {
if [.main guiReady] {
%this delete
resetErrorVars
} else {
%this delete
.main delete
exit
}
} \
-helpPressed errorHelp
.main.error popUp
}
# Display a warning.
#
proc wmtkwarning {msg} {
formatMessage msg
if [isCommand .main.warning] {
set prevMsg [.main.warning message]
if [strncmp $msg $prevMsg] {
.main.warning message "$msg\n$prevMsg"
}
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
}