Documentation/git-add: kill remaining <filepattern>
[git/mjg.git] / git-gui / lib / tools_dlg.tcl
blob7eeda9daf23161a0abbe4abcc857ebfb0e18f9de
1 # git-gui Tools menu dialogs
3 class tools_add {
5 field w ; # widget path
6 field w_name ; # new remote name widget
7 field w_cmd ; # new remote location widget
9 field name {}; # name of the tool
10 field command {}; # command to execute
11 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
18 constructor dialog {} {
19 global repo_config use_ttk NS
21 make_dialog top w
22 wm title $top [append "[appname] ([reponame]): " [mc "Add Tool"]]
23 if {$top ne {.}} {
24 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
25 wm transient $top .
28 ${NS}::label $w.header -text [mc "Add New Tool Command"] \
29 -font font_uibold -anchor center
30 pack $w.header -side top -fill x
32 ${NS}::frame $w.buttons
33 ${NS}::checkbutton $w.buttons.global \
34 -text [mc "Add globally"] \
35 -variable @add_global
36 pack $w.buttons.global -side left -padx 5
37 ${NS}::button $w.buttons.create -text [mc Add] \
38 -default active \
39 -command [cb _add]
40 pack $w.buttons.create -side right
41 ${NS}::button $w.buttons.cancel -text [mc Cancel] \
42 -command [list destroy $w]
43 pack $w.buttons.cancel -side right -padx 5
44 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
46 ${NS}::labelframe $w.desc -text [mc "Tool Details"]
48 ${NS}::label $w.desc.name_cmnt -anchor w\
49 -text [mc "Use '/' separators to create a submenu tree:"]
50 grid x $w.desc.name_cmnt -sticky we -padx {0 5} -pady {0 2}
51 ${NS}::label $w.desc.name_l -text [mc "Name:"]
52 set w_name $w.desc.name_t
53 ${NS}::entry $w_name \
54 -width 40 \
55 -textvariable @name \
56 -validate key \
57 -validatecommand [cb _validate_name %d %S]
58 grid $w.desc.name_l $w_name -sticky we -padx {0 5}
60 ${NS}::label $w.desc.cmd_l -text [mc "Command:"]
61 set w_cmd $w.desc.cmd_t
62 ${NS}::entry $w_cmd \
63 -width 40 \
64 -textvariable @command
65 grid $w.desc.cmd_l $w_cmd -sticky we -padx {0 5} -pady {0 3}
67 grid columnconfigure $w.desc 1 -weight 1
68 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
70 ${NS}::checkbutton $w.confirm \
71 -text [mc "Show a dialog before running"] \
72 -variable @confirm -command [cb _check_enable_dlg]
74 ${NS}::labelframe $w.dlg -labelwidget $w.confirm
76 ${NS}::checkbutton $w.dlg.askbranch \
77 -text [mc "Ask the user to select a revision (sets \$REVISION)"] \
78 -variable @ask_branch -state disabled
79 pack $w.dlg.askbranch -anchor w -padx 15
81 ${NS}::checkbutton $w.dlg.askargs \
82 -text [mc "Ask the user for additional arguments (sets \$ARGS)"] \
83 -variable @ask_args -state disabled
84 pack $w.dlg.askargs -anchor w -padx 15
86 pack $w.dlg -anchor nw -fill x -pady {0 8} -padx 5
88 ${NS}::checkbutton $w.noconsole \
89 -text [mc "Don't show the command output window"] \
90 -variable @no_console
91 pack $w.noconsole -anchor w -padx 5
93 ${NS}::checkbutton $w.needsfile \
94 -text [mc "Run only if a diff is selected (\$FILENAME not empty)"] \
95 -variable @needs_file
96 pack $w.needsfile -anchor w -padx 5
98 bind $w <Visibility> [cb _visible]
99 bind $w <Key-Escape> [list destroy $w]
100 bind $w <Key-Return> [cb _add]\;break
101 tkwait window $w
104 method _check_enable_dlg {} {
105 if {$confirm} {
106 $w.dlg.askbranch configure -state normal
107 $w.dlg.askargs configure -state normal
108 } else {
109 $w.dlg.askbranch configure -state disabled
110 $w.dlg.askargs configure -state disabled
114 method _add {} {
115 global repo_config
117 if {$name eq {}} {
118 error_popup [mc "Please supply a name for the tool."]
119 focus $w_name
120 return
123 set item "guitool.$name.cmd"
125 if {[info exists repo_config($item)]} {
126 error_popup [mc "Tool '%s' already exists." $name]
127 focus $w_name
128 return
131 set cmd [list git config]
132 if {$add_global} { lappend cmd --global }
133 set items {}
134 if {$no_console} { lappend items "guitool.$name.noconsole" }
135 if {$needs_file} { lappend items "guitool.$name.needsfile" }
136 if {$confirm} {
137 if {$ask_args} { lappend items "guitool.$name.argprompt" }
138 if {$ask_branch} { lappend items "guitool.$name.revprompt" }
139 if {!$ask_args && !$ask_branch} {
140 lappend items "guitool.$name.confirm"
144 if {[catch {
145 eval $cmd [list $item $command]
146 foreach citem $items { eval $cmd [list $citem yes] }
147 } err]} {
148 error_popup [mc "Could not add tool:\n%s" $err]
149 } else {
150 set repo_config($item) $command
151 foreach citem $items { set repo_config($citem) yes }
153 tools_populate_all
156 destroy $w
159 method _validate_name {d S} {
160 if {$d == 1} {
161 if {[regexp {[~?*&\[\0\"\\\{]} $S]} {
162 return 0
165 return 1
168 method _visible {} {
169 grab $w
170 $w_name icursor end
171 focus $w_name
176 class tools_remove {
178 field w ; # widget path
179 field w_names ; # name list
181 constructor dialog {} {
182 global repo_config global_config system_config use_ttk NS
184 load_config 1
186 make_dialog top w
187 wm title $top [append "[appname] ([reponame]): " [mc "Remove Tool"]]
188 if {$top ne {.}} {
189 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
190 wm transient $top .
193 ${NS}::label $w.header -text [mc "Remove Tool Commands"] \
194 -font font_uibold -anchor center
195 pack $w.header -side top -fill x
197 ${NS}::frame $w.buttons
198 ${NS}::button $w.buttons.create -text [mc Remove] \
199 -default active \
200 -command [cb _remove]
201 pack $w.buttons.create -side right
202 ${NS}::button $w.buttons.cancel -text [mc Cancel] \
203 -command [list destroy $w]
204 pack $w.buttons.cancel -side right -padx 5
205 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
207 ${NS}::frame $w.list
208 set w_names $w.list.l
209 slistbox $w_names \
210 -height 10 \
211 -width 30 \
212 -selectmode extended \
213 -exportselection false
214 pack $w.list.l -side left -fill both -expand 1
215 pack $w.list -fill both -expand 1 -pady 5 -padx 5
217 set local_cnt 0
218 foreach fullname [tools_list] {
219 # Cannot delete system tools
220 if {[info exists system_config(guitool.$fullname.cmd)]} continue
222 $w_names insert end $fullname
223 if {![info exists global_config(guitool.$fullname.cmd)]} {
224 $w_names itemconfigure end -foreground blue
225 incr local_cnt
229 if {$local_cnt > 0} {
230 ${NS}::label $w.colorlbl -foreground blue \
231 -text [mc "(Blue denotes repository-local tools)"]
232 pack $w.colorlbl -fill x -pady 5 -padx 5
235 bind $w <Visibility> [cb _visible]
236 bind $w <Key-Escape> [list destroy $w]
237 bind $w <Key-Return> [cb _remove]\;break
238 tkwait window $w
241 method _remove {} {
242 foreach i [$w_names curselection] {
243 set name [$w_names get $i]
245 catch { git config --remove-section guitool.$name }
246 catch { git config --global --remove-section guitool.$name }
249 load_config 0
250 tools_populate_all
252 destroy $w
255 method _visible {} {
256 grab $w
257 focus $w_names
262 class tools_askdlg {
264 field w ; # widget path
265 field w_rev {}; # revision browser
266 field w_args {}; # arguments
268 field is_ask_args 0; # has arguments field
269 field is_ask_revs 0; # has revision browser
271 field is_ok 0; # ok to start
272 field argstr {}; # arguments
274 constructor dialog {fullname} {
275 global M1B use_ttk NS
277 set title [get_config "guitool.$fullname.title"]
278 if {$title eq {}} {
279 regsub {/} $fullname { / } title
282 make_dialog top w -autodelete 0
283 wm title $top [append "[appname] ([reponame]): " $title]
284 if {$top ne {.}} {
285 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
286 wm transient $top .
289 set prompt [get_config "guitool.$fullname.prompt"]
290 if {$prompt eq {}} {
291 set command [get_config "guitool.$fullname.cmd"]
292 set prompt [mc "Run Command: %s" $command]
295 ${NS}::label $w.header -text $prompt -font font_uibold -anchor center
296 pack $w.header -side top -fill x
298 set argprompt [get_config "guitool.$fullname.argprompt"]
299 set revprompt [get_config "guitool.$fullname.revprompt"]
301 set is_ask_args [expr {$argprompt ne {}}]
302 set is_ask_revs [expr {$revprompt ne {}}]
304 if {$is_ask_args} {
305 if {$argprompt eq {yes} || $argprompt eq {true} || $argprompt eq {1}} {
306 set argprompt [mc "Arguments"]
309 ${NS}::labelframe $w.arg -text $argprompt
311 set w_args $w.arg.txt
312 ${NS}::entry $w_args \
313 -width 40 \
314 -textvariable @argstr
315 pack $w_args -padx 5 -pady 5 -fill both
316 pack $w.arg -anchor nw -fill both -pady 5 -padx 5
319 if {$is_ask_revs} {
320 if {$revprompt eq {yes} || $revprompt eq {true} || $revprompt eq {1}} {
321 set revprompt [mc "Revision"]
324 if {[is_config_true "guitool.$fullname.revunmerged"]} {
325 set w_rev [::choose_rev::new_unmerged $w.rev $revprompt]
326 } else {
327 set w_rev [::choose_rev::new $w.rev $revprompt]
330 pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
333 ${NS}::frame $w.buttons
334 if {$is_ask_revs} {
335 ${NS}::button $w.buttons.visualize \
336 -text [mc Visualize] \
337 -command [cb _visualize]
338 pack $w.buttons.visualize -side left
340 ${NS}::button $w.buttons.ok \
341 -text [mc OK] \
342 -command [cb _start]
343 pack $w.buttons.ok -side right
344 ${NS}::button $w.buttons.cancel \
345 -text [mc "Cancel"] \
346 -command [cb _cancel]
347 pack $w.buttons.cancel -side right -padx 5
348 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
350 bind $w <$M1B-Key-Return> [cb _start]
351 bind $w <Key-Return> [cb _start]
352 bind $w <Key-Escape> [cb _cancel]
353 wm protocol $w WM_DELETE_WINDOW [cb _cancel]
355 bind $w <Visibility> [cb _visible]
356 return $this
359 method execute {} {
360 tkwait window $w
361 set rv $is_ok
362 delete_this
363 return $rv
366 method _visible {} {
367 grab $w
368 if {$is_ask_args} {
369 focus $w_args
370 } elseif {$is_ask_revs} {
371 $w_rev focus_filter
375 method _cancel {} {
376 wm protocol $w WM_DELETE_WINDOW {}
377 destroy $w
380 method _rev {} {
381 if {[catch {$w_rev commit_or_die}]} {
382 return {}
384 return [$w_rev get]
387 method _visualize {} {
388 global current_branch
389 set rev [_rev $this]
390 if {$rev ne {}} {
391 do_gitk [list --left-right "$current_branch...$rev"]
395 method _start {} {
396 global env
398 if {$is_ask_revs} {
399 set name [_rev $this]
400 if {$name eq {}} {
401 return
403 set env(REVISION) $name
406 if {$is_ask_args} {
407 set env(ARGS) $argstr
410 set is_ok 1
411 _cancel $this