예제 #1
0
        /**
         * Updates the visible and enabled state of actions in the menu without rebuilding
         * the menu entirely.
         */

        public void UpdateMenuActions(IActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool visibleChanged             = false;
            ActionPresentation presentation = new ActionPresentation();

            foreach (DictionaryEntry de in _itemToActionMap)
            {
                presentation.Reset();
                MenuItem   item       = (MenuItem)de.Key;
                MenuAction menuAction = (MenuAction)de.Value;
                UpdateAction(menuAction, context, ref presentation);

                bool wasVisible = item.Visible;
                SetActionFlags(item, ref presentation);
                if (wasVisible != item.Visible)
                {
                    visibleChanged = true;
                }
            }

            if (visibleChanged)
            {
                UpdateSeparatorVisibility(_menuItems);
            }
        }
예제 #2
0
        private ToolStripMenuItem AddActionToMenu(MenuAction menuAction, ToolStripItemCollection curMenuItems,
                                                  IActionContext context, HashSet usedShortcuts)
        {
            ActionPresentation presentation = new ActionPresentation();

            presentation.Reset();

            ToolStripMenuItem item = new ToolStripMenuItem();

            item.Text = menuAction.Name;

            Keys?keyShortcut = Core.ActionManager.GetKeyboardShortcutEx(menuAction.Action, context);

            if (keyShortcut != null && !usedShortcuts.Contains(keyShortcut))
            {
                item.ShortcutKeys = (Keys)keyShortcut;
                usedShortcuts.Add(keyShortcut);
            }

            if (menuAction.MenuIcon != null)
            {
                item.Image = menuAction.MenuIcon;
            }

            item.Click += ExecuteMenuAction;

            curMenuItems.Add(item);
            _itemToActionMap[item] = menuAction;
            return(item);
        }
예제 #3
0
        private void CreateActionLinks(ArrayList itemList, string resType, ILinksPaneFilter filter, IResource filterRes)
        {
            ArrayList actions = (ArrayList)_typeToActions [resType];

            if (actions == null)
            {
                return;
            }

            ActionPresentation presentation = new ActionPresentation();

            foreach (LinksPaneAction action in actions)
            {
                if (filter != null && filterRes != null && !filter.AcceptAction(filterRes, action._action))
                {
                    continue;
                }

                presentation.Reset();
                presentation.Text = action._text;
                UpdateAction(action, ref presentation);
                if (!presentation.Visible)
                {
                    continue;
                }

                itemList.Add(new LinksPaneActionItem(action._action, presentation.Text, presentation.Enabled));
            }
        }
예제 #4
0
        private bool UpdateMenuActions(IActionContext context, string[] resTypes,
                                       ToolStripItemCollection items)
        {
            bool anyVisible                  = false;
            bool anyItemSinceSeparator       = false;
            ToolStripSeparator lastSeparator = null;
            ActionPresentation presentation  = new ActionPresentation();

            if (!_persistentMnemonics)
            {
                ResetUsedMnemonics();
            }

            foreach (ToolStripItem item in items)
            {
                presentation.Reset();
                if (item is ToolStripMenuItem)
                {
                    if (_itemToActionMap.ContainsKey((ToolStripMenuItem)item))
                    {
                        MenuAction menuAction = _itemToActionMap[(ToolStripMenuItem)item];
                        UpdateAction(menuAction, context, resTypes, ref presentation);
                    }
                    else
                    if (HaveGroupBySubName(item.Text))
                    {
                        presentation.Visible = UpdateMenuActions(context, resTypes, ((ToolStripMenuItem)item).DropDownItems);
                    }

                    anyItemSinceSeparator = (anyItemSinceSeparator || presentation.Visible);
                    anyVisible            = (anyVisible || presentation.Visible);

                    SetActionFlags(item, presentation);
                }
                else // ToolStripSeparator
                {
                    item.Visible          = anyItemSinceSeparator;
                    lastSeparator         = anyItemSinceSeparator ? (ToolStripSeparator)item : null;
                    anyItemSinceSeparator = false;
                }
            }

            //  Remove a separator if it is the last item in the list.
            if (!anyItemSinceSeparator && (lastSeparator != null))
            {
                lastSeparator.Visible = false;
            }

            return(anyVisible);
        }
예제 #5
0
        /**
         * Adds an item to the menu based on a MenuAction.
         */

        private MenuItem AddActionToMenu(MenuAction menuAction, Menu.MenuItemCollection curMenuItems,
                                         IActionContext context, HashSet usedShortcuts)
        {
            ActionPresentation presentation = new ActionPresentation();

            presentation.Reset();
            UpdateAction(menuAction, context, ref presentation);

            MenuItem item = new MenuItem();

            string menuItemText;

            if (!_persistentMnemonics && presentation.Visible)
            {
                menuItemText = AssignMnemonic(presentation.Text);
            }
            else
            {
                menuItemText = presentation.Text;
            }

            string keyShortcut = Core.ActionManager.GetKeyboardShortcut(menuAction.Action, context);

            if (keyShortcut != "" && presentation.Visible && !usedShortcuts.Contains(keyShortcut))
            {
                item.Text = menuItemText + "\t" + keyShortcut;
                usedShortcuts.Add(keyShortcut);
            }
            else
            {
                item.Text = menuItemText;
            }

            item.Click += new EventHandler(ExecuteMenuAction);
            SetActionFlags(item, ref presentation);
            curMenuItems.Add(item);
            _itemToActionMap [item] = menuAction;
            return(item);
        }
예제 #6
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);
        }