| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''This file contains item formatters for resource_map_header and | 6 '''This file contains item formatters for resource_map_header and |
| 7 resource_map_source files. A resource map is a mapping between resource names | 7 resource_map_source files. A resource map is a mapping between resource names |
| 8 (string) and the internal resource ID.''' | 8 (string) and the internal resource ID.''' |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 # Return the footer text. | 97 # Return the footer text. |
| 98 return '''\ | 98 return '''\ |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 const size_t %(map_name)sSize = arraysize(%(map_name)s); | 101 const size_t %(map_name)sSize = arraysize(%(map_name)s); |
| 102 ''' % { 'map_name': GetMapName(root) } | 102 ''' % { 'map_name': GetMapName(root) } |
| 103 | 103 |
| 104 | 104 |
| 105 def _FormatSource(get_key, root, lang, output_dir): | 105 def _FormatSource(get_key, root, lang, output_dir): |
| 106 from grit.format import rc_header | 106 from grit.format import rc_header |
| 107 from grit.node import include, structure | 107 from grit.node import include, structure, message |
| 108 yield _FormatSourceHeader(root) | 108 yield _FormatSourceHeader(root) |
| 109 tids = rc_header.GetIds(root) | 109 tids = rc_header.GetIds(root) |
| 110 seen = set() | 110 seen = set() |
| 111 active_descendants = [item for item in root.ActiveDescendants()] |
| 111 for item in root: | 112 for item in root: |
| 112 if isinstance(item, (include.IncludeNode, structure.StructureNode)): | 113 if isinstance(item, (include.IncludeNode, |
| 114 structure.StructureNode, |
| 115 message.MessageNode)): |
| 113 key = get_key(item) | 116 key = get_key(item) |
| 114 tid = item.attrs['name'] | 117 tid = item.attrs['name'] |
| 115 if tid in tids and key not in seen: | 118 if tid in tids and key not in seen: |
| 116 seen.add(key) | 119 seen.add(key) |
| 117 yield ' {"%s", %s},\n' % (key, tid) | 120 # For messages, only include the active ones |
| 121 if not isinstance(item, message.MessageNode) \ |
| 122 or item in active_descendants: |
| 123 yield ' {"%s", %s},\n' % (key, tid) |
| 118 yield _FormatSourceFooter(root) | 124 yield _FormatSourceFooter(root) |
| 119 | 125 |
| 120 | 126 |
| 121 def _GetItemName(item): | 127 def _GetItemName(item): |
| 122 return item.attrs['name'] | 128 return item.attrs['name'] |
| 123 | 129 |
| 124 | 130 |
| 125 def _GetItemPath(item): | 131 def _GetItemPath(item): |
| 126 return item.GetInputPath().replace("\\", "/") | 132 return item.GetInputPath().replace("\\", "/") |
| OLD | NEW |