summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-27 19:34:18 +0100
committerhut <hut@lavabit.com>2009-12-27 19:34:18 +0100
commitf3e9b24a4c14509c023ce14f27f05d5b1e6192e2 (patch)
tree189f7e31344b183274c663560cbdf0efd15840aa /ranger
parentf257e4761b725bdfed9c8d9589048fc5e3969b53 (diff)
parent0b8a9d79273a91787eb4f373989d85e7a93e673b (diff)
downloadranger-f3e9b24a4c14509c023ce14f27f05d5b1e6192e2.tar.gz
Merge branch 'cycle' into python
Diffstat (limited to 'ranger')
-rw-r--r--ranger/actions.py56
-rw-r--r--ranger/defaults/keys.py18
-rw-r--r--ranger/fsobject/directory.py32
-rw-r--r--ranger/gui/widgets/console.py2
4 files changed, 84 insertions, 24 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index e1005201..968aae4f 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -5,15 +5,53 @@ from ranger.shared import EnvironmentAware, SettingsAware
 from ranger import fsobject
 
 class Actions(EnvironmentAware, SettingsAware):
-	def search_forward(self):
-		"""Search forward for the regexp in self.env.last_search"""
-		if self.env.pwd:
-			self.env.pwd.search(self.env.last_search)
-
-	def search_backward(self):
-		"""Search backward for the regexp in self.env.last_search"""
-		if self.env.pwd:
-			self.env.pwd.search(self.env.last_search, -1)
+	search_method = 'ctime'
+	search_forward = False
+
+	def search(self, order=None, forward=True):
+		if self.search_forward:
+			direction = bool(forward)
+		else:
+			direction = not bool(forward)
+
+		if order is None:
+			order = self.search_method
+		else:
+			self.set_search_method(order=order)
+
+		if order in ('search', 'tag'):
+			if order == 'search':
+				arg = self.env.last_search
+				if arg is None:
+					return False
+				if hasattr(arg, 'search'):
+					fnc = lambda x: arg.search(x.basename)
+				else:
+					fnc = lambda x: arg in x.basename
+			elif order == 'tag':
+				fnc = lambda x: x.realpath in self.tags
+
+			return self.env.pwd.search_fnc(fnc=fnc, forward=forward)
+
+		elif order in ('size', 'mimetype', 'ctime'):
+			pwd = self.env.pwd
+			if not pwd.cycle_list:
+				lst = list(pwd.files)
+				if order == 'size':
+					fnc = lambda item: item.size
+				elif order == 'mimetype':
+					fnc = lambda item: item.mimetype
+				elif order == 'ctime':
+					fnc = lambda item: -int(item.stat and item.stat.st_ctime)
+				lst.sort(key=fnc)
+				pwd.set_cycle_list(lst)
+
+			return pwd.cycle(forward=forward)
+
+	def set_search_method(self, order, forward=True):
+		if order in ('search', 'tag', 'size', 'mimetype', 'ctime'):
+			self.search_method = order
+			self.search_forward = forward
 
 	def interrupt(self):
 		"""
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 75956b7a..c3490c4a 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -39,12 +39,14 @@ def initialize_commands(command_list):
 	bind('v', do('mark', all=True, toggle=True))
 	bind('V', do('mark', all=True, val=False))
 
-	bind('yy', 'cp', do('copy'))
-	bind('cut', do('cut'))
+	bind('yy', do('copy'))
+	bind('dd', do('cut'))
 	bind('p', do('paste'))
 
 	bind('s', do('spawn', 'bash'))
 
+	bind(TAB, do('search', order='tag'))
+
 	t_hint = "show_//h//idden //p//review_files //d//irectories_first //a//uto_load_preview //c//ollapse_preview"
 	command_list.hint(t_hint, 't')
 	bind('th', do('toggle_boolean_option', 'show_hidden'))
@@ -83,6 +85,8 @@ def initialize_commands(command_list):
 	bind('term', do('spawn', 'x-terminal-emulator'))
 	bind('du', do('runcmd', 'du --max-depth=1 -h | less'))
 	bind('tf', do('open_console', cmode.COMMAND, 'filter '))
+	d_hint = 'd//u// (disk usage) d//d// (cut)'
+	command_list.hint(d_hint, 'd')
 
 	# key combinations which change the current directory
 	def cd(path):
@@ -98,8 +102,14 @@ def initialize_commands(command_list):
 	bind('gs', do('cd', '/srv'))
 	bind('gR', do('cd', RANGERDIR))
 
-	bind('n', do('search_forward'))
-	bind('N', do('search_backward'))
+	bind('n', do('search', forward=True))
+	bind('N', do('search', forward=False))
+
+	bind('cc', do('search', forward=True, order='ctime'))
+	bind('cm', do('search', forward=True, order='mimetype'))
+	bind('cs', do('search', forward=True, order='size'))
+	c_hint = '//c//time //m//imetype //s//ize'
+	command_list.hint(c_hint, 'c')
 
 	# bookmarks
 	for key in ALLOWED_BOOKMARK_KEYS:
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index f263aa74..6c9ab7b1 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -1,6 +1,7 @@
 from ranger.fsobject import BAD_INFO, File, FileSystemObject
 from ranger.shared import SettingsAware
 from ranger.ext.accumulator import Accumulator
+from collections import deque
 from ranger import log
 import ranger.fsobject
 
@@ -18,6 +19,7 @@ class NoDirectoryGiven(Exception):
 class Directory(FileSystemObject, Accumulator, SettingsAware):
 	enterable = False
 	load_generator = None
+	cycle_list = None
 	loading = False
 
 	filenames = None
@@ -171,6 +173,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 			self.files = None
 			self.infostring = BAD_INFO
 
+		self.cycle_list = None
 		self.content_loaded = True
 		self.loading = False
 
@@ -251,21 +254,18 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 
 		Accumulator.move_to_obj(self, arg, attr='path')
 
-	def search(self, arg, direction = 1):
-		"""Search for a regular expression"""
-		if self.empty() or arg is None:
+	def search_fnc(self, fnc, forward=True):
+		if not hasattr(fnc, '__call__'):
 			return False
-		elif hasattr(arg, 'search'):
-			fnc = lambda x: arg.search(x.basename)
-		else:
-			fnc = lambda x: arg in x.basename
 
 		length = len(self)
 
-		if direction > 0:
-			generator = ((self.pointer + (x + 1)) % length for x in range(length-1))
+		if forward:
+			generator = ((self.pointer + (x + 1)) % length \
+					for x in range(length-1))
 		else:
-			generator = ((self.pointer - (x + 1)) % length for x in range(length-1))
+			generator = ((self.pointer - (x + 1)) % length \
+					for x in range(length-1))
 
 		for i in generator:
 			_file = self.files[i]
@@ -276,6 +276,18 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 				return True
 		return False
 
+	def set_cycle_list(self, lst):
+		self.cycle_list = deque(lst)
+
+	def cycle(self, forward=True):
+		if self.cycle_list:
+			if forward:
+				self.cycle_list.rotate(-1)
+			else:
+				self.cycle_list.rotate(1)
+
+			self.move_to_obj(self.cycle_list[0])
+
 	def correct_pointer(self):
 		"""Make sure the pointer is in the valid range"""
 		Accumulator.correct_pointer(self)
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 2d6df2a7..92c57a46 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -296,7 +296,7 @@ class SearchConsole(Console):
 		if self.fm.env.pwd:
 			regexp = re.compile(self.line, re.L | re.U | re.I)
 			self.fm.env.last_search = regexp
-			if self.fm.env.pwd.search(regexp):
+			if self.fm.search(order='search'):
 				self.fm.env.cf = self.fm.env.pwd.pointed_obj
 		Console.execute(self)
 
title='author hut <hut@lavabit.com> 2010-01-13 05:51:27 +0100 committer hut <hut@lavabit.com> 2010-01-13 05:51:27 +0100 updated pydoc documentation' href='/akspecs/ranger/commit/doc/pydoc/ranger.fsobject.directory.html?h=v1.8.0&id=b3556b21e23eb3381b220e0d3319d94b3a89e0ac'>b3556b21 ^
f07bb12f ^





34a60763 ^

f07bb12f ^

4c13e1f2 ^

34a60763 ^

f07bb12f ^









1cd06f3f ^
f07bb12f ^



























62cd83ba ^



f07bb12f ^


























34a60763 ^

f07bb12f ^

















































4c13e1f2 ^

b3556b21 ^
f07bb12f ^






62cd83ba ^
f07bb12f ^




34a60763 ^
f07bb12f ^



34a60763 ^


f07bb12f ^






34a60763 ^
f07bb12f ^


34a60763 ^
1cd06f3f ^
f07bb12f ^

34a60763 ^
f07bb12f ^



34a60763 ^





f07bb12f ^









34a60763 ^
f07bb12f ^

34a60763 ^
f07bb12f ^

f07bb12f ^

34a60763 ^

f07bb12f ^








b3556b21 ^



f07bb12f ^








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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389