summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-27 16:43:12 +0100
committerhut <hut@lavabit.com>2009-12-27 16:43:12 +0100
commit0b8a9d79273a91787eb4f373989d85e7a93e673b (patch)
tree17c9d982cd089d45fc6cfae8a0686241067d6b5b /ranger
parentd309f218d7d00405d5bca2f8c77344ce0c33a0bb (diff)
downloadranger-0b8a9d79273a91787eb4f373989d85e7a93e673b.tar.gz
implemented customized cycling through the directory
Diffstat (limited to 'ranger')
-rw-r--r--ranger/actions.py19
-rw-r--r--ranger/defaults/keys.py12
-rw-r--r--ranger/fsobject/directory.py15
3 files changed, 42 insertions, 4 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index 9ccbc93f..968aae4f 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -5,7 +5,7 @@ from ranger.shared import EnvironmentAware, SettingsAware
 from ranger import fsobject
 
 class Actions(EnvironmentAware, SettingsAware):
-	search_method = None
+	search_method = 'ctime'
 	search_forward = False
 
 	def search(self, order=None, forward=True):
@@ -33,8 +33,23 @@ class Actions(EnvironmentAware, SettingsAware):
 
 			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', 'type', 'time'):
+		if order in ('search', 'tag', 'size', 'mimetype', 'ctime'):
 			self.search_method = order
 			self.search_forward = forward
 
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 2f4106c3..c3490c4a 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -39,8 +39,8 @@ 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'))
@@ -85,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):
@@ -103,6 +105,12 @@ def initialize_commands(command_list):
 	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:
 		bind("`" + key, "'" + key, do('enter_bookmark', key))
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 4f35dd9e..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
 
@@ -273,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)
='author Kartik Agaram <vc@akkartik.com> 2020-11-15 15:56:02 -0800 committer Kartik Agaram <vc@akkartik.com> 2020-11-15 16:06:00 -0800 7239' href='/akkartik/mu/commit/400.mu?h=main&id=91dc5814dfeac0ad072c840ac52b1e68321fd39f'>91dc5814 ^
c54b7e96 ^
c5a3f655 ^
91dc5814 ^
492fb278 ^
71e4f381 ^
4b57c101 ^



71e4f381 ^
91dc5814 ^
cec5ef31 ^
c5a3f655 ^
cec5ef31 ^
c5a3f655 ^
b8d613e7 ^
1a1a1671 ^
91dc5814 ^


1a1a1671 ^
c5a3f655 ^
91dc5814 ^




01b72aa0 ^

91dc5814 ^

01b72aa0 ^
e2b55208 ^
01b72aa0 ^

e2b55208 ^
91dc5814 ^


c5a3f655 ^
eea6659a ^
c5a3f655 ^
86a12476 ^
1a1a1671 ^
91dc5814 ^
eea6659a ^


18d5bab2 ^

91dc5814 ^

71418907 ^

91dc5814 ^

5462619d ^
c79b93ca ^
307745bc ^
71e4f381 ^



6f65b65f ^

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