Example #1
0
        /// <summary>
        /// Builds a string from the list of keyboard shortcuts for activating this command.
        /// Should be called after any change is made to the keyboard shortcuts list.</summary>
        /// <param name="commandInfo">CommandInfo for command</param>
        public static void RebuildShortcutDisplayString(this CommandInfo commandInfo)
        {
            var menuItem = commandInfo.GetMenuItem();

            if (menuItem == null)
            {
                return;
            }

            string displayString = string.Empty;

            foreach (Keys k in commandInfo.Shortcuts)
            {
                if (k == Keys.None)
                {
                    continue;
                }

                if (displayString != string.Empty)
                {
                    displayString += " ; ";
                }

                displayString += Sce.Atf.KeysUtil.KeysToString(k, true);
            }
            menuItem.ShortcutKeyDisplayString = displayString;
        }
Example #2
0
        /// <summary>
        /// Builds a string from the list of keyboard shortcuts for activating this command.
        /// Should be called after any change is made to the keyboard shortcuts list.</summary>
        /// <param name="commandInfo">CommandInfo for command</param>
        public static void RebuildShortcutDisplayString(this CommandInfo commandInfo)
        {
            var menuItem = commandInfo.GetMenuItem();

            if (menuItem == null)
            {
                return;
            }
            menuItem.ShortcutKeyDisplayString = commandInfo.ShortcutKeyDisplayString;
        }
Example #3
0
        // Adds a command to menus
        private void AddMenuCommand(ToolStripItemCollection commands, CommandInfo info)
        {
            // make sure all necessary sub-menus exist, and get command collection to hold this command
            commands = BuildSubMenus(commands, info);

            var menuItem = info.GetMenuItem();

            menuItem.BackColor = m_mainMenuStrip.BackColor;
            menuItem.ForeColor = m_mainMenuStrip.ForeColor;
            commands.Add(menuItem);

            MaintainSeparateGroups(commands, menuItem, info.GroupTag);
        }
Example #4
0
        /// <summary>
        /// This function redraws a particular menu item's icon. This is useful if only a
        /// specific icon has been changed; for example, on mouseover.</summary>
        /// <param name="info">The command whose icon needs a refresh</param>
        public override void RefreshImage(CommandInfo info)
        {
            Image image = GetProperlySizedImage(info.ImageName);

            if (image != null)
            {
                var button = info.GetButton();
                button.AutoSize     = true;
                button.ImageScaling = ToolStripItemImageScaling.None;
                button.Image        = image;

                // Update the menu image too, but don't set AutoSize, as the menu icons
                // should always stay the same size.
                var menu = info.GetMenuItem();
                menu.Image = image;
            }
        }
Example #5
0
        // Adds a command to menus
        private void AddMenuCommand(ToolStripItemCollection commands, CommandInfo info)
        {
            // make sure all necessary sub-menus exist, and get command collection to hold this command
            commands = BuildSubMenus(commands, info);

            var menuItem = info.GetMenuItem();
            menuItem.BackColor = m_mainMenuStrip.BackColor;
            menuItem.ForeColor = m_mainMenuStrip.ForeColor;
            commands.Add(menuItem);

            MaintainSeparateGroups(commands, menuItem, info.GroupTag);
        }
Example #6
0
        /// <summary>
        /// This function redraws a particular menu item's icon. This is useful if only a
        /// specific icon has been changed; for example, on mouseover.</summary>
        /// <param name="info">The command whose icon needs a refresh</param>
        public override void RefreshImage(CommandInfo info)
        {
            Image image = GetProperlySizedImage(info.ImageName);
            if (image != null)
            {
                var button = info.GetButton();
                button.AutoSize = true;
                button.ImageScaling = ToolStripItemImageScaling.None;
                button.Image = image;

                // Update the menu image too, but don't set AutoSize, as the menu icons
                // should always stay the same size.
                var menu = info.GetMenuItem();
                menu.Image = image;
            }
        }
Example #7
0
        /// <summary>
        /// Creates and returns a context (right click popup) menu.
        /// Does not raise any events.</summary>
        /// <param name="commandTags">Commands in menu; nulls indicate separators</param>
        /// <returns>ContextMenuStrip for context menu</returns>
        public ContextMenuStrip CreateContextMenu(IEnumerable <object> commandTags)
        {
            ContextMenuStrip contextMenu = new ContextMenuStrip();
            int itemCount;

            foreach (object commandTag in commandTags)
            {
                // check for separator
                if (commandTag == null)
                {
                    itemCount = contextMenu.Items.Count;
                    if (itemCount > 0 &&
                        !(contextMenu.Items[itemCount - 1] is ToolStripSeparator))
                    {
                        contextMenu.Items.Add(new ToolStripSeparator());
                    }
                    continue;
                }

                // add the command and sort it by groups since the last separator
                CommandInfo info = GetCommandInfo(commandTag);
                if (info != null && (info.Visibility & CommandVisibility.ContextMenu) != 0)
                {
                    // allow client to update command appearance
                    UpdateCommand(info);

                    var menuItem = info.GetMenuItem();
                    if (menuItem.Enabled || !ContextMenuAutoCompact)
                    {
                        ToolStripItemCollection commands = BuildSubMenus(contextMenu.Items, info);
                        ToolStripMenuItem       clone    = new ToolStripMenuItem();
                        clone.Text                     = menuItem.Text;
                        clone.Image                    = menuItem.Image;
                        clone.Name                     = menuItem.Name;
                        clone.Enabled                  = menuItem.Enabled;
                        clone.Checked                  = menuItem.Checked;
                        clone.Tag                      = menuItem.Tag;
                        clone.ToolTipText              = menuItem.ToolTipText;
                        clone.ShortcutKeys             = menuItem.ShortcutKeys;
                        clone.ShortcutKeyDisplayString = menuItem.ShortcutKeyDisplayString;
                        clone.Click                   += contextMenu_itemClick;
                        clone.ForeColor                = m_mainMenuStrip.ForeColor;
                        clone.CheckOnClick             = info.CheckOnClick;
                        commands.Add(clone);

                        MaintainSeparateGroups(commands, clone, info.GroupTag);
                    }
                }
            }

            // Remove trailing separator.
            itemCount = contextMenu.Items.Count;
            if (itemCount > 0 &&
                (contextMenu.Items[itemCount - 1] is ToolStripSeparator))
            {
                contextMenu.Items.RemoveAt(itemCount - 1);
            }

            SkinService.ApplyActiveSkin(contextMenu);

            return(contextMenu);
        }