Exemple #1
0
        internal void RefreshDestinations(ICustomDestinationList destinationList)
        {
            if (_categorizedDestinations.Count == 0)
                return;

            foreach (int key in _categorizedDestinations.Keys)
            {
                IObjectCollection categoryContents =
                    (IObjectCollection)new CEnumerableObjectCollection();
                var destinations = _categorizedDestinations[key];
                foreach (IJumpListDestination destination in destinations)
                {
                    categoryContents.AddObject(destination.GetShellRepresentation());
                }
                destinationList.AppendCategory(
                    destinations.First().Category,
                    (IObjectArray)categoryContents);
            }
        }
Exemple #2
0
        internal void RefreshDestinations(ICustomDestinationList destinationList)
        {
            if (_categorizedDestinations.Count == 0)
            {
                return;
            }

            foreach (int key in _categorizedDestinations.Keys)
            {
                IObjectCollection categoryContents =
                    (IObjectCollection) new CEnumerableObjectCollection();
                var destinations = _categorizedDestinations[key];
                foreach (IJumpListDestination destination in destinations)
                {
                    categoryContents.AddObject(destination.GetShellRepresentation());
                }
                destinationList.AppendCategory(
                    destinations.First().Category,
                    (IObjectArray)categoryContents);
            }
        }
Exemple #3
0
        // Adds a custom category to the Jump List. Each item that should be in the category is added to an ordered collection, and then the
        // category is appended to the Jump List as a whole.
        private static void _AddCategoryToList(ICustomDestinationList pcdl, IObjectArray poaRemoved)
        {
            var poc = new IObjectCollection();

            foreach (var fn in c_rgpszFiles)
            {
                if (SHCreateItemInKnownFolder(KNOWNFOLDERID.FOLDERID_Documents.Guid(), KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, fn, typeof(IShellItem).GUID, out var ppv).Succeeded)
                {
                    var psi = ppv as IShellItem;
                    // Items listed in the removed list may not be re-added to the Jump List during this list-building transaction. They
                    // should not be re-added to the Jump List until the user has used the item again. The AppendCategory call below will
                    // fail if an attempt to add an item in the removed list is made.
                    if (!_IsItemInArray(psi, poaRemoved))
                    {
                        poc.AddObject(psi);
                    }
                }

                // Add the category to the Jump List. If there were more categories, they would appear from top to bottom in the order they
                // were appended.
                pcdl.AppendCategory("Custom Category", poc);
            }
        }
Exemple #4
0
        public void Apply()
        {
            BeginList();

            try
            {
                if (active == null)
                {
                    active = new List <JumpItemTask>();
                }
                if (active.Count > 0)
                {
                    foreach (var t in active)
                    {
                        t.Dispose();
                    }
                    active.Clear();
                }

                var count = tasks.Count;

                if (count > 0)
                {
                    IObjectCollection content = null;
                    var categories            = new Dictionary <string, IObjectCollection>();

                    for (var i = 0; i < count; ++i)
                    {
                        var t = tasks[i];

                        if (i > 0)
                        {
                            if (tasks[i - 1].CustomCategory != t.CustomCategory)
                            {
                                content = null;
                            }
                        }

                        if (content == null)
                        {
                            var c = t.CustomCategory;
                            if (c == null)
                            {
                                c = "";
                            }
                            if (!categories.TryGetValue(c, out content))
                            {
                                content = categories[c] = (IObjectCollection) new CEnumerableObjectCollection();
                            }
                        }

                        var jit = new JumpItemTask(t);
                        active.Add(jit);
                        content.AddObject(jit.NativeShellLink);
                    }

                    foreach (var k in categories.Keys)
                    {
                        if (k.Length == 0)
                        {
                            list.AddUserTasks((IObjectArray)categories[k]);
                        }
                        else
                        {
                            var r = list.AppendCategory(k, (IObjectArray)categories[k]);
                            if (r < 0)
                            {
                                if (r == -2147024891) //denied (tracking of recent files is disabled)
                                {
                                    throw new CustomCategoryException();
                                }
                                throw Marshal.GetExceptionForHR(r);
                            }
                        }
                    }
                }
            }
            finally
            {
                list.CommitList();
            }
        }
		private static void AddRecentNotes (ICustomDestinationList custom_destinationd_list, NoteManager note_manager, uint slots)
		{
			IObjectCollection object_collection =
			    (IObjectCollection) Activator.CreateInstance (Type.GetTypeFromCLSID (CLSID.EnumerableObjectCollection));

			// Prevent template notes from appearing in the menu
			Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);

			uint index = 0;
			foreach (Note note in note_manager.Notes) {
				if (note.IsSpecial)
					continue;

				// Skip template notes
				if (note.ContainsTag (template_tag))
					continue;

				string note_title = note.Title;
				if (note.IsNew) {
					note_title = String.Format (Catalog.GetString ("{0} (new)"), note_title);
				}

				IShellLink note_link = CreateShellLink (note_title, tomboy_path, "--open-note " + note.Uri,
				                                        System.IO.Path.Combine (icons_path, NoteIcon), -1);
				if (note_link != null)
					object_collection.AddObject (note_link);

				if (++index == slots - 1)
					break;
			}

			// Add Start Here note
			Note start_note = note_manager.FindByUri (NoteManager.StartNoteUri);
			if (start_note != null) {
				IShellLink start_note_link = CreateShellLink (start_note.Title, tomboy_path, "--open-note " +
				                                              NoteManager.StartNoteUri,
				                                              System.IO.Path.Combine (icons_path, NoteIcon), -1);
				if (start_note_link != null)
					object_collection.AddObject (start_note_link);
			}

			custom_destinationd_list.AppendCategory (Catalog.GetString ("Recent Notes"), (IObjectArray) object_collection);

			Marshal.ReleaseComObject (object_collection);
			object_collection = null;
		}
