Code

git-gui: use themed tk widgets with Tk 8.5
[git.git] / lib / remote_branch_delete.tcl
index bc39581b86fdb9a9dc1d091c0d07b35a00c57ed9..f872a3d89d89bc861ea3729ec7974833bdac277f 100644 (file)
@@ -23,34 +23,40 @@ field full_cache
 field cached
 
 constructor dialog {} {
-       global all_remotes M1B
+       global all_remotes M1B use_ttk NS
 
-       make_toplevel top w
-       wm title $top "[appname] ([reponame]): Delete Remote Branch"
+       make_dialog top w
+       wm title $top [append "[appname] ([reponame]): " [mc "Delete Branch Remotely"]]
        if {$top ne {.}} {
                wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
        }
 
-       label $w.header -text {Delete Remote Branch} -font font_uibold
+       ${NS}::label $w.header -text [mc "Delete Branch Remotely"] \
+               -font font_uibold -anchor center
        pack $w.header -side top -fill x
 
-       frame $w.buttons
-       button $w.buttons.delete -text Delete \
+       ${NS}::frame $w.buttons
+       ${NS}::button $w.buttons.delete -text [mc Delete] \
                -default active \
                -command [cb _delete]
        pack $w.buttons.delete -side right
-       button $w.buttons.cancel -text {Cancel} \
+       ${NS}::button $w.buttons.cancel -text [mc "Cancel"] \
                -command [list destroy $w]
        pack $w.buttons.cancel -side right -padx 5
        pack $w.buttons -side bottom -fill x -pady 10 -padx 10
 
-       labelframe $w.dest -text {From Repository}
+       ${NS}::labelframe $w.dest -text [mc "From Repository"]
        if {$all_remotes ne {}} {
-               radiobutton $w.dest.remote_r \
-                       -text {Remote:} \
+               ${NS}::radiobutton $w.dest.remote_r \
+                       -text [mc "Remote:"] \
                        -value remote \
                        -variable @urltype
-               eval tk_optionMenu $w.dest.remote_m @remote $all_remotes
+               if {$use_ttk} {
+                       ttk::combobox $w.dest.remote_m -textvariable @remote \
+                               -values $all_remotes -state readonly
+               } else {
+                       eval tk_optionMenu $w.dest.remote_m @remote $all_remotes
+               }
                grid $w.dest.remote_r $w.dest.remote_m -sticky w
                if {[lsearch -sorted -exact $all_remotes origin] != -1} {
                        set remote origin
@@ -62,13 +68,11 @@ constructor dialog {} {
        } else {
                set urltype url
        }
-       radiobutton $w.dest.url_r \
-               -text {Arbitrary URL:} \
+       ${NS}::radiobutton $w.dest.url_r \
+               -text [mc "Arbitrary Location:"] \
                -value url \
                -variable @urltype
-       entry $w.dest.url_t \
-               -borderwidth 1 \
-               -relief sunken \
+       ${NS}::entry $w.dest.url_t \
                -width 50 \
                -textvariable @url \
                -validate key \
@@ -81,42 +85,39 @@ constructor dialog {} {
        grid columnconfigure $w.dest 1 -weight 1
        pack $w.dest -anchor nw -fill x -pady 5 -padx 5
 
-       labelframe $w.heads -text {Branches}
-       listbox $w.heads.l \
+       ${NS}::labelframe $w.heads -text [mc "Branches"]
+       slistbox $w.heads.l \
                -height 10 \
                -width 70 \
                -listvariable @head_list \
-               -selectmode extended \
-               -yscrollcommand [list $w.heads.sby set]
-       scrollbar $w.heads.sby -command [list $w.heads.l yview]
+               -selectmode extended
 
-       frame $w.heads.footer
-       label $w.heads.footer.status \
+       ${NS}::frame $w.heads.footer
+       ${NS}::label $w.heads.footer.status \
                -textvariable @status \
                -anchor w \
                -justify left
-       button $w.heads.footer.rescan \
-               -text {Rescan} \
+       ${NS}::button $w.heads.footer.rescan \
+               -text [mc "Rescan"] \
                -command [cb _rescan]
-       pack $w.heads.footer.status -side left -fill x -expand 1
+       pack $w.heads.footer.status -side left -fill x
        pack $w.heads.footer.rescan -side right
 
-       pack $w.heads.footer -side bottom -fill x -expand 1
-       pack $w.heads.sby -side right -fill y
+       pack $w.heads.footer -side bottom -fill x
        pack $w.heads.l -side left -fill both -expand 1
        pack $w.heads -fill both -expand 1 -pady 5 -padx 5
 
-       labelframe $w.validate -text {Delete Only If}
-       radiobutton $w.validate.head_r \
-               -text {Merged Into:} \
+       ${NS}::labelframe $w.validate -text [mc "Delete Only If"]
+       ${NS}::radiobutton $w.validate.head_r \
+               -text [mc "Merged Into:"] \
                -value head \
                -variable @checktype
        set head_m [tk_optionMenu $w.validate.head_m @check_head {}]
        trace add variable @head_list write [cb _write_head_list]
        trace add variable @check_head write [cb _write_check_head]
        grid $w.validate.head_r $w.validate.head_m -sticky w
-       radiobutton $w.validate.always_r \
-               -text {Always (Do not perform merge checks)} \
+       ${NS}::radiobutton $w.validate.always_r \
+               -text [mc "Always (Do not perform merge checks)"] \
                -value always \
                -variable @checktype
        grid $w.validate.always_r -columnspan 2 -sticky w
@@ -131,7 +132,6 @@ constructor dialog {} {
        bind $w <$M1B-Key-R> [cb _rescan]
        bind $w <Key-Return> [cb _delete]
        bind $w <Key-Escape> [list destroy $w]
-       bind $w.header <Destroy> [list delete_this $this]
        return $w
 }
 
@@ -150,7 +150,7 @@ method _delete {} {
                                -type ok \
                                -title [wm title $w] \
                                -parent $w \
-                               -message "A branch is required for 'Merged Into'."
+                               -message [mc "A branch is required for 'Merged Into'."]
                        return
                }
                set crev $full_cache("$cache\nrefs/heads/$check_head")
@@ -182,14 +182,12 @@ method _delete {} {
        }
 
        if {$not_merged ne {}} {
-               set msg "The following branches are not completely merged into $check_head:
+               set msg [mc "The following branches are not completely merged into %s:
 
- - [join $not_merged "\n - "]"
+ - %s" $check_head [join $not_merged "\n - "]]
 
                if {$need_fetch} {
-                       append msg "
-
-One or more of the merge tests failed because you have not fetched the necessary commits.  Try fetching from $uri first."
+                       append msg "\n\n" [mc "One or more of the merge tests failed because you have not fetched the necessary commits.  Try fetching from %s first." $uri]
                }
 
                tk_messageBox \
@@ -207,26 +205,26 @@ One or more of the merge tests failed because you have not fetched the necessary
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message "Please select one or more branches to delete."
+                       -message [mc "Please select one or more branches to delete."]
                return
        }
 
-       if {[tk_messageBox \
-               -icon warning \
-               -type yesno \
-               -title [wm title $w] \
-               -parent $w \
-               -message {Recovering deleted branches is difficult.
-
-Delete the selected branches?}] ne yes} {
-               return
+       if {$checktype ne {head}} {
+               if {[tk_messageBox \
+                       -icon warning \
+                       -type yesno \
+                       -title [wm title $w] \
+                       -parent $w \
+                       -message [mc "Recovering deleted branches is difficult.\n\nDelete the selected branches?"]] ne yes} {
+                       return
+               }
        }
 
        destroy $w
 
        set cons [console::new \
                "push $uri" \
-               "Deleting branches from $uri"]
+               [mc "Deleting branches from %s" $uri]]
        console::exec $cons $push_cmd
 }
 
@@ -253,6 +251,8 @@ method _write_url        {args} { set urltype url    }
 method _write_check_head {args} { set checktype head }
 
 method _write_head_list {args} {
+       global current_branch
+
        $head_m delete 0 end
        foreach abr $head_list {
                $head_m insert end radiobutton \
@@ -261,7 +261,11 @@ method _write_head_list {args} {
                        -variable @check_head
        }
        if {[lsearch -exact -sorted $head_list $check_head] < 0} {
-               set check_head {}
+               if {[lsearch -exact -sorted $head_list $current_branch] < 0} {
+                       set check_head {}
+               } else {
+                       set check_head $current_branch
+               }
        }
 }
 
@@ -286,18 +290,18 @@ method _load {cache uri} {
                $w.heads.l conf -state disabled
                set head_list [list]
                set full_list [list]
-               set status {No repository selected.}
+               set status [mc "No repository selected."]
                return
        }
 
        if {[catch {set x $cached($cache)}]} {
-               set status "Scanning $uri..."
+               set status [mc "Scanning %s..." $uri]
                $w.heads.l conf -state disabled
                set head_list [list]
                set full_list [list]
                set head_cache($cache) [list]
                set full_cache($cache) [list]
-               set active_ls [open "| [list git ls-remote $uri]" r]
+               set active_ls [git_read ls-remote $uri]
                fconfigure $active_ls \
                        -blocking 0 \
                        -translation lf \