about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/__init__.py8
-rw-r--r--ranger/container/fsobject.py9
-rw-r--r--ranger/core/actions.py4
-rw-r--r--ranger/core/linemode.py13
-rw-r--r--ranger/gui/widgets/browsercolumn.py4
5 files changed, 18 insertions, 20 deletions
diff --git a/ranger/api/__init__.py b/ranger/api/__init__.py
index a50f706f..cc0815c2 100644
--- a/ranger/api/__init__.py
+++ b/ranger/api/__init__.py
@@ -26,3 +26,11 @@ def hook_ready(fm):
     This hook is executed after the user interface is initialized.  You should
     NOT print anything to stdout anymore from here on.  Use fm.notify instead.
     """
+
+from ranger.core.linemode import LinemodeBase
+
+def register_linemode(*linemodes):
+    """Register the linemodes in a dictionary of the available linemodes."""
+    from ranger.container.fsobject import FileSystemObject
+    for linemode in linemodes:
+        FileSystemObject.linemode_dict[linemode.name] = linemode()
diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py
index 32b1dc8b..43499e15 100644
--- a/ranger/container/fsobject.py
+++ b/ranger/container/fsobject.py
@@ -17,8 +17,7 @@ from grp import getgrgid
 from os import lstat, stat, getcwd
 from os.path import abspath, basename, dirname, realpath, splitext, extsep, relpath
 from pwd import getpwuid
-from ranger.core.linemode import REGISTERED_LINEMODES
-from ranger.core.linemode import DEFAULT_LINEMODE
+from ranger.core.linemode import DEFAULT_LINEMODE, REGISTERED_LINEMODES
 from ranger.core.shared import FileManagerAware, SettingsAware
 from ranger.ext.shell_escape import shell_escape
 from ranger.ext.spawn import spawn
@@ -85,6 +84,10 @@ class FileSystemObject(FileManagerAware, SettingsAware):
     basename_is_rel_to = None
 
     _linemode = DEFAULT_LINEMODE
+    linemode_dict = dict(
+        (linemode.name, linemode()) for linemode in
+        [DefaultLinemode, TitleLinemode, PermissionsLinemode]
+    )
 
     def __init__(self, path, preload=None, path_is_abs=False, basename_is_rel_to=None):
         if not path_is_abs:
@@ -111,7 +114,7 @@ class FileSystemObject(FileManagerAware, SettingsAware):
 
         # Set the line mode from fm.default_linemodes
         for method, argument, linemode in self.fm.default_linemodes:
-            if linemode in REGISTERED_LINEMODES:
+            if linemode in linemode_dict:
                 if method == "always":
                     self._linemode = linemode
                     break
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index aa10e34f..6e0dc797 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -27,7 +27,7 @@ from ranger.core.tab import Tab
 from ranger.container.file import File
 from ranger.core.loader import CommandLoader, CopyLoader
 from ranger.container.settings import ALLOWED_SETTINGS
-from ranger.core.linemode import REGISTERED_LINEMODES, DEFAULT_LINEMODE
+from ranger.core.linemode import DEFAULT_LINEMODE
 
 MACRO_FAIL = "<\x01\x01MACRO_HAS_NO_VALUE\x01\01>"
 
@@ -167,7 +167,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
         if mode == "normal":
             mode = DEFAULT_LINEMODE
 
-        if mode not in REGISTERED_LINEMODES:
+        if mode not in self.thisfile.linemode_dict:
             self.notify("Unhandled linemode: `%s'" % mode, bad=True)
             return
 
diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py
index 8b5084b0..ee770cb0 100644
--- a/ranger/core/linemode.py
+++ b/ranger/core/linemode.py
@@ -3,16 +3,6 @@
 from abc import *
 
 DEFAULT_LINEMODE = "filename"
-REGISTERED_LINEMODES = dict()
-
-def register_linemode(*linemodes):
-    """Register a linemode in a dictionary of available linemodes."""
-    for linemode in linemodes:
-        REGISTERED_LINEMODES[linemode.name] = linemode()
-
-def lookup_linemode(name):
-    """Lookup the linemode instance by its name"""
-    return REGISTERED_LINEMODES[name]
 
 
 class LinemodeBase(object):
@@ -86,6 +76,3 @@ class PermissionsLinemode(LinemodeBase):
 
     def infostring(self, file, metadata):
         return ""
-
-
-register_linemode(DefaultLinemode, PermissionsLinemode, TitleLinemode)
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 427a323d..2e9bf7a2 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -252,12 +252,12 @@ class BrowserColumn(Pager):
 
             # Extract linemode-related information from the drawn object
             metadata = None
-            current_linemode = linemode.lookup_linemode(drawn._linemode)
+            current_linemode = drawn.linemode_dict[drawn._linemode]
             if current_linemode.uses_metadata:
                 metadata = self.fm.metadata.get_metadata(drawn.path)
                 if not all(getattr(metadata, tag)
                            for tag in current_linemode.required_metadata):
-                    current_linemode = linemode.lookup_linemode(linemode.DEFAULT_LINEMODE)
+                    current_linemode = drawn.linemode_dict[linemode.DEFAULT_LINEMODE]
 
             metakey = hash(repr(sorted(metadata.items()))) if metadata else 0
             key = (self.wid, selected_i == i, drawn.marked, self.main_column,