Пример #1
0
        // Gets whether the menu item at the specified index is included
        // in the context menu
        private bool Included(ShellMenuItem item)
        {
            if (bDefaultOnly)
            {
                return(ItemIsDefault(item));
            }

            return(true);
        }
Пример #2
0
 // Gets whether the item at the specified index is the default
 // item; the default item can change between the 'Explore' and 'Open'
 // menu items depending on whether the shell set the Explore context
 // menu option
 private bool ItemIsDefault(ShellMenuItem item)
 {
     if (!bExplore && IsOpenItem(item))
     {
         return(true);
     }
     else if (bExplore && IsExploreItem(item))
     {
         return(true);
     }
     else if (
         (!bExplore && !HasOpenItem) ||
         (bExplore && !HasExploreItem))
     {
         return(item.Default);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        void IContextMenu.GetCommandString(int idCmd, CommandStringOptions uFlags, IntPtr pwReserved, byte[] pszName, uint cchMax)
        {
            if (idCmd > menuItems.Length - 1)
            {
                idCmd = 0;
                //return;
            }


            ShellMenuItem menuItem = menuItems[idCmd];
            string        text;

            switch (uFlags)
            {
            case CommandStringOptions.HelpTextA:
            case CommandStringOptions.HelpTextW:
                text = menuItem.HelpText;
                break;

            case CommandStringOptions.VerbA:
            case CommandStringOptions.VerbW:
                text = menuItem.Verb;
                break;

            case CommandStringOptions.ValidateA:
            case CommandStringOptions.ValidateW:
                if (idCmd < 0 || idCmd >= menuItems.Length)
                {
                    Marshal.ThrowExceptionForHR(1);            // S_FALSE
                }
                throw new Exception();                         // unreachable

            default:
                throw new ArgumentOutOfRangeException("uFlags", uFlags.ToString());
            }

            if (text == null)
            {
                text = string.Empty;
            }

            byte[] buf;

            if ((uFlags & CommandStringOptions.Unicode) == CommandStringOptions.Unicode)
            {
                buf = Encoding.Unicode.GetBytes(text);
            }
            else
            {
                buf = Encoding.ASCII.GetBytes(text);
            }

            int cch = Math.Min(buf.Length, pszName.Length - 1);

            if (cch > 0)
            {
                Array.Copy(buf, 0, pszName, 0, cch);
            }
            else
            {
                // null terminate the buffer
                pszName[0] = 0;
            }
        }
Пример #4
0
 private bool IsNewFolderItem(ShellMenuItem item)
 {
     return(item.Verb == ExploreMenuItem.NewFolderVerb);
 }
Пример #5
0
 // Gets whether the specified menu item is the 'open' menu item
 private bool IsDeleteItem(ShellMenuItem item)
 {
     return(item.Verb == ExploreMenuItem.DeleteVerb);
 }
Пример #6
0
 // Gets whether the specified menu item is the 'open' menu item
 private bool IsCopyItem(ShellMenuItem item)
 {
     return(item.Verb == ExploreMenuItem.CopyVerb);
 }
Пример #7
0
 private bool IsRenameItem(ShellMenuItem item)
 {
     return(item.Verb == ExploreMenuItem.RenameVerb);
 }
Пример #8
0
 // Gets whether the specified menu item is the 'open' menu item
 private bool IsOpenItem(ShellMenuItem item)
 {
     return(item.Verb == ExploreMenuItem.OpenVerb);
 }
Пример #9
0
 // Gets whether the specified menu item is the 'explore' menu item
 private bool IsExploreItem(ShellMenuItem item)
 {
     return(item.Verb == ExploreMenuItem.ExploreVerb);
 }