04f77c009296c88093db5eed5ca0b8647440e0c9
   1# git-gui revision chooser
   2# Copyright (C) 2006, 2007 Shawn Pearce
   3
   4class choose_rev {
   5
   6field w               ; # our megawidget path
   7field revtype       {}; # type of revision chosen
   8
   9field c_head        {}; # selected local branch head
  10field c_trck        {}; # selected tracking branch
  11field c_tag         {}; # selected tag
  12field c_expr        {}; # current revision expression
  13
  14constructor new {path {title {}}} {
  15        global all_heads current_branch
  16
  17        set w $path
  18
  19        if {$title ne {}} {
  20                labelframe $w -text $title
  21        } else {
  22                frame $w
  23        }
  24        bind $w <Destroy> [cb _delete %W]
  25
  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        }
  39
  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        }
  54
  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        }
  69
  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        }
  85
  86        grid columnconfigure $w 1 -weight 1
  87        return $this
  88}
  89
  90method 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}
  99
 100method get_commit {} {
 101        set rev [get $this]
 102        return [git rev-parse --verify "${rev}^0"]
 103}
 104
 105method _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
 115}
 116
 117method _select {value args} {
 118        set revtype $value
 119}
 120
 121method _delete {current} {
 122        if {$current eq $w} {
 123                delete_this
 124        }
 125}
 126
 127}