about summary refs log tree commit diff stats
path: root/src/UCAux.c
Commit message (Expand)AuthorAgeFilesLines
* snapshot of project "lynx", label v2-8-8dev_8mThomas E. Dickey2011-06-111-0/+629
* snapshot of project "lynx", label v2_8_8dev_9aThomas E. Dickey2011-06-111-629/+0
* snapshot of project "lynx", label v2-8-8dev_6bThomas E. Dickey2010-11-081-2/+2
* snapshot of project "lynx", label v2-8-8dev_5eThomas E. Dickey2010-09-261-5/+7
* snapshot of project "lynx", label v2-8-8dev_3cThomas E. Dickey2010-05-031-0/+627
* snapshot of project "lynx", label v2_8_8dev_6cThomas E. Dickey2010-04-291-629/+0
* snapshot of project "lynx", label v2-8-7dev_13bThomas E. Dickey2009-03-111-1/+6
* snapshot of project "lynx", label v2-8-7dev_12bThomas E. Dickey2009-01-031-2/+7
* snapshot of project "lynx", label v2-8-7dev_11dThomas E. Dickey2009-01-011-1/+4
* snapshot of project "lynx", label v2-8-7dev_9iThomas E. Dickey2008-09-061-4/+8
* snapshot of project "lynx", label v2-8-7dev_4dThomas E. Dickey2007-05-061-4/+6
* snapshot of project "lynx", label v2-8-6pre_3Thomas E. Dickey2006-09-101-3/+5
* snapshot of project "lynx", label v2-8-6dev_17Thomas E. Dickey2006-01-231-8/+76
* snapshot of project "lynx", label v2-8-6dev_16Thomas E. Dickey2005-12-181-14/+41
* snapshot of project "lynx", label v2-8-6dev_14Thomas E. Dickey2005-10-171-1/+3
* snapshot of project "lynx", label v2-8-6dev_3Thomas E. Dickey2004-05-071-238/+232
* snapshot of project "lynx", label v2-8-6dev_2Thomas E. Dickey2004-04-271-36/+36
* snapshot of project "lynx", label v2-8-5dev_9Thomas E. Dickey2002-10-071-1/+4
* snapshot of project "lynx", label v2-8-3dev_23Thomas E. Dickey2000-03-271-3/+1
* snapshot of project "lynx", label v2-8-3dev_13Thomas E. Dickey1999-10-211-1/+63
* snapshot of project "lynx", label v2-8-3dev_10Thomas E. Dickey1999-09-291-3/+2
* snapshot of project "lynx", label v2-8-3dev_7Thomas E. Dickey1999-08-261-15/+15
* snapshot of project "lynx", label v2-8-2dev_18Thomas E. Dickey1999-03-041-8/+10
* snapshot of project "lynx", label v2-8-2dev_14Thomas E. Dickey1999-01-181-7/+14
* snapshot of project "lynx", label v2-8-2dev_9Thomas E. Dickey1998-12-131-2/+2
* snapshot of project "lynx", label v2-8-2dev_4Thomas E. Dickey1998-11-181-0/+3
* snapshot of project "lynx", label v2-8-2dev_2Thomas E. Dickey1998-11-101-16/+8
* snapshot of project "lynx", label v2-8-1dev_4Thomas E. Dickey1998-11-061-8/+16
* snapshot of project "lynx", label v2-8-1dev_26Thomas E. Dickey1998-09-131-15/+8
* snapshot of project "lynx", label v2-8-1dev_20Thomas E. Dickey1998-08-061-1/+0
* snapshot of project "lynx", label v2-8-1dev_5Thomas E. Dickey1998-03-291-6/+6
* snapshot of project "lynx", label v2-7-1ac-0_114Thomas E. Dickey1998-02-131-46/+22
* snapshot of project "lynx", label v2-7-1ac_0-110Thomas E. Dickey1998-01-221-46/+33
* snapshot of project "lynx", label v2-7-1ac_0-105Thomas E. Dickey1998-01-021-2/+2
* snapshot of project "lynx", label v2-7-1ac_0-102Thomas E. Dickey1997-12-181-2/+2
* snapshot of project "lynx", label v2-7-1ac_0-95Thomas E. Dickey1997-11-171-40/+218
* snapshot of project "lynx", label v2-7-1ac_0-89Thomas E. Dickey1997-10-271-1/+25
* snapshot of project "lynx", label v2-7-1ac_0-84Thomas E. Dickey1997-10-171-22/+28
* snapshot of project "lynx", label v2-7-1ac_0-76Thomas E. Dickey1997-10-061-2/+52
* snapshot of project "lynx", label v2-7-1ac_0-69Thomas E. Dickey1997-09-191-2/+2
* snapshot of project "lynx", label v2-7-1ac_0-64Thomas E. Dickey1997-09-121-1/+12
* snapshot of project "lynx", label v2-7-1ac_0-52Thomas E. Dickey1997-08-171-2/+3
* snapshot of project "lynx", label v2-7-1ac_0-45Thomas E. Dickey1997-08-031-2/+2
* snapshot of project "lynx", label v2-7-1ac_0-42Thomas E. Dickey1997-07-271-0/+2
* snapshot of project "lynx", label v2-7-1ac_0-36Thomas E. Dickey1997-07-181-80/+83
* snapshot of project "lynx", label v2-7-1ac_0-6Thomas E. Dickey1997-04-161-0/+213
an class='oid'>4b5162c7 ^
e657119b ^

