From 35927672765f39a045a89d2ef1b392ab3ac61189 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Wed, 19 Oct 2011 12:44:39 +0100 Subject: [PATCH] git-gui: theme the search and line-number entry fields on blame screen Signed-off-by: Pat Thoyts --- lib/line.tcl | 2 +- lib/search.tcl | 8 +++-- lib/themed.tcl | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/lib/line.tcl b/lib/line.tcl index c160012de6..a026de954c 100644 --- a/lib/line.tcl +++ b/lib/line.tcl @@ -15,7 +15,7 @@ constructor new {i_w i_text args} { ${NS}::frame $w ${NS}::label $w.l -text [mc "Goto Line:"] - entry $w.ent \ + tentry $w.ent \ -textvariable ${__this}::linenum \ -background lightgreen \ -validate key \ diff --git a/lib/search.tcl b/lib/search.tcl index 15f99d8e5f..fe165724ed 100644 --- a/lib/search.tcl +++ b/lib/search.tcl @@ -35,7 +35,7 @@ constructor new {i_w i_text args} { ${NS}::frame $w ${NS}::label $w.l -text [mc Find:] - entry $w.ent -textvariable ${__this}::searchstring -background lightgreen + tentry $w.ent -textvariable ${__this}::searchstring -background lightgreen ${NS}::button $w.bn -text [mc Next] -command [cb find_next] ${NS}::button $w.bp -text [mc Prev] -command [cb find_prev] ${NS}::checkbutton $w.re -text [mc RegExp] \ @@ -162,10 +162,12 @@ method _incrsearch {} { $ctext see $here $ctext tag remove sel 1.0 end $ctext tag add sel $here "$here + $mlen c" - $w.ent configure -background lightgreen + #$w.ent configure -background lightgreen + $w.ent state !pressed _set_marks $this 1 } else { - $w.ent configure -background lightpink + #$w.ent configure -background lightpink + $w.ent state pressed } } } diff --git a/lib/themed.tcl b/lib/themed.tcl index 1da458673b..29a1696d97 100644 --- a/lib/themed.tcl +++ b/lib/themed.tcl @@ -23,10 +23,59 @@ proc InitTheme {} { ttk::style configure Gold.TFrame -background gold -relief flat # listboxes should have a theme border so embed in ttk::frame ttk::style layout SListbox.TFrame { - SListbox.Frame.Entry.field -sticky news -border true -children { - SListbox.Frame.padding -sticky news - } - } + SListbox.Frame.Entry.field -sticky news -border true -children { + SListbox.Frame.padding -sticky news + } + } + + # Handle either current Tk or older versions of 8.5 + if {[catch {set theme [ttk::style theme use]}]} { + set theme $::ttk::currentTheme + } + + if {[lsearch -exact {default alt classic clam} $theme] != -1} { + # Simple override of standard ttk::entry to change the field + # packground according to a state flag. We should use 'user1' + # but not all versions of 8.5 support that so make use of 'pressed' + # which is not normally in use for entry widgets. + ttk::style layout Edged.Entry [ttk::style layout TEntry] + ttk::style map Edged.Entry {*}[ttk::style map TEntry] + ttk::style configure Edged.Entry {*}[ttk::style configure TEntry] \ + -fieldbackground lightgreen + ttk::style map Edged.Entry -fieldbackground { + {pressed !disabled} lightpink + } + } else { + # For fancier themes, in particular the Windows ones, the field + # element may not support changing the background color. So instead + # override the fill using the default fill element. If we overrode + # the vista theme field element we would loose the themed border + # of the widget. + catch { + ttk::style element create color.fill from default + } + + ttk::style layout Edged.Entry { + Edged.Entry.field -sticky nswe -border 0 -children { + Edged.Entry.border -sticky nswe -border 1 -children { + Edged.Entry.padding -sticky nswe -children { + Edged.Entry.color.fill -sticky nswe -children { + Edged.Entry.textarea -sticky nswe + } + } + } + } + } + + ttk::style configure Edged.Entry {*}[ttk::style configure TEntry] \ + -background lightgreen -padding 0 -borderwidth 0 + ttk::style map Edged.Entry {*}[ttk::style map TEntry] \ + -background {{pressed !disabled} lightpink} + } + + if {[lsearch [bind . <>] InitTheme] == -1} { + bind . <> +[namespace code [list InitTheme]] + } } proc gold_frame {w args} { @@ -143,6 +192,47 @@ proc tspinbox {w args} { } } +proc tentry {w args} { + global use_ttk + if {$use_ttk} { + InitTheme + ttk::entry $w -style Edged.Entry + } else { + entry $w + } + + rename $w _$w + interp alias {} $w {} tentry_widgetproc $w + eval [linsert $args 0 tentry_widgetproc $w configure] + return $w +} +proc tentry_widgetproc {w cmd args} { + global use_ttk + switch -- $cmd { + state { + if {$use_ttk} { + return [uplevel 1 [list _$w $cmd] $args] + } else { + if {[lsearch -exact $args pressed] != -1} { + _$w configure -background lightpink + } else { + _$w configure -background lightgreen + } + } + } + configure { + if {$use_ttk} { + if {[set n [lsearch -exact $args -background]] != -1} { + set args [lreplace $args $n [incr n]] + if {[llength $args] == 0} {return} + } + } + return [uplevel 1 [list _$w $cmd] $args] + } + default { return [uplevel 1 [list _$w $cmd] $args] } + } +} + # Tk 8.6 provides a standard font selection dialog. This uses the native # dialogs on Windows and MacOSX or a standard Tk dialog on X11. proc tchoosefont {w title familyvar sizevar} { -- 2.11.4.GIT