git-gui / lib / branch_checkout.tclon commit Merge branch 'maint-1.6.0' into maint (f081731)
   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 [append "[appname] ([reponame]): " [mc "Checkout Branch"]]
  15        if {$top ne {.}} {
  16                wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
  17        }
  18
  19        label $w.header -text [mc "Checkout Branch"] -font font_uibold
  20        pack $w.header -side top -fill x
  21
  22        frame $w.buttons
  23        button $w.buttons.create -text [mc Checkout] \
  24                -default active \
  25                -command [cb _checkout]
  26        pack $w.buttons.create -side right
  27        button $w.buttons.cancel -text [mc 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 [mc Revision]]
  33        $w_rev bind_listbox <Double-Button-1> [cb _checkout]
  34        pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
  35
  36        labelframe $w.options -text [mc Options]
  37
  38        checkbutton $w.options.fetch \
  39                -text [mc "Fetch Tracking Branch"] \
  40                -variable @opt_fetch
  41        pack $w.options.fetch -anchor nw
  42
  43        checkbutton $w.options.detach \
  44                -text [mc "Detach From Local Branch"] \
  45                -variable @opt_detach
  46        pack $w.options.detach -anchor nw
  47
  48        pack $w.options -anchor nw -fill x -pady 5 -padx 5
  49
  50        bind $w <Visibility> [cb _visible]
  51        bind $w <Key-Escape> [list destroy $w]
  52        bind $w <Key-Return> [cb _checkout]\;break
  53        tkwait window $w
  54}
  55
  56method _checkout {} {
  57        set spec [$w_rev get_tracking_branch]
  58        if {$spec ne {} && $opt_fetch} {
  59                set new {}
  60        } elseif {[catch {set new [$w_rev commit_or_die]}]} {
  61                return
  62        }
  63
  64        if {$opt_detach} {
  65                set ref {}
  66        } else {
  67                set ref [$w_rev get_local_branch]
  68        }
  69
  70        set co [::checkout_op::new [$w_rev get] $new $ref]
  71        $co parent $w
  72        $co enable_checkout 1
  73        if {$spec ne {} && $opt_fetch} {
  74                $co enable_fetch $spec
  75        }
  76
  77        if {[$co run]} {
  78                destroy $w
  79        } else {
  80                $w_rev focus_filter
  81        }
  82}
  83
  84method _visible {} {
  85        grab $w
  86        $w_rev focus_filter
  87}
  88
  89}