@matheusbsbs / matheus-bagliano / commits / e9937d2a03
Fork 0

[PATCH] Make gitk work reasonably well on Cygwin.

The gitk gui layout was completely broken on Cygwin. If gitk was started without previous geometry in ~/.gitk, the user could drag the window sashes to get a useable layout. However, if ~/.gitk existed, this was not possible at all. The fix was to rewrite makewindow, changing the toplevel containers and the particular geometry information saved between sessions. Numerous bugs in both the Cygwin and the Linux Tk versions make this a delicate balancing act: the version here works in both but many subtle variants are competely broken in one or the other environment. Three user visible changes result: 1 - The viewer is fully functional under Cygwin. 2 - The search bar moves from the bottom to the top of the lower left pane. This was necessary to get around a layout problem on Cygwin. 3 - The window size and position is saved and restored between sessions. Again, this is necessary to get around a layout problem on Cygwin. Signed-off-by: Mark Levedahl <mdl123@verizon.net> Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Paul Mackerras <paulus@samba.org>

Junio C Hamano committed Feb 1, 2007 at 08:46 UTC e9937d2a03a426b50a424927fbd0cdfbe2ac2b40
1 file changed +150 -126
gitk
+150 -126
@@ -435,56 +435,59 @@ proc makewindow {} {
435 .bar.help configure -font $uifont
436 . configure -menu .bar
437
438 - if {![info exists geometry(canv1)]} {
439 - set geometry(canv1) [expr {45 * $charspc}]
440 - set geometry(canv2) [expr {30 * $charspc}]
441 - set geometry(canv3) [expr {15 * $charspc}]
442 - set geometry(canvh) [expr {25 * $linespc + 4}]
443 - set geometry(ctextw) 80
444 - set geometry(ctexth) 30
445 - set geometry(cflistw) 30
446 - }
438 + # the gui has upper and lower half, parts of a paned window.
439 panedwindow .ctop -orient vertical
448 - if {[info exists geometry(width)]} {
449 - .ctop conf -width $geometry(width) -height $geometry(height)
450 - set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
451 - set geometry(ctexth) [expr {($texth - 8) /
452 - [font metrics $textfont -linespace]}]
453 - }
454 - frame .ctop.top
455 - frame .ctop.top.bar
456 - frame .ctop.top.lbar
457 - pack .ctop.top.lbar -side bottom -fill x
458 - pack .ctop.top.bar -side bottom -fill x
459 - set cscroll .ctop.top.csb
460 - scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
461 - pack $cscroll -side right -fill y
462 - panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
463 - pack .ctop.top.clist -side top -fill both -expand 1
464 - .ctop add .ctop.top
465 - set canv .ctop.top.clist.canv
466 - canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
440 +
441 + # possibly use assumed geometry
442 + if {![info exists geometry(topheight)]} {
443 + set geometry(topheight) [expr {15 * $linespc}]
444 + set geometry(topwidth) [expr {80 * $charspc}]
445 + set geometry(botheight) [expr {15 * $linespc}]
446 + set geometry(botwidth) [expr {50 * $charspc}]
447 + set geometry(canv) [expr {40 * $charspc}]
448 + set geometry(canv2) [expr {20 * $charspc}]
449 + set geometry(canv3) [expr {20 * $charspc}]
450 + }
451 +
452 + # the upper half will have a paned window, a scroll bar to the right, and some stuff below
453 + frame .tf -height $geometry(topheight) -width $geometry(topwidth)
454 + frame .tf.histframe
455 + panedwindow .tf.histframe.pwclist -orient horizontal -sashpad 0 -handlesize 4
456 +
457 + # create three canvases
458 + set cscroll .tf.histframe.csb
459 + set canv .tf.histframe.pwclist.canv
460 + canvas $canv -width $geometry(canv) \
461 -background $bgcolor -bd 0 \
462 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
469 - .ctop.top.clist add $canv
470 - set canv2 .ctop.top.clist.canv2
471 - canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
463 + .tf.histframe.pwclist add $canv
464 + set canv2 .tf.histframe.pwclist.canv2
465 + canvas $canv2 -width $geometry(canv2) \
466 -background $bgcolor -bd 0 -yscrollincr $linespc
473 - .ctop.top.clist add $canv2
474 - set canv3 .ctop.top.clist.canv3
475 - canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
467 + .tf.histframe.pwclist add $canv2
468 + set canv3 .tf.histframe.pwclist.canv3
469 + canvas $canv3 -width $geometry(canv3) \
470 -background $bgcolor -bd 0 -yscrollincr $linespc
477 - .ctop.top.clist add $canv3
478 - bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
471 + .tf.histframe.pwclist add $canv3
472 +
473 + # a scroll bar to rule them
474 + scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
475 + pack $cscroll -side right -fill y
476 + bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
477 lappend bglist $canv $canv2 $canv3
478 + pack .tf.histframe.pwclist -fill both -expand 1 -side left
479
481 - set sha1entry .ctop.top.bar.sha1
480 + # we have two button bars at bottom of top frame. Bar 1
481 + frame .tf.bar
482 + frame .tf.lbar -height 15
483 +
484 + set sha1entry .tf.bar.sha1
485 set entries $sha1entry
483 - set sha1but .ctop.top.bar.sha1label
486 + set sha1but .tf.bar.sha1label
487 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
488 -command gotocommit -width 8 -font $uifont
489 $sha1but conf -disabledforeground [$sha1but cget -foreground]
487 - pack .ctop.top.bar.sha1label -side left
490 + pack .tf.bar.sha1label -side left
491 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
492 trace add variable sha1string write sha1change
493 pack $sha1entry -side left -pady 2
@@ -505,91 +508,105 @@ proc makewindow {} {
508 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
509 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
510 }
508 - button .ctop.top.bar.leftbut -image bm-left -command goback \
511 + button .tf.bar.leftbut -image bm-left -command goback \
512 -state disabled -width 26
510 - pack .ctop.top.bar.leftbut -side left -fill y
511 - button .ctop.top.bar.rightbut -image bm-right -command goforw \
513 + pack .tf.bar.leftbut -side left -fill y
514 + button .tf.bar.rightbut -image bm-right -command goforw \
515 -state disabled -width 26
513 - pack .ctop.top.bar.rightbut -side left -fill y
516 + pack .tf.bar.rightbut -side left -fill y
517
515 - button .ctop.top.bar.findbut -text "Find" -command dofind -font $uifont
516 - pack .ctop.top.bar.findbut -side left
518 + button .tf.bar.findbut -text "Find" -command dofind -font $uifont
519 + pack .tf.bar.findbut -side left
520 set findstring {}
518 - set fstring .ctop.top.bar.findstring
521 + set fstring .tf.bar.findstring
522 lappend entries $fstring
523 entry $fstring -width 30 -font $textfont -textvariable findstring
524 trace add variable findstring write find_change
522 - pack $fstring -side left -expand 1 -fill x
525 + pack $fstring -side left -expand 1 -fill x -in .tf.bar
526 set findtype Exact
524 - set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
525 - findtype Exact IgnCase Regexp]
527 + set findtypemenu [tk_optionMenu .tf.bar.findtype \
528 + findtype Exact IgnCase Regexp]
529 trace add variable findtype write find_change
527 - .ctop.top.bar.findtype configure -font $uifont
528 - .ctop.top.bar.findtype.menu configure -font $uifont
530 + .tf.bar.findtype configure -font $uifont
531 + .tf.bar.findtype.menu configure -font $uifont
532 set findloc "All fields"
530 - tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
533 + tk_optionMenu .tf.bar.findloc findloc "All fields" Headline \
534 Comments Author Committer
535 trace add variable findloc write find_change
533 - .ctop.top.bar.findloc configure -font $uifont
534 - .ctop.top.bar.findloc.menu configure -font $uifont
535 - pack .ctop.top.bar.findloc -side right
536 - pack .ctop.top.bar.findtype -side right
537 -
538 - label .ctop.top.lbar.flabel -text "Highlight: Commits " \
539 - -font $uifont
540 - pack .ctop.top.lbar.flabel -side left -fill y
536 + .tf.bar.findloc configure -font $uifont
537 + .tf.bar.findloc.menu configure -font $uifont
538 + pack .tf.bar.findloc -side right
539 + pack .tf.bar.findtype -side right
540 +
541 + # build up the bottom bar of upper window
542 + label .tf.lbar.flabel -text "Highlight: Commits " \
543 + -font $uifont
544 + pack .tf.lbar.flabel -side left -fill y
545 set gdttype "touching paths:"
542 - set gm [tk_optionMenu .ctop.top.lbar.gdttype gdttype "touching paths:" \
543 - "adding/removing string:"]
546 + set gm [tk_optionMenu .tf.lbar.gdttype gdttype "touching paths:" \
547 + "adding/removing string:"]
548 trace add variable gdttype write hfiles_change
549 $gm conf -font $uifont
546 - .ctop.top.lbar.gdttype conf -font $uifont
547 - pack .ctop.top.lbar.gdttype -side left -fill y
548 - entry .ctop.top.lbar.fent -width 25 -font $textfont \
550 + .tf.lbar.gdttype conf -font $uifont
551 + pack .tf.lbar.gdttype -side left -fill y
552 + entry .tf.lbar.fent -width 25 -font $textfont \
553 -textvariable highlight_files
554 trace add variable highlight_files write hfiles_change
551 - lappend entries .ctop.top.lbar.fent
552 - pack .ctop.top.lbar.fent -side left -fill x -expand 1
553 - label .ctop.top.lbar.vlabel -text " OR in view" -font $uifont
554 - pack .ctop.top.lbar.vlabel -side left -fill y
555 + lappend entries .tf.lbar.fent
556 + pack .tf.lbar.fent -side left -fill x -expand 1
557 + label .tf.lbar.vlabel -text " OR in view" -font $uifont
558 + pack .tf.lbar.vlabel -side left -fill y
559 global viewhlmenu selectedhlview
556 - set viewhlmenu [tk_optionMenu .ctop.top.lbar.vhl selectedhlview None]
560 + set viewhlmenu [tk_optionMenu .tf.lbar.vhl selectedhlview None]
561 $viewhlmenu entryconf None -command delvhighlight
562 $viewhlmenu conf -font $uifont
559 - .ctop.top.lbar.vhl conf -font $uifont
560 - pack .ctop.top.lbar.vhl -side left -fill y
561 - label .ctop.top.lbar.rlabel -text " OR " -font $uifont
562 - pack .ctop.top.lbar.rlabel -side left -fill y
563 + .tf.lbar.vhl conf -font $uifont
564 + pack .tf.lbar.vhl -side left -fill y
565 + label .tf.lbar.rlabel -text " OR " -font $uifont
566 + pack .tf.lbar.rlabel -side left -fill y
567 global highlight_related
564 - set m [tk_optionMenu .ctop.top.lbar.relm highlight_related None \
565 - "Descendent" "Not descendent" "Ancestor" "Not ancestor"]
568 + set m [tk_optionMenu .tf.lbar.relm highlight_related None \
569 + "Descendent" "Not descendent" "Ancestor" "Not ancestor"]
570 $m conf -font $uifont
567 - .ctop.top.lbar.relm conf -font $uifont
571 + .tf.lbar.relm conf -font $uifont
572 trace add variable highlight_related write vrel_change
569 - pack .ctop.top.lbar.relm -side left -fill y
570 -
571 - panedwindow .ctop.cdet -orient horizontal
572 - .ctop add .ctop.cdet
573 - frame .ctop.cdet.left
574 - frame .ctop.cdet.left.bot
575 - pack .ctop.cdet.left.bot -side bottom -fill x
576 - button .ctop.cdet.left.bot.search -text "Search" -command dosearch \
573 + pack .tf.lbar.relm -side left -fill y
574 +
575 + # Finish putting the upper half of the viewer together
576 + pack .tf.lbar -in .tf -side bottom -fill x
577 + pack .tf.bar -in .tf -side bottom -fill x
578 + pack .tf.histframe -fill both -side top -expand 1
579 + .ctop add .tf
580 +
581 + # now build up the bottom
582 + panedwindow .pwbottom -orient horizontal
583 +
584 + # lower left, a text box over search bar, scroll bar to the right
585 + # if we know window height, then that will set the lower text height, otherwise
586 + # we set lower text height which will drive window height
587 + if {[info exists geometry(main)]} {
588 + frame .bleft -width $geometry(botwidth)
589 + } else {
590 + frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
591 + }
592 + frame .bleft.top
593 +
594 + button .bleft.top.search -text "Search" -command dosearch \
595 -font $uifont
578 - pack .ctop.cdet.left.bot.search -side left -padx 5
579 - set sstring .ctop.cdet.left.bot.sstring
596 + pack .bleft.top.search -side left -padx 5
597 + set sstring .bleft.top.sstring
598 entry $sstring -width 20 -font $textfont -textvariable searchstring
599 lappend entries $sstring
600 trace add variable searchstring write incrsearch
601 pack $sstring -side left -expand 1 -fill x
584 - set ctext .ctop.cdet.left.ctext
602 + set ctext .bleft.ctext
603 text $ctext -background $bgcolor -foreground $fgcolor \
604 -state disabled -font $textfont \
587 - -width $geometry(ctextw) -height $geometry(ctexth) \
605 -yscrollcommand scrolltext -wrap none
589 - scrollbar .ctop.cdet.left.sb -command "$ctext yview"
590 - pack .ctop.cdet.left.sb -side right -fill y
606 + scrollbar .bleft.sb -command "$ctext yview"
607 + pack .bleft.top -side top -fill x
608 + pack .bleft.sb -side right -fill y
609 pack $ctext -side left -fill both -expand 1
592 - .ctop.cdet add .ctop.cdet.left
610 lappend bglist $ctext
611 lappend fglist $ctext
612
@@ -620,36 +637,45 @@ proc makewindow {} {
637 $ctext tag conf msep -font [concat $textfont bold]
638 $ctext tag conf found -back yellow
639
623 - frame .ctop.cdet.right
624 - frame .ctop.cdet.right.mode
625 - radiobutton .ctop.cdet.right.mode.patch -text "Patch" \
640 + .pwbottom add .bleft
641 +
642 + # lower right
643 + frame .bright
644 + frame .bright.mode
645 + radiobutton .bright.mode.patch -text "Patch" \
646 -command reselectline -variable cmitmode -value "patch"
627 - radiobutton .ctop.cdet.right.mode.tree -text "Tree" \
647 + radiobutton .bright.mode.tree -text "Tree" \
648 -command reselectline -variable cmitmode -value "tree"
629 - grid .ctop.cdet.right.mode.patch .ctop.cdet.right.mode.tree -sticky ew
630 - pack .ctop.cdet.right.mode -side top -fill x
631 - set cflist .ctop.cdet.right.cfiles
649 + grid .bright.mode.patch .bright.mode.tree -sticky ew
650 + pack .bright.mode -side top -fill x
651 + set cflist .bright.cfiles
652 set indent [font measure $mainfont "nn"]
633 - text $cflist -width $geometry(cflistw) \
653 + text $cflist \
654 -background $bgcolor -foreground $fgcolor \
655 -font $mainfont \
656 -tabs [list $indent [expr {2 * $indent}]] \
637 - -yscrollcommand ".ctop.cdet.right.sb set" \
657 + -yscrollcommand ".bright.sb set" \
658 -cursor [. cget -cursor] \
659 -spacing1 1 -spacing3 1
660 lappend bglist $cflist
661 lappend fglist $cflist
642 - scrollbar .ctop.cdet.right.sb -command "$cflist yview"
643 - pack .ctop.cdet.right.sb -side right -fill y
662 + scrollbar .bright.sb -command "$cflist yview"
663 + pack .bright.sb -side right -fill y
664 pack $cflist -side left -fill both -expand 1
665 $cflist tag configure highlight \
666 -background [$cflist cget -selectbackground]
667 $cflist tag configure bold -font [concat $mainfont bold]
648 - .ctop.cdet add .ctop.cdet.right
649 - bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
668
651 - pack .ctop -side top -fill both -expand 1
669 + .pwbottom add .bright
670 + .ctop add .pwbottom
671
672 + # restore window position if known
673 + if {[info exists geometry(main)]} {
674 + wm geometry . "$geometry(main)"
675 + }
676 +
677 + bind .pwbottom <Configure> {resizecdetpanes %W %w}
678 + pack .ctop -fill both -expand 1
679 bindall <1> {selcanvline %W %x %y}
680 #bindall <B1-Motion> {selcanvline %W %x %y}
681 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
@@ -802,18 +828,16 @@ proc savestuff {w} {
828 puts $f [list set fgcolor $fgcolor]
829 puts $f [list set colors $colors]
830 puts $f [list set diffcolors $diffcolors]
805 - puts $f "set geometry(width) [winfo width .ctop]"
806 - puts $f "set geometry(height) [winfo height .ctop]"
807 - puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
808 - puts $f "set geometry(canv2) [expr {[winfo width $canv2]-2}]"
809 - puts $f "set geometry(canv3) [expr {[winfo width $canv3]-2}]"
810 - puts $f "set geometry(canvh) [expr {[winfo height $canv]-2}]"
811 - set wid [expr {([winfo width $ctext] - 8) \
812 - / [font measure $textfont "0"]}]
813 - puts $f "set geometry(ctextw) $wid"
814 - set wid [expr {([winfo width $cflist] - 11) \
815 - / [font measure [$cflist cget -font] "0"]}]
816 - puts $f "set geometry(cflistw) $wid"
831 +
832 + puts $f "set geometry(main) [winfo geometry .]"
833 + puts $f "set geometry(topwidth) [winfo width .tf]"
834 + puts $f "set geometry(topheight) [winfo height .tf]"
835 + puts $f "set geometry(canv) [expr {[winfo width $canv]-0}]"
836 + puts $f "set geometry(canv2) [expr {[winfo width $canv2]-0}]"
837 + puts $f "set geometry(canv3) [expr {[winfo width $canv3]-0}]"
838 + puts $f "set geometry(botwidth) [winfo width .bleft]"
839 + puts $f "set geometry(botheight) [winfo height .bleft]"
840 +
841 puts -nonewline $f "set permviews {"
842 for {set v 0} {$v < $nextviewnum} {incr v} {
843 if {$viewperm($v)} {
@@ -4043,11 +4067,11 @@ proc addtohistory {cmd} {
4067 }
4068 incr historyindex
4069 if {$historyindex > 1} {
4046 - .ctop.top.bar.leftbut conf -state normal
4070 + .tf.bar.leftbut conf -state normal
4071 } else {
4048 - .ctop.top.bar.leftbut conf -state disabled
4072 + .tf.bar.leftbut conf -state disabled
4073 }
4050 - .ctop.top.bar.rightbut conf -state disabled
4074 + .tf.bar.rightbut conf -state disabled
4075 }
4076
4077 proc godo {elt} {
@@ -4067,10 +4091,10 @@ proc goback {} {
4091 if {$historyindex > 1} {
4092 incr historyindex -1
4093 godo [lindex $history [expr {$historyindex - 1}]]
4070 - .ctop.top.bar.rightbut conf -state normal
4094 + .tf.bar.rightbut conf -state normal
4095 }
4096 if {$historyindex <= 1} {
4073 - .ctop.top.bar.leftbut conf -state disabled
4097 + .tf.bar.leftbut conf -state disabled
4098 }
4099 }
4100
@@ -4081,10 +4105,10 @@ proc goforw {} {
4105 set cmd [lindex $history $historyindex]
4106 incr historyindex
4107 godo $cmd
4084 - .ctop.top.bar.leftbut conf -state normal
4108 + .tf.bar.leftbut conf -state normal
4109 }
4110 if {$historyindex >= [llength $history]} {
4087 - .ctop.top.bar.rightbut conf -state disabled
4111 + .tf.bar.rightbut conf -state disabled
4112 }
4113 }
4114
@@ -4591,7 +4615,7 @@ proc searchmarkvisible {doall} {
4615 proc scrolltext {f0 f1} {
4616 global searchstring
4617
4594 - .ctop.cdet.left.sb set $f0 $f1
4618 + .bleft.sb set $f0 $f1
4619 if {$searchstring ne {}} {
4620 searchmarkvisible 0
4621 }