Skip to content

Commit 218a900

Browse files
angavrilovpaulusmack
authored andcommitted
gitk: Implement a user-friendly Edit View dialog
Originally gitk required the user to specify all limiting options manually in the same field with the list of commits. It is rather unfriendly for new users, who may not know which options can be used, or, indeed, that it is possible to specify them at all. This commit modifies the dialog to present the most useful options as individual fields. Note that options that may be useful to an extent, but produce a severely broken view, are deliberately not included. It is still possible to specify options in the commit list field, but when the dialog is reopened, they will be extracted into their own separate fields. Signed-off-by: Alexander Gavrilov <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 887a791 commit 218a900

File tree

1 file changed

+163
-44
lines changed

1 file changed

+163
-44
lines changed

gitk

Lines changed: 163 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,8 +3467,8 @@ proc shellsplit {str} {
34673467
# Code to implement multiple views
34683468

34693469
proc newview {ishighlight} {
3470-
global nextviewnum newviewname newviewperm newishighlight
3471-
global newviewargs revtreeargs viewargscmd newviewargscmd curview
3470+
global nextviewnum newviewname newishighlight
3471+
global revtreeargs viewargscmd newviewopts curview
34723472

34733473
set newishighlight $ishighlight
34743474
set top .gitkview
@@ -3477,59 +3477,173 @@ proc newview {ishighlight} {
34773477
return
34783478
}
34793479
set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3480-
set newviewperm($nextviewnum) 0
3481-
set newviewargs($nextviewnum) [shellarglist $revtreeargs]
3482-
set newviewargscmd($nextviewnum) $viewargscmd($curview)
3480+
set newviewopts($nextviewnum,perm) 0
3481+
set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3482+
decode_view_opts $nextviewnum $revtreeargs
34833483
vieweditor $top $nextviewnum [mc "Gitk view definition"]
34843484
}
34853485

3486+
set known_view_options {
3487+
{perm b . {} {mc "Remember this view"}}
3488+
{args t50= + {} {mc "Commits to include (arguments to git log):"}}
3489+
{all b * "--all" {mc "Use all refs"}}
3490+
{dorder b . {"--date-order" "-d"} {mc "Strictly sort by date"}}
3491+
{lright b . "--left-right" {mc "Mark branch sides"}}
3492+
{since t15 + {"--since=*" "--after=*"} {mc "Since date:"}}
3493+
{until t15 . {"--until=*" "--before=*"} {mc "Until date:"}}
3494+
{limit t10 + "--max-count=*" {mc "Max count:"}}
3495+
{skip t10 . "--skip=*" {mc "Skip:"}}
3496+
{first b . "--first-parent" {mc "Limit to first parent"}}
3497+
{cmd t50= + {} {mc "Command to generate more commits to include:"}}
3498+
}
3499+
3500+
proc encode_view_opts {n} {
3501+
global known_view_options newviewopts
3502+
3503+
set rargs [list]
3504+
foreach opt $known_view_options {
3505+
set patterns [lindex $opt 3]
3506+
if {$patterns eq {}} continue
3507+
set pattern [lindex $patterns 0]
3508+
3509+
set val $newviewopts($n,[lindex $opt 0])
3510+
3511+
if {[lindex $opt 1] eq "b"} {
3512+
if {$val} {
3513+
lappend rargs $pattern
3514+
}
3515+
} else {
3516+
set val [string trim $val]
3517+
if {$val ne {}} {
3518+
set pfix [string range $pattern 0 end-1]
3519+
lappend rargs $pfix$val
3520+
}
3521+
}
3522+
}
3523+
return [concat $rargs [shellsplit $newviewopts($n,args)]]
3524+
}
3525+
3526+
proc decode_view_opts {n view_args} {
3527+
global known_view_options newviewopts
3528+
3529+
foreach opt $known_view_options {
3530+
if {[lindex $opt 1] eq "b"} {
3531+
set val 0
3532+
} else {
3533+
set val {}
3534+
}
3535+
set newviewopts($n,[lindex $opt 0]) $val
3536+
}
3537+
set oargs [list]
3538+
foreach arg $view_args {
3539+
if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
3540+
&& ![info exists found(limit)]} {
3541+
set newviewopts($n,limit) $cnt
3542+
set found(limit) 1
3543+
continue
3544+
}
3545+
catch { unset val }
3546+
foreach opt $known_view_options {
3547+
set id [lindex $opt 0]
3548+
if {[info exists found($id)]} continue
3549+
foreach pattern [lindex $opt 3] {
3550+
if {![string match $pattern $arg]} continue
3551+
if {[lindex $opt 1] ne "b"} {
3552+
set size [string length $pattern]
3553+
set val [string range $arg [expr {$size-1}] end]
3554+
} else {
3555+
set val 1
3556+
}
3557+
set newviewopts($n,$id) $val
3558+
set found($id) 1
3559+
break
3560+
}
3561+
if {[info exists val]} break
3562+
}
3563+
if {[info exists val]} continue
3564+
lappend oargs $arg
3565+
}
3566+
set newviewopts($n,args) [shellarglist $oargs]
3567+
}
3568+
34863569
proc editview {} {
34873570
global curview
3488-
global viewname viewperm newviewname newviewperm
3489-
global viewargs newviewargs viewargscmd newviewargscmd
3571+
global viewname viewperm newviewname newviewopts
3572+
global viewargs viewargscmd
34903573

34913574
set top .gitkvedit-$curview
34923575
if {[winfo exists $top]} {
34933576
raise $top
34943577
return
34953578
}
3496-
set newviewname($curview) $viewname($curview)
3497-
set newviewperm($curview) $viewperm($curview)
3498-
set newviewargs($curview) [shellarglist $viewargs($curview)]
3499-
set newviewargscmd($curview) $viewargscmd($curview)
3579+
set newviewname($curview) $viewname($curview)
3580+
set newviewopts($curview,perm) $viewperm($curview)
3581+
set newviewopts($curview,cmd) $viewargscmd($curview)
3582+
decode_view_opts $curview $viewargs($curview)
35003583
vieweditor $top $curview "Gitk: edit view $viewname($curview)"
35013584
}
35023585

