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

gitk: add menu item for editing the current view

This allows the user to change the name of the view, whether it is permanent, and the list of files/directories for the view. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Apr 25, 2006 at 21:21 UTC d16c0812a9472794175b2543c2aa2df45a927202
1 file changed +90 -37
gitk
+90 -37
@@ -360,6 +360,7 @@ proc makewindow {} {
360 menu .bar.view -font $uifont
361 .bar add cascade -label "View" -menu .bar.view
362 .bar.view add command -label "New view..." -command newview
363 + .bar.view add command -label "Edit view..." -command editview
364 .bar.view add command -label "Delete view" -command delview -state disabled
365 .bar.view add separator
366 .bar.view add radiobutton -label "All files" -command {showview 0} \
@@ -806,31 +807,59 @@ f Scroll diff view to next file
807 }
808
809 proc newview {} {
809 - global newviewname nextviewnum newviewtop newviewperm uifont
810 + global nextviewnum newviewname newviewperm uifont
811
812 set top .gitkview
813 if {[winfo exists $top]} {
814 raise $top
815 return
816 }
816 - set newviewtop $top
817 + set newviewname($nextviewnum) "View $nextviewnum"
818 + set newviewperm($nextviewnum) 0
819 + vieweditor $top $nextviewnum "Gitk view definition"
820 +}
821 +
822 +proc editview {} {
823 + global curview
824 + global viewname viewperm newviewname newviewperm
825 +
826 + set top .gitkvedit-$curview
827 + if {[winfo exists $top]} {
828 + raise $top
829 + return
830 + }
831 + set newviewname($curview) $viewname($curview)
832 + set newviewperm($curview) $viewperm($curview)
833 + vieweditor $top $curview "Gitk: edit view $viewname($curview)"
834 +}
835 +
836 +proc vieweditor {top n title} {
837 + global newviewname newviewperm viewfiles
838 + global uifont
839 +
840 toplevel $top
818 - wm title $top "Gitk view definition"
841 + wm title $top $title
842 label $top.nl -text "Name" -font $uifont
820 - entry $top.name -width 20 -textvariable newviewname
821 - set newviewname "View $nextviewnum"
843 + entry $top.name -width 20 -textvariable newviewname($n)
844 grid $top.nl $top.name -sticky w -pady 5
823 - set newviewperm 0
824 - checkbutton $top.perm -text "Remember this view" -variable newviewperm
845 + checkbutton $top.perm -text "Remember this view" -variable newviewperm($n)
846 grid $top.perm - -pady 5 -sticky w
847 message $top.l -aspect 500 -font $uifont \
848 -text "Enter files and directories to include, one per line:"
849 grid $top.l - -sticky w
850 text $top.t -width 40 -height 10 -background white
851 + if {[info exists viewfiles($n)]} {
852 + foreach f $viewfiles($n) {
853 + $top.t insert end $f
854 + $top.t insert end "\n"
855 + }
856 + $top.t delete {end - 1c} end
857 + $top.t mark set insert 0.0
858 + }
859 grid $top.t - -sticky w -padx 5
860 frame $top.buts
832 - button $top.buts.ok -text "OK" -command newviewok
833 - button $top.buts.can -text "Cancel" -command newviewcan
861 + button $top.buts.ok -text "OK" -command [list newviewok $top $n]
862 + button $top.buts.can -text "Cancel" -command [list destroy $top]
863 grid $top.buts.ok $top.buts.can
864 grid columnconfigure $top.buts 0 -weight 1 -uniform a
865 grid columnconfigure $top.buts 1 -weight 1 -uniform a
@@ -838,47 +867,64 @@ proc newview {} {
867 focus $top.t
868 }
869
841 -proc newviewok {} {
842 - global newviewtop nextviewnum newviewperm
843 - global viewname viewfiles viewperm selectedview
870 +proc viewmenuitem {n} {
871 + set nmenu [.bar.view index end]
872 + set targetcmd [list showview $n]
873 + for {set i 6} {$i <= $nmenu} {incr i} {
874 + if {[.bar.view entrycget $i -command] eq $targetcmd} {
875 + return $i
876 + }
877 + }
878 + return {}
879 +}
880 +
881 +proc newviewok {top n} {
882 + global nextviewnum newviewperm newviewname
883 + global viewname viewfiles viewperm selectedview curview
884
845 - set n $nextviewnum
846 - incr nextviewnum
847 - set viewname($n) [$newviewtop.name get]
848 - set viewperm($n) $newviewperm
885 set files {}
850 - foreach f [split [$newviewtop.t get 0.0 end] "\n"] {
886 + foreach f [split [$top.t get 0.0 end] "\n"] {
887 set ft [string trim $f]
888 if {$ft ne {}} {
889 lappend files $ft
890 }
891 }
856 - set viewfiles($n) $files
857 - catch {destroy $newviewtop}
858 - unset newviewtop
859 - .bar.view add radiobutton -label $viewname($n) \
860 - -command [list showview $n] -variable selectedview -value $n
861 - after idle showview $n
862 -}
863 -
864 -proc newviewcan {} {
865 - global newviewtop
866 -
867 - catch {destroy $newviewtop}
868 - unset newviewtop
892 + if {![info exists viewfiles($n)]} {
893 + # creating a new view
894 + incr nextviewnum
895 + set viewname($n) $newviewname($n)
896 + set viewperm($n) $newviewperm($n)
897 + set viewfiles($n) $files
898 + .bar.view add radiobutton -label $viewname($n) \
899 + -command [list showview $n] -variable selectedview -value $n
900 + after idle showview $n
901 + } else {
902 + # editing an existing view
903 + set viewperm($n) $newviewperm($n)
904 + if {$newviewname($n) ne $viewname($n)} {
905 + set viewname($n) $newviewname($n)
906 + set i [viewmenuitem $n]
907 + if {$i ne {}} {
908 + .bar.view entryconf $i -label $viewname($n)
909 + }
910 + }
911 + if {$files ne $viewfiles($n)} {
912 + set viewfiles($n) $files
913 + if {$curview == $n} {
914 + after idle updatecommits
915 + }
916 + }
917 + }
918 + catch {destroy $top}
919 }
920
921 proc delview {} {
922 global curview viewdata viewperm
923
924 if {$curview == 0} return
875 - set nmenu [.bar.view index end]
876 - set targetcmd [list showview $curview]
877 - for {set i 5} {$i <= $nmenu} {incr i} {
878 - if {[.bar.view entrycget $i -command] eq $targetcmd} {
879 - .bar.view delete $i
880 - break
881 - }
925 + set i [viewmenuitem $curview]
926 + if {$i ne {}} {
927 + .bar.view delete $i
928 }
929 set viewdata($curview) {}
930 set viewperm($curview) 0
@@ -958,6 +1004,7 @@ proc showview {n} {
1004 set curview $n
1005 set selectedview $n
1006 .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}]
1007 + .bar.view entryconf 3 -state [expr {$n == 0? "disabled": "normal"}]
1008
1009 if {![info exists viewdata($n)]} {
1010 set pending_select $selid
@@ -1025,6 +1072,11 @@ proc showview {n} {
1072 } else {
1073 . config -cursor watch
1074 settextcursor watch
1075 + if {$phase eq "getcommits"} {
1076 + global mainfont
1077 + $canv create text 3 3 -anchor nw -text "Reading commits..." \
1078 + -font $mainfont -tags textitems
1079 + }
1080 }
1081 }
1082
@@ -4260,6 +4312,7 @@ if {$cmdline_files ne {}} {
4312 .bar.view add radiobutton -label $viewname(1) -command {showview 1} \
4313 -variable selectedview -value 1
4314 .bar.view entryconf 2 -state normal
4315 + .bar.view entryconf 3 -state normal
4316 }
4317
4318 if {[info exists permviews]} {