summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/settingobject.py36
-rw-r--r--ranger/core/main.py5
-rw-r--r--ranger/core/shared.py71
3 files changed, 51 insertions, 61 deletions
diff --git a/ranger/container/settingobject.py b/ranger/container/settingobject.py
index 8fa27a43..28f1c639 100644
--- a/ranger/container/settingobject.py
+++ b/ranger/container/settingobject.py
@@ -2,9 +2,11 @@
 # This software is distributed under the terms of the GNU GPL version 3.
 
 from inspect import isfunction
-from ranger.ext.signals import SignalDispatcher
+from ranger.ext.signals import SignalDispatcher, Signal
 from ranger.core.shared import FileManagerAware
+from ranger.gui.colorscheme import _colorscheme_name_to_class
 import re
+import os
 
 ALLOWED_SETTINGS = {
     'autosave_bookmarks': bool,
@@ -70,6 +72,37 @@ class SettingObject(SignalDispatcher, FileManagerAware):
             self.signal_bind('setopt.'+name,
                     self._raw_set_with_signal, priority=0.2)
 
+    def _sanitize(self, name, value):
+        if name == 'column_ratios':
+            # TODO: cover more cases here
+            if isinstance(value, tuple):
+                return list(value)
+            if not isinstance(value, list) or len(value) < 2:
+                return [1, 1]
+            else:
+                return [int(i) if str(i).isdigit() else 1 for i in value]
+
+        elif name == 'colorscheme':
+            signal = Signal(value=value, previous="Penis", fm=self.fm)
+            _colorscheme_name_to_class(signal)
+            return signal.value
+
+        elif name == 'preview_script':
+            if isinstance(value, str):
+                result = os.path.expanduser(value)
+                if os.path.exists(result):
+                    return result
+                return None
+
+        elif name == 'use_preview_script':
+            if self._settings['preview_script'] is None and value \
+                    and self.fm.ui.is_on:
+                self.fm.notify("Preview script undefined or not found!",
+                        bad=True)
+
+        # fallback:
+        return value
+
     def set(self, name, value, path=None):
         assert name in ALLOWED_SETTINGS, "No such setting: {0}!".format(name)
         if name not in self._settings:
@@ -139,6 +172,7 @@ class SettingObject(SignalDispatcher, FileManagerAware):
     __setitem__ = __setattr__
 
     def _raw_set(self, name, value, path):
+        value = self._sanitize(name, value)
         if path:
             if not path in self._localsettings:
                 self._localsettings[path] = dict()
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 7ad71e96..67377147 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -10,6 +10,7 @@ def main():
     """initialize objects and run the filemanager"""
     import locale
     import ranger.api
+    from ranger.container.settingobject import SettingObject
     from ranger.core.shared import FileManagerAware, SettingsAware
     from ranger.core.fm import FM
 
@@ -52,7 +53,7 @@ def main():
                     sys.stdout.write(line)
         return 1 if arg.fail_unless_cd else 0 # COMPAT
 
-    SettingsAware._setup(clean=arg.clean)
+    SettingsAware._setup(SettingObject())
 
     if arg.selectfile:
         arg.selectfile = os.path.abspath(arg.selectfile)
@@ -87,7 +88,7 @@ def main():
     try:
         # Initialize objects
         fm = FM(paths=targets)
-        FileManagerAware.fm = fm
+        FileManagerAware._setup(fm)
         load_settings(fm, arg.clean)
 
         if arg.list_unused_keys:
diff --git a/ranger/core/shared.py b/ranger/core/shared.py
index 30eb9038..23f1cc24 100644
--- a/ranger/core/shared.py
+++ b/ranger/core/shared.py
@@ -4,67 +4,22 @@
 """Shared objects contain singletons for shared use."""
 
 from ranger.ext.lazy_property import lazy_property
-import os.path
 
-class Awareness(object):
-    pass
+class FileManagerAware(object):
+    """Subclass this to gain access to the global "FM" object."""
+    @staticmethod
+    def _setup(fm):
+        FileManagerAware.fm = fm
+
+class SettingsAware(object):
+    """Subclass this to gain access to the global "SettingObject" object."""
+    @staticmethod
+    def _setup(settings):
+        SettingsAware.settings = settings
 
-class EnvironmentAware(Awareness):
-    # This creates an instance implicitly, mainly for unit tests
+class EnvironmentAware(object):  # COMPAT
+    """DO NOT USE.  This is for backward compatibility only."""
     @lazy_property
     def env(self):
         from ranger.core.environment import Environment
         return Environment(".")
-
-class FileManagerAware(Awareness):
-    # This creates an instance implicitly, mainly for unit tests
-    @lazy_property
-    def fm(self):
-        from ranger.core.fm import FM
-        return FM()
-
-class SettingsAware(Awareness):
-    # This creates an instance implicitly, mainly for unit tests
-    @lazy_property
-    def settings(self):
-        from ranger.ext.openstruct import OpenStruct
-        return OpenStruct()
-
-    @staticmethod
-    def _setup(clean=True):
-        from ranger.container.settingobject import SettingObject
-        import ranger
-        import sys
-        settings = SettingObject()
-
-        from ranger.gui.colorscheme import _colorscheme_name_to_class
-        settings.signal_bind('setopt.colorscheme',
-                _colorscheme_name_to_class, priority=1)
-
-        settings.signal_bind('setopt.column_ratios',
-                _sanitize_setting_column_ratios, priority=1)
-
-        def after_setting_preview_script(signal):
-            if isinstance(signal.value, str):
-                signal.value = os.path.expanduser(signal.value)
-                if not os.path.exists(signal.value):
-                    signal.value = None
-        settings.signal_bind('setopt.preview_script',
-                after_setting_preview_script, priority=1)
-        def after_setting_use_preview_script(signal):
-            if signal.fm.settings.preview_script is None and signal.value \
-                    and signal.fm.ui.is_on:
-                signal.fm.notify("Preview script undefined or not found!",
-                        bad=True)
-        settings.signal_bind('setopt.use_preview_script',
-                after_setting_use_preview_script, priority=1)
-
-        SettingsAware.settings = settings
-
-def _sanitize_setting_column_ratios(signal):
-    if isinstance(signal.value, tuple):
-        signal.value = list(signal.value)
-    if not isinstance(signal.value, list) or len(signal.value) < 2:
-        signal.value = [1,1]
-    else:
-        signal.value = [int(i) if str(i).isdigit() else 1 for i in signal.value]
ious revision' href='/akkartik/mu/blame/032array.cc?h=hlt&id=900e6a0efe72ffb1fa4ab098689493f408a060a8'>^
c6034af3 ^
15936c91 ^
b24eb476 ^
b8348923 ^
c6520d96 ^
15936c91 ^
b8348923 ^
b24eb476 ^
b0bf5321 ^
c6520d96 ^
b24eb476 ^
795f5244 ^
c6520d96 ^
b8348923 ^

c6520d96 ^

d160a8e1 ^
5497090a ^
7e9c6925 ^
b8348923 ^



1ead3562 ^
c6520d96 ^
bc643692 ^


c6520d96 ^
d160a8e1 ^
57699011 ^



d160a8e1 ^
9edabeaa ^
1ead3562 ^
c6520d96 ^
9edabeaa ^


086acf39 ^
9edabeaa ^


93b7d983 ^
795f5244 ^
c6034af3 ^
1b76245c ^
49659e72 ^
3076bab4 ^
b8348923 ^
49659e72 ^
a55bbd06 ^
b8348923 ^




c36eb25c ^



c36eb25c ^




a0b9fa55 ^
c36eb25c ^






3adc9e08 ^
c4e143d6 ^


1b76245c ^
3adc9e08 ^

c4e143d6 ^
1b76245c ^
3adc9e08 ^

c36eb25c ^


7284d503 ^

88be3dbc ^
1ead3562 ^
c6520d96 ^
bc643692 ^


c6520d96 ^
7e9c6925 ^
7e9c6925 ^

88be3dbc ^
1ead3562 ^
c6520d96 ^
bc643692 ^



c6520d96 ^
07d35c4a ^
07d35c4a ^

1848b18f ^

a55bbd06 ^
795f5244 ^
b8515e8a ^
a55bbd06 ^
b8515e8a ^
acc4792d ^
e4630643 ^

b8515e8a ^
15936c91 ^
1ad3fe9e ^
1b76245c ^
18e626df ^

15936c91 ^





fb85b3b4 ^

15936c91 ^
fb85b3b4 ^
c6034af3 ^
bb7142db ^
1b76245c ^
fb85b3b4 ^

b8515e8a ^



c6034af3 ^
15936c91 ^
b24eb476 ^
263e6b2a ^
18e626df ^
acc4792d ^
46026f62 ^

15936c91 ^


c6034af3 ^
15936c91 ^

551d155c ^

15936c91 ^
cdd6fd09 ^
795f5244 ^
fb1fcbc9 ^




a55bbd06 ^


7e9c6925 ^
c6034af3 ^
947f06fb ^



c6034af3 ^
7e9c6925 ^

b8348923 ^








551d155c ^
5f98a10c ^
1ead3562 ^
c6520d96 ^
bc643692 ^





15936c91 ^
551d155c ^
5f98a10c ^
551d155c ^
051c4738 ^
5f98a10c ^
1ead3562 ^
c6520d96 ^
bc643692 ^





15936c91 ^
551d155c ^
5f98a10c ^
a55bbd06 ^
fb85b3b4 ^
5f98a10c ^
1ead3562 ^
fb85b3b4 ^






15936c91 ^
fb85b3b4 ^
15936c91 ^
fb85b3b4 ^
5c6840b8 ^


1ead3562 ^
5c6840b8 ^







991d76f3 ^
1848b18f ^
991d76f3 ^
1ead3562 ^
c6520d96 ^
bc643692 ^


991d76f3 ^
1848b18f ^
991d76f3 ^
1848b18f ^

991d76f3 ^
a55bbd06 ^
991d76f3 ^
b8515e8a ^
991d76f3 ^


e4630643 ^

b8515e8a ^
15936c91 ^
1ad3fe9e ^
991d76f3 ^
46026f62 ^

15936c91 ^


991d76f3 ^



15936c91 ^
fb85b3b4 ^
991d76f3 ^


fb85b3b4 ^

b8515e8a ^


991d76f3 ^
c6034af3 ^
15936c91 ^
b24eb476 ^
18e626df ^
acc4792d ^
18e626df ^

15936c91 ^


c6034af3 ^
15936c91 ^

551d155c ^

15936c91 ^
991d76f3 ^








a55bbd06 ^
c8a58cdc ^
991d76f3 ^
5f98a10c ^
1ead3562 ^
c6520d96 ^
bc643692 ^





991d76f3 ^

551d155c ^
5f98a10c ^
551d155c ^
991d76f3 ^
5f98a10c ^
1ead3562 ^
c6520d96 ^
bc643692 ^





991d76f3 ^

551d155c ^
5f98a10c ^
551d155c ^
c8a58cdc ^


1ead3562 ^
c6520d96 ^
bc643692 ^


c6520d96 ^
c8a58cdc ^





795f5244 ^
b8515e8a ^
c8a58cdc ^
b8515e8a ^
acc4792d ^
e4630643 ^

15936c91 ^



c8a58cdc ^

b8515e8a ^



15936c91 ^


acc4792d ^
18e626df ^

cfb142b9 ^
15936c91 ^
c8a58cdc ^

e74a2940 ^




991d76f3 ^
e74a2940 ^
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448