private void AppendTaskList() { if (userTasks == null || userTasks.Count == 0) { return; } IObjectCollection taskContent = (IObjectCollection) new CEnumerableObjectCollection(); // Add each task's shell representation to the object array foreach (JumpListTask task in userTasks) { JumpListSeparator seperator; JumpListLink link = task as JumpListLink; if (link != null) { taskContent.AddObject(link.NativeShellLink); } else if ((seperator = task as JumpListSeparator) != null) { taskContent.AddObject(seperator.NativeShellLink); } } // Add tasks to the taskbar HResult hr = customDestinationList.AddUserTasks((IObjectArray)taskContent); if (!CoreErrorHelper.Succeeded(hr)) { if ((uint)hr == 0x80040F03) { throw new InvalidOperationException(LocalizedMessages.JumpListFileTypeNotRegistered); } throw new ShellException(hr); } }
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(); } }