2 # Copyright (C) 2006, 2007 Shawn Pearce
6 image create
photo ::browser::img_parent -data {R0lGODlhEAAQAIUAAPwCBBxSHBxOHMTSzNzu3KzCtBRGHCSKFIzCjLzSxBQ2FAxGHDzCLCyeHBQ
+FHSmfAwuFBxKLDSCNMzizISyjJzOnDSyLAw
+FAQSDAQeDBxWJAwmDAQOBKzWrDymNAQaDAQODAwaDDyKTFSyXFTGTEy6TAQCBAQKDAwiFBQyHAwSFAwmHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAZ1QIBwSCwaj0hiQCBICpcDQsFgGAaIguhhi0gohIsrQEDYMhiNrRfgeAQC5fMCAolIDhD2hFI5WC4YRBkaBxsOE2l
/RxsHHA4dHmkfRyAbIQ4iIyQlB5NFGCAACiakpSZEJyinTgAcKSesACorgU4mJ6uxR35BACH
+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs
=}
7 image create
photo ::browser::img_rblob -data {R0lGODlhEAAQAIUAAPwCBFxaXNze3Ly2rJSWjPz
+/Ozq7GxqbJyanPT29HRydMzOzDQyNIyKjERCROTi3Pz69PTy7Pzy7PTu5Ozm3LyqlJyWlJSSjJSOhOzi1LyulPz27PTq3PTm1OzezLyqjIyKhJSKfOzaxPz29OzizLyidIyGdIyCdOTOpLymhOzavOTStMTCtMS
+rMS6pMSynMSulLyedAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAaQQIAQECgajcNkQMBkDgKEQFK4LFgLhkMBIVUKroWEYlEgMLxbBKLQUBwc52HgAQ4LBo049atWQyIPA3pEdFcQEhMUF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SUYgUHJvIHZlcnNpb24gMi41DQqpIERldmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZGV2ZWxjb3IuY29tADs
=}
10 image create
photo ::browser::img_symlink -data {R0lGODlhEAAQAIQAAPwCBCwqLLSytLy
+vERGRFRWVDQ2NKSmpAQCBKyurMTGxISChJyanHR2dIyKjGxubHRydGRmZIyOjFxeXHx6fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAVbICACwWieY1CibCCsrBkMb0zchSEcNYskCtqBBzshFkOGQFk0IRqOxqPBODRHCMhCQKteRc9FI
/KQWGOIyFYgkDC
+gPR4snCcfRGKOIKIgSMQE31
+f4OEYCZ
+IQAh
/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7
}
11 image create
photo ::browser::img_unknown -data {R0lGODlhEAAQAIUAAPwCBFxaXIyKjNTW1Nze3LS2tJyanER2RGS
+VPz
+/PTu5GxqbPz69BQ6BCxeLFSqRPT29HRydMzOzDQyNERmPKSypCRWHIyKhERCRDyGPKz2nESiLBxGHCyCHGxubPz6
/PTy7Ozi1Ly2rKSipOzm3LyqlKSWhCRyFOzizLymhNTKtNzOvOzaxOTStPz27OzWvOTOpLSupLyedMS
+rMS6pMSulLyqjLymfLyifAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAamQIAQECgajcOkYEBoDgoBQyAJOCCuiENCsWBIh9aGw9F4HCARiXciRDQoBUnlYRlcIgsMG5CxXAgMGhscBRAEBRd7AB0eBBoIgxUfICEiikSPgyMMIAokJZcBkBybJgomIaBJAZoMpyCmqkMBFCcVCrgKKAwpoSorKqchKCwtvasIFBIhLiYvLzDHsxQNMcMKLDAwMqEz3jQ1NTY3ONyrE
+jp6hN
+QQAh
/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7
}
16 field browser_files
{}
17 field browser_status
[mc
"Starting..."]
18 field browser_stack
{}
21 field ls_buf
{}; # Buffered record output from ls-tree
23 constructor new
{commit
{path
{}}} {
24 global cursor_ptr M1B use_ttk NS
27 wm title
$top [append "[appname] ([reponame]): " [mc
"File Browser"]]
30 if {[string index
$path end
] ne
{/}} {
35 set browser_commit
$commit
36 set browser_path
"$browser_commit:[escape_path $path]"
38 ${NS
}::label $w.path
\
39 -textvariable @browser_path
\
43 if {!$use_ttk} { $w.path configure
-borderwidth 1 -relief sunken
}
44 pack $w.path
-anchor w
-side top
-fill x
48 text $w_list -background white
-foreground black
\
55 -xscrollcommand [list $w.
list.sbx
set] \
56 -yscrollcommand [list $w.
list.sby
set]
58 ${NS
}::scrollbar $w.
list.sbx
-orient h
-command [list $w_list xview
]
59 ${NS
}::scrollbar $w.
list.sby
-orient v
-command [list $w_list yview
]
60 pack $w.
list.sbx
-side bottom
-fill x
61 pack $w.
list.sby
-side right
-fill y
62 pack $w_list -side left
-fill both
-expand 1
63 pack $w.
list -side top
-fill both
-expand 1
65 ${NS
}::label $w.status
\
66 -textvariable @browser_status
\
69 if {!$use_ttk} { $w.status configure
-borderwidth 1 -relief sunken
}
70 pack $w.status
-anchor w
-side bottom
-fill x
72 bind $w_list <Button-1
> "[cb _click 0 @%x,%y];break"
73 bind $w_list <Double-Button-1
> "[cb _click 1 @%x,%y];break"
74 bind $w_list <$M1B-Up
> "[cb _parent] ;break"
75 bind $w_list <$M1B-Left
> "[cb _parent] ;break"
76 bind $w_list <Up
> "[cb _move -1] ;break"
77 bind $w_list <Down
> "[cb _move 1] ;break"
78 bind $w_list <$M1B-Right
> "[cb _enter] ;break"
79 bind $w_list <Return
> "[cb _enter] ;break"
80 bind $w_list <Prior
> "[cb _page -1] ;break"
81 bind $w_list <Next
> "[cb _page 1] ;break"
82 bind $w_list <Left
> break
83 bind $w_list <Right
> break
85 bind $w_list <Visibility
> [list focus $w_list]
89 _ls
$this $browser_commit:$path $path
91 _ls
$this $browser_commit $path
97 if {$browser_busy} return
98 set lno
[lindex [split [$w index in_sel.first
] .
] 0]
100 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
101 $w tag remove in_sel
0.0 end
102 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
108 if {$browser_busy} return
109 $w yview scroll
$dir pages
111 [lindex [$w yview
] 0]
112 * [llength $browser_files]
114 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
115 $w tag remove in_sel
0.0 end
116 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
122 if {$browser_busy} return
123 set info [lindex $browser_files 0]
124 if {[lindex $info 0] eq
{parent
}} {
125 set parent
[lindex $browser_stack end-1
]
126 set browser_stack
[lrange $browser_stack 0 end-2
]
127 if {$browser_stack eq
{}} {
128 regsub {:.
*$} $browser_path {:} browser_path
130 regsub {/[^
/]+/$} $browser_path {/} browser_path
132 set browser_status
[mc
"Loading %s..." $browser_path]
133 _ls
$this [lindex $parent 0] [lindex $parent 1]
138 if {$browser_busy} return
139 set lno
[lindex [split [$w index in_sel.first
] .
] 0]
140 set info [lindex $browser_files [expr {$lno - 1}]]
142 switch -- [lindex $info 0] {
147 set name
[lindex $info 2]
148 set escn
[escape_path
$name]
149 set browser_status
[mc
"Loading %s..." $escn]
150 append browser_path
$escn
151 _ls
$this [lindex $info 1] $name
154 set name
[lindex $info 2]
156 foreach n
$browser_stack {
157 append p
[lindex $n 1]
160 blame
::new $browser_commit $p {}
166 method _click
{was_double_click pos
} {
167 if {$browser_busy} return
168 set lno
[lindex [split [$w index
$pos] .
] 0]
171 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
172 $w tag remove in_sel
0.0 end
173 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
174 if {$was_double_click} {
180 method _ls
{tree_id
{name
{}}} {
185 $w conf
-state normal
186 $w tag remove in_sel
0.0 end
188 if {$browser_stack ne
{}} {
189 $w image create end
\
190 -align center
-padx 5 -pady 1 \
192 -image ::browser::img_parent
193 $w insert end
[mc
"\[Up To Parent\]"]
194 lappend browser_files parent
196 lappend browser_stack
[list $tree_id $name]
197 $w conf
-state disabled
199 set fd
[git_read ls-tree
-z $tree_id]
200 fconfigure $fd -blocking 0 -translation binary -encoding binary
201 fileevent $fd readable
[cb _read
$fd]
205 append ls_buf
[read $fd]
206 set pck
[split $ls_buf "\0"]
207 set ls_buf
[lindex $pck end
]
209 set n
[llength $browser_files]
210 $w conf
-state normal
211 foreach p
[lrange $pck 0 end-1
] {
212 set tab
[string first
"\t" $p]
213 if {$tab == -1} continue
215 set info [split [string range
$p 0 [expr {$tab - 1}]] { }]
216 set path
[string range
$p [expr {$tab + 1}] end
]
217 set type
[lindex $info 1]
218 set object
[lindex $info 2]
222 scan [lindex $info 0] %o mode
223 if {$mode == 0120000} {
224 set image ::browser::img_symlink
225 } elseif
{($mode & 0100) != 0} {
226 set image ::browser::img_xblob
228 set image ::browser::img_rblob
232 set image ::browser::img_tree
236 set image ::browser::img_unknown
240 if {$n > 0} {$w insert end
"\n"}
241 $w image create end
\
242 -align center
-padx 5 -pady 1 \
245 $w insert end
[escape_path
$path]
246 lappend browser_files
[list $type $object $path]
248 $w conf
-state disabled
252 set browser_status
[mc
"Ready."]
256 $w tag add in_sel
1.0 2.0
268 field w
; # widget path
269 field w_rev
; # mega-widget to pick the initial revision
271 constructor dialog
{} {
275 wm title
$top [append "[appname] ([reponame]): " [mc
"Browse Branch Files"]]
277 wm geometry
$top "+[winfo rootx .]+[winfo rooty .]"
281 ${NS
}::label $w.header
\
282 -text [mc
"Browse Branch Files"] \
285 pack $w.header
-side top
-fill x
287 ${NS
}::frame $w.buttons
288 ${NS
}::button $w.buttons.browse
-text [mc Browse
] \
291 pack $w.buttons.browse
-side right
292 ${NS
}::button $w.buttons.cancel
-text [mc Cancel
] \
293 -command [list destroy $w]
294 pack $w.buttons.cancel
-side right
-padx 5
295 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
297 set w_rev
[::choose_rev::new $w.rev
[mc Revision
]]
298 $w_rev bind_listbox
<Double-Button-1
> [cb _open
]
299 pack $w.rev
-anchor nw
-fill both
-expand 1 -pady 5 -padx 5
301 bind $w <Visibility
> [cb _visible
]
302 bind $w <Key-Escape
> [list destroy $w]
303 bind $w <Key-Return
> [cb _open
]\;break
309 if {[catch {$w_rev commit_or_die
} err
]} {
312 set name
[$w_rev get
]