{"thread":{"id":"15766","subject":"[PATCH] git-gui: Fix the blame viewer destroy handler.","startedAt":"2008-10-03T07:36:52Z","lastAt":"2008-10-03T08:29:29Z","messageCount":4,"participants":["Alexander Gavrilov","Andreas Ericsson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"92227","messageId":"1223019414-24643-1-git-send-email-angavrilov@gmail.com","threadId":"15766","inReplyTo":null,"subject":"[PATCH] git-gui: Fix the blame window shape.","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-10-03T07:36:52Z","receivedAt":"2008-10-03T07:36:52Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"On modern high-resolution monitors the blame viewer\nwindow is very high, yet too narrow. This patch\nmakes it gravitate to a more sane resolution, which\ntakes the font size into account.\n\nIt also changes the default text view size to 80% of\nthe window, and slightly modifies the border decorations\nfor better appearance.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n lib/blame.tcl |   19 +++++++++++++------\n 1 files changed, 13 insertions(+), 6 deletions(-)\n\ndiff --git a/lib/blame.tcl b/lib/blame.tcl\nindex eb61374..221313c 100644\n--- a/lib/blame.tcl\n+++ b/lib/blame.tcl\n@@ -69,6 +69,8 @@ constructor new {i_commit i_path i_jump} {\n \tmake_toplevel top w\n \twm title $top [append \"[appname] ([reponame]): \" [mc \"File Viewer\"]]\n \n+\tset font_w [font measure font_diff \"0\"]\n+\n \tframe $w.header -background gold\n \tlabel $w.header.commit_l \\\n \t\t-text [mc \"Commit:\"] \\\n@@ -114,9 +116,9 @@ constructor new {i_commit i_path i_jump} {\n \tpack $w_path -fill x -side right\n \tpack $w.header.path_l -side right\n \n-\tpanedwindow $w.file_pane -orient vertical\n-\tframe $w.file_pane.out\n-\tframe $w.file_pane.cm\n+\tpanedwindow $w.file_pane -orient vertical -borderwidth 0 -sashwidth 3\n+\tframe $w.file_pane.out -relief flat -borderwidth 1\n+\tframe $w.file_pane.cm -relief sunken -borderwidth 1\n \t$w.file_pane add $w.file_pane.out \\\n \t\t-sticky nsew \\\n \t\t-minsize 100 \\\n@@ -328,9 +330,14 @@ constructor new {i_commit i_path i_jump} {\n \n \tset req_w [winfo reqwidth  $top]\n \tset req_h [winfo reqheight $top]\n-\tset scr_h [expr {[winfo screenheight $top] - 100}]\n-\tif {$req_w < 600} {set req_w 600}\n+\tset scr_w [expr {[winfo screenwidth $top] - 40}]\n+\tset scr_h [expr {[winfo screenheight $top] - 120}]\n+\tset opt_w [expr {$font_w * (80 + 5*3 + 3)}]\n+\tif {$req_w < $opt_w} {set req_w $opt_w}\n+\tif {$req_w > $scr_w} {set req_w $scr_w}\n+\tset opt_h [expr {$req_w*4/3}]\n \tif {$req_h < $scr_h} {set req_h $scr_h}\n+\tif {$req_h > $opt_h} {set req_h $opt_h}\n \tset g \"${req_w}x${req_h}\"\n \twm geometry $top $g\n \tupdate\n@@ -338,7 +345,7 @@ constructor new {i_commit i_path i_jump} {\n \tset old_height [winfo height $w.file_pane]\n \t$w.file_pane sash place 0 \\\n \t\t[lindex [$w.file_pane sash coord 0] 0] \\\n-\t\t[expr {int($old_height * 0.70)}]\n+\t\t[expr {int($old_height * 0.80)}]\n \tbind $w.file_pane <Configure> \\\n \t\"if {{$w.file_pane} eq {%W}} {[cb _resize %h]}\"\n \n-- \n1.6.0.20.g6148bc\n"},{"id":"92226","messageId":"1223019414-24643-2-git-send-email-angavrilov@gmail.com","threadId":"15766","inReplyTo":"1223019414-24643-1-git-send-email-angavrilov@gmail.com","subject":"[PATCH] git-gui: Add a search command to the blame viewer.","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-10-03T07:36:53Z","receivedAt":"2008-10-03T07:36:53Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"One of the largest deficiencies in the blame viewer at\nthe moment is the impossibility to search for a text\nstring. This commit fixes it by adding a Firefox-like\nsearch panel to the viewer.\n\nThe panel can be shown by pressing F7 or clicking a\nmenu entry, and is hidden by pressing Esc. Find Next\nis available through the F3 key.\n\nImplementation is based on the gitk code, but heavily\nrefactored. It now also supports case-insensitive\nsearches, and uses the text box background color to\nsignal success or failure of the search.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n\n\tI would have used Ctrl-F, but it is already occupied.\n\t\n\t-- Alexander\n\n\n git-gui.sh     |    3 +\n lib/blame.tcl  |   37 ++++++++++-\n lib/search.tcl |  190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 227 insertions(+), 3 deletions(-)\n create mode 100644 lib/search.tcl\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 79a108d..4f95139 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -591,6 +591,7 @@ bind . <Visibility> {\n \n if {[is_Windows]} {\n \twm iconbitmap . -default $oguilib/git-gui.ico\n+\tset ::tk::AlwaysShowSelection 1\n }\n \n ######################################################################\n@@ -1067,6 +1068,8 @@ set selected_commit_type new\n set nullid \"0000000000000000000000000000000000000000\"\n set nullid2 \"0000000000000000000000000000000000000001\"\n \n+set have_tk85 [expr {[package vcompare $tk_version \"8.5\"] >= 0}]\n+\n ######################################################################\n ##\n ## task management\ndiff --git a/lib/blame.tcl b/lib/blame.tcl\nindex 221313c..a45784c 100644\n--- a/lib/blame.tcl\n+++ b/lib/blame.tcl\n@@ -21,9 +21,11 @@ field w_amov     ; # text column: annotations + move tracking\n field w_asim     ; # text column: annotations (simple computation)\n field w_file     ; # text column: actual file data\n field w_cviewer  ; # pane showing commit message\n+field finder     ; # find mini-dialog frame\n field status     ; # status mega-widget instance\n field old_height ; # last known height of $w.file_pane\n \n+\n # Tk UI colors\n #\n variable active_color #c0edc5\n@@ -59,7 +61,7 @@ field tooltip_timer     {} ; # Current timer event for our tooltip\n field tooltip_commit    {} ; # Commit(s) in tooltip\n \n constructor new {i_commit i_path i_jump} {\n-\tglobal cursor_ptr\n+\tglobal cursor_ptr M1B M1T have_tk85\n \tvariable active_color\n \tvariable group_colors\n \n@@ -199,6 +201,11 @@ constructor new {i_commit i_path i_jump} {\n \t\t-width 80 \\\n \t\t-xscrollcommand [list $w.file_pane.out.sbx set] \\\n \t\t-font font_diff\n+\tif {$have_tk85} {\n+\t\t$w_file configure -inactiveselectbackground darkblue\n+\t}\n+\t$w_file tag conf found \\\n+\t\t-background yellow\n \n \tset w_columns [list $w_amov $w_asim $w_line $w_file]\n \n@@ -219,6 +226,11 @@ constructor new {i_commit i_path i_jump} {\n \t\t-weight 1\n \tgrid rowconfigure $w.file_pane.out 0 -weight 1\n \n+\tset finder [::searchbar::new \\\n+\t\t$w.file_pane.out.ff $w_file \\\n+\t\t-column [expr {[llength $w_columns] - 1}] \\\n+\t\t]\n+\n \tset w_cviewer $w.file_pane.cm.t\n \ttext $w_cviewer \\\n \t\t-background white \\\n@@ -259,6 +271,10 @@ constructor new {i_commit i_path i_jump} {\n \t\t-label [mc \"Copy Commit\"] \\\n \t\t-command [cb _copycommit]\n \t$w.ctxm add separator\n+\t$w.ctxm add command \\\n+\t\t-label [mc \"Find Text...\"] \\\n+\t\t-accelerator F7 \\\n+\t\t-command [list searchbar::show $finder]\n \tmenu $w.ctxm.enc\n \tbuild_encoding_menu $w.ctxm.enc [cb _setencoding]\n \t$w.ctxm add cascade \\\n@@ -280,9 +296,15 @@ constructor new {i_commit i_path i_jump} {\n \t\t\t$i tag conf color$g -background [lindex $group_colors $g]\n \t\t}\n \n+\t\tif {$i eq $w_file} {\n+\t\t\t$w_file tag raise found\n+\t\t}\n+\t\t$i tag raise sel\n+\n \t\t$i conf -cursor $cursor_ptr\n-\t\t$i conf -yscrollcommand [list many2scrollbar \\\n-\t\t\t$w_columns yview $w.file_pane.out.sby]\n+\t\t$i conf -yscrollcommand \\\n+\t\t\t\"[list ::searchbar::scrolled $finder]\n+\t\t\t [list many2scrollbar $w_columns yview $w.file_pane.out.sby]\"\n \t\tbind $i <Button-1> \"\n \t\t\t[cb _hide_tooltip]\n \t\t\t[cb _click $i @%x,%y]\n@@ -319,6 +341,11 @@ constructor new {i_commit i_path i_jump} {\n \tbind $w_cviewer <Tab>       \"[list focus $w_file];break\"\n \tbind $w_cviewer <Button-1> [list focus $w_cviewer]\n \tbind $w_file    <Visibility> [list focus $w_file]\n+\tbind $top       <F7>         [list searchbar::show $finder]\n+\tbind $top       <Escape>     [list searchbar::hide $finder]\n+\tbind $top       <F3>         [list searchbar::find_next $finder]\n+\tbind $top       <Shift-F3>   [list searchbar::find_prev $finder]\n+\tcatch { bind $top <Shift-Key-XF86_Switch_VT_3> [list searchbar::find_prev $finder] }\n \n \tgrid configure $w.header -sticky ew\n \tgrid configure $w.file_pane -sticky nsew\n@@ -873,6 +900,10 @@ method _showcommit {cur_w lno} {\n \t\tforeach i $w_columns {\n \t\t\t$i tag conf g$cmit -background $active_color\n \t\t\t$i tag raise g$cmit\n+\t\t\tif {$i eq $w_file} {\n+\t\t\t\t$w_file tag raise found\n+\t\t\t}\n+\t\t\t$i tag raise sel\n \t\t}\n \n \t\tset author_name {}\ndiff --git a/lib/search.tcl b/lib/search.tcl\nnew file mode 100644\nindex 0000000..d292f20\n--- /dev/null\n+++ b/lib/search.tcl\n@@ -0,0 +1,190 @@\n+# incremental search panel\n+# based on code from gitk, Copyright (C) Paul Mackerras\n+\n+class searchbar {\n+\n+field w\n+field ctext\n+\n+field searchstring   {}\n+field casesensitive  1\n+field searchdirn     -forwards\n+\n+field smarktop\n+field smarkbot\n+\n+constructor new {i_w i_text args} {\n+\tset w      $i_w\n+\tset ctext  $i_text\n+\n+\tframe  $w\n+\tlabel  $w.l       -text [mc Find:]\n+\tbutton $w.bn      -text [mc Next] -command [cb find_next]\n+\tbutton $w.bp      -text [mc Prev] -command [cb find_prev]\n+\tcheckbutton $w.cs -text [mc Case-Sensitive] \\\n+\t\t-variable ${__this}::casesensitive -command [cb _incrsearch]\n+\tentry  $w.ent -textvariable ${__this}::searchstring -background lightgreen\n+\tpack   $w.l   -side left\n+\tpack   $w.cs  -side right\n+\tpack   $w.bp  -side right\n+\tpack   $w.bn  -side right\n+\tpack   $w.ent -side left -expand 1 -fill x\n+\n+\teval grid conf $w -sticky we $args\n+\tgrid remove $w\n+\n+\ttrace add variable searchstring write [cb _incrsearch_cb]\n+\t\n+\tbind $w <Destroy> [cb delete_this]\n+\treturn $this\n+}\n+\n+method show {} {\n+\tif {![winfo ismapped $w]} {\n+\t\tgrid $w\n+\t}\n+\tfocus -force $w.ent\n+}\n+\n+method hide {} {\n+\tif {[winfo ismapped $w]} {\n+\t\tfocus $ctext\n+\t\tgrid remove $w\n+\t}\n+}\n+\n+method _get_new_anchor {} {\n+\t# use start of selection if it is visible,\n+\t# or the bounds of the visible area\n+\tset top    [$ctext index @0,0]\n+\tset bottom [$ctext index @0,[winfo height $ctext]]\n+\tset sel    [$ctext tag ranges sel]\n+\tif {$sel ne {}} {\n+\t\tset spos [lindex $sel 0]\n+\t\tif {[lindex $spos 0] >= [lindex $top 0] &&\n+\t\t    [lindex $spos 0] <= [lindex $bottom 0]} {\n+\t\t\treturn $spos\n+\t\t}\n+\t}\n+\tif {$searchdirn eq \"-forwards\"} {\n+\t\treturn $top\n+\t} else {\n+\t\treturn $bottom\n+\t}\n+}\n+\n+method _get_wrap_anchor {dir} {\n+\tif {$dir eq \"-forwards\"} {\n+\t\treturn 1.0\n+\t} else {\n+\t\treturn end\n+\t}\n+}\n+\n+method _do_search {start {mlenvar {}} {dir {}} {endbound {}}} {\n+\tset cmd [list $ctext search]\n+\tif {$mlenvar ne {}} {\n+\t\tupvar $mlenvar mlen\n+\t\tlappend cmd -count mlen\n+\t}\n+\tif {!$casesensitive} {\n+\t\tlappend cmd -nocase\n+\t}\n+\tif {$dir eq {}} {\n+\t\tset dir $searchdirn\n+\t}\n+\tlappend cmd $dir -- $searchstring\n+\tif {$endbound ne {}} {\n+\t\tset here [eval $cmd [list $start] [list $endbound]]\n+\t} else {\n+\t\tset here [eval $cmd [list $start]]\n+\t\tif {$here eq {}} {\n+\t\t\tset here [eval $cmd [_get_wrap_anchor $this $dir]]\n+\t\t}\n+\t}\n+\treturn $here\n+}\n+\n+method _incrsearch_cb {name ix op} {\n+\tafter idle [cb _incrsearch]\n+}\n+\n+method _incrsearch {} {\n+\t$ctext tag remove found 1.0 end\n+\tif {[catch {$ctext index anchor}]} {\n+\t\t$ctext mark set anchor [_get_new_anchor $this]\n+\t}\n+\tif {$searchstring ne {}} {\n+\t\tset here [_do_search $this anchor mlen]\n+\t\tif {$here ne {}} {\n+\t\t\t$ctext see $here\n+\t\t\t$ctext tag remove sel 1.0 end\n+\t\t\t$ctext tag add sel $here \"$here + $mlen c\"\n+\t\t\t$w.ent configure -background lightgreen\n+\t\t\t_set_marks $this 1\n+\t\t} else {\n+\t\t\t$w.ent configure -background lightpink\n+\t\t}\n+\t}\n+}\n+\n+method find_prev {} {\n+\tfind_next $this -backwards\n+}\n+\n+method find_next {{dir -forwards}} {\n+\tfocus $w.ent\n+\t$w.ent icursor end\n+\tset searchdirn $dir\n+\t$ctext mark unset anchor\n+\tif {$searchstring ne {}} {\n+\t\tset start [_get_new_anchor $this]\n+\t\tif {$dir eq \"-forwards\"} {\n+\t\t\tset start \"$start + 1c\"\n+\t\t}\n+\t\tset match [_do_search $this $start mlen]\n+\t\t$ctext tag remove sel 1.0 end\n+\t\tif {$match ne {}} {\n+\t\t\t$ctext see $match\n+\t\t\t$ctext tag add sel $match \"$match + $mlen c\"\n+\t\t}\n+\t}\n+}\n+\n+method _mark_range {first last} {\n+\tset mend $first.0\n+\twhile {1} {\n+\t\tset match [_do_search $this $mend mlen -forwards $last.end]\n+\t\tif {$match eq {}} break\n+\t\tset mend \"$match + $mlen c\"\n+\t\t$ctext tag add found $match $mend\n+\t}\n+}\n+\n+method _set_marks {doall} {\n+\tset topline [lindex [split [$ctext index @0,0] .] 0]\n+\tset botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]\n+\tif {$doall || $botline < $smarktop || $topline > $smarkbot} {\n+\t\t# no overlap with previous\n+\t\t_mark_range $this $topline $botline\n+\t\tset smarktop $topline\n+\t\tset smarkbot $botline\n+\t} else {\n+\t\tif {$topline < $smarktop} {\n+\t\t\t_mark_range $this $topline [expr {$smarktop-1}]\n+\t\t\tset smarktop $topline\n+\t\t}\n+\t\tif {$botline > $smarkbot} {\n+\t\t\t_mark_range $this [expr {$smarkbot+1}] $botline\n+\t\t\tset smarkbot $botline\n+\t\t}\n+\t}\n+}\n+\n+method scrolled {} {\n+\tif {$searchstring ne {}} {\n+\t\tafter idle [cb _set_marks 0]\n+\t}\n+}\n+\n+}\n\\ No newline at end of file\n-- \n1.6.0.20.g6148bc\n"},{"id":"92225","messageId":"1223019414-24643-3-git-send-email-angavrilov@gmail.com","threadId":"15766","inReplyTo":"1223019414-24643-1-git-send-email-angavrilov@gmail.com","subject":"[PATCH] git-gui: Fix the blame viewer destroy handler.","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-10-03T07:36:54Z","receivedAt":"2008-10-03T07:36:54Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"It did not delete the object, which is not very good.\nAlso, destroy may be fired up for subwindows, so we\nshould check %W.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n\n\tMy own bug. I hope that now I understand\n\tTcl better than 2 months ago.\n\t\n\t-- Alexander\n\n lib/blame.tcl |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/lib/blame.tcl b/lib/blame.tcl\nindex a45784c..765d08c 100644\n--- a/lib/blame.tcl\n+++ b/lib/blame.tcl\n@@ -377,11 +377,18 @@ constructor new {i_commit i_path i_jump} {\n \t\"if {{$w.file_pane} eq {%W}} {[cb _resize %h]}\"\n \n \twm protocol $top WM_DELETE_WINDOW \"destroy $top\"\n-\tbind $top <Destroy> [cb _kill]\n+\tbind $top <Destroy> [cb _handle_destroy %W]\n \n \t_load $this $i_jump\n }\n \n+method _handle_destroy {win} {\n+\tif {$win eq $w} {\n+\t\t_kill $this\n+\t\tdelete_this\n+\t}\n+}\n+\n method _kill {} {\n \tif {$current_fd ne {}} {\n \t\tkill_file_process $current_fd\n-- \n1.6.0.20.g6148bc\n"},{"id":"92229","messageId":"48E5D7E9.6060302@op5.se","threadId":"15766","inReplyTo":"1223019414-24643-2-git-send-email-angavrilov@gmail.com","subject":"Re: [PATCH] git-gui: Add a search command to the blame viewer.","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2008-10-03T08:29:29Z","receivedAt":"2008-10-03T08:29:29Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Alexander Gavrilov wrote:\n> One of the largest deficiencies in the blame viewer at\n> the moment is the impossibility to search for a text\n> string. This commit fixes it by adding a Firefox-like\n> search panel to the viewer.\n> \n> The panel can be shown by pressing F7 or clicking a\n> menu entry, and is hidden by pressing Esc. Find Next\n> is available through the F3 key.\n> \n> Implementation is based on the gitk code, but heavily\n> refactored. It now also supports case-insensitive\n> searches, and uses the text box background color to\n> signal success or failure of the search.\n> \n> Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n> ---\n> \n\nWhat with me being a total tcl nubling, I can't comment on the\npatch, but the intentions are clearly full of win and awesome.\nI was utterly surprised to notice this functionality wasn't in\nthere the first time I needed it.\n\nThanks.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"}]}