# -*- coding: utf-8 -*-
# (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
# (c) 2003 Benoît PIN <mailto:pin@cri.ensmp.fr>

from Products.CMFCore.DirectoryView import registerDirectory
from Products.CMFCore import utils
from Products.CMFCore.permissions import AddPortalContent, ManagePortal


import MosaicDocument
import MosaicBlock
import ImageSlot, StringSlot, FileSlot, SpacerSlot

import MosaicTool
from MosaicBlockInformation import \
     MosaicBlockInformation, addMosaicBlockInformationForm, addMosaicBlockInformation, \
     SlotInfo, addSlotInfo, \
     RuleInfo, addRuleInfo

contentClasses = (
    MosaicDocument.MosaicDocument,
    MosaicBlock.MosaicBlock,
    ImageSlot.ImageSlot,
    StringSlot.StringSlot,
    FileSlot.FileSlot,
    SpacerSlot.SpacerSlot
    )

contentConstructors = (
    MosaicDocument.addMosaicDocument,
    MosaicBlock.addMosaicBlock,
    ImageSlot.addImageSlot,
    StringSlot.addStringSlot,
    FileSlot.addFileSlot,
    SpacerSlot.addSpacerSlot
    )

fti = (
    MosaicDocument.factory_type_information +
    ImageSlot.factory_type_information +
    StringSlot.factory_type_information +
    FileSlot.factory_type_information +
    SpacerSlot.factory_type_information +
    ()
    )

for path in ('default_blocks', 'default_slots', 'skins') :
    registerDirectory(path, globals())

def initialize(registrar) :
    utils.ContentInit(
        'Mosaic Document',
        content_types = contentClasses,
        permission = AddPortalContent,
        extra_constructors = contentConstructors,
        fti = fti,
        ).initialize(registrar)
    
    utils.ToolInit(
        'Mosaic Tool',
        tools = (MosaicTool.MosaicTool, ),
        icon = 'tool.gif',
        ).initialize(registrar)
    
    registrar.registerClass(
        MosaicBlockInformation,
        constructors = (addMosaicBlockInformationForm, addMosaicBlockInformation),
        icon = 'dtml/block_icon.gif')

    registrar.registerClass(
        SlotInfo,
        constructors=(addSlotInfo,)
        )

    registrar.registerClass(
        RuleInfo,
        constructors=(addRuleInfo,)
        )

    
## monkey patching ZPublisher.Converters
from ZPublisher.Converters import type_converters
type_converters.update({'expr' : MosaicDocument.Expression})