blob: c0fa69af561b7789cdcfea46b14bf6d2646f5962 [file] [log] [blame]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -04001# git-gui branch (create/delete) support
2# Copyright (C) 2006, 2007 Shawn Pearce
3
Shawn O. Pearceaba15f72008-02-20 23:37:07 -05004proc _error_parent {} {
Shawn O. Pearce85ec3e72008-02-21 12:22:08 -05005 set p [grab current .]
6 if {$p eq {}} {
7 return .
8 }
9 return $p
Shawn O. Pearceaba15f72008-02-20 23:37:07 -050010}
11
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040012proc error_popup {msg} {
13 set title [appname]
14 if {[reponame] ne {}} {
15 append title " ([reponame])"
16 }
17 set cmd [list tk_messageBox \
18 -icon error \
19 -type ok \
Christian Stimming1ac17952007-07-21 14:21:34 +020020 -title [append "$title: " [mc "error"]] \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040021 -message $msg]
Shawn O. Pearceaba15f72008-02-20 23:37:07 -050022 if {[winfo ismapped [_error_parent]]} {
23 lappend cmd -parent [_error_parent]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040024 }
25 eval $cmd
26}
27
28proc warn_popup {msg} {
29 set title [appname]
30 if {[reponame] ne {}} {
31 append title " ([reponame])"
32 }
33 set cmd [list tk_messageBox \
34 -icon warning \
35 -type ok \
Christian Stimming1ac17952007-07-21 14:21:34 +020036 -title [append "$title: " [mc "warning"]] \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040037 -message $msg]
Shawn O. Pearceaba15f72008-02-20 23:37:07 -050038 if {[winfo ismapped [_error_parent]]} {
39 lappend cmd -parent [_error_parent]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040040 }
41 eval $cmd
42}
43
Shawn O. Pearceaba15f72008-02-20 23:37:07 -050044proc info_popup {msg} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040045 set title [appname]
46 if {[reponame] ne {}} {
47 append title " ([reponame])"
48 }
49 tk_messageBox \
Shawn O. Pearce094fbbf2008-02-28 01:28:45 -050050 -parent [_error_parent] \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040051 -icon info \
52 -type ok \
53 -title $title \
54 -message $msg
55}
56
57proc ask_popup {msg} {
58 set title [appname]
59 if {[reponame] ne {}} {
60 append title " ([reponame])"
61 }
Shawn O. Pearce23701642007-07-17 22:45:53 -040062 set cmd [list tk_messageBox \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040063 -icon question \
64 -type yesno \
65 -title $title \
66 -message $msg]
Shawn O. Pearceaba15f72008-02-20 23:37:07 -050067 if {[winfo ismapped [_error_parent]]} {
68 lappend cmd -parent [_error_parent]
Shawn O. Pearce23701642007-07-17 22:45:53 -040069 }
70 eval $cmd
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040071}
72
Shawn O. Pearceed76cb72008-01-20 14:46:59 -050073proc hook_failed_popup {hook msg {is_fatal 1}} {
Pat Thoytsc80d7be2010-01-26 00:05:31 +000074 global use_ttk NS
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040075 set w .hookfail
Pat Thoytsc80d7be2010-01-26 00:05:31 +000076 Dialog $w
77 wm withdraw $w
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040078
Pat Thoytsc80d7be2010-01-26 00:05:31 +000079 ${NS}::frame $w.m
80 ${NS}::label $w.m.l1 -text "$hook hook failed:" \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040081 -anchor w \
82 -justify left \
83 -font font_uibold
84 text $w.m.t \
Philipp A. Hartmannc382fdd2008-03-05 17:54:22 +010085 -background white \
86 -foreground black \
87 -borderwidth 1 \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040088 -relief sunken \
89 -width 80 -height 10 \
90 -font font_diff \
91 -yscrollcommand [list $w.m.sby set]
Pat Thoytsc80d7be2010-01-26 00:05:31 +000092 ${NS}::scrollbar $w.m.sby -command [list $w.m.t yview]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040093 pack $w.m.l1 -side top -fill x
Shawn O. Pearceed76cb72008-01-20 14:46:59 -050094 if {$is_fatal} {
Pat Thoytsc80d7be2010-01-26 00:05:31 +000095 ${NS}::label $w.m.l2 \
Shawn O. Pearceed76cb72008-01-20 14:46:59 -050096 -text [mc "You must correct the above errors before committing."] \
97 -anchor w \
98 -justify left \
99 -font font_uibold
100 pack $w.m.l2 -side bottom -fill x
101 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400102 pack $w.m.sby -side right -fill y
103 pack $w.m.t -side left -fill both -expand 1
104 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
105
106 $w.m.t insert 1.0 $msg
107 $w.m.t conf -state disabled
108
Pat Thoytsc80d7be2010-01-26 00:05:31 +0000109 ${NS}::button $w.ok -text OK \
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400110 -width 15 \
111 -command "destroy $w"
112 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
113
114 bind $w <Visibility> "grab $w; focus $w"
115 bind $w <Key-Return> "destroy $w"
Shawn O. Pearcec87238e2008-01-20 14:43:38 -0500116 wm title $w [strcat "[appname] ([reponame]): " [mc "error"]]
Pat Thoytsc80d7be2010-01-26 00:05:31 +0000117 wm deiconify $w
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400118 tkwait window $w
119}