ae943ecb ^


eaaeed3d ^
7327aab1 ^


4b5162c7 ^





7327aab1 ^



681d9f6a ^
7327aab1 ^


dad0644f ^




7327aab1 ^

ae943ecb ^

1cbc0f48 ^
43d4c88c ^
9506fb8e ^
49ae0dd1 ^

d621586e ^
13370392 ^
d621586e ^

ab1a2682 ^
437c12d9 ^
d621586e ^

3a9e3382 ^
9e09af36 ^
3a9e3382 ^

d621586e ^


42fd3690 ^
d88232a3 ^

d621586e ^
31642154 ^
42fd3690 ^



9b83f114 ^


fe14923b ^
b712bbcf ^
1cb6afa9 ^
a2ccfbe1 ^
1cb6afa9 ^




a808a661 ^
a2ccfbe1 ^
42fd3690 ^



ab1a2682 ^
42fd3690 ^

ab1a2682 ^
42fd3690 ^


a808a661 ^
f257e476 ^
31642154 ^
d88232a3 ^
17f83af2 ^
9506fb8e ^
a23a3649 ^
328c6565 ^
9506fb8e ^
30b25795 ^
437c12d9 ^
328c6565 ^
30b25795 ^
ea87d005 ^
177a6d04 ^

328c6565 ^
f257e476 ^
177a6d04 ^

419e4aa5 ^
31642154 ^
d88232a3 ^
f027adc0 ^
3a9e3382 ^


77f59786 ^
7d9ae552 ^
17f83af2 ^

7d9ae552 ^
b6e32668 ^
a23a3649 ^
b6e32668 ^

7d9ae552 ^
77f59786 ^
ca665e06 ^
dd7a4f63 ^
9506fb8e ^
f027adc0 ^
a23a3649 ^
f027adc0 ^
9506fb8e ^
dd7a4f63 ^
8b60e8ca ^

a23a3649 ^
8b60e8ca ^


31642154 ^
dd7a4f63 ^
fabec26d ^
6e152710 ^
fabec26d ^
5599636d ^
dd7a4f63 ^
f027adc0 ^
5805deca ^

e92d708f ^
5805deca ^

dd7a4f63 ^
f498e2ce ^





1d3d94aa ^
e92d708f ^


f027adc0 ^
dc91c286 ^


f498e2ce ^


e690d4e9 ^

f498e2ce ^
6e152710 ^

f498e2ce ^
f027adc0 ^


e92d708f ^
3201b163 ^
e690d4e9 ^
2d0c856b ^
3201b163 ^
20f94973 ^

e690d4e9 ^
dc91c286 ^
20f94973 ^
e92d708f ^
f027adc0 ^
419e4aa5 ^
f027adc0 ^
419e4aa5 ^
0bec64f6 ^







729286d7 ^

