コード例 #1
0
        private static ActionCommand CreateActionCommand(object cmdEnum, ActionType cmdType, string label, string shortCut, string macShortCut, bool isArray)
        {
            ActionCommand actionCommand = !isArray ? (ActionCommand) new CommandProxy() : (ActionCommand) new CommandArrayProxy();

            actionCommand.ActionType   = cmdType;
            actionCommand.CommandArray = isArray;
            actionCommand.Id           = (object)(cmdEnum.GetType().FullName + "." + cmdEnum.ToString());
            actionCommand.Text         = label;
            if (macShortCut == null)
            {
                macShortCut = shortCut;
            }
            string binding = Platform.IsMac ? macShortCut : shortCut;

            if (Platform.IsWindows && !string.IsNullOrEmpty(shortCut))
            {
                binding = shortCut;
            }
            actionCommand.AccelKey = KeyBindingManager.CanonicalizeBinding(binding);
            GlobalCommand.GlobalCmdManager.RegisterCommand((Command)actionCommand);
            return(actionCommand);
        }
コード例 #2
0
ファイル: CommandCodon.cs プロジェクト: plonk/monodevelop
        public override object CreateInstance()
        {
            ActionType ct       = ActionType.Normal;
            bool       isArray  = false;
            bool       custom   = false;
            bool       isAction = false;

            foreach (string p in type.Split('|'))
            {
                switch (p)
                {
                case "check":
                    ct = ActionType.Check;
                    if (isAction)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    isAction = true;
                    break;

                case "radio":
                    ct = ActionType.Radio;
                    if (isAction)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    isAction = true;
                    break;

                case "normal":
                    ct = ActionType.Normal;
                    if (isAction)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    isAction = true;
                    break;

                case "custom":
                    if (widget == null)
                    {
                        throw new InvalidOperationException("Widget type not specified in custom command.");
                    }
                    custom = true;
                    break;

                case "array":
                    isArray = true;
                    break;

                default:
                    throw new InvalidOperationException("Unknown command type: " + p);
                }
            }

            if (isAction && custom)
            {
                throw new InvalidOperationException("Invalid command type combination: " + type);
            }

            Command cmd;

            if (custom)
            {
                if (isArray)
                {
                    throw new InvalidOperationException("Array custom commands are not allowed.");
                }

                CustomCommand ccmd = new CustomCommand();
                ccmd.Text       = label;
                ccmd.WidgetType = Addin.GetType(widget);
                if (ccmd.WidgetType == null)
                {
                    throw new InvalidOperationException("Could not find command type '" + widget + "'.");
                }
                cmd = ccmd;
            }
            else
            {
                if (widget != null)
                {
                    throw new InvalidOperationException("Widget type can only be specified for custom commands.");
                }

                ActionCommand acmd = new ActionCommand();
                acmd.ActionType   = ct;
                acmd.CommandArray = isArray;

                if (defaultHandler != null)
                {
                    acmd.SetDefaultHandlerTypeInfo(Addin, defaultHandler);
                }

                cmd = acmd;
            }

            cmd.Id   = ParseCommandId(this);
            cmd.Text = StringParserService.Parse(BrandingService.BrandApplicationName(label));
            if (!String.IsNullOrWhiteSpace(_displayName))
            {
                cmd.DisplayName = StringParserService.Parse(BrandingService.BrandApplicationName(_displayName));
            }
            if ((_description != null) && (_description.Length > 0))
            {
                cmd.Description = BrandingService.BrandApplicationName(_description);
            }
            cmd.Description = cmd.Description;

            if (icon != null)
            {
                cmd.Icon = GetStockId(Addin, icon);
            }

            var keyBinding = Platform.IsMac ? macShortcut : shortcut;

            if (Platform.IsWindows && !string.IsNullOrEmpty(winShortcut))
            {
                keyBinding = winShortcut;
            }
            string[] splittedKeys = (keyBinding ?? "").Split(' ');

            cmd.AccelKey = KeyBindingManager.FixChordSeparators(KeyBindingManager.CanonicalizeBinding(splittedKeys[0]));
            if (splittedKeys.Length > 1)
            {
                cmd.AlternateAccelKeys = splittedKeys.Skip(1).Select(key => KeyBindingManager.FixChordSeparators(key)).ToArray();
            }

            cmd.DisabledVisible = disabledVisible;

            // Assign the category of the command
            CommandCategoryCodon cat = Parent as CommandCategoryCodon;

            if (cat != null)
            {
                cmd.Category = cat.Name;
            }

            return(cmd);
        }
