Example #1
0
        private bool BeginList()
        {
            if (UserRemovedItems == null)
            {
                throw new InvalidOperationException(
                    "You must register for the JumpListManager.UserRemovedItems event before adding any items");
            }

            object obj;
            _customDestinationList.BeginList(
                out _maxSlotsInList,
                ref SafeNativeMethods.IID_IObjectArray,
                out obj);

            IObjectArray removedItems = (IObjectArray)obj;
            uint count;
            removedItems.GetCount(out count);
            if (count == 0)
                return true;

            string[] removedItemsArr = new string[count];
            for (uint i = 0; i < count; ++i)
            {
                object item;
                removedItems.GetAt(i, ref SafeNativeMethods.IID_IUnknown, out item);

                try
                {
                    IShellLinkW shellLink = (IShellLinkW)item;
                    if (shellLink != null)
                    {
                        StringBuilder sb = new StringBuilder(256);
                        shellLink.GetPath(sb, sb.Capacity, IntPtr.Zero, 2);
                        removedItemsArr[i] = sb.ToString();
                    }
                    continue;
                }
                catch (InvalidCastException)//It's not a shell link
                {
                }
                try
                {
                    VistaBridgeInterop.IShellItem shellItem = (VistaBridgeInterop.IShellItem)item;
                    if (shellItem != null)
                    {
                        string path;
                        shellItem.GetDisplayName(
                            VistaBridgeInterop.SafeNativeMethods.SIGDN.SIGDN_FILESYSPATH,
                            out path);
                        removedItemsArr[i] = path;
                    }
                }
                catch (InvalidCastException)
                {
                    //It's neither a shell link nor a shell item.
                    //This is impossible.
                    Debug.Assert(false,
                        "List of removed items contains something that is neither a shell item nor a shell link");
                }
            }

            UserRemovedItemsEventArgs args = new UserRemovedItemsEventArgs(removedItemsArr);
            UserRemovedItems(this, args);
            if (args.CancelCurrentOperation)
            {
                _customDestinationList.AbortList();
            }
            return !args.CancelCurrentOperation;
        }
Example #2
0
        private bool BeginList()
        {
            if (UserRemovedItems == null)
            {
                throw new InvalidOperationException(
                          "You must register for the JumpListManager.UserRemovedItems event before adding any items");
            }

            object obj;

            _customDestinationList.BeginList(
                out _maxSlotsInList,
                ref SafeNativeMethods.IID_IObjectArray,
                out obj);

            IObjectArray removedItems = (IObjectArray)obj;
            uint         count;

            removedItems.GetCount(out count);
            if (count == 0)
            {
                return(true);
            }

            string[] removedItemsArr = new string[count];
            for (uint i = 0; i < count; ++i)
            {
                object item;
                removedItems.GetAt(i, ref SafeNativeMethods.IID_IUnknown, out item);

                try
                {
                    IShellLinkW shellLink = (IShellLinkW)item;
                    if (shellLink != null)
                    {
                        StringBuilder sb = new StringBuilder(256);
                        shellLink.GetPath(sb, sb.Capacity, IntPtr.Zero, 2);
                        removedItemsArr[i] = sb.ToString();
                    }
                    continue;
                }
                catch (InvalidCastException)//It's not a shell link
                {
                }
                try
                {
                    VistaBridgeInterop.IShellItem shellItem = (VistaBridgeInterop.IShellItem)item;
                    if (shellItem != null)
                    {
                        string path;
                        shellItem.GetDisplayName(
                            VistaBridgeInterop.SafeNativeMethods.SIGDN.SIGDN_FILESYSPATH,
                            out path);
                        removedItemsArr[i] = path;
                    }
                }
                catch (InvalidCastException)
                {
                    //It's neither a shell link nor a shell item.
                    //This is impossible.
                    Debug.Assert(false,
                                 "List of removed items contains something that is neither a shell item nor a shell link");
                }
            }

            UserRemovedItemsEventArgs args = new UserRemovedItemsEventArgs(removedItemsArr);

            UserRemovedItems(this, args);
            if (args.CancelCurrentOperation)
            {
                _customDestinationList.AbortList();
            }
            return(!args.CancelCurrentOperation);
        }