2 # Copyright (C) 2006, 2007 Shawn Pearce
10 field browser_status
{Starting...
}
11 field browser_stack
{}
14 constructor new
{commit
} {
17 wm title
$top "[appname] ([reponame]): File Browser"
19 set browser_commit
$commit
20 set browser_path
$browser_commit:
23 -textvariable @browser_path
\
29 pack $w.path
-anchor w
-side top
-fill x
33 text $w_list -background white
-borderwidth 0 \
39 -xscrollcommand [list $w.
list.sbx
set] \
40 -yscrollcommand [list $w.
list.sby
set]
41 $w_list tag conf in_sel
\
42 -background [$w_list cget
-foreground] \
43 -foreground [$w_list cget
-background]
44 scrollbar $w.
list.sbx
-orient h
-command [list $w_list xview
]
45 scrollbar $w.
list.sby
-orient v
-command [list $w_list yview
]
46 pack $w.
list.sbx
-side bottom
-fill x
47 pack $w.
list.sby
-side right
-fill y
48 pack $w_list -side left
-fill both
-expand 1
49 pack $w.
list -side top
-fill both
-expand 1
52 -textvariable @browser_status
\
57 pack $w.status
-anchor w
-side bottom
-fill x
59 bind $w_list <Button-1
> "[cb _click 0 @%x,%y];break"
60 bind $w_list <Double-Button-1
> "[cb _click 1 @%x,%y];break"
61 bind $w_list <$M1B-Up
> "[cb _parent] ;break"
62 bind $w_list <$M1B-Left
> "[cb _parent] ;break"
63 bind $w_list <Up
> "[cb _move -1] ;break"
64 bind $w_list <Down
> "[cb _move 1] ;break"
65 bind $w_list <$M1B-Right
> "[cb _enter] ;break"
66 bind $w_list <Return
> "[cb _enter] ;break"
67 bind $w_list <Prior
> "[cb _page -1] ;break"
68 bind $w_list <Next
> "[cb _page 1] ;break"
69 bind $w_list <Left
> break
70 bind $w_list <Right
> break
72 bind $w_list <Visibility
> [list focus $w_list]
73 bind $w_list <Destroy
> [list delete_this
$this]
75 _ls
$this $browser_commit
80 if {$browser_busy} return
81 set lno
[lindex [split [$w index in_sel.first
] .
] 0]
83 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
84 $w tag remove in_sel
0.0 end
85 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
91 if {$browser_busy} return
92 $w yview scroll
$dir pages
95 * [llength $browser_files]
97 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
98 $w tag remove in_sel
0.0 end
99 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
105 if {$browser_busy} return
106 set info [lindex $browser_files 0]
107 if {[lindex $info 0] eq
{parent
}} {
108 set parent
[lindex $browser_stack end-1
]
109 set browser_stack
[lrange $browser_stack 0 end-2
]
110 if {$browser_stack eq
{}} {
111 regsub {:.
*$} $browser_path {:} browser_path
113 regsub {/[^
/]+$} $browser_path {} browser_path
115 set browser_status
"Loading $browser_path..."
116 _ls
$this [lindex $parent 0] [lindex $parent 1]
121 if {$browser_busy} return
122 set lno
[lindex [split [$w index in_sel.first
] .
] 0]
123 set info [lindex $browser_files [expr {$lno - 1}]]
125 switch -- [lindex $info 0] {
130 set name
[lindex $info 2]
131 set escn
[escape_path
$name]
132 set browser_status
"Loading $escn..."
133 append browser_path
$escn
134 _ls
$this [lindex $info 1] $name
137 set name
[lindex $info 2]
139 foreach n
$browser_stack {
140 append p
[lindex $n 1]
143 blame
::new $browser_commit $p
149 method _click
{was_double_click pos
} {
150 if {$browser_busy} return
151 set lno
[lindex [split [$w index
$pos] .
] 0]
154 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
155 $w tag remove in_sel
0.0 end
156 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
157 if {$was_double_click} {
163 method _ls
{tree_id
{name
{}}} {
164 set browser_buffer
{}
168 $w conf
-state normal
169 $w tag remove in_sel
0.0 end
171 if {$browser_stack ne
{}} {
172 $w image create end
\
173 -align center
-padx 5 -pady 1 \
176 $w insert end
{[Up To Parent
]}
177 lappend browser_files parent
179 lappend browser_stack
[list $tree_id $name]
180 $w conf
-state disabled
182 set cmd
[list git ls-tree
-z $tree_id]
183 set fd
[open "| $cmd" r
]
184 fconfigure $fd -blocking 0 -translation binary -encoding binary
185 fileevent $fd readable
[cb _read
$fd]
189 append browser_buffer
[read $fd]
190 set pck
[split $browser_buffer "\0"]
191 set browser_buffer
[lindex $pck end
]
193 set n
[llength $browser_files]
194 $w conf
-state normal
195 foreach p
[lrange $pck 0 end-1
] {
196 set info [split $p "\t"]
197 set path
[lindex $info 1]
198 set info [split [lindex $info 0] { }]
199 set type
[lindex $info 1]
200 set object
[lindex $info 2]
211 set image file_question
215 if {$n > 0} {$w insert end
"\n"}
216 $w image create end
\
217 -align center
-padx 5 -pady 1 \
220 $w insert end
[escape_path
$path]
221 lappend browser_files
[list $type $object $path]
223 $w conf
-state disabled
227 set browser_status Ready.
231 $w tag add in_sel
1.0 2.0