示例#1
0
        private void UpdateUndoRedoMenuCommandsStatus()
        {
            MenuCommandService menuCommandService = GetService(typeof(MenuCommandService)) as MenuCommandService;
            var undoMenuCommand = menuCommandService.FindCommand(StandardCommands.Undo);
            var redoMenuCommand = menuCommandService.FindCommand(StandardCommands.Redo);

            if (undoMenuCommand is object)
            {
                undoMenuCommand.Enabled = currentPos > 0;
            }
            if (redoMenuCommand is object)
            {
                redoMenuCommand.Enabled = currentPos < undoUnitList.Count;
            }
        }
        private void UpdateUndoRedoMenuCommandsStatus()
        {
            // this components maybe cached.
            MenuCommandService menuCommandService = GetService(typeof(MenuCommandService)) as MenuCommandService;
            MenuCommand        undoMenuCommand    = menuCommandService.FindCommand(StandardCommands.Undo);
            MenuCommand        redoMenuCommand    = menuCommandService.FindCommand(StandardCommands.Redo);

            if (undoMenuCommand != null)
            {
                undoMenuCommand.Enabled = currentPos > 0;
            }
            if (redoMenuCommand != null)
            {
                redoMenuCommand.Enabled = currentPos < this.undoUnitList.Count;
            }
        }
示例#3
0
        private void ChangeCommand(int commandId, bool enabled)
        {
            var command  = new CommandID(GuidList.guidthreadfix_pluginCmdSet, commandId);
            var menuItem = MenuCommandService.FindCommand(command);

            if (menuItem != null)
            {
                menuItem.Enabled = enabled;
            }
        }
 public MenuCommand FindCommand(CommandID commandID)
 {
     return(_menuCommandService.FindCommand(commandID));
 }
示例#5
0
        protected override void OnBeforeShowContextMenu()
        {
            // Creating commands for adding scalar and complex properties to complex types (one for each complex type from the model).
            // Since the scalar types can change dependent on the schemaVersion and since complex types can be added or deleted
            // we need to compute these commands each time a context menu is requested

            // only need to do this if selected is ExplorerComplexType
            var selectedElement = CurrentExplorerInfo._explorerFrame.GetSelectedExplorerEFElement();

            if (selectedElement is ExplorerComplexType)
            {
                var service = EditingContext.GetEFArtifactService();
                Debug.Assert(service != null && service.Artifact != null, "service and service.Artifact must both be non-null");
                if (service != null &&
                    service.Artifact != null)
                {
                    // Creating commands for adding scalar properties to complex types (one for each primitive type)
                    var i = 0;
                    foreach (var type in ModelHelper.AllPrimitiveTypesSorted(service.Artifact.SchemaVersion))
                    {
                        var cmdId = new CommandID(
                            PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddScalarPropertyBase + i);
                        var cmd = MenuCommandService.FindCommand(cmdId);
                        if (cmd == null)
                        {
                            cmd = new DynamicStatusMenuCommand(OnStatusAddComplexTypeProperty, OnMenuAddComplexTypeProperty, cmdId);
                            cmd.Properties[PackageConstants.guidEscherCmdSet] = type;
                            MenuCommandService.AddCommand(cmd);
                        }
                        else
                        {
                            cmd.Properties[PackageConstants.guidEscherCmdSet] = type;
                        }
                        i++;
                    }

                    // set up commands for complex types
                    var conceptualModel = service.Artifact.ConceptualModel();
                    Debug.Assert(conceptualModel != null, "service.Artifact.ConceptualModel() should not be null");
                    if (conceptualModel != null)
                    {
                        var complexTypes = new List <ComplexType>(conceptualModel.ComplexTypes());
                        complexTypes.Sort(EFElement.EFElementDisplayNameComparison);

                        i = 0;
                        foreach (var complexType in complexTypes)
                        {
                            // don't add an item for a ComplexType that is same as currently selected one
                            if (selectedElement.ModelItem == complexType)
                            {
                                continue;
                            }

                            // if we find an old command with the same cmdId remove it and replace
                            // with the new one to force VS to refresh the text
                            var cmdId = new CommandID(
                                PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddComplexPropertyBase + i);
                            var cmd = MenuCommandService.FindCommand(cmdId);
                            if (cmd != null)
                            {
                                MenuCommandService.RemoveCommand(cmd);
                            }
                            cmd = new DynamicStatusMenuCommand(OnStatusAddComplexTypeProperty, OnMenuAddComplexTypeProperty, cmdId);
                            cmd.Properties[PackageConstants.guidEscherCmdSet] = complexType;
                            MenuCommandService.AddCommand(cmd);

                            i++;
                            if (i >= AddComplexPropertyCommandMaxCount)
                            {
                                // break after adding 10 ComplexTypes
                                break;
                            }
                        }

                        // if some of the complex types were removed, we need to remove unnecessary commands
                        var cmd2 =
                            MenuCommandService.FindCommand(
                                new CommandID(PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddComplexPropertyBase + i));
                        while (i < AddComplexPropertyCommandMaxCount &&
                               cmd2 != null)
                        {
                            MenuCommandService.RemoveCommand(cmd2);
                            i++;
                            cmd2 =
                                MenuCommandService.FindCommand(
                                    new CommandID(
                                        PackageConstants.guidEscherCmdSet, PackageConstants.cmdIdExplorerAddComplexPropertyBase + i));
                        }
                    }
                }
            }
        }