5805deca ^
fabec26d ^
eb3795d3 ^

2025de1d ^
f027adc0 ^
e92d708f ^
dd7a4f63 ^
6e152710 ^


e690d4e9 ^
ce421875 ^
6e152710 ^
ce421875 ^
6e152710 ^
ce421875 ^
6e152710 ^
ce421875 ^
f498e2ce ^



ce421875 ^
f498e2ce ^
f027adc0 ^
17f83af2 ^
1d3d94aa ^


f027adc0 ^
e690d4e9 ^

20f94973 ^
dc91c286 ^
20f94973 ^
f027adc0 ^
9506fb8e ^
31642154 ^
d88232a3 ^
65cb1a32 ^
dd7a4f63 ^


5599636d ^
dd7a4f63 ^





d494f019 ^


dd7a4f63 ^





db9bb0c9 ^

31642154 ^
db9bb0c9 ^
dd7a4f63 ^









ea87d005 ^
dd7a4f63 ^

31642154 ^
d88232a3 ^
31642154 ^
dd7a4f63 ^
9506fb8e ^
d6e2900a ^

ab7bf8b0 ^
d6e2900a ^

ea87d005 ^
42fd3690 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
                        
                                                                       
 



                                                                      
 






                                                                       
 
                                                                            
           

                     
                    
                        
                                    
                                            
 
                           
                           

                                  
                     
                             
                                              
 


                      
                                       







                                                                 

                                          
                                  
 





                                                                               
                                         
                                                   
 

                                         

                                                                           

                                    


                                       
                                              


                                                                                 





                                                                              



                                                                                   
                                                                      


                                                                                       




                                                                                                 

                                                    

                     
                                                            
                                                     
 

                           
                              
                                       

                                    
                                       
                                                         

                                            
                                            
                                                                                    

                                            


                           
                                 

                                                           
                       
                                                                   



                                                  


                                                                              
                                                             
                                                                                           
                                                                  
                                                       




                                                                                
                                                       
 



                                               
                                                 

                                                 
                                                      


                                                      
                                                      
 
                             
                                                                          
                                   
                                              
                                                                
                                         
                              
 
                                                                        
                                         
                              
 

                                                                      
                                         
                     

                                          
 
                                  
                                                      
 


                                                                            
                                           
 

                                   
                                                  
                                              
                                                     

                                          
 
                                    
                                                        
 
                                              
                                                       
                                                                
                                          
                              
 

                                                       
                                                       


                                          
                                        
 
                                                        
                                                                        
 
                                                
                                            
                                                    

                            
                                                            

                                          
 





                                                                                      
                                             


                                                                                
 


                                                                                   


                                                          

                                                                       
 

                                                                     
 


                                                             
                                        
                                                           
                                                                                                 
                                                         
 

                                                           
                                                                                                 
                                                                   
 
                                              
                                                              
                             
                                                         
 







                                                                       

                                                                   
 
                                                

                                                                                      
                                         
                                                         
                                                                                   
 


                                                                    
                                                                                         
                                          
                                                                        
                                                  
                                                                        
                             
                                                                
 



                                                                             
                                         
                                                                        
 
                                                                    


                                                                                      
 

                                                                                            
                                                               
                                                                                      
 
                                          
 
                                    
                                                                                        
                                                    


                                          
                                                





                                                   


                                





                                                                                     

                                                                    
                                                       
 









                                                                             
 

                               
                                    
                                                    
                                                            
                                                            
 

                                            
                                       

                                                 
 

                                                                               
# -*- encoding: utf8 -*-
# Copyright (C) 2009, 2010, 2011  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""The BrowserColumn widget displays the contents of a directory or file."""
import stat
from time import time

from . import Widget
from .pager import Pager
from ranger.fsobject import BAD_INFO
from ranger.ext.widestring import WideString

