1#   Copyright (C) 1987-2015 by Jeffery P. Hansen
2#
3#   This program is free software; you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation; either version 2 of the License, or
6#   (at your option) any later version.
7#
8#   This program is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#   GNU General Public License for more details.
12#
13#   You should have received a copy of the GNU General Public License along
14#   with this program; if not, write to the Free Software Foundation, Inc.,
15#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17# Last edit by hansen on Tue Feb  3 10:31:35 2009
18#
19
20########################################################################
21#
22# This file contains procedures for displaying and maniuplating
23# the error list.  The error list is a box listing any errors that
24# occured when starting the simulator.  The user can click on an
25# error messsage and cause the editor to jump to the location
26# of the error.
27#
28#
29# ErrBox methods:
30#   post			Pop up the error message box
31#   unpost			Delete the error box
32#   addError "error message"	Add a message to the box
33#   report			Call back to report selection
34#
35# C callbacks used:
36#   gat_errBoxReport		Display error position
37#
38
39namespace eval ErrBox {
40  variable errbox_x 50
41  variable errbox_y 50
42  variable is_active 0
43
44  #tkg_errBoxReport
45  proc report {} {
46    action ShowErr {
47      gat_errBoxReport [.errbox.lframe.list curselection]
48    }
49  }
50
51  #tkg_delErrBox
52  proc unpost {} {
53    variable is_active
54    variable errbox_x
55    variable errbox_y
56
57    set is_active 0
58    transAction - {
59      gat_errBoxReport -1
60    }
61    catch {
62      set errbox_x [expr [winfo rootx .errbox] - [winfo rootx .]]
63      set errbox_y [expr [winfo rooty .errbox] - [winfo rooty .]]
64      destroy .errbox
65    }
66  }
67
68  #tkg_errBoxUp
69  proc selectUp {} {
70    if { [catch {set N [.errbox.lframe.list curselection]} ] } {
71      return
72    }
73
74
75    if { $N == "" } {
76      set N 0
77    } else {
78      set N [expr $N - 1]
79    }
80    .errbox.lframe.list selection clear 0 end
81    .errbox.lframe.list selection set $N
82    .errbox.lframe.list see $N
83    report
84  }
85
86  #tkg_errBoxDown
87  proc selectDown {} {
88    if { [catch {set N [.errbox.lframe.list curselection]} ] } {
89      return
90    }
91
92    if { $N == "" } {
93      set N 0
94    } else {
95      set N [expr $N + 1]
96    }
97    .errbox.lframe.list selection clear 0 end
98    .errbox.lframe.list selection set $N
99    .errbox.lframe.list see $N
100    report
101  }
102
103  #tkg_errBoxAdd
104  proc addError args {
105    .errbox.lframe.list insert end [join $args ]
106  }
107
108  proc hadFatalErrors {} {
109    catch { .errbox.image.exp configure -text [m db.err.explain.err] }
110  }
111
112  proc post {} {
113    variable is_active
114    variable errbox_x
115    variable errbox_y
116
117    toplevel .errbox
118    wm title .errbox [m db.err.title]
119    wm geometry .errbox [offsetgeometry . $errbox_x $errbox_y]
120    wm transient .errbox .
121
122    dialogImage .errbox.image -image [gifI bug.gif] -caption [m db.err.caption] -explaination [m db.err.explain.warn]
123    pack .errbox.image -fill both -side left -pady 10
124
125    frame .errbox.lframe
126
127    listbox .errbox.lframe.list -width 60 -height 15 -yscrollcommand ".errbox.lframe.vert set" -xscrollcommand ".errbox.lframe.horz set" -bg white
128    scrollbar .errbox.lframe.vert -command ".errbox.lframe.list yview"
129    scrollbar .errbox.lframe.horz -orient horizontal -command ".errbox.lframe.list xview"
130
131    grid rowconfigure .errbox.lframe 0 -weight 1
132    grid columnconfigure .errbox.lframe 0 -weight 1
133    grid .errbox.lframe.list -row 0 -column 0 -sticky nsew
134    grid .errbox.lframe.vert -row 0 -column 1 -sticky ns
135    grid .errbox.lframe.horz -row 1 -column 0 -sticky ew
136
137    pack .errbox.lframe -side top  -padx 5 -pady 5 -fill both -expand 1
138
139    bind .errbox.lframe.list <ButtonRelease-1> { catch { ErrBox::report } }
140
141    frame .errbox.dframe
142    button .errbox.dframe.dismiss -text [m b.dismiss] -command ErrBox::unpost
143    pack .errbox.dframe.dismiss -padx 5 -pady 5 -anchor e
144    pack .errbox.dframe -side bottom  -padx 5 -pady 5 -fill both
145
146
147    bind .errbox <Up>		{ Action::errBoxUp }
148    bind .errbox <Down>		{ Action::errBoxDown }
149    bind .errbox <p>		{ Action::errBoxUp }
150    bind .errbox <n>		{ Action::errBoxDown }
151    bind .errbox <Control-p>	{ Action::errBoxUp }
152    bind .errbox <Control-n>	{ Action::errBoxDown }
153
154    set is_active 1
155  }
156}
157
158
159
160
161