Esempio n. 1
0
        /// <summary>
        /// Set the JumpList attached property on an Application.
        /// </summary>
        public static void SetJumpList(Application application, JumpList value)
        {
            Verify.IsNotNull(application, "application");

            lock (s_lock)
            {
                // If this was associated with a different application, remove the association.
                JumpList oldValue;
                if (s_applicationMap.TryGetValue(application, out oldValue) && oldValue != null)
                {
                    oldValue._application = null;
                }

                // Associate the jumplist with the application so we can retrieve it later.
                s_applicationMap[application] = value;

                if (value != null)
                {
                    value._application = application;
                }
            }

            if (value != null)
            {
                // Changes will only get applied if the list isn't in an ISupportInitialize block.
                value.ApplyFromApplication();
            }
        }
Esempio n. 2
0
 private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath)
 {
     try
     {
         return(JumpList.GetShellItemForPath(Path.GetFullPath(jumpPath.Path)));
     }
     catch (Exception)
     {
     }
     return(null);
 }
Esempio n. 3
0
        private static object GetShellObjectForJumpItem(JumpItem jumpItem)
        {
            JumpPath jumpPath = jumpItem as JumpPath;
            JumpTask jumpTask = jumpItem as JumpTask;

            if (jumpPath != null)
            {
                return(JumpList.CreateItemFromJumpPath(jumpPath));
            }
            if (jumpTask != null)
            {
                return(JumpList.CreateLinkFromJumpTask(jumpTask, true));
            }
            return(null);
        }
Esempio n. 4
0
 public static void AddToRecentCategory(JumpTask jumpTask)
 {
     Verify.IsNotNull <JumpTask>(jumpTask, "jumpTask");
     if (Utility.IsOSWindows7OrNewer)
     {
         IShellLinkW shellLinkW = JumpList.CreateLinkFromJumpTask(jumpTask, false);
         try
         {
             if (shellLinkW != null)
             {
                 NativeMethods.SHAddToRecentDocs(shellLinkW);
             }
         }
         finally
         {
             Utility.SafeRelease <IShellLinkW>(ref shellLinkW);
         }
     }
 }
Esempio n. 5
0
        private static bool ListContainsShellObject(List <JumpList._ShellObjectPair> removedList, object shellObject)
        {
            if (removedList.Count == 0)
            {
                return(false);
            }
            IShellItem shellItem = shellObject as IShellItem;

            if (shellItem != null)
            {
                foreach (JumpList._ShellObjectPair current in removedList)
                {
                    IShellItem shellItem2 = current.ShellObject as IShellItem;
                    if (shellItem2 != null && shellItem.Compare(shellItem2, (SICHINT)805306368u) == 0)
                    {
                        bool result = true;
                        return(result);
                    }
                }
                return(false);
            }
            IShellLinkW shellLinkW = shellObject as IShellLinkW;

            if (shellLinkW != null)
            {
                foreach (JumpList._ShellObjectPair current2 in removedList)
                {
                    IShellLinkW shellLinkW2 = current2.ShellObject as IShellLinkW;
                    if (shellLinkW2 != null)
                    {
                        string a = JumpList.ShellLinkToString(shellLinkW2);
                        string b = JumpList.ShellLinkToString(shellLinkW);
                        if (a == b)
                        {
                            bool result = true;
                            return(result);
                        }
                    }
                }
                return(false);
            }
            return(false);
        }
Esempio n. 6
0
 public static void SetJumpList(Application application, JumpList value)
 {
     Verify.IsNotNull <Application>(application, "application");
     lock (JumpList.s_lock)
     {
         JumpList jumpList;
         if (JumpList.s_applicationMap.TryGetValue(application, out jumpList) && jumpList != null)
         {
             jumpList._application = null;
         }
         JumpList.s_applicationMap[application] = value;
         if (value != null)
         {
             value._application = application;
         }
     }
     if (value != null)
     {
         value.ApplyFromApplication();
     }
 }
