OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import copy | 5 import copy |
6 import json | 6 import json |
7 import logging | |
8 | |
9 import compiled_file_system as compiled_fs | |
10 from third_party.json_schema_compiler.model import UnixName | |
11 | 7 |
12 class SidenavDataSource(object): | 8 class SidenavDataSource(object): |
13 """This class reads in and caches a JSON file representing the side navigation | 9 """This class reads in and caches a JSON file representing the side navigation |
14 menu. | 10 menu. |
15 """ | 11 """ |
16 class Factory(object): | 12 class Factory(object): |
17 def __init__(self, compiled_fs_factory, json_path): | 13 def __init__(self, compiled_fs_factory, json_path): |
18 self._cache = compiled_fs_factory.Create(self._CreateSidenavDict, | 14 self._cache = compiled_fs_factory.Create(self._CreateSidenavDict, |
19 SidenavDataSource) | 15 SidenavDataSource) |
20 self._json_path = json_path | 16 self._json_path = json_path |
(...skipping 29 matching lines...) Expand all Loading... |
50 if item.get('fileName', '') == self._file_name: | 46 if item.get('fileName', '') == self._file_name: |
51 item['selected'] = True | 47 item['selected'] = True |
52 return True | 48 return True |
53 if 'items' in item: | 49 if 'items' in item: |
54 if self._AddSelected(item['items']): | 50 if self._AddSelected(item['items']): |
55 item['child_selected'] = True | 51 item['child_selected'] = True |
56 return True | 52 return True |
57 return False | 53 return False |
58 | 54 |
59 def get(self, key): | 55 def get(self, key): |
60 sidenav = copy.deepcopy(self._cache.GetFromFile( | 56 sidenav_items = copy.deepcopy(self._cache.GetFromFile( |
61 '%s/%s_sidenav.json' % (self._json_path, key))) | 57 '%s/%s_sidenav.json' % (self._json_path, key))) |
62 self._AddSelected(sidenav) | 58 self._AddSelected(sidenav_items) |
63 return sidenav | 59 return sidenav_items |
OLD | NEW |