Esempio n. 1
0
 public CcsCmdHandler(MenuHandler handler)
 {
     this.Handler = handler;
 }
Esempio n. 2
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);
        }