git-gui: Save window geometry to .git/config during exit.
I started to find it very annoying that my test application kept opening at the wrong location on my desktop, so now we save the basic window geometry and sash positions into the config file as gui.geometry. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 8, 2006 at 23:42 UTC
2d19516db4a6807e817879e6d30fd3137a4a7817
1 file changed
+88
-61
git-gui
+88
-61
@@ -7,6 +7,86 @@ exec wish "$0" -- "$@"
7
# and distributed under the terms of the GNU General Public Licence,
8
# either version 2, or (at your option) any later version.
9
10
+######################################################################
11
+##
12
+## config
13
+
14
+proc load_repo_config {} {
15
+ global repo_config
16
+ global cfg_trust_mtime
17
+
18
+ array unset repo_config
19
+ catch {
20
+ set fd_rc [open "| git repo-config --list" r]
21
+ while {[gets $fd_rc line] >= 0} {
22
+ if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
23
+ lappend repo_config($name) $value
24
+ }
25
+ }
26
+ close $fd_rc
27
+ }
28
+
29
+ if {[catch {set cfg_trust_mtime \
30
+ [lindex $repo_config(gui.trustmtime) 0]
31
+ }]} {
32
+ set cfg_trust_mtime false
33
+ }
34
+}
35
+
36
+proc save_my_config {} {
37
+ global repo_config
38
+ global cfg_trust_mtime
39
+
40
+ if {[catch {set rc_trustMTime $repo_config(gui.trustmtime)}]} {
41
+ set rc_trustMTime [list false]
42
+ }
43
+ if {$cfg_trust_mtime != [lindex $rc_trustMTime 0]} {
44
+ exec git repo-config gui.trustMTime $cfg_trust_mtime
45
+ set repo_config(gui.trustmtime) [list $cfg_trust_mtime]
46
+ }
47
+
48
+ set cfg_geometry [list \
49
+ [wm geometry .] \
50
+ [.vpane sash coord 0] \
51
+ [.vpane.files sash coord 0] \
52
+ ]
53
+ if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
54
+ set rc_geometry [list [list]]
55
+ }
56
+ if {$cfg_geometry != [lindex $rc_geometry 0]} {
57
+ exec git repo-config gui.geometry $cfg_geometry
58
+ set repo_config(gui.geometry) [list $cfg_geometry]
59
+ }
60
+}
61
+
62
+######################################################################
63
+##
64
+## repository setup
65
+
66
+set appname [lindex [file split $argv0] end]
67
+set gitdir {}
68
+set GIT_COMMITTER_IDENT {}
69
+
70
+if {[catch {set cdup [exec git rev-parse --show-cdup]} err]} {
71
+ show_msg {} . "Cannot find the git directory: $err"
72
+ exit 1
73
+}
74
+if {$cdup != ""} {
75
+ cd $cdup
76
+}
77
+unset cdup
78
+
79
+if {[catch {set gitdir [exec git rev-parse --git-dir]} err]} {
80
+ show_msg {} . "Cannot find the git directory: $err"
81
+ exit 1
82
+}
83
+
84
+if {$appname == {git-citool}} {
85
+ set single_commit 1
86
+}
87
+
88
+load_repo_config
89
+
90
######################################################################
91
##
92
## task management
@@ -903,39 +983,7 @@ proc toggle_mode {path} {
983
984
######################################################################
985
##
906
-## config (fetch push pull)
907
-
908
-proc load_repo_config {} {
909
- global repo_config
910
- global cfg_trust_mtime
911
-
912
- array unset repo_config
913
- catch {
914
- set fd_rc [open "| git repo-config --list" r]
915
- while {[gets $fd_rc line] >= 0} {
916
- if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
917
- lappend repo_config($name) $value
918
- }
919
- }
920
- close $fd_rc
921
- }
922
-
923
- if {[catch {set cfg_trust_mtime $repo_config(gui.trustmtime)}]} {
924
- set cfg_trust_mtime false
925
- }
926
-}
927
-
928
-proc save_my_config {} {
929
- global repo_config
930
- global cfg_trust_mtime
931
-
932
- if {[catch {set rc_trustMTime $repo_config(gui.trustmtime)}]} {
933
- set rc_trustMTime false
934
- }
935
- if {$cfg_trust_mtime != $rc_trustMTime} {
936
- exec git repo-config gui.trustMTime $cfg_trust_mtime
937
- }
938
-}
986
+## remote management
987
988
proc load_all_remotes {} {
989
global gitdir all_remotes repo_config
@@ -1398,8 +1446,6 @@ proc do_include_all {} {
1446
}
1447
}
1448
1401
-set GIT_COMMITTER_IDENT {}
1402
-
1449
proc do_signoff {} {
1450
global ui_comm GIT_COMMITTER_IDENT
1451
@@ -1724,6 +1770,13 @@ label .status -textvariable ui_status_value \
1770
-font $mainfont
1771
pack .status -anchor w -side bottom -fill x
1772
1773
+# -- Load geometry
1774
+catch {
1775
+wm geometry . [lindex $repo_config(gui.geometry) 0 0]
1776
+eval .vpane sash place 0 [lindex $repo_config(gui.geometry) 0 1]
1777
+eval .vpane.files sash place 0 [lindex $repo_config(gui.geometry) 0 2]
1778
+}
1779
+
1780
# -- Key Bindings
1781
bind $ui_comm <$M1B-Key-Return> {do_commit;break}
1782
bind . <Destroy> do_quit
@@ -1746,34 +1799,8 @@ foreach i [list $ui_index $ui_other] {
1799
}
1800
unset i M1B M1T
1801
1749
-######################################################################
1750
-##
1751
-## main
1752
-
1753
-set appname [lindex [file split $argv0] end]
1754
-set gitdir {}
1755
-
1756
-if {[catch {set cdup [exec git rev-parse --show-cdup]} err]} {
1757
- show_msg {} . "Cannot find the git directory: $err"
1758
- exit 1
1759
-}
1760
-if {$cdup != ""} {
1761
- cd $cdup
1762
-}
1763
-unset cdup
1764
-
1765
-if {[catch {set gitdir [exec git rev-parse --git-dir]} err]} {
1766
- show_msg {} . "Cannot find the git directory: $err"
1767
- exit 1
1768
-}
1769
-
1770
-if {$appname == {git-citool}} {
1771
- set single_commit 1
1772
-}
1773
-
1802
wm title . "$appname ([file normalize [file dirname $gitdir]])"
1803
focus -force $ui_comm
1776
-load_repo_config
1804
load_all_remotes
1805
populate_remote_menu .mbar.fetch From fetch_from
1806
populate_remote_menu .mbar.push To push_to