Example #1
0
        /// <summary>
        /// Returns a collection of <see cref="T:Dataweb.NShape.Advanced.MenuItemDef" /> for constructing context menus etc.
        /// </summary>
        protected IEnumerable <MenuItemDef> GetMenuItemDefs()
        {
            if (layerController == null || diagramPresenter == null)
            {
                yield break;
            }

            string pluralPostFix = (selectedLayers.Count > 1) ? "s" : string.Empty;

            bool separatorNeeded = false;

            foreach (MenuItemDef controllerAction in LayerController.GetMenuItemDefs(diagramPresenter.Diagram, selectedLayers))
            {
                if (!separatorNeeded)
                {
                    separatorNeeded = true;
                }
                yield return(controllerAction);
            }

            if (separatorNeeded)
            {
                yield return(new SeparatorMenuItemDef());
            }

            bool   isFeasible;
            string description;

            isFeasible = selectedLayers.Count == 1;
            if (selectedLayers.Count == 0)
            {
                description = string.Empty;
            }
            else if (selectedLayers.Count == 1)
            {
                description = string.Format("Rename layer '{0}'", selectedLayers[0].Title);
            }
            else
            {
                description = "Too many layers selected";
            }
            yield return(new DelegateMenuItemDef("Rename Layer", Properties.Resources.RenameBtn,
                                                 description, isFeasible, Permission.ModifyData, (a, p) => BeginRenameSelectedLayer()));

            isFeasible = selectedLayers.Count > 0;
            if (isFeasible)
            {
                description = string.Format("Set {0} layer{1} as the active layer{1}", selectedLayers.Count, pluralPostFix);
            }
            else
            {
                description = "No layers selected";
            }
            yield return(new DelegateMenuItemDef(string.Format("Activate Layer{0}", pluralPostFix),
                                                 Properties.Resources.Enabled, description, isFeasible, Permission.ModifyData,
                                                 (a, p) => ActivateSelectedLayers()));

            isFeasible  = selectedLayers.Count > 0;
            description = isFeasible ? string.Format("Deactivate {0} layer{1}", selectedLayers.Count, pluralPostFix) :
                          "No layers selected";
            yield return(new DelegateMenuItemDef(string.Format("Deactivate Layer{0}", pluralPostFix),
                                                 Properties.Resources.Disabled, description, isFeasible, Permission.ModifyData,
                                                 (a, p) => DeactivateSelectedLayers()));

            yield return(new SeparatorMenuItemDef());

            isFeasible  = selectedLayers.Count > 0;
            description = isFeasible ? string.Format("Show {0} layer{1}", selectedLayers.Count, pluralPostFix) :
                          "No layers selected";
            yield return(new DelegateMenuItemDef(string.Format("Show Layer{0}", pluralPostFix),
                                                 Properties.Resources.Visible, description, isFeasible, Permission.None,
                                                 (a, p) => ShowSelectedLayers()));

            isFeasible  = selectedLayers.Count > 0;
            description = isFeasible ? string.Format("Hide {0} layer{1}", selectedLayers.Count, pluralPostFix) :
                          "No layers selected";
            yield return(new DelegateMenuItemDef(string.Format("Hide Layer{0}", pluralPostFix),
                                                 Properties.Resources.Invisible, description, isFeasible, Permission.None,
                                                 (a, p) => HideSelectedLayers()));
        }
Example #2
0
        /// <summary>
        /// Returns a collection of <see cref="T:Dataweb.NShape.Advanced.MenuItemDef" /> for constructing context menus etc.
        /// </summary>
        protected IEnumerable <MenuItemDef> GetMenuItemDefs()
        {
            if (_layerController == null || _diagramPresenter == null || _diagramPresenter.Diagram == null)
            {
                yield break;
            }

            bool separatorNeeded = false;

            foreach (MenuItemDef controllerAction in LayerController.GetMenuItemDefs(_diagramPresenter.Diagram, _selectedLayers))
            {
                if (!separatorNeeded)
                {
                    separatorNeeded = true;
                }
                yield return(controllerAction);
            }

            string layersText = (_selectedLayers.Count > 1) ? Properties.Resources.Text_Layers : Properties.Resources.Text_Layer;

            if (separatorNeeded)
            {
                yield return(new SeparatorMenuItemDef());
            }

            bool   isFeasible;
            string description;
            char   securityDomain = (_diagramPresenter.Diagram != null) ? _diagramPresenter.Diagram.SecurityDomainName : '-';

            isFeasible = _selectedLayers.Count == 1;
            if (_selectedLayers.Count == 0)
            {
                description = string.Empty;
            }
            else if (_selectedLayers.Count == 1)
            {
                description = string.Format(Properties.Resources.MessageFmt_RenameLayer0, _selectedLayers[0].Title);
            }
            else
            {
                description = Properties.Resources.MessageTxt_TooManyLayersSelected;
            }
            yield return(new DelegateMenuItemDef(LayerController.MenuItemNameRenameLayer,
                                                 Properties.Resources.CaptionTxt_RenameLayer, Properties.Resources.RenameBtn, description,
                                                 isFeasible, Permission.Data, securityDomain, (a, p) => BeginRenameSelectedLayer()));

            isFeasible = _selectedLayers.Count > 0;
            if (isFeasible)
            {
                description = string.Format(Properties.Resources.MessageFmt_Activate01, _selectedLayers.Count, layersText);
            }
            else
            {
                description = Properties.Resources.MessageTxt_NoLayersSelected;
            }
            yield return(new DelegateMenuItemDef(LayerController.MenuItemNameActivateLayers,
                                                 string.Format(Properties.Resources.CaptionFmt_Activate0, layersText), Properties.Resources.Enabled, description,
                                                 isFeasible, Permission.Data, securityDomain, (a, p) => ActivateSelectedLayers()));

            isFeasible  = _selectedLayers.Count > 0;
            description = isFeasible ? string.Format(Properties.Resources.MessageFmt_Deactivate01, _selectedLayers.Count, layersText)
                                : Properties.Resources.MessageTxt_NoLayersSelected;
            yield return(new DelegateMenuItemDef(LayerController.MenuItemNameDeactivateLayers,
                                                 string.Format(Properties.Resources.CaptionFmt_Deactivate0, layersText), Properties.Resources.Disabled, description,
                                                 isFeasible, Permission.Data, securityDomain, (a, p) => DeactivateSelectedLayers()
                                                 ));

            yield return(new SeparatorMenuItemDef());

            isFeasible  = _selectedLayers.Count > 0;
            description = isFeasible ? string.Format(Properties.Resources.MessageFmt_Show01, _selectedLayers.Count, layersText)
                                : Properties.Resources.MessageTxt_NoLayersSelected;
            yield return(new DelegateMenuItemDef(LayerController.MenuItemNameShowLayers,
                                                 string.Format(Properties.Resources.CaptionFmt_Show0, layersText), Properties.Resources.Visible, description,
                                                 isFeasible, Permission.None, (a, p) => ShowSelectedLayers()
                                                 ));

            isFeasible  = _selectedLayers.Count > 0;
            description = isFeasible ? string.Format(Properties.Resources.MessageFmt_Hide01, _selectedLayers.Count, layersText)
                                : Properties.Resources.MessageTxt_NoLayersSelected;
            yield return(new DelegateMenuItemDef(LayerController.MenuItemNameHideLayers,
                                                 string.Format(Properties.Resources.CaptionFmt_Hide0, layersText), Properties.Resources.Invisible, description,
                                                 isFeasible, Permission.None, (a, p) => HideSelectedLayers()
                                                 ));
        }