Esempio n. 7
0
 public static void SetJumpList(Application application, JumpList value)
 {
     Standard.Verify.IsNotNull <Application>(application, "application");
     lock (s_lock)
     {
         JumpList list;
         if (s_applicationMap.TryGetValue(application, out list) && (list != null))
         {
             list._application = null;
         }
         s_applicationMap[application] = value;
         if (value != null)
         {
             value._application = application;
         }
     }
     if (value != null)
     {
         value.ApplyFromApplication();
     }
 }
Esempio n. 8
0
        private static void AddCategory(ICustomDestinationList cdl, string category, List <JumpList._ShellObjectPair> jumpItems, List <JumpItem> successList, List <JumpList._RejectedJumpItemPair> rejectionList, bool isHeterogenous)
        {
            IObjectCollection objectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("2d3468c1-36a7-43b6-ac24-d3f02fd9607a")));

            foreach (JumpList._ShellObjectPair shellObjectPair in jumpItems)
            {
                objectCollection.AddObject(shellObjectPair.ShellObject);
            }
            HRESULT hrLeft;

            if (string.IsNullOrEmpty(category))
            {
                hrLeft = cdl.AddUserTasks(objectCollection);
            }
            else
            {
                hrLeft = cdl.AppendCategory(category, objectCollection);
            }
            if (hrLeft.Succeeded)
            {
                int num = jumpItems.Count;
                while (--num >= 0)
                {
                    successList.Add(jumpItems[num].JumpItem);
                }
                return;
            }
            if (isHeterogenous && hrLeft == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER)
            {
                Utility.SafeRelease <IObjectCollection>(ref objectCollection);
                List <JumpList._ShellObjectPair> list = new List <JumpList._ShellObjectPair>();
                foreach (JumpList._ShellObjectPair shellObjectPair2 in jumpItems)
                {
                    if (shellObjectPair2.JumpItem is JumpPath)
                    {
                        rejectionList.Add(new JumpList._RejectedJumpItemPair
                        {
                            JumpItem = shellObjectPair2.JumpItem,
                            Reason   = JumpItemRejectionReason.NoRegisteredHandler
                        });
                    }
                    else
                    {
                        list.Add(shellObjectPair2);
                    }
                }
                if (list.Count > 0)
                {
                    JumpList.AddCategory(cdl, category, list, successList, rejectionList, false);
                    return;
                }
            }
            else
            {
                foreach (JumpList._ShellObjectPair shellObjectPair3 in jumpItems)
                {
                    rejectionList.Add(new JumpList._RejectedJumpItemPair
                    {
                        JumpItem = shellObjectPair3.JumpItem,
                        Reason   = JumpItemRejectionReason.InvalidItem
                    });
                }
            }
        }
Esempio n. 9
0
 private static void AddCategory(ICustomDestinationList cdl, string category, List <JumpList._ShellObjectPair> jumpItems, List <JumpItem> successList, List <JumpList._RejectedJumpItemPair> rejectionList)
 {
     JumpList.AddCategory(cdl, category, jumpItems, successList, rejectionList, true);
 }
Esempio n. 10
0
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
     Verify.IsNotNull <JumpPath>(jumpPath, "jumpPath");
     JumpList.AddToRecentCategory(jumpPath.Path);
 }
