public CommandManager(Gtk.Window root)
 {
     rootWidget = root;
     ActionCommand c = new ActionCommand (CommandSystemCommands.ToolbarList, "Toolbar List", null, null, ActionType.Check);
     c.CommandArray = true;
     RegisterCommand (c, "");
 }
        public MenuButtonEntry(Gtk.Entry entry, Gtk.Button button)
        {
            if (entry == null) entry = new Gtk.Entry ();
            if (button == null) button = new Gtk.Button (">");

            this.entry = entry;

            manager = new CommandManager ();
            manager.RegisterGlobalHandler (this);

            PackStart (entry, true, true, 0);
            PackStart (button, false, false, 6);

            ActionCommand cmd = new ActionCommand ("InsertOption", "InsertOption", null);
            cmd.CommandArray = true;
            manager.RegisterCommand (cmd);
            entrySet = new CommandEntrySet ();
            entrySet.AddItem ("InsertOption");

            button.Clicked += new EventHandler (ShowQuickInsertMenu);
        }
        public override object BuildItem(object owner, ArrayList subItems, ConditionCollection conditions)
        {
            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.Description = description;
                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.DefaultHandlerType = AddIn.GetType (defaultHandler);
                    if (acmd.DefaultHandlerType == null)
                        throw new InvalidOperationException ("Could not find handler type '" + defaultHandler + "' for command " + ID);
                }

                cmd = acmd;
            }

            cmd.Id = ParseCommandId (this);
            cmd.Text = Runtime.StringParserService.Parse (GettextCatalog.GetString (label));
            cmd.Description = GettextCatalog.GetString (description);
            if (icon != null)
                cmd.Icon = ResourceService.GetStockId (AddIn, icon);
            cmd.AccelKey = shortcut;
            cmd.DisabledVisible = disabledVisible;

            return cmd;
        }