Added paragraphs add menu divider
authorThierry Florac <thierry.florac@onf.fr>
Tue, 06 Feb 2018 11:15:55 +0100
changeset 354 871c7cb35fd6
parent 353 4839285629d1
child 355 5dce53509832
Added paragraphs add menu divider
src/pyams_content/component/paragraph/zmi/__init__.py
--- a/src/pyams_content/component/paragraph/zmi/__init__.py	Mon Feb 05 17:04:08 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/__init__.py	Tue Feb 06 11:15:55 2018 +0100
@@ -17,24 +17,28 @@
 
 # import interfaces
 from pyams_content.component.paragraph.interfaces import IBaseParagraph, IParagraphFactorySettings
+from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerView
 from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
 from pyams_content.shared.common.interfaces import IWfSharedContent
 from pyams_form.interfaces.form import IFormHelp
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces.container import ITableElementName
+from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
 from pyams_zmi.interfaces.menu import IPropertiesMenu
 from pyams_zmi.layer import IAdminLayer
 
 # import packages
+from pyams_content.component.paragraph import IParagraphContainerTarget, IParagraphFactory
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerTable, ParagraphContainerBaseTable
 from pyams_form.form import AJAXEditForm, AJAXAddForm
 from pyams_form.help import FormHelp
 from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.menu import MenuItem
+from pyams_skin.viewlet.menu import MenuItem, MenuDivider
 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import query_utility
 from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogEditForm
@@ -105,6 +109,20 @@
         return ToolbarMenuItem.__new__(cls)
 
 
+@viewlet_config(name='custom-paragraphs.divider', context=IParagraphContainerTarget, view=IParagraphContainerView,
+                layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=500)
+class ParagraphsAddMenuDivider(MenuDivider):
+    """Paragraphs add menu divider"""
+
+    def __new__(cls, context, request, view, manager):
+        settings = get_parent(context, IParagraphFactorySettings)
+        for factory_name in settings.allowed_paragraphs:
+            factory = query_utility(IParagraphFactory, name=factory_name)
+            if factory.custom_menu:
+                return MenuDivider.__new__(cls)
+        return None
+
+
 class BaseParagraphAJAXAddForm(AJAXAddForm):
     """Base paragraph AJAX add form"""