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]
74 _ls
$this $browser_commit
79 if {$browser_busy} return
80 set lno
[lindex [split [$w index in_sel.first
] .
] 0]
82 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
83 $w tag remove in_sel
0.0 end
84 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
90 if {$browser_busy} return
91 $w yview scroll
$dir pages
94 * [llength $browser_files]
96 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
97 $w tag remove in_sel
0.0 end
98 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
104 if {$browser_busy} return
105 set info [lindex $browser_files 0]
106 if {[lindex $info 0] eq
{parent
}} {
107 set parent
[lindex $browser_stack end-1
]
108 set browser_stack
[lrange $browser_stack 0 end-2
]
109 if {$browser_stack eq
{}} {
110 regsub {:.
*$} $browser_path {:} browser_path
112 regsub {/[^
/]+$} $browser_path {} browser_path
114 set browser_status
"Loading $browser_path..."
115 _ls
$this [lindex $parent 0] [lindex $parent 1]
120 if {$browser_busy} return
121 set lno
[lindex [split [$w index in_sel.first
] .
] 0]
122 set info [lindex $browser_files [expr {$lno - 1}]]
124 switch -- [lindex $info 0] {
129 set name
[lindex $info 2]
130 set escn
[escape_path
$name]
131 set browser_status
"Loading $escn..."
132 append browser_path
$escn
133 _ls
$this [lindex $info 1] $name
136 set name
[lindex $info 2]
138 foreach n
$browser_stack {
139 append p
[lindex $n 1]
142 blame
::new $browser_commit $p
148 method _click
{was_double_click pos
} {
149 if {$browser_busy} return
150 set lno
[lindex [split [$w index
$pos] .
] 0]
153 if {[lindex $browser_files [expr {$lno - 1}]] ne
{}} {
154 $w tag remove in_sel
0.0 end
155 $w tag add in_sel
$lno.0 [expr {$lno + 1}].0
156 if {$was_double_click} {
162 method _ls
{tree_id
{name
{}}} {
163 set browser_buffer
{}
167 $w conf
-state normal
168 $w tag remove in_sel
0.0 end
170 if {$browser_stack ne
{}} {
171 $w image create end
\
172 -align center
-padx 5 -pady 1 \
175 $w insert end
{[Up To Parent
]}
176 lappend browser_files parent
178 lappend browser_stack
[list $tree_id $name]
179 $w conf
-state disabled
181 set fd
[git_read ls-tree
-z $tree_id]
182 fconfigure $fd -blocking 0 -translation binary -encoding binary
183 fileevent $fd readable
[cb _read
$fd]
187 append browser_buffer
[read $fd]
188 set pck
[split $browser_buffer "\0"]
189 set browser_buffer
[lindex $pck end
]
191 set n
[llength $browser_files]
192 $w conf
-state normal
193 foreach p
[lrange $pck 0 end-1
] {
194 set info [split $p "\t"]
195 set path
[lindex $info 1]
196 set info [split [lindex $info 0] { }]
197 set type
[lindex $info 1]
198 set object
[lindex $info 2]
209 set image file_question
213 if {$n > 0} {$w insert end
"\n"}
214 $w image create end
\
215 -align center
-padx 5 -pady 1 \
218 $w insert end
[escape_path
$path]
219 lappend browser_files
[list $type $object $path]
221 $w conf
-state disabled
225 set browser_status Ready.
229 $w tag add in_sel
1.0 2.0