class BrowserColumn(Pager):
	main_column = False
	display_infostring = False
	scroll_begin = 0
	target = None
	last_redraw_time = -1
	ellipsis = { False: '~', True: '…' }

	old_dir = None
	old_cf = None

	def __init__(self, win, level):
		"""
		win = the curses window object of the BrowserView
		level = what to display?

		level >0 => previews
		level 0 => current file/directory
		level <0 => parent directories
		"""
		Pager.__init__(self, win)
		Widget.__init__(self, win)
		self.level = level

		self.settings.signal_bind('setopt.display_size_in_main_column',
				self.request_redraw, weak=True)

	def request_redraw(self):
		self.need_redraw = True

	def resize(self, y, x, hei, wid):
		Widget.resize(self, y, x, hei, wid)

	def click(self, event):
		"""Handle a MouseEvent"""
		direction = event.mouse_wheel_direction()
		if not (event.pressed(1) or event.pressed(3) or direction):
			return False

		if self.target is None:
			pass

		elif self.target.is_directory:
			if self.target.accessible and self.target.content_loaded:
				index = self.scroll_begin + event.y - self.y

				if direction:
					if self.level == -1:
						self.fm.move_parent(direction)
					else:
						return False
				elif event.pressed(1):
					if not self.main_column:
						self.fm.enter_dir(self.target.path)

					if index < len(self.target):
						self.fm.move(to=index)
				elif event.pressed(3):
					try:
						clicked_file = self.target.files[index]
						if clicked_file.is_directory:
							self.fm.enter_dir(clicked_file.path)
						elif self.level == 0:
							self.fm.env.cwd.move_to_obj(clicked_file)
							self.fm.execute_file(clicked_file)
					except:
						pass

		else:
			if self.level > 0 and not direction:
				self.fm.move(right=0)

		return True

	def has_preview(self):
		if self.target is None:
			return False

		if self.target.is_file:
			if not self.target.has_preview():
				return False

		if self.target.is_directory:
			if self.level > 0 and not self.settings.preview_directories:
				return False

		return True

	def poke(self):
		Widget.poke(self)
		self.target = self.env.at_level(self.level)

	def draw(self):
		"""Call either _draw_file() or _draw_directory()"""
		if self.target != self.old_dir:
			self.need_redraw = True
			self.old_dir = self.target

		if self.target:  # don't garbage collect this directory please
			self.target.use()

		if self.target and self.target.is_directory \
				and (self.level <= 0 or self.settings.preview_directories):
			if self.target.pointed_obj != self.old_cf:
				self.need_redraw = True
				self.old_cf = self.target.pointed_obj

			if self.target.load_content_if_outdated() \
			or self.target.sort_if_outdated() \
			or self.last_redraw_time < self.target.last_update_time:
				self.need_redraw = True

		if self.need_redraw:
			self.win.erase()
			if self.target is None:
				pass
			elif self.target.is_file:
				Pager.open(self)
				self._draw_file()
			elif self.target.is_directory:
				self._draw_directory()
				Widget.draw(self)
			self.need_redraw = False
			self.last_redraw_time = time()

	def _draw_file(self):
		"""Draw a preview of the file, if the settings allow it"""
		self.win.move(0, 0)
		if not self.target.accessible:
			self.addnstr("not accessible", self.wid)
			Pager.close(self)
			return

		if self.target is None or not self.target.has_preview():
			Pager.close(self)
			return

		f = self.target.get_preview_source(self.wid, self.hei)
		if f is None:
			Pager.close(self)
		else:
			self.set_source(f)
			Pager.draw(self)

	def _draw_directory(self):
		"""Draw the contents of a directory"""

		if self.level > 0 and not self.settings.preview_directories:
			return

		base_color = ['in_browser']

		self.win.move(0, 0)

		if not self.target.content_loaded:
			self.color(base_color)
			self.addnstr("...", self.wid)
			self.color_reset()
			return

		if self.main_column:
			base_color.append('main_column')

		if not self.target.accessible:
			self.color(base_color, 'error')
			self.addnstr("not accessible", self.wid)
			self.color_reset()
			return

		if self.target.empty():
			self.color(base_color, 'empty')
			self.addnstr("empty", self.wid)
			self.color_reset()
			return

		self._set_scroll_begin()

		copied = [f.path for f in self.env.copy]
		ellipsis = self.ellipsis[self.settings.unicode_ellipsis]

		selected_i = self.target.pointer
		for line in range(self.hei):
			i = line + self.scroll_begin

			try:
				drawn = self.target.files[i]
			except IndexError:
				break

			if self.display_infostring and drawn.infostring \
					and self.settings.display_size_in_main_column:
				infostring = str(drawn.infostring) + " "
			else:
				infostring = ""

			bad_info_color = None
			this_color = base_color + list(drawn.mimetype_tuple)
			text = drawn.basename
			tagged = self.fm.tags and drawn.realpath in self.fm.tags

			if tagged:
				tagged_marker = self.fm.tags.marker(drawn.realpath)

			space = self.wid - len(infostring)
			if self.main_column:
				space -= 2
			elif self.settings.display_tags_in_all_columns:
				space -= 1