Exemple #6
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
                    });
                }
            }
        }
Exemple #7
0
        private void AppendCustomCategories()
        {
            // Initialize our current index in the custom categories list
            int currentIndex = 0;

            // Keep track whether we add the Known Categories to our list
            bool knownCategoriesAdded = false;

            if (customCategoriesCollection != null)
            {
                // Append each category to list
                foreach (JumpListCustomCategory category in customCategoriesCollection)
                {
                    // If our current index is same as the KnownCategory OrdinalPosition,
                    // append the Known Categories
                    if (!knownCategoriesAdded && currentIndex == KnownCategoryOrdinalPosition)
                    {
                        AppendKnownCategories();
                        knownCategoriesAdded = true;
                    }

                    // Don't process empty categories
                    if (category.JumpListItems.Count == 0)
                    {
                        continue;
                    }

                    IObjectCollection categoryContent =
                        (IObjectCollection) new CEnumerableObjectCollection();

                    // Add each link's shell representation to the object array
                    foreach (IJumpListItem link in category.JumpListItems)
                    {
                        JumpListItem listItem = link as JumpListItem;
                        JumpListLink listLink = link as JumpListLink;
                        if (listItem != null)
                        {
                            categoryContent.AddObject(listItem.NativeShellItem);
                        }
                        else if (listLink != null)
                        {
                            categoryContent.AddObject(listLink.NativeShellLink);
                        }
                    }

                    // Add current category to destination list
                    HResult hr = customDestinationList.AppendCategory(
                        category.Name,
                        (IObjectArray)categoryContent);

                    if (!CoreErrorHelper.Succeeded(hr))
                    {
                        if ((uint)hr == 0x80040F03)
                        {
                            throw new InvalidOperationException(LocalizedMessages.JumpListFileTypeNotRegistered);
                        }
                        else if ((uint)hr == 0x80070005 /*E_ACCESSDENIED*/)
                        {
                            // If the recent documents tracking is turned off by the user,
                            // custom categories or items to an existing category cannot be added.
                            // The recent documents tracking can be changed via:
                            //      1. Group Policy “Do not keep history of recently opened documents”.
                            //      2. Via the user setting “Store and display recently opened items in
                            //         the Start menu and the taskbar” in the Start menu property dialog.
                            //
                            throw new UnauthorizedAccessException(LocalizedMessages.JumpListCustomCategoriesDisabled);
                        }

                        throw new ShellException(hr);
                    }

                    // Increase our current index
                    currentIndex++;
                }
            }

            // If the ordinal position was out of range, append the Known Categories
            // at the end
            if (!knownCategoriesAdded)
            {
                AppendKnownCategories();
            }
        }
