git-gui: Refactor options menu into an options dialog.
I decided that the options menu was going to turn into a mess after a while as I start to add additional features to git-gui. The better approach would be to create a dialog that lets the user edit the options, including their --global options. We also wisely let the user press Cancel (or destroy the window) to abort any sort of option editing session, without the options being changed. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 12, 2006 at 03:47 UTC
51f4d16b1d8e2e709f28a4e52b951236950cb1d5
1 file changed
+158
-46
git-gui
+158
-46
@@ -14,49 +14,90 @@ set gitdir {}
14
##
15
## config
16
17
-proc load_repo_config {} {
18
- global repo_config
19
- global cfg_trust_mtime
17
+set default_config(gui.trustmtime) false
18
+
19
+proc is_many_config {name} {
20
+ switch -glob -- $name {
21
+ remote.*.fetch -
22
+ remote.*.push
23
+ {return 1}
24
+ *
25
+ {return 0}
26
+ }
27
+}
28
29
+proc load_config {} {
30
+ global repo_config global_config default_config
31
+
32
+ array unset global_config
33
array unset repo_config
34
+ catch {
35
+ set fd_rc [open "| git repo-config --global --list" r]
36
+ while {[gets $fd_rc line] >= 0} {
37
+ if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
38
+ if {[is_many_config $name]} {
39
+ lappend global_config($name) $value
40
+ } else {
41
+ set global_config($name) $value
42
+ }
43
+ }
44
+ }
45
+ close $fd_rc
46
+ }
47
catch {
48
set fd_rc [open "| git repo-config --list" r]
49
while {[gets $fd_rc line] >= 0} {
50
if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
26
- lappend repo_config($name) $value
51
+ if {[is_many_config $name]} {
52
+ lappend repo_config($name) $value
53
+ } else {
54
+ set repo_config($name) $value
55
+ }
56
}
57
}
58
close $fd_rc
59
}
60
32
- if {[catch {set cfg_trust_mtime \
33
- [lindex $repo_config(gui.trustmtime) 0]
34
- }]} {
35
- set cfg_trust_mtime false
61
+ foreach name [array names default_config] {
62
+ if {[catch {set v $global_config($name)}]} {
63
+ set global_config($name) $default_config($name)
64
+ }
65
+ if {[catch {set v $repo_config($name)}]} {
66
+ set repo_config($name) $default_config($name)
67
+ }
68
}
69
}
70
39
-proc save_my_config {} {
40
- global repo_config
41
- global cfg_trust_mtime
71
+proc save_config {} {
72
+ global repo_config global_config default_config
73
+ global repo_config_new global_config_new
74
43
- if {[catch {set rc_trustMTime $repo_config(gui.trustmtime)}]} {
44
- set rc_trustMTime [list false]
45
- }
46
- if {$cfg_trust_mtime != [lindex $rc_trustMTime 0]} {
47
- exec git repo-config gui.trustMTime $cfg_trust_mtime
48
- set repo_config(gui.trustmtime) [list $cfg_trust_mtime]
75
+ foreach name [array names global_config_new] {
76
+ set value $global_config_new($name)
77
+ if {$value != $global_config($name)} {
78
+ if {$value == $default_config($name)} {
79
+ catch {exec git repo-config --global --unset $name}
80
+ } else {
81
+ catch {exec git repo-config --global $name $value}
82
+ }
83
+ set global_config($name) $value
84
+ if {$value == $repo_config($name)} {
85
+ catch {exec git repo-config --unset $name}
86
+ set repo_config($name) $value
87
+ }
88
+ }
89
}
90
51
- set cfg_geometry [wm geometry .]
52
- append cfg_geometry " [lindex [.vpane sash coord 0] 1]"
53
- append cfg_geometry " [lindex [.vpane.files sash coord 0] 0]"
54
- if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
55
- set rc_geometry [list [list]]
56
- }
57
- if {$cfg_geometry != [lindex $rc_geometry 0]} {
58
- exec git repo-config gui.geometry $cfg_geometry
59
- set repo_config(gui.geometry) [list $cfg_geometry]
91
+ foreach name [array names repo_config_new] {
92
+ set value $repo_config_new($name)
93
+ if {$value != $repo_config($name)} {
94
+ if {$value == $global_config($name)} {
95
+ catch {exec git repo-config --unset $name}
96
+ } else {
97
+ catch {exec git repo-config $name $value}
98
+ }
99
+ set repo_config($name) $value
100
+ }
101
}
102
}
103
@@ -117,7 +158,7 @@ if {$appname == {git-citool}} {
158
set single_commit 1
159
}
160
120
-load_repo_config
161
+load_config
162
163
######################################################################
164
##
@@ -183,7 +224,7 @@ proc update_status {{final Ready.}} {
224
global HEAD PARENT commit_type
225
global ui_index ui_other ui_status_value ui_comm
226
global status_active file_states
186
- global cfg_trust_mtime
227
+ global repo_config
228
229
if {$status_active || ![lock_index read]} return
230
@@ -209,7 +250,7 @@ proc update_status {{final Ready.}} {
250
$ui_comm edit reset
251
}
252
212
- if {$cfg_trust_mtime == {true}} {
253
+ if {$repo_config(gui.trustmtime) == {true}} {
254
update_status_stage2 {} $final
255
} else {
256
set status_active 1
@@ -409,7 +450,7 @@ proc handle_empty_diff {} {
450
451
The modification date of this file was updated by another
452
application and you currently have the Trust File Modification
412
-Timestamps feature enabled, so Git did not automatically detect
453
+Timestamps option enabled, so Git did not automatically detect
454
that there are no content differences in this file.
455
456
This file will now be removed from the modified files list, to
@@ -502,7 +543,7 @@ proc show_diff {path {w {}} {lno {}}} {
543
544
proc read_diff {fd} {
545
global ui_diff ui_status_value diff_3way diff_active
505
- global cfg_trust_mtime
546
+ global repo_config
547
548
while {[gets $fd line] >= 0} {
549
if {[string match {diff --git *} $line]} continue
@@ -550,7 +591,8 @@ proc read_diff {fd} {
591
unlock_index
592
set ui_status_value {Ready.}
593
553
- if {$cfg_trust_mtime && [$ui_diff index end] == {2.0}} {
594
+ if {$repo_config(gui.trustmtime) == {true}
595
+ && [$ui_diff index end] == {2.0}} {
596
handle_empty_diff
597
}
598
}
@@ -1314,7 +1356,6 @@ proc hook_failed_popup {hook msg} {
1356
1357
set w .hookfail
1358
toplevel $w
1317
- wm transient $w .
1359
1360
frame $w.m
1361
label $w.m.l1 -text "$hook hook failed:" \
@@ -1535,11 +1576,13 @@ proc do_repack {} {
1576
set is_quitting 0
1577
1578
proc do_quit {} {
1538
- global gitdir ui_comm is_quitting
1579
+ global gitdir ui_comm is_quitting repo_config
1580
1581
if {$is_quitting} return
1582
set is_quitting 1
1583
1584
+ # -- Stash our current commit buffer.
1585
+ #
1586
set save [file join $gitdir GITGUI_MSG]
1587
set msg [string trim [$ui_comm get 0.0 end]]
1588
if {[$ui_comm edit modified] && $msg != {}} {
@@ -1552,7 +1595,19 @@ proc do_quit {} {
1595
file delete $save
1596
}
1597
1555
- save_my_config
1598
+ # -- Stash our current window geometry into this repository.
1599
+ #
1600
+ set cfg_geometry [list]
1601
+ lappend cfg_geometry [wm geometry .]
1602
+ lappend cfg_geometry [lindex [.vpane sash coord 0] 1]
1603
+ lappend cfg_geometry [lindex [.vpane.files sash coord 0] 0]
1604
+ if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
1605
+ set rc_geometry {}
1606
+ }
1607
+ if {$cfg_geometry != $rc_geometry} {
1608
+ catch {exec git repo-config gui.geometry $cfg_geometry}
1609
+ }
1610
+
1611
destroy .
1612
}
1613
@@ -1624,6 +1679,69 @@ proc do_commit {} {
1679
commit_tree
1680
}
1681
1682
+proc do_options {} {
1683
+ global appname gitdir
1684
+ global repo_config global_config
1685
+ global repo_config_new global_config_new
1686
+
1687
+ load_config
1688
+ array unset repo_config_new
1689
+ array unset global_config_new
1690
+ foreach name [array names repo_config] {
1691
+ set repo_config_new($name) $repo_config($name)
1692
+ }
1693
+ foreach name [array names global_config] {
1694
+ set global_config_new($name) $global_config($name)
1695
+ }
1696
+
1697
+ set w .options_editor
1698
+ toplevel $w
1699
+
1700
+ label $w.header -text "$appname Options" \
1701
+ -font font_uibold
1702
+ pack $w.header -side top -fill x
1703
+
1704
+ frame $w.buttons
1705
+ button $w.buttons.save -text Save \
1706
+ -font font_ui \
1707
+ -command "save_config; destroy $w"
1708
+ pack $w.buttons.save -side right
1709
+ button $w.buttons.cancel -text {Cancel} \
1710
+ -font font_ui \
1711
+ -command "destroy $w"
1712
+ pack $w.buttons.cancel -side right
1713
+ pack $w.buttons -side bottom -anchor e -pady 10 -padx 10
1714
+
1715
+ labelframe $w.repo -text {This Repository} \
1716
+ -relief raised -borderwidth 2
1717
+ labelframe $w.global -text {Global (All Repositories)} \
1718
+ -relief raised -borderwidth 2
1719
+ pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
1720
+ pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
1721
+
1722
+ foreach option {
1723
+ {trustmtime {Trust File Modification Timestamps}}
1724
+ } {
1725
+ set name [lindex $option 0]
1726
+ set text [lindex $option 1]
1727
+ foreach f {repo global} {
1728
+ checkbutton $w.$f.$name -text $text \
1729
+ -variable ${f}_config_new(gui.$name) \
1730
+ -onvalue true \
1731
+ -offvalue false \
1732
+ -font font_ui
1733
+ pack $w.$f.$name -side top -anchor w
1734
+ }
1735
+ }
1736
+
1737
+ bind $w <Visibility> "grab $w; focus $w"
1738
+ bind $w <Key-Escape> "destroy $w"
1739
+ wm title $w "$appname ([lindex [file split \
1740
+ [file normalize [file dirname $gitdir]]] \
1741
+ end]): Options"
1742
+ tkwait window $w
1743
+}
1744
+
1745
# shift == 1: left click
1746
# 3: right click
1747
proc click {w x y shift wx wy} {
@@ -1690,7 +1808,6 @@ menu .mbar -tearoff 0
1808
.mbar add cascade -label Fetch -menu .mbar.fetch
1809
.mbar add cascade -label Pull -menu .mbar.pull
1810
.mbar add cascade -label Push -menu .mbar.push
1693
-.mbar add cascade -label Options -menu .mbar.options
1811
. configure -menu .mbar
1812
1813
# -- Project Menu
@@ -1739,6 +1856,10 @@ menu .mbar.edit
1856
-command {catch {[focus] tag add sel 0.0 end}} \
1857
-accelerator $M1T-A \
1858
-font font_ui
1859
+.mbar.edit add separator
1860
+.mbar.edit add command -label {Options...} \
1861
+ -command do_options \
1862
+ -font font_ui
1863
1864
# -- Commit Menu
1865
menu .mbar.commit
@@ -1779,15 +1900,6 @@ menu .mbar.pull
1900
# -- Push Menu
1901
menu .mbar.push
1902
1782
-# -- Options Menu
1783
-menu .mbar.options
1784
-.mbar.options add checkbutton \
1785
- -label {Trust File Modification Timestamps} \
1786
- -font font_ui \
1787
- -offvalue false \
1788
- -onvalue true \
1789
- -variable cfg_trust_mtime
1790
-
1903
# -- Main Window Layout
1904
panedwindow .vpane -orient vertical
1905
panedwindow .vpane.files -orient horizontal
@@ -2032,7 +2144,7 @@ pack .status -anchor w -side bottom -fill x
2144
2145
# -- Load geometry
2146
catch {
2035
-set gm [lindex $repo_config(gui.geometry) 0]
2147
+set gm $repo_config(gui.geometry)
2148
wm geometry . [lindex $gm 0]
2149
.vpane sash place 0 \
2150
[lindex [.vpane sash coord 0] 0] \