From afe2098ddd3e21d1d1afc428d3c8d91f37b01692 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:07:46 -0400 Subject: [PATCH 1/3] git-gui: Font chooser to handle a large number of font families Simon Sasburg noticed that on X11 if there are more fonts than can fit in the height of the screen Tk's native tk_optionMenu does not offer scroll arrows to the user and it is not possible to review all choices or to select those that are off-screen. On Mac OS X the tk_optionMenu works properly but is awkward to navigate if the list is long. This is a rewrite of our font selection by providing a new modal dialog that the user can launch from the git-gui Options panel. The dialog offers the user a scrolling list of fonts in a pane. An example text shows the user what the font looks like at the size they have selected. But I have to admit the example pane is less than ideal. For example in the case of our diff font we really should show the user an example diff complete with our native diff syntax coloring. Signed-off-by: Shawn O. Pearce Acked-by: Simon Sasburg --- lib/choose_font.tcl | 165 ++++++++++++++++++++++++++++++++++++++++++++ lib/option.tcl | 28 +++++--- 2 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 lib/choose_font.tcl diff --git a/lib/choose_font.tcl b/lib/choose_font.tcl new file mode 100644 index 0000000000..b69215c91e --- /dev/null +++ b/lib/choose_font.tcl @@ -0,0 +1,165 @@ +# git-gui font chooser +# Copyright (C) 2007 Shawn Pearce + +class choose_font { + +field w +field w_family ; # UI widget of all known family names +field w_example ; # Example to showcase the chosen font + +field f_family ; # Currently chosen family name +field f_size ; # Currently chosen point size + +field v_family ; # Name of global variable for family +field v_size ; # Name of global variable for size + +variable all_families [list] ; # All fonts known to Tk + +constructor pick {path title a_family a_size} { + variable all_families + + set v_family $a_family + set v_size $a_size + + upvar #0 $v_family pv_family + upvar #0 $v_size pv_size + + set f_family $pv_family + set f_size $pv_size + + make_toplevel top w + wm title $top "[appname] ([reponame]): $title" + wm geometry $top "+[winfo rootx $path]+[winfo rooty $path]" + + label $w.header -text $title -font font_uibold + pack $w.header -side top -fill x + + frame $w.buttons + button $w.buttons.select \ + -text [mc Select] \ + -default active \ + -command [cb _select] + button $w.buttons.cancel \ + -text [mc Cancel] \ + -command [list destroy $w] + pack $w.buttons.select -side right + pack $w.buttons.cancel -side right -padx 5 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + frame $w.inner + + frame $w.inner.family + label $w.inner.family.l \ + -text [mc "Font Family"] \ + -anchor w + set w_family $w.inner.family.v + text $w_family \ + -background white \ + -borderwidth 1 \ + -relief sunken \ + -cursor $::cursor_ptr \ + -wrap none \ + -width 30 \ + -height 10 \ + -yscrollcommand [list $w.inner.family.sby set] + scrollbar $w.inner.family.sby -command [list $w_family yview] + pack $w.inner.family.l -side top -fill x + pack $w.inner.family.sby -side right -fill y + pack $w_family -fill both -expand 1 + + frame $w.inner.size + label $w.inner.size.l \ + -text [mc "Font Size"] \ + -anchor w + spinbox $w.inner.size.v \ + -textvariable @f_size \ + -from 2 -to 80 -increment 1 \ + -width 3 + bind $w.inner.size.v {%W selection range 0 end} + pack $w.inner.size.l -fill x -side top + pack $w.inner.size.v -fill x -padx 2 + + grid configure $w.inner.family $w.inner.size -sticky nsew + grid rowconfigure $w.inner 0 -weight 1 + grid columnconfigure $w.inner 0 -weight 1 + pack $w.inner -fill both -expand 1 -padx 5 -pady 5 + + frame $w.example + label $w.example.l \ + -text [mc "Font Example"] \ + -anchor w + set w_example $w.example.t + text $w_example \ + -background white \ + -borderwidth 1 \ + -relief sunken \ + -height 3 \ + -width 40 + $w_example tag conf example -justify center + $w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example + $w_example conf -state disabled + pack $w.example.l -fill x + pack $w_example -fill x + pack $w.example -fill x -padx 5 + + if {$all_families eq {}} { + set all_families [lsort [font families]] + } + + $w_family tag conf pick + $w_family tag bind pick [cb _pick_family %x %y]\;break + $w_family tag conf cpck -background lightgray + foreach f $all_families { + set sel [list pick] + if {$f eq $f_family} { + lappend sel cpck + } + $w_family insert end "$f\n" $sel + } + $w_family conf -state disabled + _update $this + + trace add variable @f_size write [cb _update] + bind $w [list destroy $w] + bind $w [cb _select]\;break + bind $w " + grab $w + focus $w + " + tkwait window $w +} + +method _select {} { + upvar #0 $v_family pv_family + upvar #0 $v_size pv_size + + set pv_family $f_family + set pv_size $f_size + + destroy $w +} + +method _pick_family {x y} { + variable all_families + + set i [lindex [split [$w_family index @$x,$y] .] 0] + set n [lindex $all_families [expr {$i - 1}]] + if {$n ne {}} { + $w_family tag remove cpck 0.0 end + $w_family tag add cpck $i.0 [expr {$i + 1}].0 + set f_family $n + _update $this + } +} + +method _update {args} { + variable all_families + + set i [lsearch -exact $all_families $f_family] + if {$i < 0} return + + $w_example tag conf example -font [list $f_family $f_size] + $w_family see [expr {$i + 1}].0 +} + +} diff --git a/lib/option.tcl b/lib/option.tcl index aa9f783afd..063f5df6f7 100644 --- a/lib/option.tcl +++ b/lib/option.tcl @@ -255,17 +255,23 @@ proc do_options {} { frame $w.global.$name label $w.global.$name.l -text "$text:" - pack $w.global.$name.l -side left -anchor w -fill x - eval tk_optionMenu $w.global.$name.family \ - global_config_new(gui.$font^^family) \ - $all_fonts - spinbox $w.global.$name.size \ - -textvariable global_config_new(gui.$font^^size) \ - -from 2 -to 80 -increment 1 \ - -width 3 - bind $w.global.$name.size {%W selection range 0 end} - pack $w.global.$name.size -side right -anchor e - pack $w.global.$name.family -side right -anchor e + button $w.global.$name.b \ + -text [mc "Change Font"] \ + -command [list \ + choose_font::pick \ + $w \ + [mc "Choose %s" $text] \ + global_config_new(gui.$font^^family) \ + global_config_new(gui.$font^^size) \ + ] + label $w.global.$name.f -textvariable global_config_new(gui.$font^^family) + label $w.global.$name.s -textvariable global_config_new(gui.$font^^size) + label $w.global.$name.pt -text [mc "pt."] + pack $w.global.$name.l -side left -anchor w + pack $w.global.$name.b -side right -anchor e + pack $w.global.$name.pt -side right -anchor w + pack $w.global.$name.s -side right -anchor w + pack $w.global.$name.f -side right -anchor w pack $w.global.$name -side top -anchor w -fill x } From 042f53c569c92b40e63c6993c8998d2aac22e383 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:50:35 -0400 Subject: [PATCH 2/3] git-gui: Provide 'uninstall' Makefile target to undo an installation Several users have requested a "make uninstall" target be provided in the stock git-gui Makefile so that they can undo an install if git-gui goes to the wrong place during the initial install, or if they are unhappy with the tool and want to remove it from their system. We currently assume that the complete set of files we need to delete are those defined by our Makefile and current source directory. This could differ from what the user actually has installed if they installed one version then attempt to use another to perform the uninstall. Right now I'm just going to say that is "pilot error". Users should uninstall git-gui using the same version of source that they used to make the installation. Perhaps in the future we could read tclIndex and base our uninstall decisions on its contents. Signed-off-by: Shawn O. Pearce --- Makefile | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f11cf26760..18e6750137 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,9 @@ ifndef INSTALL INSTALL = install endif +RM_F ?= rm -f +RMDIR ?= rmdir + INSTALL_D0 = $(INSTALL) -d -m755 # space is required here INSTALL_D1 = INSTALL_R0 = $(INSTALL) -m644 # space is required here @@ -42,6 +45,12 @@ INSTALL_L1 = && ln # space is required here INSTALL_L2 = INSTALL_L3 = +REMOVE_D0 = $(RMDIR) # space is required here +REMOVE_D1 = || true +REMOVE_F0 = $(RM_F) # space is required here +REMOVE_F1 = +CLEAN_DST = true + ifndef V QUIET = @ QUIET_GEN = $(QUIET)echo ' ' GEN $@ && @@ -60,6 +69,12 @@ ifndef V INSTALL_L1 = && src= INSTALL_L2 = && dst= INSTALL_L3 = && echo ' ' 'LINK ' `basename "$$dst"` '->' `basename "$$src"` && rm -f "$$dst" && ln "$$src" "$$dst" + + CLEAN_DST = echo ' ' UNINSTALL + REMOVE_D0 = dir= + REMOVE_D1 = && echo ' ' REMOVE $$dir && test -d "$$dir" && $(RMDIR) "$$dir" || true + REMOVE_F0 = dst= + REMOVE_F1 = && echo ' ' REMOVE `basename "$$dst"` && $(RM_F) "$$dst" endif TCL_PATH ?= tclsh @@ -146,6 +161,17 @@ install: all $(QUIET)$(INSTALL_R0)lib/tclIndex $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' $(QUIET)$(foreach p,$(ALL_LIBFILES), $(INSTALL_R0)$p $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' &&) true +uninstall: + $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)' + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1) + $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true + $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(libdir_SQ)' + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/tclIndex $(REMOVE_F1) + $(QUIET)$(foreach p,$(ALL_LIBFILES), $(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/$(notdir $p) $(REMOVE_F1) &&) true + $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(REMOVE_D1) + $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(libdir_SQ)' $(REMOVE_D1) + $(QUIET)$(REMOVE_D0)`dirname '$(DESTDIR_SQ)$(libdir_SQ)'` $(REMOVE_D1) + dist-version: @mkdir -p $(TARDIR) @echo $(GITGUI_VERSION) > $(TARDIR)/version @@ -154,6 +180,6 @@ clean:: rm -f $(ALL_PROGRAMS) lib/tclIndex rm -f GIT-VERSION-FILE GIT-GUI-VARS -.PHONY: all install dist-version clean +.PHONY: all install uninstall dist-version clean .PHONY: .FORCE-GIT-VERSION-FILE .PHONY: .FORCE-GIT-GUI-VARS From 55bad4f096b1f18eec94169c864c39bf0abda1db Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 20:08:53 -0400 Subject: [PATCH 3/3] git-gui: Paper bag fix "Commit->Revert" format arguments The recent bug fix to correctly handle filenames with %s (or any other valid Tcl format specifier) missed a \ on this line and caused the remaining format arguments to not be supplied when we updated the status bar. This caused a Tcl error anytime the user was trying to perform a file revert. Signed-off-by: Shawn O. Pearce --- lib/index.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.tcl b/lib/index.tcl index cbbce13a77..44689ab63b 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -168,7 +168,7 @@ proc checkout_index {msg pathList after} { ui_status [format \ "%s... %i/%i files (%.2f%%)" \ - $msg + $msg \ $update_index_cp \ $totalCnt \ 0.0]