summary refs log tree commit diff stats
path: root/tests/run/txmltree.nim
Commit message (Collapse)AuthorAgeFilesLines
* got rid of 'accept' dir in the testsAraq2011-11-191-0/+13
t.com> 2009-11-27 10:49:48 +0100 committer hut <hut@lavabit.com> 2009-11-27 10:49:48 +0100 more VROOM' href='/akspecs/ranger/commit/ranger/environment.py?h=v1.9.2&id=9506fb8e79f2d04a1ab78039bacdbee7b22109b5'>9506fb8e ^
f8e96a97 ^

9506fb8e ^
9506fb8e ^
ffec67de ^
9506fb8e ^




3ea48208 ^
45cb587d ^

9506fb8e ^













dd7a4f63 ^

419e4aa5 ^

dd7a4f63 ^

3ea48208 ^
9506fb8e ^
3d566884 ^
9506fb8e ^





dd7a4f63 ^

dd7a4f63 ^

419e4aa5 ^

dd7a4f63 ^

dd7a4f63 ^
419e4aa5 ^
45cb587d ^
















dd7a4f63 ^
45cb587d ^












cc952d63 ^

9506fb8e ^
419e4aa5 ^
9506fb8e ^
3ea48208 ^




9506fb8e ^
3ea48208 ^
9506fb8e ^
3ea48208 ^
9506fb8e ^








3d566884 ^
9506fb8e ^


dd7a4f63 ^

9506fb8e ^
419e4aa5 ^

3ea48208 ^
419e4aa5 ^
45cb587d ^


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



                                                              

                                                     
                              
                                 
                                       




                                                   
                                        

                                          













                                                              

                                                                     

                                              

                                              
        
                                      
                                    





                                                                

                                                                    

                                                   

                                                

                                        
                                                                 
                                        
















                                                                                                  
 












                                                                                           

                                
                                       
                                                                  
 




                                                          
                                
                                  
 
                                                   








                                                                           
                                                                    


                                                                               

                                                      
                                       

                                                                          
                                               
 


                                              
                           
 
from os.path import abspath, normpath, join, expanduser
from ranger.directory import Directory, NoDirectoryGiven

class Environment():
	# A collection of data which is relevant for more than
	# one class.
	def __init__(self, path, opt):
		self.path = abspath(expanduser(path))
		self.opt = opt
		self.pathway = ()
		self.last_search = None
		self.directories = {}
		self.pwd = None # current directory
		self.cf = None # current file
		self.keybuffer = ()
		self.copy = None
		self.termsize = (24, 80)
		self.history = []
		self.history_position = -1

	def key_append(self, key):
		self.keybuffer += (key, )

	def key_clear(self):
		self.keybuffer = ()
	
	def at_level(self, level):
		if level <= 0:
			try:
				return self.pathway[level - 1]
			except IndexError:
				return None
		else:
			try:
				return self.directories[self.cf.path]
			except AttributeError:
				return None
			except KeyError:
				return self.cf
	
	def get_directory(self, path):
		path = abspath(path)
		try:
			return self.directories[path]
		except KeyError:
			self.directories[path] = Directory(path)
			return self.directories[path]

	def assign_correct_cursor_positions(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_pointer_to_file_path(last_path)
			last_path = path
	
	def history_go(self, relative):
		if not self.history:
			return

		if self.history_position == -1:
			if relative > 0:
				return
			elif relative < 0:
				self.history_position = max( 0, len(self.history) - 1 + relative )
		else:
			self.history_position += relative
			if self.history_position < 0:
				self.history_position = 0

		if self.history_position >= len(self.history) - 1:
			self.history_position = -1

		self.enter_dir(self.history[self.history_position], history=False)

	def history_add(self, path):
		if self.opt['max_history_size']:
			if len(self.history) > self.history_position > (-1):
				self.history = self.history[0 : self.history_position + 1]
			if not self.history or (self.history and self.history[-1] != path):
				self.history_position = -1
				self.history.append(path)
			if len(self.history) > self.opt['max_history_size']:
				self.history.pop(0)

	def enter_dir(self, path, history = True):
		path = str(path)

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

		try:
			new_pwd = self.get_directory(path)
		except NoDirectoryGiven:
			return False

		self.path = path
		self.pwd = new_pwd

		self.pwd.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_correct_cursor_positions()

		# set the current file.
		self.pwd.directories_first = self.opt['directories_first']
		self.pwd.sort_if_outdated()
		self.cf = self.pwd.pointed_file

		if history:
			self.history_add(path)

		return True