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 <angavrilov@gmail.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Alexander Gavrilov committed
Nov 2, 2008 at 21:59 UTC
218a900bd8efd0d49f8a0d9491aa4786a998d4f4
1 file changed
+163
-44
gitk
+163
-44
@@ -3467,8 +3467,8 @@ proc shellsplit {str} {
3467
# Code to implement multiple views
3468
3469
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
3472
3473
set newishighlight $ishighlight
3474
set top .gitkview
@@ -3477,59 +3477,173 @@ proc newview {ishighlight} {
3477
return
3478
}
3479
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
3483
vieweditor $top $nextviewnum [mc "Gitk view definition"]
3484
}
3485
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
+
3569
proc editview {} {
3570
global curview
3488
- global viewname viewperm newviewname newviewperm
3489
- global viewargs newviewargs viewargscmd newviewargscmd
3571
+ global viewname viewperm newviewname newviewopts
3572
+ global viewargs viewargscmd
3573
3574
set top .gitkvedit-$curview
3575
if {[winfo exists $top]} {
3576
raise $top
3577
return
3578
}
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)
3583
vieweditor $top $curview "Gitk: edit view $viewname($curview)"
3584
}
3585
3586
proc vieweditor {top n title} {
3504
- global newviewname newviewperm viewfiles bgcolor
3587
+ global newviewname newviewopts viewfiles bgcolor
3588
+ global known_view_options
3589
3590
toplevel $top
3591
wm title $top $title
3592
wm transient $top .
3593
+
3594
+ # View name
3595
+ frame $top.nfr
3596
label $top.nl -text [mc "Name"]
3597
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 \
3644
-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
3647
if {[info exists viewfiles($n)]} {
3648
foreach f $viewfiles($n) {
3649
$top.t insert end $f
@@ -3538,15 +3652,19 @@ proc vieweditor {top n title} {
3652
$top.t delete {end - 1c} end
3653
$top.t mark set insert 0.0
3654
}
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
3656
frame $top.buts
3657
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]
3659
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]
3662
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
3664
grid columnconfigure $top.buts 0 -weight 1 -uniform a
3665
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
3668
focus $top.t
3669
}
3670
@@ -3567,13 +3685,13 @@ proc allviewmenus {n op args} {
3685
# doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
3686
}
3687
3570
-proc newviewok {top n} {
3688
+proc newviewok {top n {apply 0}} {
3689
global nextviewnum newviewperm newviewname newishighlight
3690
global viewname viewfiles viewperm selectedview curview
3573
- global viewargs newviewargs viewargscmd newviewargscmd viewhlmenu
3691
+ global viewargs viewargscmd newviewopts viewhlmenu
3692
3693
if {[catch {
3576
- set newargs [shellsplit $newviewargs($n)]
3694
+ set newargs [encode_view_opts $n]
3695
} err]} {
3696
error_popup "[mc "Error in commit selection arguments:"] $err" $top
3697
return
@@ -3589,10 +3707,10 @@ proc newviewok {top n} {
3707
# creating a new view
3708
incr nextviewnum
3709
set viewname($n) $newviewname($n)
3592
- set viewperm($n) $newviewperm($n)
3710
+ set viewperm($n) $newviewopts($n,perm)
3711
set viewfiles($n) $files
3712
set viewargs($n) $newargs
3595
- set viewargscmd($n) $newviewargscmd($n)
3713
+ set viewargscmd($n) $newviewopts($n,cmd)
3714
addviewmenu $n
3715
if {!$newishighlight} {
3716
run showview $n
@@ -3601,7 +3719,7 @@ proc newviewok {top n} {
3719
}
3720
} else {
3721
# editing an existing view
3604
- set viewperm($n) $newviewperm($n)
3722
+ set viewperm($n) $newviewopts($n,perm)
3723
if {$newviewname($n) ne $viewname($n)} {
3724
set viewname($n) $newviewname($n)
3725
doviewmenu .bar.view 5 [list showview $n] \
@@ -3610,15 +3728,16 @@ proc newviewok {top n} {
3728
# entryconf [list -label $viewname($n) -value $viewname($n)]
3729
}
3730
if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
3613
- $newviewargscmd($n) ne $viewargscmd($n)} {
3731
+ $newviewopts($n,cmd) ne $viewargscmd($n)} {
3732
set viewfiles($n) $files
3733
set viewargs($n) $newargs
3616
- set viewargscmd($n) $newviewargscmd($n)
3734
+ set viewargscmd($n) $newviewopts($n,cmd)
3735
if {$curview == $n} {
3736
run reloadcommits
3737
}
3738
}
3739
}
3740
+ if {$apply} return
3741
catch {destroy $top}
3742
}
3743