@matheusbsbs / matheus-bagliano / commits / 39fa2a983d
Fork 0

git-gui: Save geometry before the window layout is damaged

Because Tk does not assure us the order that it will process children in before it destroys the main toplevel we cannot safely save our geometry data during a "bind . <Destroy>" event binding. The geometry may have already changed as a result of a one or more children being removed from the layout. This was pointed out in gitk by Mark Levedahl, and patched over there by commit b6047c5a8166a71e01c6b63ebbb67c6894d95114. So we now also use "wm protocol . WM_DELETE_WINDOW" to detect when the window is closed by the user, and forward that close event to our main do_quit routine. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jun 11, 2007 at 23:52 UTC 39fa2a983d55b37759b99e67f9f1892879efb775
6 files changed +26 -9
git-gui.sh
+1 -1
@@ -1622,7 +1622,7 @@ unset browser doc_path doc_url
1622
1623 # -- Standard bindings
1624 #
1625 -bind . <Destroy> {if {{%W} eq {.}} do_quit}
1625 +wm protocol . WM_DELETE_WINDOW do_quit
1626 bind all <$M1B-Key-q> do_quit
1627 bind all <$M1B-Key-Q> do_quit
1628 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
lib/blame.tcl
-1
@@ -289,7 +289,6 @@ constructor new {i_commit i_path} {
289
290 bind $w_cviewer <Button-1> [list focus $w_cviewer]
291 bind $top <Visibility> [list focus $top]
292 - bind $w_file <Destroy> [list delete_this $this]
292
293 grid configure $w.header -sticky ew
294 grid configure $w.file_pane -sticky nsew
lib/browser.tcl
-1
@@ -70,7 +70,6 @@ constructor new {commit} {
70 bind $w_list <Right> break
71
72 bind $w_list <Visibility> [list focus $w_list]
73 - bind $w_list <Destroy> [list delete_this $this]
73 set w $w_list
74 _ls $this $browser_commit
75 return $this
lib/class.tcl
+21 -3
@@ -120,10 +120,21 @@ proc delete_this {{t {}}} {
120 if {[namespace exists $t]} {namespace delete $t}
121 }
122
123 -proc make_toplevel {t w} {
124 - upvar $t top $w pfx
123 +proc make_toplevel {t w args} {
124 + upvar $t top $w pfx this this
125 +
126 + if {[llength $args] % 2} {
127 + error "make_toplevel topvar winvar {options}"
128 + }
129 + set autodelete 1
130 + foreach {name value} $args {
131 + switch -exact -- $name {
132 + -autodelete {set autodelete $value}
133 + default {error "unsupported option $name"}
134 + }
135 + }
136 +
137 if {[winfo ismapped .]} {
126 - upvar this this
138 regsub -all {::} $this {__} w
139 set top .$w
140 set pfx $top
@@ -132,6 +143,13 @@ proc make_toplevel {t w} {
143 set top .
144 set pfx {}
145 }
146 +
147 + if {$autodelete} {
148 + wm protocol $top WM_DELETE_WINDOW "
149 + [list delete_this $this]
150 + [list destroy $top]
151 + "
152 + }
153 }
154
155
lib/console.tcl
+1 -1
@@ -17,7 +17,7 @@ constructor new {short_title long_title} {
17
18 method _init {} {
19 global M1B
20 - make_toplevel top w
20 + make_toplevel top w -autodelete 0
21 wm title $top "[appname] ([reponame]): $t_short"
22 set console_cr 1.0
23
lib/merge.tcl
+3 -2
@@ -125,7 +125,8 @@ Please select fewer branches. To merge more than 15 branches, merge the branche
125 set cons [console::new "Merge" $msg]
126 console::exec $cons $cmd \
127 [namespace code [list _finish $revcnt $cons]]
128 - bind $w <Destroy> {}
128 +
129 + wm protocol $w WM_DELETE_WINDOW {}
130 destroy $w
131 }
132
@@ -250,7 +251,7 @@ proc dialog {} {
251 bind $w <$M1B-Key-Return> $_start
252 bind $w <Visibility> "grab $w; focus $w.source.l"
253 bind $w <Key-Escape> "unlock_index;destroy $w"
253 - bind $w <Destroy> unlock_index
254 + wm protocol $w WM_DELETE_WINDOW "unlock_index;destroy $w"
255 wm title $w "[appname] ([reponame]): Merge"
256 tkwait window $w
257 }