Code

04f77c009296c88093db5eed5ca0b8647440e0c9
[git.git] / lib / choose_rev.tcl
1 # git-gui revision chooser
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 class choose_rev {
6 field w               ; # our megawidget path
7 field revtype       {}; # type of revision chosen
9 field c_head        {}; # selected local branch head
10 field c_trck        {}; # selected tracking branch
11 field c_tag         {}; # selected tag
12 field c_expr        {}; # current revision expression
14 constructor new {path {title {}}} {
15         global all_heads current_branch
17         set w $path
19         if {$title ne {}} {
20                 labelframe $w -text $title
21         } else {
22                 frame $w
23         }
24         bind $w <Destroy> [cb _delete %W]
26         if {$all_heads ne {}} {
27                 set c_head $current_branch
28                 radiobutton $w.head_r \
29                         -text {Local Branch:} \
30                         -value head \
31                         -variable @revtype
32                 eval tk_optionMenu $w.head_m @c_head $all_heads
33                 grid $w.head_r $w.head_m -sticky w
34                 if {$revtype eq {}} {
35                         set revtype head
36                 }
37                 trace add variable @c_head write [cb _select head]
38         }
40         set all_trackings [all_tracking_branches]
41         if {$all_trackings ne {}} {
42                 set c_trck [lindex $all_trackings 0]
43                 radiobutton $w.trck_r \
44                         -text {Tracking Branch:} \
45                         -value trck \
46                         -variable @revtype
47                 eval tk_optionMenu $w.trck_m @c_trck $all_trackings
48                 grid $w.trck_r $w.trck_m -sticky w
49                 if {$revtype eq {}} {
50                         set revtype trck
51                 }
52                 trace add variable @c_trck write [cb _select trck]
53         }
55         set all_tags [load_all_tags]
56         if {$all_tags ne {}} {
57                 set c_tag [lindex $all_tags 0]
58                 radiobutton $w.tag_r \
59                         -text {Tag:} \
60                         -value tag \
61                         -variable @revtype
62                 eval tk_optionMenu $w.tag_m @c_tag $all_tags
63                 grid $w.tag_r $w.tag_m -sticky w
64                 if {$revtype eq {}} {
65                         set revtype tag
66                 }
67                 trace add variable @c_tag write [cb _select tag]
68         }
70         radiobutton $w.expr_r \
71                 -text {Revision Expression:} \
72                 -value expr \
73                 -variable @revtype
74         entry $w.expr_t \
75                 -borderwidth 1 \
76                 -relief sunken \
77                 -width 50 \
78                 -textvariable @c_expr \
79                 -validate key \
80                 -validatecommand [cb _validate %d %S]
81         grid $w.expr_r $w.expr_t -sticky we -padx {0 5}
82         if {$revtype eq {}} {
83                 set revtype expr
84         }
86         grid columnconfigure $w 1 -weight 1
87         return $this
88 }
90 method get {} {
91         switch -- $revtype {
92         head { return $c_head }
93         trck { return $c_trck }
94         tag  { return $c_tag  }
95         expr { return $c_expr }
96         default { error "unknown type of revision" }
97         }
98 }
100 method get_commit {} {
101         set rev [get $this]
102         return [git rev-parse --verify "${rev}^0"]
105 method _validate {d S} {
106         if {$d == 1} {
107                 if {[regexp {\s} $S]} {
108                         return 0
109                 }
110                 if {[string length $S] > 0} {
111                         set revtype expr
112                 }
113         }
114         return 1
117 method _select {value args} {
118         set revtype $value
121 method _delete {current} {
122         if {$current eq $w} {
123                 delete_this
124         }