62230efe430f93f7bbdc051cb3687e39b93283c9
   1# git-gui branch checkout support
   2# Copyright (C) 2007 Shawn Pearce
   3
   4class branch_checkout {
   5
   6field w              ; # widget path
   7field w_rev          ; # mega-widget to pick the initial revision
   8
   9field opt_fetch     1; # refetch tracking branch if used?
  10field opt_detach    0; # force a detached head case?
  11
  12constructor dialog {} {
  13        make_toplevel top w
  14        wm title $top "[appname] ([reponame]): Checkout Branch"
  15        if {$top ne {.}} {
  16                wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
  17        }
  18
  19        label $w.header -text {Checkout Branch} -font font_uibold
  20        pack $w.header -side top -fill x
  21
  22        frame $w.buttons
  23        button $w.buttons.create -text Checkout \
  24                -default active \
  25                -command [cb _checkout]
  26        pack $w.buttons.create -side right
  27        button $w.buttons.cancel -text {Cancel} \
  28                -command [list destroy $w]
  29        pack $w.buttons.cancel -side right -padx 5
  30        pack $w.buttons -side bottom -fill x -pady 10 -padx 10
  31
  32        set w_rev [::choose_rev::new $w.rev {Revision}]
  33        pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
  34
  35        labelframe $w.options -text {Options}
  36
  37        checkbutton $w.options.fetch \
  38                -text {Fetch Tracking Branch} \
  39                -variable @opt_fetch
  40        pack $w.options.fetch -anchor nw
  41
  42        checkbutton $w.options.detach \
  43                -text {Detach From Local Branch} \
  44                -variable @opt_detach
  45        pack $w.options.detach -anchor nw
  46
  47        pack $w.options -anchor nw -fill x -pady 5 -padx 5
  48
  49        bind $w <Visibility> [cb _visible]
  50        bind $w <Key-Escape> [list destroy $w]
  51        bind $w <Key-Return> [cb _checkout]\;break
  52        tkwait window $w
  53}
  54
  55method _checkout {} {
  56        set spec [$w_rev get_tracking_branch]
  57        if {$spec ne {} && $opt_fetch} {
  58                set new {}
  59        } elseif {[catch {set new [$w_rev commit_or_die]}]} {
  60                return
  61        }
  62
  63        if {$opt_detach} {
  64                set ref {}
  65        } else {
  66                set ref [$w_rev get_local_branch]
  67        }
  68
  69        set co [::checkout_op::new [$w_rev get] $new $ref]
  70        $co parent $w
  71        $co enable_checkout 1
  72        if {$spec ne {} && $opt_fetch} {
  73                $co enable_fetch $spec
  74        }
  75
  76        if {[$co run]} {
  77                destroy $w
  78        } else {
  79                $w_rev focus_filter
  80        }
  81}
  82
  83method _visible {} {
  84        grab $w
  85        $w_rev focus_filter
  86}
  87
  88}