9
field w_next ; # Next button
10
field o_cons ; # Console object (if active)
11
field w_types ; # List of type buttons in clone
12
+field w_recentlist ; # Listbox containing recent repositories
13
14
field action new ; # What action are we going to perform?
15
field done 0 ; # Finished picking the repository?
18
field origin_name origin ; # What we shall call 'origin'
19
field clone_type hardlink ; # Type of clone to construct
20
field readtree_err ; # Error output from read-tree (if any)
21
+field sorted_recent ; # recent repositories (sorted)
22
23
constructor pick {} {
24
global M1T M1B
84
pack $w_body.new -anchor w -fill x
85
pack $w_body.clone -anchor w -fill x
86
pack $w_body.open -anchor w -fill x
87
+
88
+ set sorted_recent [_get_recentrepos]
89
+ if {[llength $sorted_recent] > 0} {
90
+ label $w_body.space
91
+ label $w_body.recentlabel \
92
+ -anchor w \
93
+ -text [mc "Open Recent Repository:"]
94
+ set w_recentlist $w_body.recentlist
95
+ text $w_recentlist \
96
+ -cursor $::cursor_ptr \
97
+ -relief flat \
98
+ -background [$w_body.recentlabel cget -background] \
99
+ -wrap none \
100
+ -width 50 \
101
+ -height 10
102
+ $w_recentlist tag conf link \
103
+ -foreground blue \
104
+ -underline 1
105
+ set home "[file normalize $::env(HOME)][file separator]"
106
+ set hlen [string length $home]
107
+ foreach p $sorted_recent {
108
+ if {[string equal -length $hlen $home $p]} {
109
+ set p "~[file separator][string range $p $hlen end]"
110
+ }
111
+ regsub -all "\n" $p "\\n" p
112
+ $w_recentlist insert end $p link
113
+ $w_recentlist insert end "\n"
114
+ }
115
+ $w_recentlist conf -state disabled
116
+ $w_recentlist tag bind link <1> [cb _open_recent %x,%y]
117
+ pack $w_body.space -anchor w -fill x
118
+ pack $w_body.recentlabel -anchor w -fill x
119
+ pack $w_recentlist -anchor w -fill x
120
+ }
121
pack $w_body -fill x -padx 10 -pady 10
122
123
frame $w.buttons
170
}
171
}
172
173
+proc _get_recentrepos {} {
174
+ set recent [list]
175
+ foreach p [get_config gui.recentrepo] {
176
+ if {[_is_git [file join $p .git]]} {
177
+ lappend recent $p
178
+ }
179
+ }
180
+ return [lsort $recent]
181
+}
182
+
183
+proc _unset_recentrepo {p} {
184
+ regsub -all -- {([()\[\]{}\.^$+*?\\])} $p {\\\1} p
185
+ git config --global --unset gui.recentrepo "^$p\$"
186
+}
187
+
188
+proc _append_recentrepos {path} {
189
+ set path [file normalize $path]
190
+ set recent [get_config gui.recentrepo]
191
+
192
+ if {[lindex $recent end] eq $path} {
193
+ return
194
+ }
195
+
196
+ set i [lsearch $recent $path]
197
+ if {$i >= 0} {
198
+ _unset_recentrepo $path
199
+ set recent [lreplace $recent $i $i]
200
+ }
201
+
202
+ lappend recent $path
203
+ git config --global --add gui.recentrepo $path
204
+
205
+ while {[llength $recent] > 10} {
206
+ _unset_recentrepo [lindex $recent 0]
207
+ set recent [lrange $recent 1 end]
208
+ }
209
+}
210
+
211
+method _open_recent {xy} {
212
+ set id [lindex [split [$w_recentlist index @$xy] .] 0]
213
+ set local_path [lindex $sorted_recent [expr {$id - 1}]]
214
+ _do_open2 $this
215
+}
216
+
217
method _next {} {
218
destroy $w_body
219
_do_$action $this
254
return 0
255
}
256
257
+ _append_recentrepos [pwd]
258
set ::_gitdir .git
259
set ::_prefix {}
260
return 1
937
return
938
}
939
940
+ _append_recentrepos [pwd]
941
set ::_gitdir .git
942
set ::_prefix {}
943
set done 1