1 # git-gui Tools menu dialogs
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 {} {
22 wm title $top [append "[appname] ([reponame]): " [mc "Add Tool"]]
24 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
28 label $w.header -text [mc "Add New Tool Command"] -font font_uibold
29 pack $w.header -side top -fill x
32 checkbutton $w.buttons.global \
33 -text [mc "Add globally"] \
35 pack $w.buttons.global -side left -padx 5
36 button $w.buttons.create -text [mc Add] \
39 pack $w.buttons.create -side right
40 button $w.buttons.cancel -text [mc Cancel] \
41 -command [list destroy $w]
42 pack $w.buttons.cancel -side right -padx 5
43 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
45 labelframe $w.desc -text [mc "Tool Details"]
47 label $w.desc.name_cmnt -anchor w\
48 -text [mc "Use '/' separators to create a submenu tree:"]
49 grid x $w.desc.name_cmnt -sticky we -padx {0 5} -pady {0 2}
50 label $w.desc.name_l -text [mc "Name:"]
51 set w_name $w.desc.name_t
58 -validatecommand [cb _validate_name %d %S]
59 grid $w.desc.name_l $w_name -sticky we -padx {0 5}
61 label $w.desc.cmd_l -text [mc "Command:"]
62 set w_cmd $w.desc.cmd_t
67 -textvariable @command
68 grid $w.desc.cmd_l $w_cmd -sticky we -padx {0 5} -pady {0 3}
70 grid columnconfigure $w.desc 1 -weight 1
71 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
73 checkbutton $w.confirm \
74 -text [mc "Show a dialog before running"] \
75 -variable @confirm -command [cb _check_enable_dlg]
77 labelframe $w.dlg -labelwidget $w.confirm
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
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
89 pack $w.dlg -anchor nw -fill x -pady {0 8} -padx 5
91 checkbutton $w.noconsole \
92 -text [mc "Don't show the command output window"] \
94 pack $w.noconsole -anchor w -padx 5
96 checkbutton $w.needsfile \
97 -text [mc "Run only if a diff is selected (\$FILENAME not empty)"] \
99 pack $w.needsfile -anchor w -padx 5
101 bind $w <Visibility> [cb _visible]
102 bind $w <Key-Escape> [list destroy $w]
103 bind $w <Key-Return> [cb _add]\;break
107 method _check_enable_dlg {} {
109 $w.dlg.askbranch configure -state normal
110 $w.dlg.askargs configure -state normal
112 $w.dlg.askbranch configure -state disabled
113 $w.dlg.askargs configure -state disabled
121 error_popup [mc "Please supply a name for the tool."]
126 set item "guitool.$name.cmd"
128 if {[info exists repo_config($item)]} {
129 error_popup [mc "Tool '%s' already exists." $name]
134 set cmd [list git config]
135 if {$add_global} { lappend cmd --global }
137 if {$no_console} { lappend items "guitool.$name.noconsole" }
138 if {$needs_file} { lappend items "guitool.$name.needsfile" }
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"
148 eval $cmd [list $item $command]
149 foreach citem $items { eval $cmd [list $citem yes] }
151 error_popup [mc "Could not add tool:\n%s" $err]
153 set repo_config($item) $command
154 foreach citem $items { set repo_config($citem) yes }
162 method _validate_name {d S} {
164 if {[regexp {[~?*&\[\0\"\\\{]} $S]} {
181 field w ; # widget path
182 field w_names ; # name list
184 constructor dialog {} {
185 global repo_config global_config system_config
190 wm title $top [append "[appname] ([reponame]): " [mc "Remove Tool"]]
192 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
196 label $w.header -text [mc "Remove Tool Commands"] -font font_uibold
197 pack $w.header -side top -fill x
200 button $w.buttons.create -text [mc Remove] \
202 -command [cb _remove]
203 pack $w.buttons.create -side right
204 button $w.buttons.cancel -text [mc Cancel] \
205 -command [list destroy $w]
206 pack $w.buttons.cancel -side right -padx 5
207 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
210 set w_names $w.list.l
214 -selectmode extended \
215 -exportselection false \
216 -yscrollcommand [list $w.list.sby set]
217 scrollbar $w.list.sby -command [list $w.list.l yview]
218 pack $w.list.sby -side right -fill y
219 pack $w.list.l -side left -fill both -expand 1
220 pack $w.list -fill both -expand 1 -pady 5 -padx 5
223 foreach fullname [tools_list] {
224 # Cannot delete system tools
225 if {[info exists system_config(guitool.$fullname.cmd)]} continue
227 $w_names insert end $fullname
228 if {![info exists global_config(guitool.$fullname.cmd)]} {
229 $w_names itemconfigure end -foreground blue
234 if {$local_cnt > 0} {
235 label $w.colorlbl -foreground blue \
236 -text [mc "(Blue denotes repository-local tools)"]
237 pack $w.colorlbl -fill x -pady 5 -padx 5
240 bind $w <Visibility> [cb _visible]
241 bind $w <Key-Escape> [list destroy $w]
242 bind $w <Key-Return> [cb _remove]\;break
247 foreach i [$w_names curselection] {
248 set name [$w_names get $i]
250 catch { git config --remove-section guitool.$name }
251 catch { git config --global --remove-section guitool.$name }
269 field w ; # widget path
270 field w_rev {}; # revision browser
271 field w_args {}; # arguments
273 field is_ask_args 0; # has arguments field
274 field is_ask_revs 0; # has revision browser
276 field is_ok 0; # ok to start
277 field argstr {}; # arguments
279 constructor dialog {fullname} {
282 set title [get_config "guitool.$fullname.title"]
284 regsub {/} $fullname { / } title
287 make_toplevel top w -autodelete 0
288 wm title $top [append "[appname] ([reponame]): " $title]
290 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
294 set prompt [get_config "guitool.$fullname.prompt"]
296 set command [get_config "guitool.$fullname.cmd"]
297 set prompt [mc "Run Command: %s" $command]
300 label $w.header -text $prompt -font font_uibold
301 pack $w.header -side top -fill x
303 set argprompt [get_config "guitool.$fullname.argprompt"]
304 set revprompt [get_config "guitool.$fullname.revprompt"]
306 set is_ask_args [expr {$argprompt ne {}}]
307 set is_ask_revs [expr {$revprompt ne {}}]
310 if {$argprompt eq {yes} || $argprompt eq {true} || $argprompt eq {1}} {
311 set argprompt [mc "Arguments"]
314 labelframe $w.arg -text $argprompt
316 set w_args $w.arg.txt
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
327 if {$revprompt eq {yes} || $revprompt eq {true} || $revprompt eq {1}} {
328 set revprompt [mc "Revision"]
331 if {[is_config_true "guitool.$fullname.revunmerged"]} {
332 set w_rev [::choose_rev::new_unmerged $w.rev $revprompt]
334 set w_rev [::choose_rev::new $w.rev $revprompt]
337 pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
342 button $w.buttons.visualize \
343 -text [mc Visualize] \
344 -command [cb _visualize]
345 pack $w.buttons.visualize -side left
347 button $w.buttons.ok \
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
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]
362 bind $w <Visibility> [cb _visible]
377 } elseif {$is_ask_revs} {
383 wm protocol $w WM_DELETE_WINDOW {}
388 if {[catch {$w_rev commit_or_die}]} {
394 method _visualize {} {
395 global current_branch
398 do_gitk [list --left-right "$current_branch...$rev"]
406 set name [_rev $this]
410 set env(REVISION) $name
414 set env(ARGS) $argstr