Skip to content

Commit 39fa2a9

Browse files
committed
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 b6047c5. 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 <[email protected]>
1 parent b2f3bb1 commit 39fa2a9

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

git-gui.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ unset browser doc_path doc_url
16221622

16231623
# -- Standard bindings
16241624
#
1625-
bind . <Destroy> {if {{%W} eq {.}} do_quit}
1625+
wm protocol . WM_DELETE_WINDOW do_quit
16261626
bind all <$M1B-Key-q> do_quit
16271627
bind all <$M1B-Key-Q> do_quit
16281628
bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}

lib/blame.tcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ constructor new {i_commit i_path} {
289289

290290
bind $w_cviewer <Button-1> [list focus $w_cviewer]
291291
bind $top <Visibility> [list focus $top]
292-
bind $w_file <Destroy> [list delete_this $this]
293292

294293
grid configure $w.header -sticky ew
295294
grid configure $w.file_pane -sticky nsew

lib/browser.tcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ constructor new {commit} {
7070
bind $w_list <Right> break
7171

7272
bind $w_list <Visibility> [list focus $w_list]
73-
bind $w_list <Destroy> [list delete_this $this]
7473
set w $w_list
7574
_ls $this $browser_commit
7675
return $this

lib/class.tcl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,21 @@ proc delete_this {{t {}}} {
120120
if {[namespace exists $t]} {namespace delete $t}
121121
}
122122

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+
125137
if {[winfo ismapped .]} {
126-
upvar this this
127138
regsub -all {::} $this {__} w
128139
set top .$w
129140
set pfx $top
@@ -132,6 +143,13 @@ proc make_toplevel {t w} {
132143
set top .
133144
set pfx {}
134145
}
146+
147+
if {$autodelete} {
148+
wm protocol $top WM_DELETE_WINDOW "
149+
[list delete_this $this]
150+
[list destroy $top]
151+
"
152+
}
135153
}
136154

137155

lib/console.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ constructor new {short_title long_title} {
1717

1818
method _init {} {
1919
global M1B
20-
make_toplevel top w
20+
make_toplevel top w -autodelete 0
2121
wm title $top "[appname] ([reponame]): $t_short"
2222
set console_cr 1.0
2323

lib/merge.tcl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ Please select fewer branches. To merge more than 15 branches, merge the branche
125125
set cons [console::new "Merge" $msg]
126126
console::exec $cons $cmd \
127127
[namespace code [list _finish $revcnt $cons]]
128-
bind $w <Destroy> {}
128+
129+
wm protocol $w WM_DELETE_WINDOW {}
129130
destroy $w
130131
}
131132

@@ -250,7 +251,7 @@ proc dialog {} {
250251
bind $w <$M1B-Key-Return> $_start
251252
bind $w <Visibility> "grab $w; focus $w.source.l"
252253
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"
254255
wm title $w "[appname] ([reponame]): Merge"
255256
tkwait window $w
256257
}

0 commit comments

Comments
 (0)