PageRenderTime 27ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/git-gui/lib/option.tcl

https://gitlab.com/Blueprint-Marketing/git
TCL | 349 lines | 318 code | 29 blank | 2 comment | 26 complexity | 4b107b289bd4aa316eabcf4f56abc1d2 MD5 | raw file
  1. # git-gui options editor
  2. # Copyright (C) 2006, 2007 Shawn Pearce
  3. proc config_check_encodings {} {
  4. global repo_config_new global_config_new
  5. set enc $global_config_new(gui.encoding)
  6. if {$enc eq {}} {
  7. set global_config_new(gui.encoding) [encoding system]
  8. } elseif {[tcl_encoding $enc] eq {}} {
  9. error_popup [mc "Invalid global encoding '%s'" $enc]
  10. return 0
  11. }
  12. set enc $repo_config_new(gui.encoding)
  13. if {$enc eq {}} {
  14. set repo_config_new(gui.encoding) [encoding system]
  15. } elseif {[tcl_encoding $enc] eq {}} {
  16. error_popup [mc "Invalid repo encoding '%s'" $enc]
  17. return 0
  18. }
  19. return 1
  20. }
  21. proc save_config {} {
  22. global default_config font_descs
  23. global repo_config global_config system_config
  24. global repo_config_new global_config_new
  25. global ui_comm_spell
  26. foreach option $font_descs {
  27. set name [lindex $option 0]
  28. set font [lindex $option 1]
  29. font configure $font \
  30. -family $global_config_new(gui.$font^^family) \
  31. -size $global_config_new(gui.$font^^size)
  32. font configure ${font}bold \
  33. -family $global_config_new(gui.$font^^family) \
  34. -size $global_config_new(gui.$font^^size)
  35. font configure ${font}italic \
  36. -family $global_config_new(gui.$font^^family) \
  37. -size $global_config_new(gui.$font^^size)
  38. set global_config_new(gui.$name) [font configure $font]
  39. unset global_config_new(gui.$font^^family)
  40. unset global_config_new(gui.$font^^size)
  41. }
  42. foreach name [array names default_config] {
  43. set value $global_config_new($name)
  44. if {$value ne $global_config($name)} {
  45. if {$value eq $system_config($name)} {
  46. catch {git config --global --unset $name}
  47. } else {
  48. regsub -all "\[{}\]" $value {"} value
  49. git config --global $name $value
  50. }
  51. set global_config($name) $value
  52. if {$value eq $repo_config($name)} {
  53. catch {git config --unset $name}
  54. set repo_config($name) $value
  55. }
  56. }
  57. }
  58. foreach name [array names default_config] {
  59. set value $repo_config_new($name)
  60. if {$value ne $repo_config($name)} {
  61. if {$value eq $global_config($name)} {
  62. catch {git config --unset $name}
  63. } else {
  64. regsub -all "\[{}\]" $value {"} value
  65. git config $name $value
  66. }
  67. set repo_config($name) $value
  68. }
  69. }
  70. if {[info exists repo_config(gui.spellingdictionary)]} {
  71. set value $repo_config(gui.spellingdictionary)
  72. if {$value eq {none}} {
  73. if {[info exists ui_comm_spell]} {
  74. $ui_comm_spell stop
  75. }
  76. } elseif {[info exists ui_comm_spell]} {
  77. $ui_comm_spell lang $value
  78. }
  79. }
  80. }
  81. proc do_options {} {
  82. global repo_config global_config font_descs
  83. global repo_config_new global_config_new
  84. global ui_comm_spell use_ttk NS
  85. array unset repo_config_new
  86. array unset global_config_new
  87. foreach name [array names repo_config] {
  88. set repo_config_new($name) $repo_config($name)
  89. }
  90. load_config 1
  91. foreach name [array names repo_config] {
  92. switch -- $name {
  93. gui.diffcontext {continue}
  94. }
  95. set repo_config_new($name) $repo_config($name)
  96. }
  97. foreach name [array names global_config] {
  98. set global_config_new($name) $global_config($name)
  99. }
  100. set w .options_editor
  101. Dialog $w
  102. wm withdraw $w
  103. wm transient $w [winfo parent $w]
  104. wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
  105. ${NS}::frame $w.buttons
  106. ${NS}::button $w.buttons.restore -text [mc "Restore Defaults"] \
  107. -default normal \
  108. -command do_restore_defaults
  109. pack $w.buttons.restore -side left
  110. ${NS}::button $w.buttons.save -text [mc Save] \
  111. -default active \
  112. -command [list do_save_config $w]
  113. pack $w.buttons.save -side right
  114. ${NS}::button $w.buttons.cancel -text [mc "Cancel"] \
  115. -default normal \
  116. -command [list destroy $w]
  117. pack $w.buttons.cancel -side right -padx 5
  118. pack $w.buttons -side bottom -fill x -pady 10 -padx 10
  119. ${NS}::labelframe $w.repo -text [mc "%s Repository" [reponame]]
  120. ${NS}::labelframe $w.global -text [mc "Global (All Repositories)"]
  121. pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
  122. pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
  123. set optid 0
  124. foreach option {
  125. {t user.name {mc "User Name"}}
  126. {t user.email {mc "Email Address"}}
  127. {b merge.summary {mc "Summarize Merge Commits"}}
  128. {i-1..5 merge.verbosity {mc "Merge Verbosity"}}
  129. {b merge.diffstat {mc "Show Diffstat After Merge"}}
  130. {t merge.tool {mc "Use Merge Tool"}}
  131. {b gui.trustmtime {mc "Trust File Modification Timestamps"}}
  132. {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
  133. {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
  134. {b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
  135. {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
  136. {i-0..100 gui.maxrecentrepo {mc "Maximum Length of Recent Repositories List"}}
  137. {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
  138. {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
  139. {i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
  140. {t gui.diffopts {mc "Additional Diff Parameters"}}
  141. {i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
  142. {t gui.newbranchtemplate {mc "New Branch Name Template"}}
  143. {c gui.encoding {mc "Default File Contents Encoding"}}
  144. {b gui.warndetachedcommit {mc "Warn before committing to a detached head"}}
  145. {s gui.stageuntracked {mc "Staging of untracked files"} {list "yes" "no" "ask"}}
  146. {b gui.displayuntracked {mc "Show untracked files"}}
  147. {i-1..99 gui.tabsize {mc "Tab spacing"}}
  148. } {
  149. set type [lindex $option 0]
  150. set name [lindex $option 1]
  151. set text [eval [lindex $option 2]]
  152. incr optid
  153. foreach f {repo global} {
  154. switch -glob -- $type {
  155. b {
  156. ${NS}::checkbutton $w.$f.$optid -text $text \
  157. -variable ${f}_config_new($name) \
  158. -onvalue true \
  159. -offvalue false
  160. pack $w.$f.$optid -side top -anchor w
  161. }
  162. i-* {
  163. regexp -- {-(\d+)\.\.(\d+)$} $type _junk min max
  164. ${NS}::frame $w.$f.$optid
  165. ${NS}::label $w.$f.$optid.l -text "$text:"
  166. pack $w.$f.$optid.l -side left -anchor w -fill x
  167. tspinbox $w.$f.$optid.v \
  168. -textvariable ${f}_config_new($name) \
  169. -from $min \
  170. -to $max \
  171. -increment 1 \
  172. -width [expr {1 + [string length $max]}]
  173. bind $w.$f.$optid.v <FocusIn> {%W selection range 0 end}
  174. pack $w.$f.$optid.v -side right -anchor e -padx 5
  175. pack $w.$f.$optid -side top -anchor w -fill x
  176. }
  177. c -
  178. t {
  179. ${NS}::frame $w.$f.$optid
  180. ${NS}::label $w.$f.$optid.l -text "$text:"
  181. ${NS}::entry $w.$f.$optid.v \
  182. -width 20 \
  183. -textvariable ${f}_config_new($name)
  184. pack $w.$f.$optid.l -side left -anchor w
  185. pack $w.$f.$optid.v -side left -anchor w \
  186. -fill x -expand 1 \
  187. -padx 5
  188. if {$type eq {c}} {
  189. menu $w.$f.$optid.m
  190. build_encoding_menu $w.$f.$optid.m \
  191. [list set ${f}_config_new($name)] 1
  192. ${NS}::button $w.$f.$optid.b \
  193. -text [mc "Change"] \
  194. -command [list popup_btn_menu \
  195. $w.$f.$optid.m $w.$f.$optid.b]
  196. pack $w.$f.$optid.b -side left -anchor w
  197. }
  198. pack $w.$f.$optid -side top -anchor w -fill x
  199. }
  200. s {
  201. set opts [eval [lindex $option 3]]
  202. ${NS}::frame $w.$f.$optid
  203. ${NS}::label $w.$f.$optid.l -text "$text:"
  204. if {$use_ttk} {
  205. ttk::combobox $w.$f.$optid.v \
  206. -textvariable ${f}_config_new($name) \
  207. -values $opts -state readonly
  208. } else {
  209. eval tk_optionMenu $w.$f.$optid.v \
  210. ${f}_config_new($name) \
  211. $opts
  212. }
  213. pack $w.$f.$optid.l -side left -anchor w -fill x
  214. pack $w.$f.$optid.v -side right -anchor e -padx 5
  215. pack $w.$f.$optid -side top -anchor w -fill x
  216. }
  217. }
  218. }
  219. }
  220. set all_dicts [linsert \
  221. [spellcheck::available_langs] \
  222. 0 \
  223. none]
  224. incr optid
  225. foreach f {repo global} {
  226. if {![info exists ${f}_config_new(gui.spellingdictionary)]} {
  227. if {[info exists ui_comm_spell]} {
  228. set value [$ui_comm_spell lang]
  229. } else {
  230. set value none
  231. }
  232. set ${f}_config_new(gui.spellingdictionary) $value
  233. }
  234. ${NS}::frame $w.$f.$optid
  235. ${NS}::label $w.$f.$optid.l -text [mc "Spelling Dictionary:"]
  236. if {$use_ttk} {
  237. ttk::combobox $w.$f.$optid.v \
  238. -textvariable ${f}_config_new(gui.spellingdictionary) \
  239. -values $all_dicts -state readonly
  240. } else {
  241. eval tk_optionMenu $w.$f.$optid.v \
  242. ${f}_config_new(gui.spellingdictionary) \
  243. $all_dicts
  244. }
  245. pack $w.$f.$optid.l -side left -anchor w -fill x
  246. pack $w.$f.$optid.v -side right -anchor e -padx 5
  247. pack $w.$f.$optid -side top -anchor w -fill x
  248. }
  249. unset all_dicts
  250. set all_fonts [lsort [font families]]
  251. foreach option $font_descs {
  252. set name [lindex $option 0]
  253. set font [lindex $option 1]
  254. set text [eval [lindex $option 2]]
  255. set global_config_new(gui.$font^^family) \
  256. [font configure $font -family]
  257. set global_config_new(gui.$font^^size) \
  258. [font configure $font -size]
  259. ${NS}::frame $w.global.$name
  260. ${NS}::label $w.global.$name.l -text "$text:"
  261. ${NS}::button $w.global.$name.b \
  262. -text [mc "Change Font"] \
  263. -command [list \
  264. tchoosefont \
  265. $w \
  266. [mc "Choose %s" $text] \
  267. global_config_new(gui.$font^^family) \
  268. global_config_new(gui.$font^^size) \
  269. ]
  270. ${NS}::label $w.global.$name.f -textvariable global_config_new(gui.$font^^family)
  271. ${NS}::label $w.global.$name.s -textvariable global_config_new(gui.$font^^size)
  272. ${NS}::label $w.global.$name.pt -text [mc "pt."]
  273. pack $w.global.$name.l -side left -anchor w
  274. pack $w.global.$name.b -side right -anchor e
  275. pack $w.global.$name.pt -side right -anchor w
  276. pack $w.global.$name.s -side right -anchor w
  277. pack $w.global.$name.f -side right -anchor w
  278. pack $w.global.$name -side top -anchor w -fill x
  279. }
  280. bind $w <Visibility> "grab $w; focus $w.buttons.save"
  281. bind $w <Key-Escape> "destroy $w"
  282. bind $w <Key-Return> [list do_save_config $w]
  283. if {[is_MacOSX]} {
  284. set t [mc "Preferences"]
  285. } else {
  286. set t [mc "Options"]
  287. }
  288. wm title $w "[appname] ([reponame]): $t"
  289. wm deiconify $w
  290. tkwait window $w
  291. }
  292. proc do_restore_defaults {} {
  293. global font_descs default_config repo_config system_config
  294. global repo_config_new global_config_new
  295. foreach name [array names default_config] {
  296. set repo_config_new($name) $system_config($name)
  297. set global_config_new($name) $system_config($name)
  298. }
  299. foreach option $font_descs {
  300. set name [lindex $option 0]
  301. set repo_config(gui.$name) $system_config(gui.$name)
  302. }
  303. apply_config
  304. foreach option $font_descs {
  305. set name [lindex $option 0]
  306. set font [lindex $option 1]
  307. set global_config_new(gui.$font^^family) \
  308. [font configure $font -family]
  309. set global_config_new(gui.$font^^size) \
  310. [font configure $font -size]
  311. }
  312. }
  313. proc do_save_config {w} {
  314. if {![config_check_encodings]} return
  315. if {[catch {save_config} err]} {
  316. error_popup [strcat [mc "Failed to completely save options:"] "\n\n$err"]
  317. }
  318. reshow_diff
  319. destroy $w
  320. }