Esempio n. 11
0
        private void _BuildShellLists(out List <JumpItem> successList, out List <JumpList._RejectedJumpItemPair> rejectedList, out List <JumpList._ShellObjectPair> removedList)
        {
            List <List <JumpList._ShellObjectPair> > list = null;

            removedList = null;
            ICustomDestinationList customDestinationList = CLSID.CoCreateInstance <ICustomDestinationList>("77f10cf0-3db5-4966-b520-b7c54fd35ed6");

            try
            {
                string runtimeId = JumpList._RuntimeId;
                if (!string.IsNullOrEmpty(runtimeId))
                {
                    customDestinationList.SetAppID(runtimeId);
                }
                Guid         guid = new Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9");
                uint         num;
                IObjectArray shellObjects = (IObjectArray)customDestinationList.BeginList(out num, ref guid);
                removedList  = JumpList.GenerateJumpItems(shellObjects);
                successList  = new List <JumpItem>(this.JumpItems.Count);
                rejectedList = new List <JumpList._RejectedJumpItemPair>(this.JumpItems.Count);
                list         = new List <List <JumpList._ShellObjectPair> >
                {
                    new List <JumpList._ShellObjectPair>()
                };
                foreach (JumpItem jumpItem in this.JumpItems)
                {
                    if (jumpItem == null)
                    {
                        rejectedList.Add(new JumpList._RejectedJumpItemPair
                        {
                            JumpItem = jumpItem,
                            Reason   = JumpItemRejectionReason.InvalidItem
                        });
                    }
                    else
                    {
                        object obj = null;
                        try
                        {
                            obj = JumpList.GetShellObjectForJumpItem(jumpItem);
                            if (obj == null)
                            {
                                rejectedList.Add(new JumpList._RejectedJumpItemPair
                                {
                                    Reason   = JumpItemRejectionReason.InvalidItem,
                                    JumpItem = jumpItem
                                });
                            }
                            else if (JumpList.ListContainsShellObject(removedList, obj))
                            {
                                rejectedList.Add(new JumpList._RejectedJumpItemPair
                                {
                                    Reason   = JumpItemRejectionReason.RemovedByUser,
                                    JumpItem = jumpItem
                                });
                            }
                            else
                            {
                                JumpList._ShellObjectPair item = new JumpList._ShellObjectPair
                                {
                                    JumpItem    = jumpItem,
                                    ShellObject = obj
                                };
                                if (string.IsNullOrEmpty(jumpItem.CustomCategory))
                                {
                                    list[0].Add(item);
                                }
                                else
                                {
                                    bool flag = false;
                                    foreach (List <JumpList._ShellObjectPair> list2 in list)
                                    {
                                        if (list2.Count > 0 && list2[0].JumpItem.CustomCategory == jumpItem.CustomCategory)
                                        {
                                            list2.Add(item);
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (!flag)
                                    {
                                        list.Add(new List <JumpList._ShellObjectPair>
                                        {
                                            item
                                        });
                                    }
                                }
                                obj = null;
                            }
                        }
                        finally
                        {
                            Utility.SafeRelease <object>(ref obj);
                        }
                    }
                }
                list.Reverse();
                if (this.ShowFrequentCategory)
                {
                    customDestinationList.AppendKnownCategory(KDC.FREQUENT);
                }
                if (this.ShowRecentCategory)
                {
                    customDestinationList.AppendKnownCategory(KDC.RECENT);
                }
                foreach (List <JumpList._ShellObjectPair> list3 in list)
                {
                    if (list3.Count > 0)
                    {
                        string customCategory = list3[0].JumpItem.CustomCategory;
                        JumpList.AddCategory(customDestinationList, customCategory, list3, successList, rejectedList);
                    }
                }
                customDestinationList.CommitList();
                successList.Reverse();
            }
            finally
            {
                Utility.SafeRelease <ICustomDestinationList>(ref customDestinationList);
                if (list != null)
                {
                    foreach (List <JumpList._ShellObjectPair> list4 in list)
                    {
                        JumpList._ShellObjectPair.ReleaseShellObjects(list4);
                    }
                }
                JumpList._ShellObjectPair.ReleaseShellObjects(removedList);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Set the JumpList attached property on an Application.
        /// </summary>
        public static void SetJumpList(Application application, JumpList value)
        {
            Verify.IsNotNull(application, "application");

            lock (s_lock)
            {
                // If this was associated with a different application, remove the association.
                JumpList oldValue;
                if (s_applicationMap.TryGetValue(application, out oldValue) && oldValue != null)
                {
                    oldValue._application = null;
                }

                // Associate the jumplist with the application so we can retrieve it later.
                s_applicationMap[application] = value;

                if (value != null)
                {
                    value._application = application;
                }
            }

            if (value != null)
            {
                // Changes will only get applied if the list isn't in an ISupportInitialize block.
                value.ApplyFromApplication();
            }
        }