about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2014-12-03 16:45:37 +0100
committerhut <hut@lepus.uberspace.de>2014-12-03 16:45:37 +0100
commit3e0aa7a0ae37768dbe19f07ae086d3ded0064d19 (patch)
tree0e778f942d6a38bb3de0a4f0b9b301a9dbe2b65d /ranger
parent5c97716aa0e260ec2b0cd6cffee1ea74fd9ff8f8 (diff)
downloadranger-3e0aa7a0ae37768dbe19f07ae086d3ded0064d19.tar.gz
allow setting a "linemode" for each file/directory
Diffstat (limited to 'ranger')
-rw-r--r--ranger/container/directory.py4
-rw-r--r--ranger/container/file.py2
-rw-r--r--ranger/container/fsobject.py6
-rw-r--r--ranger/core/actions.py36
4 files changed, 48 insertions, 0 deletions
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index c6987a76..c331053a 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -567,6 +567,10 @@ class Directory(FileSystemObject, Accumulator, Loadable):
         """Is the directory empty?"""
         return self.files is None or len(self.files) == 0
 
+    def _set_linemode_of_children(self, mode):
+        for f in self.files:
+            f._set_linemode(mode)
+
     def __nonzero__(self):
         """Always True"""
         return True
diff --git a/ranger/container/file.py b/ranger/container/file.py
index ab677125..7297dc30 100644
--- a/ranger/container/file.py
+++ b/ranger/container/file.py
@@ -43,6 +43,8 @@ class File(FileSystemObject):
     preview_known = False
     preview_loading = False
 
+    _linemode = "filename"
+
     @property
     def firstbytes(self):
         try:
diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py
index 6f206d0d..1bdbcde7 100644
--- a/ranger/container/fsobject.py
+++ b/ranger/container/fsobject.py
@@ -80,6 +80,9 @@ class FileSystemObject(FileManagerAware, SettingsAware):
 
     basename_is_rel = False
 
+    # the line mode may be "filename", "details" or "title"
+    _linemode = "filename"
+
     def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel=False):
         if not path_is_abs:
             path = abspath(path)
@@ -373,3 +376,6 @@ class FileSystemObject(FileManagerAware, SettingsAware):
                 self.vcs_outdated = True
             return True
         return False
+
+    def _set_linemode(self, mode):
+        self._linemode = mode
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index ba6b3658..f3f1f04c 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -151,6 +151,42 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
         """Redraw the window"""
         self.ui.redraw_window()
 
+    def linemode(self, mode, directory=None, depth=0):
+        """
+        Change what is displayed as a filename.
+
+        "mode" may be: "filename", "details", "title"
+        "directory" specifies the directory. None means the current directory
+        "depth" specifies the recursion depth
+        """
+
+        assert mode in ("filename", "details", "title")
+
+        if directory is None:
+            directory = self.fm.thisdir
+
+        directories = set([directory])
+        bucket = set()
+
+        current_depth = 0
+
+        while True:
+            if current_depth >= depth:
+                for direct in directories:
+                    direct._set_linemode_of_children(mode)
+                break
+
+            else:
+                for direct in directories:
+                    direct._set_linemode_of_children(mode)
+                    for file_ in direct.files:
+                        if file_.is_directory:
+                            bucket.add(file_)
+
+                directories, bucket = bucket, directories
+                bucket.clear()
+                current_depth += 1
+
     def open_console(self, string='', prompt=None, position=None):
         """Open the console"""
         self.change_mode('normal')