Author: jmorliaguet
Date: Sun Oct  9 19:57:26 2005
New Revision: 28089

Modified:
   z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py
   z3lab/cpsskins/branches/jmo-perspectives/thememanager.py
Log:

- functional INodeMoving between slots (more code cleanup to come)



Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py   Sun Oct 
 9 19:57:26 2005
@@ -81,11 +81,14 @@
 
         tmutil = getThemeManager()
 
+        # the element is not physically moved but slot -> portlet relations
+        # need to be updated.
         tmutil.movePortlet(
             src_slot=src_container,
             dest_slot=dest_container,
             portlet=content,
             )
+
         return content
 
 class SlotRemoving(BrowserView):
@@ -121,7 +124,7 @@
         display.remove(content)
 
 class SlotOrdering(BrowserView):
-    """A view for removing elements from slots
+    """A view for reordering elements in slots
     """
     implements(INodeOrdering)
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/thememanager.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/thememanager.py    (original)
+++ z3lab/cpsskins/branches/jmo-perspectives/thememanager.py    Sun Oct  9 
19:57:26 2005
@@ -179,10 +179,10 @@
     def movePortlet(self, src_slot, dest_slot, portlet):
         """Move a portlet between slots.
         """
-
         reltool = RelationTool(portlet)
 
-        relations = reltool.search(
+        # TODO: let compound predicates support predicates of different arities
+        old_relations = reltool.search(
             predicate=hasPortlet,
             first=src_slot,
             second=portlet,
@@ -191,69 +191,46 @@
             first=src_slot,
             second=portlet,
             )
-
-        rel = relations[0]
+        rel = reltool.get(old_relations[0])
         perspective = len(rel) == 3 and rel.third or None
-
-        if perspective is not None:
-            relation = TriadicRelation(
-                predicate=hasPortletFromPerspective,
-                first=dest_slot,
-                second=portlet,
-                third=perspective,
-                )
-            ids = reltool.search(
-                predicate=hasPortletFromPerspective,
-                first=src_slot,
-                second=portlet,
-                third=perspective,
-                )
-        else:
-            relation = DyadicRelation(
-                predicate=hasPortlet,
-                first=dest_slot,
-                second=portlet,
-                )
-            ids = reltool.search(
-                predicate=hasPortlet,
-                first=src_slot,
-                second=portlet,
-                )
-
-        theme = self.getThemeInContext(src_slot)
-        relations = theme.getStorage(IRelationStorage)
-        relations.add(relation)
-
-        reltool.remove(ids)
-
+        # set the dest_slot -> portlet relation
+        self.setPortlet(dest_slot, portlet, perspective)
+        # remove old src_slot -> portlet relations
+        reltool.remove(old_relations)
+        # set the portlet's parent explicitly
         portlet.__parent__ = dest_slot
 
-    def setPortlet(self, slot, portlet, perspective):
-        """Set a portlet in a slot
+    def addPortlet(self, slot, portlet, perspective):
+        """Add a portlet to a slot
         """
         theme = self.getThemeInContext(slot)
         portlets = theme.getStorage(IPortletStorage)
         portlets.add(portlet)
 
-        if perspective is not None:
-            relation = TriadicRelation(
-                predicate=hasPortletFromPerspective,
+        self.setPortlet(slot, portlet, perspective)
+        return portlet
+
+    def setPortlet(self, slot, portlet, perspective):
+        """Set a portlet in a slot
+        """
+        if perspective is None:
+            relation = DyadicRelation(
+                predicate=hasPortlet,
                 first=slot,
                 second=portlet,
-                third=perspective,
                 )
         else:
-            relation = DyadicRelation(
-                predicate=hasPortlet,
+            relation = TriadicRelation(
+                predicate=hasPortletFromPerspective,
                 first=slot,
                 second=portlet,
+                third=perspective,
                 )
 
+        theme = self.getThemeInContext(slot)
         relations = theme.getStorage(IRelationStorage)
         relations.add(relation)
 
-        return portlet
-
     def removePortlet(self, slot, portlet, perspective=None):
         """Remove a portlet
         """
@@ -261,35 +238,23 @@
         portlets = theme.getStorage(IPortletStorage)
 
         reltool = RelationTool(slot)
-        if perspective is not None:
+        if perspective is None:
             ids = reltool.search(
-                predicate=hasPortletFromPerspective,
+                predicate=hasPortlet,
                 first=slot,
                 second=portlet,
-                third=perspective,
                 )
         else:
             ids = reltool.search(
-                predicate=hasPortlet,
+                predicate=hasPortletFromPerspective,
                 first=slot,
                 second=portlet,
+                third=perspective,
                 )
 
         reltool.remove(ids)
         del portlets[portlet.name()]
 
-    def setFormat(self, object=None, format=None, predicate=hasFormat):
-        """Set a format
-        """
-        theme = self.getThemeInContext(object)
-        formats = theme.getStorage(IFormatStorage)
-        format = formats.add(format)
-
-        relation = DyadicRelation(predicate, object, format)
-        relations = theme.getStorage(IRelationStorage)
-        relations.add(relation)
-        return format
-
     def removeDisplays(self, object):
         """Remove the displays of a given element
         """
@@ -318,6 +283,7 @@
         relations = reltool.search(first=object, predicate=hasFormat)
         reltool.remove(relations)
 
+
 def getThemeManager():
     return queryUtility(IThemeManagement, THEMES_MANAGER_NAME)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to