Exemple #8
0
        private static void AddCategory(ICustomDestinationList cdl, string category, List<_ShellObjectPair> jumpItems, List<JumpItem> successList, List<_RejectedJumpItemPair> rejectionList, bool isHeterogenous)
        {
            Debug.Assert(jumpItems.Count != 0);
            Debug.Assert(cdl != null);

            HRESULT hr;
            var shellObjectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.EnumerableObjectCollection)));

            foreach (var itemMap in jumpItems)
            {
                shellObjectCollection.AddObject(itemMap.ShellObject);
            }

            if (string.IsNullOrEmpty(category))
            {
                hr = cdl.AddUserTasks((IObjectArray)shellObjectCollection);
            }
            else
            {
                hr = cdl.AppendCategory(category, (IObjectArray)shellObjectCollection);
            }

            if (hr.Succeeded)
            {
                // Woot! Add these items to the list.
                // Do it in reverse order so Apply has the items in the correct order.
                for (int i = jumpItems.Count; --i >= 0;)
                {
                    successList.Add(jumpItems[i].JumpItem);
                }
            }
            else
            {
                // If the list contained items that could not be added because this object isn't a handler
                // then drop all ShellItems and retry without them.
                if (isHeterogenous && hr == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER)
                {
                    Utility.SafeRelease(ref shellObjectCollection);
                    var linksOnlyList = new List<_ShellObjectPair>();
                    foreach (var itemMap in jumpItems)
                    {
                        if (itemMap.JumpItem is JumpPath)
                        {
                            rejectionList.Add(new _RejectedJumpItemPair { JumpItem = itemMap.JumpItem, Reason = JumpItemRejectionReason.NoRegisteredHandler });
                        }
                        else
                        {
                            linksOnlyList.Add(itemMap);
                        }
                    }
                    if (linksOnlyList.Count > 0)
                    {
                        // There's not a reason I know of that we should reject a list of only links...
                        Debug.Assert(jumpItems.Count != linksOnlyList.Count);
                        AddCategory(cdl, category, linksOnlyList, successList, rejectionList, false);
                    }
                }
                else
                {
                    Debug.Assert(HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER != hr);
                    // If we failed for some other reason, just reject everything.
                    foreach (var item in jumpItems)
                    {
                        rejectionList.Add(new _RejectedJumpItemPair { JumpItem = item.JumpItem, Reason = JumpItemRejectionReason.InvalidItem });
                    }
                }
            }
        }
Exemple #9
0
        private static void AddRecentNotes(ICustomDestinationList custom_destinationd_list, NoteManager note_manager, uint slots)
        {
            IObjectCollection object_collection =
                (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID.EnumerableObjectCollection));

            // Prevent template notes from appearing in the menu
            Tag template_tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag);

            uint index = 0;

            foreach (Note note in note_manager.Notes)
            {
                if (note.IsSpecial)
                {
                    continue;
                }

                // Skip template notes
                if (note.ContainsTag(template_tag))
                {
                    continue;
                }

                string note_title = note.Title;
                if (note.IsNew)
                {
                    note_title = String.Format(Catalog.GetString("{0} (new)"), note_title);
                }

                IShellLink note_link = CreateShellLink(note_title, tomboy_path, "--open-note " + note.Uri,
                                                       System.IO.Path.Combine(icons_path, NoteIcon), -1);
                if (note_link != null)
                {
                    object_collection.AddObject(note_link);
                }

                if (++index == slots - 1)
                {
                    break;
                }
            }

            // Add Start Here note
            Note start_note = note_manager.FindByUri(NoteManager.StartNoteUri);

            if (start_note != null)
            {
                IShellLink start_note_link = CreateShellLink(start_note.Title, tomboy_path, "--open-note " +
                                                             NoteManager.StartNoteUri,
                                                             System.IO.Path.Combine(icons_path, NoteIcon), -1);
                if (start_note_link != null)
                {
                    object_collection.AddObject(start_note_link);
                }
            }

            custom_destinationd_list.AppendCategory(Catalog.GetString("Recent Notes"), (IObjectArray)object_collection);

            Marshal.ReleaseComObject(object_collection);
            object_collection = null;
        }
