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
16 constructor dialog
{} {
20 wm title
$top [append "[appname] ([reponame]): " [mc
"Add Tool"]]
22 wm geometry
$top "+[winfo rootx .]+[winfo rooty .]"
26 label $w.header
-text [mc
"Add New Tool Command"] -font font_uibold
27 pack $w.header
-side top
-fill x
30 checkbutton $w.buttons.
global \
31 -text [mc
"Add globally"] \
33 pack $w.buttons.
global -side left
-padx 5
34 button $w.buttons.create
-text [mc Add
] \
37 pack $w.buttons.create
-side right
38 button $w.buttons.cancel
-text [mc Cancel
] \
39 -command [list destroy $w]
40 pack $w.buttons.cancel
-side right
-padx 5
41 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
43 labelframe $w.desc
-text [mc
"Tool Details"]
45 label $w.desc.name_cmnt
-anchor w
\
46 -text [mc
"Use '/' separators to create a submenu tree:"]
47 grid x
$w.desc.name_cmnt
-sticky we
-padx {0 5} -pady {0 2}
48 label $w.desc.name_l
-text [mc
"Name:"]
49 set w_name
$w.desc.name_t
56 -validatecommand [cb _validate_name
%d
%S
]
57 grid $w.desc.name_l
$w_name -sticky we
-padx {0 5}
59 label $w.desc.cmd_l
-text [mc
"Command:"]
60 set w_cmd
$w.desc.cmd_t
65 -textvariable @command
66 grid $w.desc.cmd_l
$w_cmd -sticky we
-padx {0 5} -pady {0 3}
68 grid columnconfigure
$w.desc
1 -weight 1
69 pack $w.desc
-anchor nw
-fill x
-pady 5 -padx 5
71 checkbutton $w.confirm
\
72 -text [mc
"Ask for confirmation before running"] \
74 pack $w.confirm
-anchor w
-pady {5 0} -padx 5
76 checkbutton $w.noconsole
\
77 -text [mc
"Don't show the command output window"] \
79 pack $w.noconsole
-anchor w
-padx 5
81 checkbutton $w.needsfile
\
82 -text [mc
"Run only if a diff is selected (\$FILENAME not empty)"] \
84 pack $w.needsfile
-anchor w
-padx 5
86 bind $w <Visibility
> [cb _visible
]
87 bind $w <Key-Escape
> [list destroy $w]
88 bind $w <Key-Return
> [cb _add
]\;break
96 error_popup
[mc
"Please supply a name for the tool."]
101 set item
"guitool.$name.cmd"
103 if {[info exists repo_config
($item)]} {
104 error_popup
[mc
"Tool '%s' already exists." $name]
109 set cmd
[list git config
]
110 if {$add_global} { lappend cmd
--global }
112 if {$no_console} { lappend items
"guitool.$name.noconsole" }
113 if {$confirm} { lappend items
"guitool.$name.confirm" }
114 if {$needs_file} { lappend items
"guitool.$name.needsfile" }
117 eval $cmd [list $item $command]
118 foreach citem
$items { eval $cmd [list $citem yes
] }
120 error_popup
[mc
"Could not add tool:\n%s" $err]
122 set repo_config
($item) $command
123 foreach citem
$items { set repo_config
($citem) yes
}
131 method _validate_name
{d S
} {
133 if {[regexp {[~?
*&\[\0\"\\\{]} $S]} {
150 field w
; # widget path
151 field w_names
; # name list
153 constructor dialog
{} {
154 global repo_config global_config system_config
159 wm title
$top [append "[appname] ([reponame]): " [mc
"Remove Tool"]]
161 wm geometry
$top "+[winfo rootx .]+[winfo rooty .]"
165 label $w.header
-text [mc
"Remove Tool Commands"] -font font_uibold
166 pack $w.header
-side top
-fill x
169 button $w.buttons.create
-text [mc Remove
] \
171 -command [cb _remove
]
172 pack $w.buttons.create
-side right
173 button $w.buttons.cancel
-text [mc Cancel
] \
174 -command [list destroy $w]
175 pack $w.buttons.cancel
-side right
-padx 5
176 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
179 set w_names
$w.
list.l
183 -selectmode extended
\
184 -exportselection false
\
185 -yscrollcommand [list $w.
list.sby
set]
186 scrollbar $w.
list.sby
-command [list $w.
list.l yview
]
187 pack $w.
list.sby
-side right
-fill y
188 pack $w.
list.l
-side left
-fill both
-expand 1
189 pack $w.
list -fill both
-expand 1 -pady 5 -padx 5
192 foreach fullname
[tools_list
] {
193 # Cannot delete system tools
194 if {[info exists system_config
(guitool.
$fullname.cmd
)]} continue
196 $w_names insert end
$fullname
197 if {![info exists global_config
(guitool.
$fullname.cmd
)]} {
198 $w_names itemconfigure end
-foreground blue
203 if {$local_cnt > 0} {
204 label $w.colorlbl
-foreground blue
\
205 -text [mc
"(Blue denotes repository-local tools)"]
206 pack $w.colorlbl
-fill x
-pady 5 -padx 5
209 bind $w <Visibility
> [cb _visible
]
210 bind $w <Key-Escape
> [list destroy $w]
211 bind $w <Key-Return
> [cb _remove
]\;break
216 foreach i
[$w_names curselection
] {
217 set name
[$w_names get
$i]
219 catch { git config
--remove-section guitool.
$name }
220 catch { git config
--global --remove-section guitool.
$name }