示例#1
0
        public void RegisterActionGroup(string groupId, ListAnchor anchor)
        {
            if (FindActionGroup(groupId) != null)
            {
                return;
            }

            ToolbarActionGroup newGroup = new ToolbarActionGroup(groupId);

            _actionGroups.Add(groupId, newGroup, anchor);
            int newGroupIndex = _actionGroups.IndexOf(newGroup);

            if (newGroupIndex == 0)
            {
                newGroup.StartIndex = 0;
            }
            else
            {
                newGroup.StartIndex = ((ToolbarActionGroup)_actionGroups [newGroupIndex - 1]).EndIndex;
            }

            ToolStripSeparator separator = new ToolStripSeparator();

            _toolBar.Items.Insert(newGroup.StartIndex, separator);
            newGroup.Separator = separator;
            AdjustGroupIndices(newGroup, 1);
        }
示例#2
0
        private void CreateToolbarButton(IAction action, string groupId, ListAnchor anchor,
                                         int imageIndex, string text, string toolTip, string resourceType,
                                         IActionStateFilter[] filters)
        {
            if (groupId == null)
            {
                RegisterActionGroup(_defaultGroupId, ListAnchor.First);
                groupId = _defaultGroupId;
            }

            ToolbarActionGroup group = FindActionGroup(groupId);

            if (group == null)
            {
                throw new ArgumentException("\"" + groupId + "\" is not a registered toolbar action group.", "groupId");
            }

            ToolStripButton button = new ToolStripButton();

            button.Click += OnToolbarButtonClick;

            // Set the tooltip
            if (text == null)
            {
                text = "";
            }
            if (toolTip == null)                // Use button text for a tooltip by default
            {
                toolTip = text;
            }
            string kbdShortcut = Core.ActionManager.GetKeyboardShortcut(action);

            if (kbdShortcut.Length > 0)
            {
                button.ToolTipText = toolTip + " (" + kbdShortcut + ")";
            }
            else
            {
                button.ToolTipText = toolTip;
            }

            button.Tag        = action;
            button.ImageIndex = imageIndex;
            if (text.Length > 0)
            {
                button.Text = text;
            }
            ToolbarAction tbAction = new ToolbarAction(action, button, text, toolTip, resourceType, filters);
            int           index    = group.Actions.Add(action.ToString(), tbAction, anchor);

            if (index < 0)
            {
                throw new ActionException(String.Format("Attempt to register a duplicate toolbar action \"{0}\" in group \"{1}\" as \"{2}\", which conflicts with action \"{3}\" in the same group.", text, groupId, action.ToString(), ((ToolbarAction)group.Actions.FindByKey(action.ToString()))._defaultText));
            }
            _toolBar.Items.Insert(group.StartIndex + index, button);
            AdjustGroupIndices(group, 1);
        }
示例#3
0
        private void AdjustGroupIndices(ToolbarActionGroup group, int delta)
        {
            int groupIndex = _actionGroups.IndexOf(group);

            for (int i = groupIndex + 1; i < _actionGroups.Count; i++)
            {
                ToolbarActionGroup nextGroup = (ToolbarActionGroup)_actionGroups [i];
                nextGroup.StartIndex = nextGroup.StartIndex + delta;
            }
        }
示例#4
0
        private int UpdateGroupButtons(ToolbarActionGroup group, IActionContext context, string[] resTypes)
        {
            int groupIndex                  = _actionGroups.IndexOf(group);
            int visibleActionsCount         = 0;
            ActionPresentation presentation = new ActionPresentation();

            foreach (ToolbarAction tbAction in group.Actions)
            {
                presentation.Reset();
                presentation.Text    = tbAction._defaultText;
                presentation.ToolTip = tbAction._defaultToolTip;
                ToolStripButton btn = (ToolStripButton)tbAction._toolbarButton;

                if (tbAction._resType != null)
                {
                    if (resTypes.Length != 1 || String.Compare(resTypes [0], tbAction._resType, true) != 0)
                    {
                        presentation.Visible = true;
                        presentation.Enabled = false;
                    }
                }

                IAction action = tbAction._action;
                if (action == null)
                {
                    continue;
                }

                if (tbAction._filters != null)
                {
                    foreach (IActionStateFilter filter in tbAction._filters)
                    {
                        filter.Update(context, ref presentation);
                        if (!presentation.Visible)
                        {
                            break;
                        }
                    }
                }

                if (presentation.Visible)
                {
                    action.Update(context, ref presentation);
                }

                try
                {
                    btn.Visible     = presentation.Visible;
                    btn.Enabled     = presentation.Enabled;
                    btn.Text        = presentation.Text;
                    btn.ToolTipText = presentation.ToolTip;
                    if (presentation.Checked)
                    {
                        btn.CheckOnClick = true;
                    }
                    btn.Checked = presentation.Checked;
                }
                catch (SEHException)
                {
                    // ignore (#4686)
                }

                if (presentation.Visible)
                {
                    visibleActionsCount++;
                }
            }

            try
            {
                group.Separator.Visible = (visibleActionsCount > 0 && groupIndex < _actionGroups.Count - 1);
            }
            catch (SEHException)
            {
                // ignore (OM-5509)
            }

            return(visibleActionsCount);
        }