|
| 1 | +#!/bin/sh |
| 2 | +# Tcl ignores the next line -*- tcl -*- \ |
| 3 | +exec wish "$0" -- "$@" |
| 4 | + |
| 5 | +# This is an implementation of a simple yes no dialog |
| 6 | +# which is injected into the git commandline by git gui |
| 7 | +# in case a yesno question needs to be answered. |
| 8 | +# |
| 9 | +# The window title, which defaults to "Question?", can be |
| 10 | +# overridden via the optional `--title` command-line |
| 11 | +# option. |
| 12 | + |
| 13 | +set NS {} |
| 14 | +set use_ttk [package vsatisfies [package provide Tk] 8.5] |
| 15 | +if {$use_ttk} { |
| 16 | + set NS ttk |
| 17 | +} |
| 18 | + |
| 19 | +set title "Question?" |
| 20 | +if {$argc < 1} { |
| 21 | + puts stderr "Usage: $argv0 <question>" |
| 22 | + exit 1 |
| 23 | +} else { |
| 24 | + if {$argc > 2 && [lindex $argv 0] == "--title"} { |
| 25 | + set title [lindex $argv 1] |
| 26 | + set argv [lreplace $argv 0 1] |
| 27 | + } |
| 28 | + set prompt [join $argv " "] |
| 29 | +} |
| 30 | + |
| 31 | +${NS}::frame .t |
| 32 | +${NS}::label .t.m -text $prompt -justify center -width 40 |
| 33 | +.t.m configure -wraplength 400 |
| 34 | +pack .t.m -side top -fill x -padx 20 -pady 20 -expand 1 |
| 35 | +pack .t -side top -fill x -ipadx 20 -ipady 20 -expand 1 |
| 36 | + |
| 37 | +${NS}::frame .b |
| 38 | +${NS}::frame .b.left -width 200 |
| 39 | +${NS}::button .b.yes -text Yes -command {exit 0} |
| 40 | +${NS}::button .b.no -text No -command {exit 1} |
| 41 | + |
| 42 | +pack .b.left -side left -expand 1 -fill x |
| 43 | +pack .b.yes -side left -expand 1 |
| 44 | +pack .b.no -side right -expand 1 -ipadx 5 |
| 45 | +pack .b -side bottom -fill x -ipadx 20 -ipady 15 |
| 46 | + |
| 47 | +bind . <Key-Return> {exit 0} |
| 48 | +bind . <Key-Escape> {exit 1} |
| 49 | + |
| 50 | +if {$::tcl_platform(platform) eq {windows}} { |
| 51 | + set icopath [file dirname [file normalize $argv0]] |
| 52 | + if {[file tail $icopath] eq {git-core}} { |
| 53 | + set icopath [file dirname $icopath] |
| 54 | + } |
| 55 | + set icopath [file dirname $icopath] |
| 56 | + set icopath [file join $icopath share git git-for-windows.ico] |
| 57 | + if {[file exists $icopath]} { |
| 58 | + wm iconbitmap . -default $icopath |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +wm title . $title |
| 63 | +tk::PlaceWindow . |
0 commit comments