#			if len(text) > space:
#				text = text[:space-1] + self.ellipsis

			if i == selected_i:
				this_color.append('selected')

			if drawn.marked:
				this_color.append('marked')
				if self.main_column or self.settings.display_tags_in_all_columns:
					text = " " + text

			if tagged:
				this_color.append('tagged')
				if self.main_column or self.settings.display_tags_in_all_columns:
					text = tagged_marker + text

			if drawn.is_directory:
				this_color.append('directory')
			else:
				this_color.append('file')

			if drawn.stat:
				mode = drawn.stat.st_mode
				if mode & stat.S_IXUSR:
					this_color.append('executable')
				if stat.S_ISFIFO(mode):
					this_color.append('fifo')
				if stat.S_ISSOCK(mode):
					this_color.append('socket')
				if drawn.is_device:
					this_color.append('device')

			if drawn.path in copied:
				this_color.append('cut' if self.env.cut else 'copied')

			if drawn.is_link:
				this_color.append('link')
				this_color.append(drawn.exists and 'good' or 'bad')

			wtext = WideString(text)
			if len(wtext) > space:
				wtext = wtext[:space - 1] + ellipsis
			if self.main_column or self.settings.display_tags_in_all_columns:
				if tagged:
					self.addstr(line, 0, str(wtext))
				elif self.wid > 1:
					self.addstr(line, 1, str(wtext))
			else:
				self.addstr(line, 0, str(wtext))

			if infostring:
				x = self.wid - 1 - len(infostring)
				if infostring is BAD_INFO:
					bad_info_color = (x, len(infostring))
				if x > 0:
					self.addstr(line, x, infostring)

			self.color_at(line, 0, self.wid, this_color)
			if bad_info_color:
				start, wid = bad_info_color
				self.color_at(line, start, wid, this_color, 'badinfo')

			if (self.main_column or self.settings.display_tags_in_all_columns) \
					and tagged and self.wid > 2:
				this_color.append('tag_marker')
				self.color_at(line, 0, len(tagged_marker), this_color)

			self.color_reset()

	def _get_scroll_begin(self):
		"""Determines scroll_begin (the position of the first displayed file)"""
		offset = self.settings.scroll_offset
		dirsize = len(self.target)
		winsize = self.hei
		halfwinsize = winsize // 2
		index = self.target.pointer or 0
		original = self.target.scroll_begin
		projected = index - original

		upper_limit = winsize - 1 - offset
		lower_limit = offset

		if original < 0:
			return 0

		if dirsize < winsize:
			return 0

		if halfwinsize < offset:
			return min( dirsize - winsize, max( 0, index - halfwinsize ))

		if original > dirsize - winsize:
			self.target.scroll_begin = dirsize - winsize
			return self._get_scroll_begin()

		if projected < upper_limit and projected > lower_limit:
			return original

		if projected > upper_limit:
			return min( dirsize - winsize,
					original + (projected - upper_limit))

		if projected < upper_limit:
			return max( 0,
					original - (lower_limit - projected))

		return original

	def _set_scroll_begin(self):
		"""Updates the scroll_begin value"""
		self.scroll_begin = self._get_scroll_begin()
		self.target.scroll_begin = self.scroll_begin

	def scroll(self, n):
		"""scroll down by n lines"""
		self.need_redraw = True
		self.target.move(down=n)
		self.target.scroll_begin += 3 * n

	def __str__(self):
		return self.__class__.__name__ + ' at level ' + str(self.level)