[Zope-CVS] CVS: Products/PageDesign - IPageElement.py:1.1.2.2 PageDesign.py:1.2.2.8 ReferencedElement.py:1.1.2.2 Slot.py:1.1.2.8 IPalette.py:NONE

Shane Hathaway shane@cvs.zope.org
Sat, 10 Aug 2002 11:11:12 -0400


Update of /cvs-repository/Products/PageDesign
In directory cvs.zope.org:/tmp/cvs-serv10510

Modified Files:
      Tag: page-redesign-branch
	IPageElement.py PageDesign.py ReferencedElement.py Slot.py 
Removed Files:
      Tag: page-redesign-branch
	IPalette.py 
Log Message:
Added object icons, turned the add element dialog into a simple file chooser,
and in the process made it so page designs don't have to be aware of
palettes at all.  This is a good thing. ;-)


=== Products/PageDesign/IPageElement.py 1.1.2.1 => 1.1.2.2 ===
--- Products/PageDesign/IPageElement.py:1.1.2.1	Sat Aug  3 15:58:03 2002
+++ Products/PageDesign/IPageElement.py	Sat Aug 10 11:11:11 2002
@@ -24,6 +24,10 @@
         """Returns the title of this element.
         """
 
+    def getIconURL():
+        """Returns the URL to an icon for this element if any.
+        """
+
     def getEditURL():
         """Returns the URL for editing this element.
 


=== Products/PageDesign/PageDesign.py 1.2.2.7 => 1.2.2.8 ===
--- Products/PageDesign/PageDesign.py:1.2.2.7	Fri Aug  9 23:33:40 2002
+++ Products/PageDesign/PageDesign.py	Sat Aug 10 11:11:11 2002
@@ -41,7 +41,6 @@
 from ISlotProvider import ISlotProvider
 from IClipboardSource import IClipboardSource
 from IClipboardTarget import IClipboardTarget
-from IPalette import IPalette
 
 # Permission name
 change_page_designs = 'Change Page Designs'
@@ -62,7 +61,6 @@
     """
     _slots = None  # { slot_name -> (element_id,) }
     template_id = None
-    default_palette_id = None
     title = ''
     _v_rendering = 0
     slots = SlotProvider()
@@ -237,39 +235,68 @@
         return guarded_getattr(aq_parent(aq_inner(self)), id)
 
 
-    security.declareProtected(change_page_designs, 'getDefaultPaletteId')
-    def getDefaultPaletteId(self):
-        return self.default_palette_id
+    security.declarePublic('computeParentPaths')
+    def computeParentPaths(self, path):
+        path = str(path)
+        names = path.split('/')
+        while names and not names[0]:
+            names = names[1:]
+        res = []
+        for n in range(len(names)):
+            res.append('/' + '/'.join(names[:n]))
+        return res
 
 
-    security.declareProtected(change_page_designs, 'getPaletteIds')
-    def getPaletteIds(self):
-        #meta_types = self.all_meta_types(interfaces=(IPalette,))
-        meta_types = ('Folder',)  # Quick hack ;-)
-        values = self.superValues(meta_types)
-        res = {}
-        for v in values:
-            res[v.getId()] = 1
-        res = res.keys()
-        res.sort()
-        return res
+    security.declareProtected(change_page_designs, 'getFolderContentsInfo')
+    def getFolderContentsInfo(self, folder, REQUEST=None):
+        res = []
+        sort_on = None
+        sort_order = ''
+        if REQUEST is not None:
+            sort_on = str(REQUEST.get('sort_on', 'id')).lower()
+            sort_order = REQUEST.get('sort_order', '')
+
+        for ob in folder.objectValues():
+            base = aq_base(ob)
+            if hasattr(base, 'Title'):
+                title = ob.Title()
+            else:
+                title = str(getattr(ob, 'title', ''))
 
+            if hasattr(base, 'getId'):
+                id = ob.getId()
+            else:
+                id = str(getattr(ob, 'id', ''))
 
-    security.declareProtected(change_page_designs, 'getPalette')
-    def getPalette(self, id):
-        pal = guarded_getattr(aq_parent(aq_inner(self)), id)
-        #if not IPalette.isImplementedBy(pal):
-        #    raise DesignError, 'Not a palette'
-        return pal
+            if hasattr(base, 'Type'):
+                typ = ob.Type()
+            else:
+                typ = str(ob.meta_type)
 
