Beispiel #1
0
        /// <summary>
        /// Creates the <see cref="IToolBarControl"/> for a <see cref="Tool"/>.
        /// </summary>
        /// <param name="tool">The <see cref="Tool"/> to create the control for.</param>
        /// <param name="controlType">The type of control.</param>
        /// <returns>The <see cref="IToolBarControl"/> for the <paramref name="tool"/> using the given
        /// <paramref name="controlType"/>, or null if the <paramref name="controlType"/> is
        /// <see cref="ToolBarControlType.None"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="tool"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="controlType"/> does not contain a defined value of the
        /// <see cref="ToolBarControlType"/> enum.</exception>
        public static IToolBarControl CreateToolControl(Tool tool, ToolBarControlType controlType)
        {
            if (tool == null)
            {
                throw new ArgumentNullException("tool");
            }
            if (!EnumHelper <ToolBarControlType> .IsDefined(controlType))
            {
                throw new ArgumentOutOfRangeException("controlType");
            }

            // Create the control
            ToolStripItem c;

            switch (controlType)
            {
            case ToolBarControlType.None:
                return(null);

            case ToolBarControlType.Button:
                c = new ToolBarItemButton(tool);
                break;

            case ToolBarControlType.ComboBox:
                c = new ToolBarItemComboBox(tool);
                break;

            case ToolBarControlType.DropDownButton:
                c = new ToolBarItemDropDownButton(tool);
                break;

            case ToolBarControlType.Label:
                c = new ToolBarItemLabel(tool);
                break;

            case ToolBarControlType.ProgressBar:
                c = new ToolBarItemProgressBar(tool);
                break;

            case ToolBarControlType.SplitButton:
                c = new ToolBarItemSplitButton(tool);
                break;

            case ToolBarControlType.TextBox:
                c = new ToolBarItemTextBox(tool);
                break;

            default:
                const string errmsg = "ToolBarControlType `{0}` is not supported - could not create control for tool `{1}`.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, controlType, tool);
                }
                Debug.Fail(string.Format(errmsg, controlType, tool));
                return(null);
            }

            return((IToolBarControl)c);
        }
Beispiel #2
0
        /// <summary>
        /// Creates the <see cref="IToolBarControl"/> for a <see cref="Tool"/>.
        /// </summary>
        /// <param name="tool">The <see cref="Tool"/> to create the control for.</param>
        /// <param name="controlType">The type of control.</param>
        /// <returns>The <see cref="IToolBarControl"/> for the <paramref name="tool"/> using the given
        /// <paramref name="controlType"/>, or null if the <paramref name="controlType"/> is
        /// <see cref="ToolBarControlType.None"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="tool"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="controlType"/> does not contain a defined value of the
        /// <see cref="ToolBarControlType"/> enum.</exception>
        public static IToolBarControl CreateToolControl(Tool tool, ToolBarControlType controlType)
        {
            if (tool == null)
                throw new ArgumentNullException("tool");
            if (!EnumHelper<ToolBarControlType>.IsDefined(controlType))
                throw new ArgumentOutOfRangeException("controlType");

            // Create the control
            ToolStripItem c;
            switch (controlType)
            {
                case ToolBarControlType.None:
                    return null;

                case ToolBarControlType.Button:
                    c = new ToolBarItemButton(tool);
                    break;

                case ToolBarControlType.ComboBox:
                    c = new ToolBarItemComboBox(tool);
                    break;

                case ToolBarControlType.DropDownButton:
                    c = new ToolBarItemDropDownButton(tool);
                    break;

                case ToolBarControlType.Label:
                    c = new ToolBarItemLabel(tool);
                    break;

                case ToolBarControlType.ProgressBar:
                    c = new ToolBarItemProgressBar(tool);
                    break;

                case ToolBarControlType.SplitButton:
                    c = new ToolBarItemSplitButton(tool);
                    break;

                case ToolBarControlType.TextBox:
                    c = new ToolBarItemTextBox(tool);
                    break;

                default:
                    const string errmsg = "ToolBarControlType `{0}` is not supported - could not create control for tool `{1}`.";
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, controlType, tool);
                    Debug.Fail(string.Format(errmsg, controlType, tool));
                    return null;
            }

            return (IToolBarControl)c;
        }
 public ToolBarItemButtonBuilder(ToolBarItemButton settings)
 {
     container = settings;
 }