@@ -12,6 +12,8 @@ field add_global 0; # add to the --global config
12
12
field no_console 0; # disable using the console
13
13
field needs_file 0; # ensure filename is set
14
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
15
17
16
18
constructor dialog {} {
17
19
global repo_config
@@ -69,9 +71,22 @@ constructor dialog {} {
69
71
pack $w .desc -anchor nw -fill x -pady 5 -padx 5
70
72
71
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
75
90
76
91
checkbutton $w .noconsole \
77
92
-text [mc " Don't show the command output window" ] \
@@ -89,6 +104,16 @@ constructor dialog {} {
89
104
tkwait window $w
90
105
}
91
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
+
92
117
method _add {} {
93
118
global repo_config
94
119
@@ -110,8 +135,14 @@ method _add {} {
110
135
if {$add_global } { lappend cmd --global }
111
136
set items {}
112
137
if {$no_console } { lappend items " guitool.$name .noconsole" }
113
- if {$confirm } { lappend items " guitool.$name .confirm" }
114
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
+ }
115
146
116
147
if {[catch {
117
148
eval $cmd [list $item $command ]
@@ -232,3 +263,159 @@ method _visible {} {
232
263
}
233
264
234
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
+ }
0 commit comments