예제 #1
0
        private void RemoveCommand(EntityDesignerCommand command)
        {
            var commandID = GetCommandID(command);

            if (commandID != null)
            {
                if (PackageManager.Package.CommandSet.RemoveCommand(commandID))
                {
                    _commands2ids.Remove(command);

                    var indexToRemove = commandID.ID;
                    Debug.Assert(indexToRemove >= 0, "The index to remove is less than zero");
                    if (indexToRemove >= 0)
                    {
                        _intIds2commands.Remove(indexToRemove);

                        // Add the Id of the command we remove to the free list, so that we can fill the command Id gaps
                        // when we next load a dynamic command. The list differs for a refactoring command since
                        // those commands live in a different Command ID range.
                        var freeList = _commandIdFreeList;
                        if (command.IsRefactoringCommand)
                        {
                            freeList = _refactoringCommandIdFreeList;
                        }

                        freeList.Add(indexToRemove);
                        freeList.Sort();
                    }
                }
            }
        }
예제 #2
0
        private bool AddEnableLayerCommand(
            IEntityDesignerLayer layer, bool isAlreadyEnabled, out EntityDesignerCommand entityDesignerCommand)
        {
            var menuItemText = GetEnableLayerCommandText(layer.Name, isAlreadyEnabled);

            entityDesignerCommand = new EntityDesignerCommand(menuItemText, (xel, dv, ss, pc, iss) => { ToggleLayerEnabled(layer, xel); });

            return(AddCommand(entityDesignerCommand));
        }
예제 #3
0
        private bool AddCommand(EntityDesignerCommand command)
        {
            var usingIdFromFreeList = false;

            int newCommandId;

            // If this is a refactoring command, we have a separate
            // free list and counter to keep track of it since it
            // lives in a separate command ID range.
            var currentCommandId = _currentCommandId;
            var freeList         = _commandIdFreeList;

            if (command.IsRefactoringCommand)
            {
                freeList         = _refactoringCommandIdFreeList;
                currentCommandId = _currentRefactoringCommandId;
            }

            if (freeList.Count > 0)
            {
                // _commandIdFreeList is tracking gaps in our command IDs, so use these instead of incrementing the current Id counter
                // if available.
                newCommandId        = freeList[0];
                usingIdFromFreeList = true;
            }
            else
            {
                newCommandId = currentCommandId;
            }

            var commandId = new CommandID(PackageConstants.guidEscherCmdSet, newCommandId);

            DynamicStatusMenuCommand menuCommand;

            if (PackageManager.Package.CommandSet.AddCommand(commandId, command, out menuCommand))
            {
                // If we are attempting to use an id from the free list then we should
                // remove it from the free list if we've successfully added the command, or
                // just increment our current counter. This is different for refactoring commands
                // since refactoring commands live in a separate command ID range.
                if (command.IsRefactoringCommand)
                {
                    if (usingIdFromFreeList)
                    {
                        _refactoringCommandIdFreeList.RemoveAt(0);
                    }
                    else
                    {
                        _currentRefactoringCommandId = newCommandId + 1;
                    }
                }
                else
                {
                    if (usingIdFromFreeList)
                    {
                        _commandIdFreeList.RemoveAt(0);
                    }
                    else
                    {
                        _currentCommandId = newCommandId + 1;
                    }
                }

                _commands2ids.Add(command, commandId);
                _intIds2commands.Add(commandId.ID, command);

                return(true);
            }

            return(false);
        }
예제 #4
0
 private CommandID GetCommandID(EntityDesignerCommand command)
 {
     return(_commands2ids.Where(kvp => kvp.Key.Equals(command)).Select(kvp => kvp.Value).FirstOrDefault());
 }