@matheusbsbs / matheus-bagliano / commits / 67df911cee
Fork 0

git-gui: Allow Tools request arguments from the user.

While static commands are already useful, some tools need additional parameters to reach maximum usability. This commit adds support for passing them one revision name parameter, and one arbitrary string. With this addition, the tools menu becomes flexible enough to implement basic rebase support: [core] editor = kwrite [guitool "Rebase/Abort"] cmd = git rebase --abort confirm = yes [guitool "Rebase/Continue"] cmd = git rebase --continue [guitool "Rebase/Skip Commit"] cmd = git rebase --skip confirm = yes [guitool "Rebase/Start..."] cmd = git rebase $ARGS $REVISION $CUR_BRANCH title = Start Rebase prompt = Rebase Current Branch argprompt = Flags revprompt = New Base revunmerged = yes Some of the options, like title or prompt, are intentionally not included in the Add dialog to avoid clutter. Also, the dialog handles argprompt and revprompt as boolean vars. 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 67df911ceebb57596b0d3aea405e1d12137bc6f4
2 files changed +203 -5
lib/tools.tcl
+12 -1
@@ -77,7 +77,16 @@ proc tools_exec {fullname} {
77 }
78 }
79
80 - if {[is_config_true "guitool.$fullname.confirm"]} {
80 + catch { unset env(ARGS) }
81 + catch { unset env(REVISION) }
82 +
83 + if {[get_config "guitool.$fullname.revprompt"] ne {} ||
84 + [get_config "guitool.$fullname.argprompt"] ne {}} {
85 + set dlg [tools_askdlg::dialog $fullname]
86 + if {![tools_askdlg::execute $dlg]} {
87 + return
88 + }
89 + } elseif {[is_config_true "guitool.$fullname.confirm"]} {
90 if {[ask_popup [mc "Are you sure you want to run %s?" $fullname]] ne {yes}} {
91 return
92 }
@@ -105,4 +114,6 @@ proc tools_exec {fullname} {
114 unset env(GIT_GUITOOL)
115 unset env(FILENAME)
116 unset env(CUR_BRANCH)
117 + catch { unset env(ARGS) }
118 + catch { unset env(REVISION) }
119 }
lib/tools_dlg.tcl
+191 -4
@@ -12,6 +12,8 @@ field add_global 0; # add to the --global config
12 field no_console 0; # disable using the console
13 field needs_file 0; # ensure filename is set
14 field confirm 0; # ask for confirmation
15 +field ask_branch 0; # ask for a revision
16 +field ask_args 0; # ask for additional args
17
18 constructor dialog {} {
19 global repo_config
@@ -69,9 +71,22 @@ constructor dialog {} {
71 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
72
73 checkbutton $w.confirm \
72 - -text [mc "Ask for confirmation before running"] \
73 - -variable @confirm
74 - pack $w.confirm -anchor w -pady {5 0} -padx 5
74 + -text [mc "Show a dialog before running"] \
75 + -variable @confirm -command [cb _check_enable_dlg]
76 +
77 + labelframe $w.dlg -labelwidget $w.confirm
78 +
79 + checkbutton $w.dlg.askbranch \
80 + -text [mc "Ask the user to select a revision (sets \$REVISION)"] \
81 + -variable @ask_branch -state disabled
82 + pack $w.dlg.askbranch -anchor w -padx 15
83 +
84 + checkbutton $w.dlg.askargs \
85 + -text [mc "Ask the user for additional arguments (sets \$ARGS)"] \
86 + -variable @ask_args -state disabled
87 + pack $w.dlg.askargs -anchor w -padx 15
88 +
89 + pack $w.dlg -anchor nw -fill x -pady {0 8} -padx 5
90
91 checkbutton $w.noconsole \
92 -text [mc "Don't show the command output window"] \
@@ -89,6 +104,16 @@ constructor dialog {} {
104 tkwait window $w
105 }
106
107 +method _check_enable_dlg {} {
108 + if {$confirm} {
109 + $w.dlg.askbranch configure -state normal
110 + $w.dlg.askargs configure -state normal
111 + } else {
112 + $w.dlg.askbranch configure -state disabled
113 + $w.dlg.askargs configure -state disabled
114 + }
115 +}
116 +
117 method _add {} {
118 global repo_config
119
@@ -110,8 +135,14 @@ method _add {} {
135 if {$add_global} { lappend cmd --global }
136 set items {}
137 if {$no_console} { lappend items "guitool.$name.noconsole" }
113 - if {$confirm} { lappend items "guitool.$name.confirm" }
138 if {$needs_file} { lappend items "guitool.$name.needsfile" }
139 + if {$confirm} {
140 + if {$ask_args} { lappend items "guitool.$name.argprompt" }
141 + if {$ask_branch} { lappend items "guitool.$name.revprompt" }
142 + if {!$ask_args && !$ask_branch} {
143 + lappend items "guitool.$name.confirm"
144 + }
145 + }
146
147 if {[catch {
148 eval $cmd [list $item $command]
@@ -232,3 +263,159 @@ method _visible {} {
263 }
264
265 }
266 +
267 +class tools_askdlg {
268 +
269 +field w ; # widget path
270 +field w_rev {}; # revision browser
271 +field w_args {}; # arguments
272 +
273 +field is_ask_args 0; # has arguments field
274 +field is_ask_revs 0; # has revision browser
275 +
276 +field is_ok 0; # ok to start
277 +field argstr {}; # arguments
278 +
279 +constructor dialog {fullname} {
280 + global M1B
281 +
282 + set title [get_config "guitool.$fullname.title"]
283 + if {$title eq {}} {
284 + regsub {/} $fullname { / } title
285 + }
286 +
287 + make_toplevel top w -autodelete 0
288 + wm title $top [append "[appname] ([reponame]): " $title]
289 + if {$top ne {.}} {
290 + wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
291 + wm transient $top .
292 + }
293 +
294 + set prompt [get_config "guitool.$fullname.prompt"]
295 + if {$prompt eq {}} {
296 + set command [get_config "guitool.$fullname.cmd"]
297 + set prompt [mc "Run Command: %s" $command]
298 + }
299 +
300 + label $w.header -text $prompt -font font_uibold
301 + pack $w.header -side top -fill x
302 +
303 + set argprompt [get_config "guitool.$fullname.argprompt"]
304 + set revprompt [get_config "guitool.$fullname.revprompt"]
305 +
306 + set is_ask_args [expr {$argprompt ne {}}]
307 + set is_ask_revs [expr {$revprompt ne {}}]
308 +
309 + if {$is_ask_args} {
310 + if {$argprompt eq {yes} || $argprompt eq {true} || $argprompt eq {1}} {
311 + set argprompt [mc "Arguments"]
312 + }
313 +
314 + labelframe $w.arg -text $argprompt
315 +
316 + set w_args $w.arg.txt
317 + entry $w_args \
318 + -borderwidth 1 \
319 + -relief sunken \
320 + -width 40 \
321 + -textvariable @argstr
322 + pack $w_args -padx 5 -pady 5 -fill both
323 + pack $w.arg -anchor nw -fill both -pady 5 -padx 5
324 + }
325 +
326 + if {$is_ask_revs} {
327 + if {$revprompt eq {yes} || $revprompt eq {true} || $revprompt eq {1}} {
328 + set revprompt [mc "Revision"]
329 + }
330 +
331 + if {[is_config_true "guitool.$fullname.revunmerged"]} {
332 + set w_rev [::choose_rev::new_unmerged $w.rev $revprompt]
333 + } else {
334 + set w_rev [::choose_rev::new $w.rev $revprompt]
335 + }
336 +
337 + pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
338 + }
339 +
340 + frame $w.buttons
341 + if {$is_ask_revs} {
342 + button $w.buttons.visualize \
343 + -text [mc Visualize] \
344 + -command [cb _visualize]
345 + pack $w.buttons.visualize -side left
346 + }
347 + button $w.buttons.ok \
348 + -text [mc OK] \
349 + -command [cb _start]
350 + pack $w.buttons.ok -side right
351 + button $w.buttons.cancel \
352 + -text [mc "Cancel"] \
353 + -command [cb _cancel]
354 + pack $w.buttons.cancel -side right -padx 5
355 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10
356 +
357 + bind $w <$M1B-Key-Return> [cb _start]
358 + bind $w <Key-Return> [cb _start]
359 + bind $w <Key-Escape> [cb _cancel]
360 + wm protocol $w WM_DELETE_WINDOW [cb _cancel]
361 +
362 + bind $w <Visibility> [cb _visible]
363 + return $this
364 +}
365 +
366 +method execute {} {
367 + tkwait window $w
368 + set rv $is_ok
369 + delete_this
370 + return $rv
371 +}
372 +
373 +method _visible {} {
374 + grab $w
375 + if {$is_ask_args} {
376 + focus $w_args
377 + } elseif {$is_ask_revs} {
378 + $w_rev focus_filter
379 + }
380 +}
381 +
382 +method _cancel {} {
383 + wm protocol $w WM_DELETE_WINDOW {}
384 + destroy $w
385 +}
386 +
387 +method _rev {} {
388 + if {[catch {$w_rev commit_or_die}]} {
389 + return {}
390 + }
391 + return [$w_rev get]
392 +}
393 +
394 +method _visualize {} {
395 + global current_branch
396 + set rev [_rev $this]
397 + if {$rev ne {}} {
398 + do_gitk [list --left-right "$current_branch...$rev"]
399 + }
400 +}
401 +
402 +method _start {} {
403 + global env
404 +
405 + if {$is_ask_revs} {
406 + set name [_rev $this]
407 + if {$name eq {}} {
408 + return
409 + }
410 + set env(REVISION) $name
411 + }
412 +
413 + if {$is_ask_args} {
414 + set env(ARGS) $argstr
415 + }
416 +
417 + set is_ok 1
418 + _cancel $this
419 +}
420 +
421 +}