コード例 #3
0
        public override object CreateInstance()
        {
            ActionType ct       = ActionType.Normal;
            bool       isArray  = false;
            bool       custom   = false;
            bool       isAction = false;

            foreach (string p in type.Split('|'))
            {
                switch (p)
                {
                case "check":
                    ct = ActionType.Check;
                    if (isAction)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    isAction = true;
                    break;

                case "radio":
                    ct = ActionType.Radio;
                    if (isAction)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    isAction = true;
                    break;

                case "normal":
                    ct = ActionType.Normal;
                    if (isAction)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    isAction = true;
                    break;

                case "custom":
                    if (widget == null)
                    {
                        throw new InvalidOperationException("Widget type not specified in custom command.");
                    }
                    custom = true;
                    break;

                case "array":
                    isArray = true;
                    break;

                default:
                    throw new InvalidOperationException("Unknown command type: " + p);
                }
            }

            if (isAction && custom)
            {
                throw new InvalidOperationException("Invalid command type combination: " + type);
            }

            Command cmd;

            if (custom)
            {
                if (isArray)
                {
                    throw new InvalidOperationException("Array custom commands are not allowed.");
                }

                CustomCommand ccmd = new CustomCommand();
                ccmd.Text       = label;
                ccmd.WidgetType = Addin.GetType(widget);
                if (ccmd.WidgetType == null)
                {
                    throw new InvalidOperationException("Could not find command type '" + widget + "'.");
                }
                cmd = ccmd;
            }
            else
            {
                if (widget != null)
                {
                    throw new InvalidOperationException("Widget type can only be specified for custom commands.");
                }

                ActionCommand acmd = new ActionCommand();
                acmd.ActionType   = ct;
                acmd.CommandArray = isArray;

                if (defaultHandler != null)
                {
                    acmd.SetDefaultHandlerTypeInfo(Addin, defaultHandler);
                }

                cmd = acmd;
            }

            cmd.Id   = ParseCommandId(this);
            cmd.Text = StringParserService.Parse(label);
            if ((_description != null) && (_description.Length > 0))
            {
                cmd.Description = _description;
            }
            cmd.Description = cmd.Description;

            if (icon != null)
            {
                cmd.Icon = GetStockId(Addin, icon);
            }

            cmd.AccelKey = KeyBindingManager.CanonicalizeBinding(PropertyService.IsMac? macShortcut : shortcut);

            cmd.DisabledVisible = disabledVisible;

            // Assign the category of the command
            CommandCategoryCodon cat = Parent as CommandCategoryCodon;

            if (cat != null)
            {
                cmd.Category = cat.Name;
            }

            return(cmd);
        }
コード例 #4
0
        private Command CreateCommand()
        {
            ActionType actionType = ActionType.Normal;
            bool       flag1      = false;
            bool       flag2      = false;
            bool       flag3      = false;
            string     type       = this.type;

            char[] chArray = new char[1] {
                '|'
            };
            foreach (string str in type.Split(chArray))
            {
                switch (str)
                {
                case "check":
                    actionType = ActionType.Check;
                    if (flag3)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    flag3 = true;
                    break;

                case "radio":
                    actionType = ActionType.Radio;
                    if (flag3)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    flag3 = true;
                    break;

                case "normal":
                    actionType = ActionType.Normal;
                    if (flag3)
                    {
                        throw new InvalidOperationException("Action type specified twice.");
                    }
                    flag3 = true;
                    break;

                case "custom":
                    if (this.widget == null)
                    {
                        throw new InvalidOperationException("Widget type not specified in custom command.");
                    }
                    flag2 = true;
                    break;

                case "array":
                    flag1 = true;
                    break;

                default:
                    throw new InvalidOperationException("Unknown command type: " + str);
                }
            }
            if (flag3 && flag2)
            {
                throw new InvalidOperationException("Invalid command type combination: " + this.type);
            }
            Command command;

            if (flag2)
            {
                if (flag1)
                {
                    throw new InvalidOperationException("Array custom commands are not allowed.");
                }
                CustomCommand customCommand = new CustomCommand();
                customCommand.Text       = this.label;
                customCommand.WidgetType = this.Addin.GetType(this.widget);
                if (customCommand.WidgetType == (Type)null)
                {
                    throw new InvalidOperationException("Could not find command type '" + this.widget + "'.");
                }
                command = (Command)customCommand;
            }
            else
            {
                if (this.widget != null)
                {
                    throw new InvalidOperationException("Widget type can only be specified for custom commands.");
                }
                ActionCommand actionCommand = new ActionCommand();
                actionCommand.ActionType   = actionType;
                actionCommand.CommandArray = flag1;
                if (this.handler != null)
                {
                    try
                    {
                        MenuHandler instance = (MenuHandler)Activator.CreateInstance(this.Addin.GetType(this.handler, true));
                        if (instance != null)
                        {
                            actionCommand.DefaultHandler     = (CommandHandler) new CcsCmdHandler(instance);
                            actionCommand.DefaultHandlerType = actionCommand.DefaultHandler.GetType();
                        }
                    }
                    catch
                    {
                        LogConfig.Output.Error((object)string.Format("Failed to create MenuHandler: {0}", (object)this.handler));
                    }
                }
                command = (Command)actionCommand;
            }
            command.Id   = CmdEntryCodon.ParseCommandId((ExtensionNode)this);
            command.Text = this.label;
            if (this.description != null && this.description.Length > 0)
            {
                command.Description = BrandingService.BrandApplicationName(this.description);
            }
            command.Description = command.Description;
            if (this.icon != null)
            {
                command.Icon = (IconId)CmdEntryCodon.GetStockId(this.Addin, this.icon);
            }
            string str1 = Platform.IsMac ? this.macShortcut : this.shortcut;

            if (Platform.IsWindows && !string.IsNullOrEmpty(this.winShortcut))
            {
                str1 = this.winShortcut;
            }
            string[] strArray = (str1 ?? "").Split(' ');
            command.AccelKey = KeyBindingManager.CanonicalizeBinding(strArray[0]);
            if (strArray.Length > 1)
            {
                command.AlternateAccelKeys = ((IEnumerable <string>)strArray).Skip <string>(1).ToArray <string>();
            }
            command.DisabledVisible = this.disabledVisible;
            CommandCategoryCodon parent = this.Parent as CommandCategoryCodon;

            if (parent != null)
            {
                command.Category = parent.Name;
            }
            return(command);
        }