Code

git-gui: use themed tk widgets with Tk 8.5
[git.git] / lib / branch_rename.tcl
index 405101637f0d224e341abd1177e3660cf8ea73a8..63988773ba0d02af3dc91474b4a1669ecda27c5c 100644 (file)
@@ -8,10 +8,11 @@ field oldname
 field newname
 
 constructor dialog {} {
-       global all_heads current_branch
+       global current_branch use_ttk NS
 
-       make_toplevel top w
-       wm title $top "[appname] ([reponame]): Rename Branch"
+       make_dialog top w
+       wm withdraw $w
+       wm title $top [append "[appname] ([reponame]): " [mc "Rename Branch"]]
        if {$top ne {.}} {
                wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
        }
@@ -19,27 +20,31 @@ constructor dialog {} {
        set oldname $current_branch
        set newname [get_config gui.newbranchtemplate]
 
-       label $w.header -text {Rename Branch} -font font_uibold
+       ${NS}::label $w.header -text [mc "Rename Branch"]\
+               -font font_uibold -anchor center
        pack $w.header -side top -fill x
 
-       frame $w.buttons
-       button $w.buttons.rename -text Rename \
+       ${NS}::frame $w.buttons
+       ${NS}::button $w.buttons.rename -text [mc Rename] \
                -default active \
                -command [cb _rename]
        pack $w.buttons.rename -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
 
-       frame $w.rename
-       label $w.rename.oldname_l -text {Branch:}
-       eval tk_optionMenu $w.rename.oldname_m @oldname $all_heads
+       ${NS}::frame $w.rename
+       ${NS}::label $w.rename.oldname_l -text [mc "Branch:"]
+       if {$use_ttk} {
+               ttk::combobox $w.rename.oldname_m -textvariable @oldname \
+                       -values [load_all_heads] -state readonly
+       } else {
+               eval tk_optionMenu $w.rename.oldname_m @oldname [load_all_heads]
+       }
 
-       label $w.rename.newname_l -text {New Name:}
-       entry $w.rename.newname_t \
-               -borderwidth 1 \
-               -relief sunken \
+       ${NS}::label $w.rename.newname_l -text [mc "New Name:"]
+       ${NS}::entry $w.rename.newname_t \
                -width 40 \
                -textvariable @newname \
                -validate key \
@@ -60,11 +65,12 @@ constructor dialog {} {
                $w.rename.newname_t icursor end
                focus $w.rename.newname_t
        "
+       wm deiconify $w
        tkwait window $w
 }
 
 method _rename {} {
-       global all_heads current_branch
+       global current_branch
 
        if {$oldname eq {}} {
                tk_messageBox \
@@ -72,7 +78,7 @@ method _rename {} {
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message "Please select a branch to rename."
+                       -message [mc "Please select a branch to rename."]
                focus $w.rename.oldname_m
                return
        }
@@ -83,7 +89,7 @@ method _rename {} {
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message "Please supply a branch name."
+                       -message [mc "Please supply a branch name."]
                focus $w.rename.newname_t
                return
        }
@@ -93,7 +99,7 @@ method _rename {} {
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message "Branch '$newname' already exists."
+                       -message [mc "Branch '%s' already exists." $newname]
                focus $w.rename.newname_t
                return
        }
@@ -103,7 +109,7 @@ method _rename {} {
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message "We do not like '$newname' as a branch name."
+                       -message [mc "'%s' is not an acceptable branch name." $newname]
                focus $w.rename.newname_t
                return
        }
@@ -114,18 +120,10 @@ method _rename {} {
                        -type ok \
                        -title [wm title $w] \
                        -parent $w \
-                       -message "Failed to rename '$oldname'.\n\n$err"
+                       -message [strcat [mc "Failed to rename '%s'." $oldname] "\n\n$err"]
                return
        }
 
-       set oldidx [lsearch -exact -sorted $all_heads $oldname]
-       if {$oldidx >= 0} {
-               set all_heads [lreplace $all_heads $oldidx $oldidx]
-       }
-       lappend all_heads $newname
-       set all_heads [lsort $all_heads]
-       populate_branch_menu
-
        if {$current_branch eq $oldname} {
                set current_branch $newname
        }