Exemple #10
0
        private static void AddCategory(ICustomDestinationList cdl, string category, List <_ShellObjectPair> jumpItems, List <JumpItem> successList,
                                        List <_RejectedJumpItemPair> rejectionList, bool isHeterogenous = true)
        {
            Debug.Assert(jumpItems.Count != 0);
            Debug.Assert(cdl != null);
            var shellObjectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.EnumerableObjectCollection)));

            foreach (var itemMap in jumpItems)
            {
                shellObjectCollection.AddObject(itemMap.ShellObject);
            }
            var hr = string.IsNullOrEmpty(category) ? cdl.AddUserTasks(shellObjectCollection) : cdl.AppendCategory(category, shellObjectCollection);

            if (hr.Succeeded)
            {
                for (var i = jumpItems.Count; --i >= 0;)
                {
                    successList.Add(jumpItems[i].JumpItem);
                }
            }
            else
            {
                if (isHeterogenous && hr == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER)
                {
                    Utility.SafeRelease(ref shellObjectCollection);
                    var linksOnlyList = new List <_ShellObjectPair>();
                    foreach (var itemMap in jumpItems)
                    {
                        if (itemMap.JumpItem is JumpPath)
                        {
                            rejectionList.Add(new _RejectedJumpItemPair {
                                JumpItem = itemMap.JumpItem, Reason = JumpItemRejectionReason.NoRegisteredHandler
                            });
                        }
                        else
                        {
                            linksOnlyList.Add(itemMap);
                        }
                    }
                    if (linksOnlyList.Count > 0)
                    {
                        Debug.Assert(jumpItems.Count != linksOnlyList.Count);
                        AddCategory(cdl, category, linksOnlyList, successList, rejectionList, false);
                    }
                }
                else
                {
                    Debug.Assert(HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER != hr);

                    foreach (var item in jumpItems)
                    {
                        rejectionList.Add(new _RejectedJumpItemPair {
                            JumpItem = item.JumpItem, Reason = JumpItemRejectionReason.InvalidItem
                        });
                    }
                }
            }
        }
Exemple #11
0
        private static void AddCategory(ICustomDestinationList cdl, string category, List <_ShellObjectPair> jumpItems, List <JumpItem> successList, List <_RejectedJumpItemPair> rejectionList, bool isHeterogenous)
        {
            Debug.Assert(jumpItems.Count != 0);
            Debug.Assert(cdl != null);

            HRESULT hr;
            var     shellObjectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.EnumerableObjectCollection)));

            foreach (var itemMap in jumpItems)
            {
                shellObjectCollection.AddObject(itemMap.ShellObject);
            }

            if (string.IsNullOrEmpty(category))
            {
                hr = cdl.AddUserTasks((IObjectArray)shellObjectCollection);
            }
            else
            {
                hr = cdl.AppendCategory(category, (IObjectArray)shellObjectCollection);
            }

            if (hr.Succeeded)
            {
                // Woot! Add these items to the list.
                // Do it in reverse order so Apply has the items in the correct order.
                for (int i = jumpItems.Count; --i >= 0;)
                {
                    successList.Add(jumpItems[i].JumpItem);
                }
            }
            else
            {
                // If the list contained items that could not be added because this object isn't a handler
                // then drop all ShellItems and retry without them.
                if (isHeterogenous && hr == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER)
                {
                    if (TraceShell.IsEnabled)
                    {
                        TraceShell.Trace(TraceEventType.Error, TraceShell.RejectingJumpListCategoryBecauseNoRegisteredHandler(category));
                    }

                    Utilities.SafeRelease(ref shellObjectCollection);
                    var linksOnlyList = new List <_ShellObjectPair>();
                    foreach (var itemMap in jumpItems)
                    {
                        if (itemMap.JumpItem is JumpPath)
                        {
                            rejectionList.Add(new _RejectedJumpItemPair {
                                JumpItem = itemMap.JumpItem, Reason = JumpItemRejectionReason.NoRegisteredHandler
                            });
                        }
                        else
                        {
                            linksOnlyList.Add(itemMap);
                        }
                    }
                    if (linksOnlyList.Count > 0)
                    {
                        // There's not a reason I know of that we should reject a list of only links...
                        Debug.Assert(jumpItems.Count != linksOnlyList.Count);
                        AddCategory(cdl, category, linksOnlyList, successList, rejectionList, false);
                    }
                }
                else
                {
                    Debug.Assert(HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER != hr);
                    // If we failed for some other reason, just reject everything.
                    foreach (var item in jumpItems)
                    {
                        rejectionList.Add(new _RejectedJumpItemPair {
                            JumpItem = item.JumpItem, Reason = JumpItemRejectionReason.InvalidItem
                        });
                    }
                }
            }
        }