about summary refs log tree commit diff stats
Commit message (Expand)AuthorAgeFilesLines
...
* added screen-border snapping in floating mode, feels quite wellarg@mig292006-10-303-0/+10
* and another fixarg@mig292006-10-272-3/+4
* applied sanders try2 patcharg@mig292006-10-274-7/+6
* applied sanders max size fixarg@mig292006-10-272-1/+5
* stupid urxvt needs bg to highlight selections in a sane way, though that make...arg@mig292006-10-271-1/+1
* reverting to originalarg@mig292006-10-261-1/+1
* applied sander's config.*h nitpick patcharg@mig292006-10-262-5/+5
* some other changearg@mig292006-10-261-3/+3
* apply small fix to prevent apps like mplayer wandering when toggling fullscreenarg@mig292006-10-261-2/+2
* forgot to use -tr, which actually prevents the ugly flicker (using xsetroot -...arg@mig292006-10-261-1/+1
* using MASTER 600 again, it is definately better, and using urxvtc for the mom...arg@mig292006-10-261-2/+2
* changing MASTER in config.arg.h from 600 to 550 per thousandarg@mig292006-10-261-1/+1
* my new 1920x1200 Z61p arrived, now I can use terminus in a sane way...arg@mig292006-10-261-1/+1
* moved MOUSEMASK into event.c (not used in other places)Anselm R. Garbe2006-10-162-1/+1
* now being at v2.0Anselm R. Garbe2006-10-141-1/+1
* using lsx instead of Jukka's shell constructAnselm R. Garbe2006-10-131-4/+3
* hotfixAnselm R. Garbe2006-10-061-1/+2
* Added tag 1.9 for changeset a5567a0d30112822db2627a04a2e7aa3b6c38148Anselm R. Garbe2006-10-061-0/+1
* do* has no Arg arument anymore (never called directly) 1.9Anselm R. Garbe2006-10-065-18/+18
* code polishing, removed unnecessary newlinesAnselm R. Garbe2006-10-0610-86/+23
* yet another small fix and simplification of dotileAnselm R. Garbe2006-10-061-18/+10
* removed the stack position stuffAnselm R. Garbe2006-10-058-96/+26
* small boundary check fixAnselm R. Garbe2006-10-051-2/+2
* changing MASTER value from percent into per millAnselm R. Garbe2006-10-054-9/+9
* Added tag 1.8 for changeset c71952fa3c7ca848ec38a6923b5c6d0e18fff431Anselm R. Garbe2006-10-051-0/+1
* simplified dotile(), removed misleading line 1.8Anselm R. Garbe2006-10-051-2/+3
* final fix for man pageAnselm R. Garbe2006-10-051-3/+3
* keep master ratio on resizecol -> arrangeAnselm R. Garbe2006-10-055-24/+20
* yet another simplification of dotile()Anselm R. Garbe2006-10-051-30/+25
* simplified dotile()Anselm R. Garbe2006-10-052-37/+20
* applied resizecol fix by JukkaAnselm R. Garbe2006-10-051-2/+4
* Button3 click on mode label toggles stack position nowAnselm R. Garbe2006-10-052-2/+5
* applied dave's highlight patch for big fontsAnselm R. Garbe2006-09-291-1/+1
* using ff tiled again, seems to work perfectly with new bottom stackAnselm R. Garbe2006-09-291-1/+1
* applied ality's hardcode-0 patchesAnselm R. Garbe2006-09-291-5/+5
* added symbols for different modesAnselm R. Garbe2006-09-294-6/+13
* removed useless updatemasterAnselm R. Garbe2006-09-294-9/+3
* documented the new behavior in man pageAnselm R. Garbe2006-09-291-0/+3
* fixed small offset issueAnselm R. Garbe2006-09-291-1/+1
* fixed the z-layer issue described on mailinglistAnselm R. Garbe2006-09-291-1/+8
* removed the direction flippingAnselm R. Garbe2006-09-294-66/+18
* small fix of a corner caseAnselm R. Garbe2006-09-291-1/+1
* small changeAnselm R. Garbe2006-09-292-2/+2
* added the new dotile as described on mlAnselm R. Garbe2006-09-296-36/+112
* prelim of dotile()Anselm R. Garbe2006-09-292-37/+68
* I changed sanders patch to fix the ff issue to be simplier, though it needs t...Anselm R. Garbe2006-09-291-3/+2
* first step to a more flexible dotile() algorithmAnselm R. Garbe2006-09-297-35/+52
* renamed column into areaAnselm R. Garbe2006-09-282-7/+25
* small change to READMEAnselm R. Garbe2006-09-281-1/+1
* applied Jukkas patchAnselm R. Garbe2006-09-283-17/+19
e>9e63489a ^
9506fb8e ^
728fb838 ^
ea87d005 ^
67bb838c ^



91e5b943 ^
9506fb8e ^

728fb838 ^
5645f266 ^
ea87d005 ^
9506fb8e ^
1f62d7db ^


b4b0eb24 ^
1f62d7db ^

9506fb8e ^





1f62d7db ^







dd7a4f63 ^
1f62d7db ^
419e4aa5 ^

dd7a4f63 ^
1f62d7db ^
871c502d ^
9b83f114 ^
728fb838 ^
9b83f114 ^
871c502d ^
9b83f114 ^



ea87d005 ^
3201b163 ^
766a5b6a ^

3201b163 ^
ea87d005 ^
9506fb8e ^
728fb838 ^
3d566884 ^
9506fb8e ^


3201b163 ^


ea87d005 ^
a1274aba ^
eaaeed3d ^
a1274aba ^
9506fb8e ^
89660a64 ^
728fb838 ^
dd7a4f63 ^

419e4aa5 ^

dd7a4f63 ^

5599636d ^
419e4aa5 ^
ea87d005 ^
581cce8c ^
766a5b6a ^

581cce8c ^
45cb587d ^
728fb838 ^
4162b636 ^
871c502d ^
45cb587d ^

728fb838 ^
4162b636 ^
cc952d63 ^

227f75db ^

9506fb8e ^
419e4aa5 ^
9506fb8e ^
e48e3c5c ^
3ea48208 ^
c6953a55 ^
3ea48208 ^
ecd0d386 ^



9506fb8e ^
766a5b6a ^
9506fb8e ^
766a5b6a ^
9506fb8e ^








3d566884 ^
9506fb8e ^


89660a64 ^
dd7a4f63 ^
9506fb8e ^
876e288a ^

766a5b6a ^

419e4aa5 ^
45cb587d ^
766a5b6a ^
45cb587d ^
227f75db ^

3ea48208 ^
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
                                                                 
 



                                                                      
 






                                                                       
 
             
         



                                                              
                                     
                                                           
                                                         
                                       
 
                                                                     

                          
                                                   



                                                               
                                       
                   
                  
                  






                          
                         
 
                                 
                                               
                                                     
                               

                                     
                                                      
                                                                              
                                 
                                                                      
 






                                                                          















                                                                                
                                  
                                                   
 



                                              
                                       

                            
                                         
                                      
 
                                  


                                                                
                                                 

                                              





                                                              







                                                                         
                            
                                                                       

                                              
                                        
                                                
 
                                       
                                                     
                                                   
                                                     



                                                                                     
 
                                

                                                       
                            
 
                                      
                                                                
                                    


                                                     


                                                    
 
                                       
                                       
                                                   
 
                                                      
                                                                        

                                                   

                                                

                                        
                                                   
                                        
 
                                         

                                                  
 
                                       
                                              
                                
                                                        

                                                  
                                      
                                       

                                

                                   
                                       
                                                                  
 
                                   
                                    
                                                  
 



                                      
                                
                                  
 
                                                   








                                                                           
                                                                    


                                                                               
                                                          
 
                                       

                                                                                      

                                              
 
                           
                                                 
 

                                                                       
                           
# Copyright (C) 2009, 2010  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/>.

import curses
import os
import pwd
import socket
from os.path import abspath, normpath, join, expanduser, isdir

from ranger.fsobject import Directory
from ranger.container import KeyBuffer, KeyManager, History
from ranger.ext.signal_dispatcher import SignalDispatcher
from ranger.shared import SettingsAware

ALLOWED_CONTEXTS = ('browser', 'pager', 'embedded_pager', 'taskview',
		'console')

class Environment(SettingsAware, SignalDispatcher):
	"""A collection of data which is relevant for more than
	one class.
	"""

	cwd = None  # current directory
	copy = None
	cmd = None
	cut = None
	termsize = None
	history = None
	directories = None
	last_search = None
	pathway = None
	path = None
	keybuffer = None
	keymanager = None

	def __init__(self, path):
		SignalDispatcher.__init__(self)
		self.path = abspath(expanduser(path))
		self._cf = None
		self.pathway = ()
		self.directories = {}
		self.keybuffer = KeyBuffer(None, None)
		self.keymanager = KeyManager(self.keybuffer, ALLOWED_CONTEXTS)
		self.copy = set()
		self.history = History(self.settings.max_history_size)

		try:
			self.username = pwd.getpwuid(os.geteuid()).pw_name
		except:
			self.username = 'uid:' + str(os.geteuid())
		self.hostname = socket.gethostname()
		self.home_path = os.path.expanduser('~')

		self.signal_bind('move', self._set_cf_from_signal, priority=0.1,
				weak=True)

	def _set_cf_from_signal(self, signal):
		self._cf = signal.new

	def _set_cf(self, value):
		if value is not self._cf:
			previous = self._cf
			self.signal_emit('move', previous=previous, new=value)

	def _get_cf(self):
		return self._cf

	cf = property(_get_cf, _set_cf)

	def key_append(self, key):
		"""Append a key to the keybuffer"""

		# special keys:
		if key == curses.KEY_RESIZE:
			self.keybuffer.clear()

		self.keybuffer.add(key)

	def key_clear(self):
		"""Clear the keybuffer"""
		self.keybuffer.clear()

	def at_level(self, level):
		"""
		Returns the FileSystemObject at the given level.
		level >0 => previews
		level 0 => current file/directory
		level <0 => parent directories
		"""
		if level <= 0:
			try:
				return self.pathway[level - 1]
			except IndexError:
				return None
		else:
			directory = self.cf
			for i in range(level - 1):
				if directory is None:
					return None
				if directory.is_directory:
					directory = directory.pointed_obj
				else:
					return None
			try:
				return self.directories[directory.path]
			except AttributeError:
				return None
			except KeyError:
				return directory

	def garbage_collect(self, age):
		"""Delete unused directory objects"""
		for key in tuple(self.directories):
			value = self.directories[key]
			if value.is_older_than(age): # and not value in self.pathway:
				del self.directories[key]
				if value.is_directory:
					value.files = None

	def get_selection(self):
		if self.cwd:
			return self.cwd.get_selection()
		return set()

	def get_directory(self, path):
		"""Get the directory object at the given path"""
		path = abspath(path)
		try:
			return self.directories[path]
		except KeyError:
			obj = Directory(path)
			self.directories[path] = obj
			return obj

	def get_free_space(self, path):
		stat = os.statvfs(path)
		return stat.f_bavail * stat.f_bsize

	def assign_cursor_positions_for_subdirs(self):
		"""Assign correct cursor positions for subdirectories"""
		last_path = None
		for path in reversed(self.pathway):
			if last_path is None:
				last_path = path
				continue

			path.move_to_obj(last_path)
			last_path = path

	def ensure_correct_pointer(self):
		if self.cwd:
			self.cwd.correct_pointer()

	def history_go(self, relative):
		"""Move relative in history"""
		if self.history:
			self.history.move(relative).go()

	def enter_dir(self, path, history = True):
		"""Enter given path"""
		if path is None: return
		path = str(path)

		previous = self.cwd

		# get the absolute path
		path = normpath(join(self.path, expanduser(path)))

		if not isdir(path):
			return False
		new_cwd = self.get_directory(path)

		try:
			os.chdir(path)
		except:
			return True
		self.path = path
		self.cwd = new_cwd

		self.cwd.load_content_if_outdated()

		# build the pathway, a tuple of directory objects which lie
		# on the path to the current directory.
		if path == '/':
			self.pathway = (self.get_directory('/'), )
		else:
			pathway = []
			currentpath = '/'
			for dir in path.split('/'):
				currentpath = join(currentpath, dir)
				pathway.append(self.get_directory(currentpath))
			self.pathway = tuple(pathway)

		self.assign_cursor_positions_for_subdirs()

		# set the current file.
		self.cwd.sort_directories_first = self.settings.sort_directories_first
		self.cwd.sort_reverse = self.settings.sort_reverse
		self.cwd.sort_if_outdated()
		self.cf = self.cwd.pointed_obj

		if history:
			self.history.add(new_cwd)

		self.signal_emit('cd', previous=previous, new=self.cwd)

		return True