Merge branch 'color-fix' of https://github.com/qykth-git/gitk
[gitweb.git] / gitk
diff --git a/gitk b/gitk
index 07bdff6e5f2b714762d667c781a90e1bf1944893..5f1255c860486571ef1159695318c74c73f8c340 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -1442,7 +1442,7 @@ proc getcommitlines {fd inst view updating}  {
            if {[string range $err 0 4] == "usage"} {
                set err "Gitk: error reading commits$fv:\
                        bad arguments to git log."
-               if {$viewname($view) eq "Command line"} {
+               if {$viewname($view) eq [mc "Command line"]} {
                    append err \
                        "  (Note: arguments to gitk are passed to git log\
                         to allow selection of commits to be displayed.)"
@@ -1894,13 +1894,13 @@ proc make_transient {window origin} {
     }
 }
 
-proc show_error {w top msg {mc mc}} {
+proc show_error {w top msg} {
     global NS
     if {![info exists NS]} {set NS ""}
     if {[wm state $top] eq "withdrawn"} { wm deiconify $top }
     message $w.m -text $msg -justify center -aspect 400
     pack $w.m -side top -fill x -padx 20 -pady 20
-    ${NS}::button $w.ok -default active -text [$mc OK] -command "destroy $top"
+    ${NS}::button $w.ok -default active -text [mc OK] -command "destroy $top"
     pack $w.ok -side bottom -fill x
     bind $top <Visibility> "grab $top; focus $top"
     bind $top <Key-Return> "destroy $top"
@@ -1943,6 +1943,8 @@ proc confirm_popup {msg {owner .}} {
 }
 
 proc setoptions {} {
+    global use_ttk
+
     if {[tk windowingsystem] ne "win32"} {
         option add *Panedwindow.showHandle 1 startupFile
         option add *Panedwindow.sashRelief raised startupFile
@@ -1965,6 +1967,18 @@ proc setoptions {} {
     option add *Listbox.font mainfont startupFile
 }
 
+proc setttkstyle {} {
+    eval font configure TkDefaultFont [fontflags mainfont]
+    eval font configure TkTextFont [fontflags textfont]
+    eval font configure TkHeadingFont [fontflags mainfont]
+    eval font configure TkCaptionFont [fontflags mainfont] -weight bold
+    eval font configure TkTooltipFont [fontflags uifont]
+    eval font configure TkFixedFont   [fontflags textfont]
+    eval font configure TkIconFont    [fontflags uifont]
+    eval font configure TkMenuFont    [fontflags uifont]
+    eval font configure TkSmallCaptionFont [fontflags uifont]
+}
+
 # Make a menu and submenus.
 # m is the window name for the menu, items is the list of menu items to add.
 # Each item is a list {mc label type description options...}
@@ -2065,33 +2079,33 @@ proc makewindow {} {
     # The "mc" arguments here are purely so that xgettext
     # sees the following string as needing to be translated
     set file {
-       mc "File" cascade {
-           {mc "Update" command updatecommits -accelerator F5}
-           {mc "Reload" command reloadcommits -accelerator Shift-F5}
-           {mc "Reread references" command rereadrefs}
-           {mc "List references" command showrefs -accelerator F2}
+       mc "&File" cascade {
+           {mc "&Update" command updatecommits -accelerator F5}
+           {mc "&Reload" command reloadcommits -accelerator Shift-F5}
+           {mc "Reread re&ferences" command rereadrefs}
+           {mc "&List references" command showrefs -accelerator F2}
            {xx "" separator}
-           {mc "Start git gui" command {exec git gui &}}
+           {mc "Start git &gui" command {exec git gui &}}
            {xx "" separator}
-           {mc "Quit" command doquit -accelerator Meta1-Q}
+           {mc "&Quit" command doquit -accelerator Meta1-Q}
        }}
     set edit {
-       mc "Edit" cascade {
-           {mc "Preferences" command doprefs}
+       mc "&Edit" cascade {
+           {mc "&Preferences" command doprefs}
        }}
     set view {
-       mc "View" cascade {
-           {mc "New view..." command {newview 0} -accelerator Shift-F4}
-           {mc "Edit view..." command editview -state disabled -accelerator F4}
-           {mc "Delete view" command delview -state disabled}
+       mc "&View" cascade {
+           {mc "&New view..." command {newview 0} -accelerator Shift-F4}
+           {mc "&Edit view..." command editview -state disabled -accelerator F4}
+           {mc "&Delete view" command delview -state disabled}
            {xx "" separator}
-           {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
+           {mc "&All files" radiobutton {selectedview 0} -command {showview 0}}
        }}
     if {[tk windowingsystem] ne "aqua"} {
        set help {
-       mc "Help" cascade {
-           {mc "About gitk" command about}
-           {mc "Key bindings" command keys}
+       mc "&Help" cascade {
+           {mc "&About gitk" command about}
+           {mc "&Key bindings" command keys}
        }}
        set bar [list $file $edit $view $help]
     } else {
@@ -2099,13 +2113,13 @@ proc makewindow {} {
        proc ::tk::mac::Quit {} {doquit}
        lset file end [lreplace [lindex $file end] end-1 end]
        set apple {
-       xx "Apple" cascade {
-           {mc "About gitk" command about}
+       xx "&Apple" cascade {
+           {mc "&About gitk" command about}
            {xx "" separator}
        }}
        set help {
-       mc "Help" cascade {
-           {mc "Key bindings" command keys}
+       mc "&Help" cascade {
+           {mc "&Key bindings" command keys}
        }}
        set bar [list $apple $file $view $help]
     }
@@ -2251,7 +2265,7 @@ proc makewindow {} {
        set h [expr {[font metrics uifont -linespace] + 2}]
        set progresscanv .tf.bar.progress
        canvas $progresscanv -relief sunken -height $h -borderwidth 2
-       set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
+       set progressitem [$progresscanv create rect -1 0 0 $h -fill lime]
        set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
        set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
     }
@@ -2347,6 +2361,9 @@ proc makewindow {} {
     ${NS}::frame .bleft.mid
     ${NS}::frame .bleft.bottom
 
+    # gap between sub-widgets
+    set wgap [font measure uifont "i"]
+
     ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
     pack .bleft.top.search -side left -padx 5
     set sstring .bleft.top.sstring
@@ -2361,8 +2378,9 @@ proc makewindow {} {
        -command changediffdisp -variable diffelide -value {0 1}
     ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
        -command changediffdisp -variable diffelide -value {1 0}
+
     ${NS}::label .bleft.mid.labeldiffcontext -text "      [mc "Lines of context"]: "
-    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
+    pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
     spinbox .bleft.mid.diffcontext -width 5 \
        -from 0 -increment 1 -to 10000000 \
        -validate all -validatecommand "diffcontextvalidate %P" \
@@ -2370,7 +2388,7 @@ proc makewindow {} {
     .bleft.mid.diffcontext set $diffcontext
     trace add variable diffcontextstring write diffcontextchange
     lappend entries .bleft.mid.diffcontext
-    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
+    pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
     ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
        -command changeignorespace -variable ignorespace
     pack .bleft.mid.ignspace -side left -padx 5
@@ -2568,6 +2586,7 @@ proc makewindow {} {
     bindkey b prevfile
     bindkey d "$ctext yview scroll 18 units"
     bindkey u "$ctext yview scroll -18 units"
+    bindkey g {$sha1entry delete 0 end; focus $sha1entry}
     bindkey / {focus $fstring}
     bindkey <Key-KP_Divide> {focus $fstring}
     bindkey <Key-Return> {dofind 1 1}
@@ -2617,6 +2636,7 @@ proc makewindow {} {
        {mc "Diff selected -> this" command {diffvssel 1}}
        {mc "Make patch" command mkpatch}
        {mc "Create tag" command mktag}
+       {mc "Copy commit summary" command copysummary}
        {mc "Write commit to file" command writecommit}
        {mc "Create new branch" command mkbranch}
        {mc "Cherry-pick this commit" command cherrypick}
@@ -2645,6 +2665,7 @@ proc makewindow {} {
     makemenu $headctxmenu {
        {mc "Check out this branch" command cobranch}
        {mc "Remove this branch" command rmbranch}
+       {mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
     }
     $headctxmenu configure -tearoff 0
 
@@ -2655,6 +2676,7 @@ proc makewindow {} {
        {mc "Highlight this only" command {flist_hl 1}}
        {mc "External diff" command {external_diff}}
        {mc "Blame parent commit" command {external_blame 1}}
+       {mc "Copy path" command {clipboard clear; clipboard append $flist_menu_file}}
     }
     $flist_menu configure -tearoff 0
 
@@ -3069,6 +3091,7 @@ proc keys {} {
 [mc "<%s-F>            Find" $M1T]
 [mc "<%s-G>            Move to next find hit" $M1T]
 [mc "<Return>  Move to next find hit"]
+[mc "g         Go to commit"]
 [mc "/         Focus the search box"]
 [mc "?         Move to previous find hit"]
 [mc "f         Scroll diff view to next file"]
@@ -3374,7 +3397,7 @@ set rectmask {
        0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
        0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
 }
-image create bitmap reficon-H -background black -foreground green \
+image create bitmap reficon-H -background black -foreground lime \
     -data $rectdata -maskdata $rectmask
 image create bitmap reficon-o -background black -foreground "#ddddff" \
     -data $rectdata -maskdata $rectmask
@@ -4034,6 +4057,19 @@ proc shellsplit {str} {
     return $l
 }
 
+proc set_window_title {} {
+    global appname curview viewname vrevs
+    set rev [mc "All files"]
+    if {$curview ne 0} {
+       if {$viewname($curview) eq [mc "Command line"]} {
+           set rev [string map {"--gitk-symmetric-diff-marker" "--merge"} $vrevs($curview)]
+       } else {
+           set rev $viewname($curview)
+       }
+    }
+    wm title . "[reponame]: $rev - $appname"
+}
+
 # Code to implement multiple views
 
 proc newview {ishighlight} {
@@ -4450,8 +4486,8 @@ proc showview {n} {
 
     set curview $n
     set selectedview $n
-    .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
-    .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
+    .bar.view entryconf [mca "&Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
+    .bar.view entryconf [mca "&Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
 
     run refill_reflist
     if {![info exists viewcomplete($n)]} {
@@ -4510,6 +4546,7 @@ proc showview {n} {
     } elseif {$numcommits == 0} {
        show_status [mc "No commits selected"]
     }
+    set_window_title
 }
 
 # Stuff relating to the highlighting facility
@@ -6650,6 +6687,7 @@ proc show_status {msg} {
     global canv fgcolor
 
     clear_display
+    set_window_title
     $canv create text 3 3 -anchor nw -text $msg -font mainfont \
        -tags text -fill $fgcolor
 }
@@ -8876,13 +8914,13 @@ proc rowmenu {x y id} {
     if {$id ne $nullid && $id ne $nullid2} {
        set menu $rowctxmenu
        if {$mainhead ne {}} {
-           $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
+           $menu entryconfigure 8 -label [mc "Reset %s branch to here" $mainhead] -state normal
        } else {
-           $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
+           $menu entryconfigure 8 -label [mc "Detached head: can't reset" $mainhead] -state disabled
        }
-       $menu entryconfigure 9 -state $mstate
        $menu entryconfigure 10 -state $mstate
        $menu entryconfigure 11 -state $mstate
+       $menu entryconfigure 12 -state $mstate
     } else {
        set menu $fakerowmenu
     }
@@ -9341,6 +9379,20 @@ proc mktaggo {} {
     mktagcan
 }
 
+proc copysummary {} {
+    global rowmenuid autosellen
+
+    set format "%h (\"%s\", %ad)"
+    set cmd [list git show -s --pretty=format:$format --date=short]
+    if {$autosellen < 40} {
+        lappend cmd --abbrev=$autosellen
+    }
+    set summary [eval exec $cmd $rowmenuid]
+
+    clipboard clear
+    clipboard append $summary
+}
+
 proc writecommit {} {
     global rowmenuid wrcomtop commitinfo wrcomcmd NS
 
@@ -9819,8 +9871,10 @@ proc showrefs {} {
        -width 30 -height 20 -cursor $maincursor \
        -spacing1 1 -spacing3 1 -state disabled
     $top.list tag configure highlight -background $selectbgcolor
-    lappend bglist $top.list
-    lappend fglist $top.list
+    if {![lsearch -exact $bglist $top.list]} {
+       lappend bglist $top.list
+       lappend fglist $top.list
+    }
     ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
     ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
     grid $top.list $top.ysb -sticky nsew
@@ -11532,7 +11586,9 @@ proc choosecolor {v vi w x cmd} {
 proc setselbg {c} {
     global bglist cflist
     foreach w $bglist {
-       $w configure -selectbackground $c
+       if {[winfo exists $w]} {
+           $w configure -selectbackground $c
+       }
     }
     $cflist tag configure highlight \
        -background [$cflist cget -selectbackground]
@@ -11558,7 +11614,9 @@ proc setbg {c} {
     global bglist
 
     foreach w $bglist {
-       $w conf -background $c
+       if {[winfo exists $w]} {
+           $w conf -background $c
+       }
     }
 }
 
@@ -11566,7 +11624,9 @@ proc setfg {c} {
     global fglist canv
 
     foreach w $fglist {
-       $w conf -foreground $c
+       if {[winfo exists $w]} {
+           $w conf -foreground $c
+       }
     }
     allcanvs itemconf text -fill $c
     $canv itemconf circle -outline $c
@@ -12008,10 +12068,29 @@ proc get_path_encoding {path} {
     return $tcl_enc
 }
 
+## For msgcat loading, first locate the installation location.
+if { [info exists ::env(GITK_MSGSDIR)] } {
+    ## Msgsdir was manually set in the environment.
+    set gitk_msgsdir $::env(GITK_MSGSDIR)
+} else {
+    ## Let's guess the prefix from argv0.
+    set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
+    set gitk_libdir [file join $gitk_prefix share gitk lib]
+    set gitk_msgsdir [file join $gitk_libdir msgs]
+    unset gitk_prefix
+}
+
+## Internationalization (i18n) through msgcat and gettext. See
+## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
+package require msgcat
+namespace import ::msgcat::mc
+## And eventually load the actual message catalog
+::msgcat::mcload $gitk_msgsdir
+
 # First check that Tcl/Tk is recent enough
 if {[catch {package require Tk 8.4} err]} {
-    show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
-                    Gitk requires at least Tcl/Tk 8.4." list
+    show_error {} . [mc "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
+                        Gitk requires at least Tcl/Tk 8.4."]
     exit 1
 }
 
@@ -12109,7 +12188,7 @@ if {[tk windowingsystem] eq "aqua"} {
     set extdifftool "meld"
 }
 
-set colors {green red blue magenta darkgrey brown orange}
+set colors {lime red blue magenta darkgrey brown orange}
 if {[tk windowingsystem] eq "win32"} {
     set uicolor SystemButtonFace
     set uifgcolor SystemButtonText
@@ -12127,12 +12206,12 @@ if {[tk windowingsystem] eq "win32"} {
 }
 set diffcolors {red "#00a000" blue}
 set diffcontext 3
-set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
+set mergecolors {red blue lime purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
 set ignorespace 0
 set worddiff ""
 set markbgcolor "#e0e0ff"
 
-set headbgcolor green
+set headbgcolor lime
 set headfgcolor black
 set headoutlinecolor black
 set remotebgcolor #ffddaa
@@ -12147,7 +12226,7 @@ set linehoverfgcolor black
 set linehoveroutlinecolor black
 set mainheadcirclecolor yellow
 set workingfilescirclecolor red
-set indexcirclecolor green
+set indexcirclecolor lime
 set circlecolors {white blue gray blue blue}
 set linkfgcolor blue
 set circleoutlinecolor $fgcolor
@@ -12161,25 +12240,6 @@ if {[tk windowingsystem] eq "aqua"} {
     set ctxbut <Button-3>
 }
 
-## For msgcat loading, first locate the installation location.
-if { [info exists ::env(GITK_MSGSDIR)] } {
-    ## Msgsdir was manually set in the environment.
-    set gitk_msgsdir $::env(GITK_MSGSDIR)
-} else {
-    ## Let's guess the prefix from argv0.
-    set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
-    set gitk_libdir [file join $gitk_prefix share gitk lib]
-    set gitk_msgsdir [file join $gitk_libdir msgs]
-    unset gitk_prefix
-}
-
-## Internationalization (i18n) through msgcat and gettext. See
-## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
-package require msgcat
-namespace import ::msgcat::mc
-## And eventually load the actual message catalog
-::msgcat::mcload $gitk_msgsdir
-
 catch {
     # follow the XDG base directory specification by default. See
     # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
@@ -12314,6 +12374,10 @@ if {![info exists have_ttk]} {
 set use_ttk [expr {$have_ttk && $want_ttk}]
 set NS [expr {$use_ttk ? "ttk" : ""}]
 
+if {$use_ttk} {
+    setttkstyle
+}
+
 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
 
 set show_notes {}
@@ -12393,7 +12457,7 @@ catch {
 }
 # wait for the window to become visible
 tkwait visibility .
-wm title . "[reponame] - $appname"
+set_window_title
 update
 readrefs
 
@@ -12410,8 +12474,8 @@ if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
     set viewchanged(1) 0
     set vdatemode(1) 0
     addviewmenu 1
-    .bar.view entryconf [mca "Edit view..."] -state normal
-    .bar.view entryconf [mca "Delete view"] -state normal
+    .bar.view entryconf [mca "&Edit view..."] -state normal
+    .bar.view entryconf [mca "&Delete view"] -state normal
 }
 
 if {[info exists permviews]} {