One more check on valid display which is known to be in the startup
[xcircuit.git] / lib / tcl / files.tcl
blob34394e33ce23a9ecb5cbabffe987f36cd414a458
1 #---------------------------------------------------------------------------
2 # files.tcl ---
4 # xcircuit Tcl script for handling multiple-file writes
6 # Tim Edwards 12/5/05 for MultiGiG
7 #---------------------------------------------------------------------------
9 set XCOps(module,files) 1
11 #---------------------------------------------------------------------------
12 # Forced write all
13 #---------------------------------------------------------------------------
15 proc xcircuit::forcewriteall {} {
16 set pages [page links all]
17 for {set i 1} {$i <= $pages} {incr i} {
18 page $i changes 1
19 set techlist [technology used $i]
20 foreach tech $techlist {
21 if {[technology writable $tech]} {technology changed $tech 1}
24 destroy .writeall
25 xcircuit::promptwriteall
28 #---------------------------------------------------------------------------
29 # Write all pages. Determine which pages are enabled/disabled in the
30 # ".writeall" window, and save each one.
31 #---------------------------------------------------------------------------
33 proc xcircuit::writeall {} {
34 global XCOps
36 if {![catch {raise .writeall}]} {
37 set rows [lindex [grid size .writeall.list] 1]
38 incr rows -1
39 for {set i 1} {$i <= $rows} {incr i} {
40 if {$XCOps(cbox${i}) > 0} {
41 set pagelist [pack slaves .writeall.list.pframe${i}]
42 set firstpage [lindex $pagelist 0]
43 set pageno [${firstpage} cget -text]
44 if {$pageno == "-" || $pageno == "X"} {
45 set tname [.writeall.list.f${i} cget -text]
46 set fname [technology filename $tname]
47 if {$fname == "(no associated file)"} {
48 # Fix me: this works only on one technology at a time!
49 xcircuit::promptsavetech
50 } else {
51 technology save $tname
53 } else {
54 page ${pageno} update
55 page ${pageno} save
58 unset XCOps(cbox${i})
60 destroy .writeall
64 #---------------------------------------------------------------------------
65 # Prompt for writing all pages
66 #---------------------------------------------------------------------------
68 proc xcircuit::promptwriteall {} {
69 global XCOps
71 # Get list of unique filenames.
73 set pages [page links all]
74 set filelist {}
75 for {set i 1} {$i <= $pages} {incr i} {
76 set changes [page $i changes]
77 if {$changes > 0} {
78 if {[page $i filename] == {}} {
79 page $i filename [page $i label]
81 lappend filelist [page $i filename]
84 set filelist [lsort -unique -dictionary $filelist]
86 set techlist {}
87 set badtechslist {}
88 foreach tech [technology list] {
89 if {[technology changed $tech] > 0} {
90 if {[technology writable $tech] > 0} {
91 lappend techlist $tech
92 } else {
93 lappend badtechslist $tech
98 set filestowrite [expr [llength $filelist] + [llength $techlist]]
100 # Set up the "writeall" window
102 catch {destroy .writeall}
103 toplevel .writeall -bg beige
104 frame .writeall.tbar -bg beige
105 frame .writeall.list -bg beige
106 frame .writeall.bbar -bg beige
108 pack .writeall.tbar -side top -padx 5 -pady 5 -fill x
109 pack .writeall.list -side top -padx 5 -pady 5 -fill x
110 pack .writeall.bbar -side top -padx 5 -pady 5 -fill x
112 if {$filestowrite == 0} {
113 label .writeall.tbar.title -text \
114 "(No modified pages or technologies to write)" -bg \
115 beige -fg gray40
116 pack .writeall.tbar.title -side left
117 } else {
118 label .writeall.tbar.title -text "Write All Modified Pages and Technologies:" \
119 -bg beige -fg blue
120 pack .writeall.tbar.title -side left
122 label .writeall.list.ftitle -text "Filename" -bg beige -fg brown
123 label .writeall.list.ptitle -text "Pages" -bg beige -fg brown
124 label .writeall.list.wtitle -text "Write?" -bg beige -fg brown
125 grid .writeall.list.ftitle -row 0 -column 0 -sticky news
126 grid .writeall.list.ptitle -row 0 -column 1 -sticky news
127 grid .writeall.list.wtitle -row 0 -column 2 -sticky news
130 set k 0
131 foreach j $filelist {
132 incr k
133 label .writeall.list.f${k} -text "$j" -anchor w -bg beige
134 frame .writeall.list.pframe${k} -bg beige
135 set XCOps(cbox${k}) 1
136 checkbutton .writeall.list.cbox${k} -bg beige -variable XCOps(cbox${k})
138 set l 0
139 for {set i 1} {$i <= $pages} {incr i} {
140 if {[page $i filename] == $j} {
141 set changes [page $i changes]
142 if {$changes > 0} {
143 incr l
144 button .writeall.list.pframe${k}.b${l} -text "$i" -bg \
145 white -command "page goto $i ; \
146 promptsavepage"
147 pack .writeall.list.pframe${k}.b${l} -side left -padx 5
151 grid .writeall.list.f${k} -row $k -column 0 -sticky news
152 grid .writeall.list.pframe${k} -row $k -column 1 -sticky news
153 grid .writeall.list.cbox${k} -row $k -column 2 -sticky news
156 foreach j $techlist {
157 incr k
158 label .writeall.list.f${k} -text "$j" -anchor w -bg beige
159 frame .writeall.list.pframe${k} -bg beige
160 set XCOps(cbox${k}) 1
161 checkbutton .writeall.list.cbox${k} -bg beige -variable XCOps(cbox${k})
163 button .writeall.list.pframe${k}.b1 -text "-" -bg white \
164 -command "set XCOps(technology) $j ; \
165 xcircuit::promptsavetech"
166 pack .writeall.list.pframe${k}.b1 -side left -padx 5
167 grid .writeall.list.f${k} -row $k -column 0 -sticky news
168 grid .writeall.list.pframe${k} -row $k -column 1 -sticky news
169 grid .writeall.list.cbox${k} -row $k -column 2 -sticky news
172 foreach j $badtechslist {
173 incr k
174 label .writeall.list.f${k} -text "$j" -anchor w -bg beige -fg gray60
175 frame .writeall.list.pframe${k} -bg beige
176 set XCOps(cbox${k}) 0
177 checkbutton .writeall.list.cbox${k} -bg beige -variable XCOps(cbox${k})
179 button .writeall.list.pframe${k}.b1 -text "X" -bg white -fg gray60 \
180 -command "set XCOps(technology) $j ; \
181 xcircuit::promptsavetech"
182 pack .writeall.list.pframe${k}.b1 -side left -padx 5
183 grid .writeall.list.f${k} -row $k -column 0 -sticky news
184 grid .writeall.list.pframe${k} -row $k -column 1 -sticky news
185 grid .writeall.list.cbox${k} -row $k -column 2 -sticky news
188 if {$filestowrite > 0} {
189 button .writeall.bbar.okay -text Write -bg beige -command \
190 {xcircuit::writeall}
191 pack .writeall.bbar.okay -side left -ipadx 10 -padx 5
194 if {$filestowrite < $pages} {
195 button .writeall.bbar.force -text Force -bg beige -command \
196 {xcircuit::forcewriteall}
197 pack .writeall.bbar.force -side left -ipadx 10 -padx 5
200 button .writeall.bbar.cancel -text Cancel -bg beige -command \
201 {destroy .writeall}
202 pack .writeall.bbar.cancel -side right -ipadx 10 -padx 5