git-gui: Implement automatic rescan after Tool execution.
The Tools menu is generally intended for commands that affect the working directory or repository state. Thus, the user would usually want to initiate rescan after execution of a tool. This commit implements it. In case somebody would want to avoid rescanning after certain tools, it also adds an option that controls it, although it is not made available through the Add dialog. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Alexander Gavrilov committed
Nov 16, 2008 at 21:46 UTC
b8dfb16d3668c57b1286d854e762368c25a2eaaf
1 file changed
+42
-2
lib/tools.tcl
+42
-2
@@ -102,13 +102,15 @@ proc tools_exec {fullname} {
102
103
set cmdline $repo_config(guitool.$fullname.cmd)
104
if {[is_config_true "guitool.$fullname.noconsole"]} {
105
- exec sh -c $cmdline &
105
+ tools_run_silent [list sh -c $cmdline] \
106
+ [list tools_complete $fullname {}]
107
} else {
108
regsub {/} $fullname { / } title
109
set w [console::new \
110
[mc "Tool: %s" $title] \
111
[mc "Running: %s" $cmdline]]
111
- console::exec $w [list sh -c $cmdline]
112
+ console::exec $w [list sh -c $cmdline] \
113
+ [list tools_complete $fullname $w]
114
}
115
116
unset env(GIT_GUITOOL)
@@ -117,3 +119,41 @@ proc tools_exec {fullname} {
119
catch { unset env(ARGS) }
120
catch { unset env(REVISION) }
121
}
122
+
123
+proc tools_run_silent {cmd after} {
124
+ lappend cmd 2>@1
125
+ set fd [_open_stdout_stderr $cmd]
126
+
127
+ fconfigure $fd -blocking 0 -translation binary
128
+ fileevent $fd readable [list tools_consume_input $fd $after]
129
+}
130
+
131
+proc tools_consume_input {fd after} {
132
+ read $fd
133
+ if {[eof $fd]} {
134
+ fconfigure $fd -blocking 1
135
+ if {[catch {close $fd}]} {
136
+ uplevel #0 $after 0
137
+ } else {
138
+ uplevel #0 $after 1
139
+ }
140
+ }
141
+}
142
+
143
+proc tools_complete {fullname w {ok 1}} {
144
+ if {$w ne {}} {
145
+ console::done $w $ok
146
+ }
147
+
148
+ if {$ok} {
149
+ set msg [mc "Tool completed succesfully: %s" $fullname]
150
+ } else {
151
+ set msg [mc "Tool failed: %s" $fullname]
152
+ }
153
+
154
+ if {[is_config_true "guitool.$fullname.norescan"]} {
155
+ ui_status $msg
156
+ } else {
157
+ rescan [list ui_status $msg]
158
+ }
159
+}