Luke Plant avatar Luke Plant committed 9775698

Removed some code duplication.

Comments (0)

Files changed (1)

semanticeditor/utils/presentation.py

     # of 'newrow_' or 'newcol_' + id of block they precede.
 
     sect_dict = dict((s.sect_id, s) for s in structure)
-    row_info = {} # key = sect_id, val = [PresentationInfo]
-    col_info = {} # key = sect_id, val = [PresentationInfo]
+    command_info = {}
+    for c in COMMANDS:
+        # for each command, store a dictionary that is
+        # key = sect_id, val = [PresentationInfo]
+        command_info[c.name] = {}
+
     for sect_id, presinfo in styleinfo.items():
-        if sect_id.startswith(_NEWROW_PREFIX):
-            real_sect_id = sect_id[len(_NEWROW_PREFIX):]
-            sect = sect_dict.get(real_sect_id)
-            if sect is not None:
-                parent = get_parent(root, sect.node)
-                if not is_root(parent):
-                    raise BadStructure("Section \"%(name)s\" is not at the top level of "
-                                       "the document, and therefore cannot have a column "
-                                       "structure applied to it.  Please move the 'New row' "
-                                       "command to a top level element." %
-                                       dict(name=sect.name))
+        for c in COMMANDS:
+            prefix = c.name + "_"
+            if sect_id.startswith(prefix):
+                real_sect_id = sect_id[len(prefix):]
+                sect = sect_dict.get(real_sect_id)
+                if sect is not None:
+                    parent = get_parent(root, sect.node)
+                    if not is_root(parent):
+                        raise BadStructure("Section \"%(name)s\" is not at the top level of the"
+                                           " document, and therefore cannot have a column"
+                                           " structure applied to it.  Please move the"
+                                           " '%(commandname)s' command to a top level element." %
+                                           dict(name=sect.name,
+                                                commandname=c.name))
 
-                row_info[real_sect_id] = presinfo
+                command_info[c.name][real_sect_id] = presinfo
 
-        if sect_id.startswith(_NEWCOL_PREFIX):
-            real_sect_id = sect_id[len(_NEWCOL_PREFIX):]
-            sect = sect_dict.get(real_sect_id)
-            if sect is not None:
-                parent = get_parent(root, sect.node)
-                if not is_root(parent):
-                    raise BadStructure("Section \"%(name)s\" is not at the top level of "
-                                       "the document, and therefore cannot have a column "
-                                       "structure applied to it.  Please move the 'New column' "
-                                       "command to a top level element." %
-                                       dict(name=sect.name))
-                col_info[real_sect_id] = presinfo
-
-    return row_info, col_info
+    return command_info
 
 def _create_layout(root, styleinfo, structure):
     # Find the layout commands
-    row_info, col_info = _find_layout_commands(root, structure, styleinfo)
+    command_info = _find_layout_commands(root, structure, styleinfo)
+    row_info = command_info[NEWROW.name]
+    col_info = command_info[NEWCOL.name]
 
     # Build a Layout structure
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.