35033586
proc vieweditor {top n title} {
3504-
global newviewname newviewperm viewfiles bgcolor
3587+
global newviewname newviewopts viewfiles bgcolor
3588+
global known_view_options
35053589

35063590
toplevel $top
35073591
wm title $top $title
35083592
wm transient $top .
3593+
3594+
# View name
3595+
frame $top.nfr
35093596
label $top.nl -text [mc "Name"]
35103597
entry $top.name -width 20 -textvariable newviewname($n)
3511-
grid $top.nl $top.name -sticky w -pady 5
3512-
checkbutton $top.perm -text [mc "Remember this view"] \
3513-
-variable newviewperm($n)
3514-
grid $top.perm - -pady 5 -sticky w
3515-
message $top.al -aspect 1000 \
3516-
-text [mc "Commits to include (arguments to git log):"]
3517-
grid $top.al - -sticky w -pady 5
3518-
entry $top.args -width 50 -textvariable newviewargs($n) \
3519-
-background $bgcolor
3520-
grid $top.args - -sticky ew -padx 5
3521-
3522-
message $top.ac -aspect 1000 \
3523-
-text [mc "Command to generate more commits to include:"]
3524-
grid $top.ac - -sticky w -pady 5
3525-
entry $top.argscmd -width 50 -textvariable newviewargscmd($n) \
3526-
-background white
3527-
grid $top.argscmd - -sticky ew -padx 5
3528-
3529-
message $top.l -aspect 1000 \
3598+
pack $top.nfr -in $top -fill x -pady 5 -padx 3
3599+
pack $top.nl -in $top.nfr -side left -padx {0 30}
3600+
pack $top.name -in $top.nfr -side left
3601+
3602+
# View options
3603+
set cframe $top.nfr
3604+
set cexpand 0
3605+
set cnt 0
3606+
foreach opt $known_view_options {
3607+
set id [lindex $opt 0]
3608+
set type [lindex $opt 1]
3609+
set flags [lindex $opt 2]
3610+
set title [eval [lindex $opt 4]]
3611+
set lxpad 0
3612+
3613+
if {$flags eq "+" || $flags eq "*"} {
3614+
set cframe $top.fr$cnt
3615+
incr cnt
3616+
frame $cframe
3617+
pack $cframe -in $top -fill x -pady 3 -padx 3
3618+
set cexpand [expr {$flags eq "*"}]
3619+
} else {
3620+
set lxpad 5
3621+
}
3622+
3623+
if {$type eq "b"} {
3624+
checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
3625+
pack $cframe.c_$id -in $cframe -side left \
3626+
-padx [list $lxpad 0] -expand $cexpand -anchor w
3627+
} elseif {[regexp {^t(\d+)$} $type type sz]} {
3628+
message $cframe.l_$id -aspect 1500 -text $title
3629+
entry $cframe.e_$id -width $sz -background $bgcolor \
3630+
-textvariable newviewopts($n,$id)
3631+
pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
3632+
pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
3633+
} elseif {[regexp {^t(\d+)=$} $type type sz]} {
3634+
message $cframe.l_$id -aspect 1500 -text $title
3635+
entry $cframe.e_$id -width $sz -background $bgcolor \
3636+
-textvariable newviewopts($n,$id)
3637+
pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
3638+
pack $cframe.e_$id -in $cframe -side top -fill x
3639+
}
3640+
}
3641+
3642+
# Path list
3643+
message $top.l -aspect 1500 \
35303644
-text [mc "Enter files and directories to include, one per line:"]
3531-
grid $top.l - -sticky w
3532-
text $top.t -width 40 -height 10 -background $bgcolor -font uifont
3645+
pack $top.l -in $top -side top -pady [list 7 0] -anchor w -padx 3
3646+
text $top.t -width 40 -height 5 -background $bgcolor -font uifont
35333647
if {[info exists viewfiles($n)]} {
35343648
foreach f $viewfiles($n) {
35353649
$top.t insert end $f
@@ -3538,15 +3652,19 @@ proc vieweditor {top n title} {
35383652
$top.t delete {end - 1c} end
35393653
$top.t mark set insert 0.0
35403654
}
3541-
grid $top.t - -sticky ew -padx 5
3655+
pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
35423656
frame $top.buts
35433657
button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
3658+
button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
35443659
button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
3660+
bind $top <Control-Return> [list newviewok $top $n]
3661+
bind $top <F5> [list newviewok $top $n 1]
35453662
bind $top <Escape> [list destroy $top]
3546-
grid $top.buts.ok $top.buts.can
3663+
grid $top.buts.ok $top.buts.apply $top.buts.can
35473664
grid columnconfigure $top.buts 0 -weight 1 -uniform a
35483665
grid columnconfigure $top.buts 1 -weight 1 -uniform a
3549-
grid $top.buts - -pady 10 -sticky ew
3666+
grid columnconfigure $top.buts 2 -weight 1 -uniform a
3667+
pack $top.buts -in $top -side top -fill x
35503668
focus $top.t
35513669
}
35523670

@@ -3567,13 +3685,13 @@ proc allviewmenus {n op args} {
35673685
# doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
35683686
}
35693687

3570-
proc newviewok {top n} {
3688+
proc newviewok {top n {apply 0}} {
35713689
global nextviewnum newviewperm newviewname newishighlight
35723690
global viewname viewfiles viewperm selectedview curview
3573-
global viewargs newviewargs viewargscmd newviewargscmd viewhlmenu
3691+
global viewargs viewargscmd newviewopts viewhlmenu
35743692

35753693
if {[catch {
3576-
set newargs [shellsplit $newviewargs($n)]
3694+
set newargs [encode_view_opts $n]
35773695
} err]} {
35783696
error_popup "[mc "Error in commit selection arguments:"] $err" $top
35793697
return
@@ -3589,10 +3707,10 @@ proc newviewok {top n} {
35893707
# creating a new view
35903708
incr nextviewnum
35913709
set viewname($n) $newviewname($n)
3592-
set viewperm($n) $newviewperm($n)
3710+
set viewperm($n) $newviewopts($n,perm)
35933711
set viewfiles($n) $files
35943712
set viewargs($n) $newargs
3595-
set viewargscmd($n) $newviewargscmd($n)
3713+
set viewargscmd($n) $newviewopts($n,cmd)
35963714
addviewmenu $n
35973715
if {!$newishighlight} {
35983716
run showview $n
@@ -3601,7 +3719,7 @@ proc newviewok {top n} {
36013719
}
36023720
} else {
36033721
# editing an existing view
3604-
set viewperm($n) $newviewperm($n)
3722+
set viewperm($n) $newviewopts($n,perm)
36053723
if {$newviewname($n) ne $viewname($n)} {
36063724
set viewname($n) $newviewname($n)
36073725
doviewmenu .bar.view 5 [list showview $n] \
@@ -3610,15 +3728,16 @@ proc newviewok {top n} {
36103728
# entryconf [list -label $viewname($n) -value $viewname($n)]
36113729
}
36123730
if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
3613-
$newviewargscmd($n) ne $viewargscmd($n)} {
3731+
$newviewopts($n,cmd) ne $viewargscmd($n)} {
36143732
set viewfiles($n) $files
36153733
set viewargs($n) $newargs
3616-
set viewargscmd($n) $newviewargscmd($n)
3734+
set viewargscmd($n) $newviewopts($n,cmd)
36173735
if {$curview == $n} {
36183736
run reloadcommits
36193737
}
36203738
}
36213739
}
3740+
if {$apply} return
36223741
catch {destroy $top}
36233742
}
36243743

0 commit comments

Comments
 (0)