+            if hasattr(base, 'getIcon'):
+                icon = ob.getIcon()
+            else:
+                icon = str(ob.icon)
 
-    security.declareProtected(change_page_designs, 'getPaletteContents')
-    def getPaletteContents(self, palette_id, REQUEST=None):
-        pal = self.getPalette(palette_id)
-        res = pal.objectValues()
-        # TODO: sort and batch based on REQUEST data:
-        # sort_on, sort_order, b_start
-        return res
+            folderish = not not getattr(base, 'isPrincipiaFolderish', None)
+            info = {
+                'id': id,
+                'title': title,
+                'type': typ,
+                'folderish': folderish,
+                'path': '/'.join(ob.getPhysicalPath()),
+                'icon': icon,
+                }
+            if sort_on == 'id':
+                # Show folders first
+                key = (not folderish, id.lower())
+            else:
+                key = str(info.get(sort_on)).lower()
+            res.append((key, info))
+        res.sort()
+        if sort_order == 'reverse':
+            res.reverse()
+        return [item[1] for item in res]
 
 
     security.declarePrivate('insertEditScripts')
@@ -369,7 +396,6 @@
     _properties = (
         {'id': 'title', 'type': 'string', 'mode': 'w'},
         {'id': 'template_id', 'type': 'string', 'mode': 'w'},
-        {'id': 'default_palette_id', 'type': 'string', 'mode': 'w'},
         )
 
     security.declareProtected(change_page_designs, 'manage_propertiesForm')


=== Products/PageDesign/ReferencedElement.py 1.1.2.1 => 1.1.2.2 ===
--- Products/PageDesign/ReferencedElement.py:1.1.2.1	Thu Aug  8 22:58:46 2002
+++ Products/PageDesign/ReferencedElement.py	Sat Aug 10 11:11:11 2002
@@ -46,6 +46,20 @@
             s = str(ob)
         return s
 
+    def getIconURL(self):
+        """Returns an URL to an icon for this element if available.
+        """
+        ob = self._deref()
+        icon = None
+        if hasattr(aq_base(ob), 'getIcon'):
+            icon = ob.getIcon()
+        elif hasattr(aq_base(ob), 'icon'):
+            icon = ob.icon
+        if icon:
+            return '/' + icon
+        else:
+            return ''
+
     def getTitle(self):
         """Returns the title of this element.
         """


=== Products/PageDesign/Slot.py 1.1.2.7 => 1.1.2.8 ===
--- Products/PageDesign/Slot.py:1.1.2.7	Fri Aug  9 23:33:40 2002
+++ Products/PageDesign/Slot.py	Sat Aug 10 11:11:11 2002
@@ -79,7 +79,7 @@
 
     element_html = '''<div class="design-element" id="%(clipboard_path)s">
     <table class="design-element-titlebar" width="100%%"><tr>
-    <td align="left">&nbsp;%(title)s</td>
+    <td align="left">%(titlebar)s</td>
     <td align="right">%(controls)s</td>
     </tr></table>
     <div class="design-element-body">%(text)s</div></div>'''
@@ -100,7 +100,7 @@
         return self.target_html % kw
 
 
-    def renderSourceHTML(self, **kw):
+    def renderSourceHTML(self, element, **kw):
         c = []
         for name in ('moveup', 'movedown', 'remove'):
             url = kw.get(name + '_url')
@@ -108,6 +108,16 @@
                 # TODO: use server-wide icons
                 c.append('<a href="%s"><img src="%s_icon" border="0" /></a>'
                          % (url, name))
+        icon_tag = edit_tag = ''
+        icon_url = element.getIconURL()
+        if icon_url:
+            icon_tag = '<img border="0" src="%s" />' % icon_url
+        edit_url = element.getEditURL()
+        if edit_url:
+            edit_tag = ('<a href="%s"><img border="0" src="edit_icon" /></a>'
+                        % edit_url)
+        
+        kw['titlebar'] = icon_tag + ' ' + escape(kw['title']) + edit_tag
         kw['controls'] = '\n'.join(c)
         return self.element_html % kw
 
@@ -188,10 +198,10 @@
                     design_url, path)
 
                 text = self.renderSourceHTML(
+                    element=e,
                     clipboard_path=path,
                     title=e.getTitle(),
                     text=text,
-                    edit_url=e.getEditURL(),
                     moveup_url=move_up_url,
                     movedown_url=move_down_url,
                     remove_url=remove_url,

=== Removed File Products/PageDesign/IPalette.py ===