Example #1
0
        private static void AddUserTasks(ICustomDestinationList custom_destinationd_list)
        {
            IObjectCollection object_collection =
                (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID.EnumerableObjectCollection));

            IShellLink search_notes = CreateShellLink(Catalog.GetString("Search All Notes"), tomboy_path, "--search",
                                                      System.IO.Path.Combine(icons_path, SearchIcon), -1);

            if (search_notes != null)
            {
                object_collection.AddObject(search_notes);
            }

            //IShellLink new_notebook = CreateShellLink("New Notebook", topmboy_path, "--new-notebook",
            //    icons_path, (int)TomboyIcons.NewNotebook);
            //if (new_notebook != null)
            //    object_collection.AddObject(new_notebook);

            IShellLink new_note = CreateShellLink(Catalog.GetString("Create New Note"), tomboy_path, "--new-note",
                                                  System.IO.Path.Combine(icons_path, NewNoteIcon), -1);

            if (new_note != null)
            {
                object_collection.AddObject(new_note);
            }

            custom_destinationd_list.AddUserTasks((IObjectArray)object_collection);

            Marshal.ReleaseComObject(object_collection);
            object_collection = null;
        }
Example #2
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
                        });
                    }
                }
            }
        }
Example #3
0
        internal void RefreshTasks(ICustomDestinationList destinationList)
        {
            if (_tasks.Count == 0)
            {
                return;
            }

            IObjectCollection taskCollection =
                (IObjectCollection) new CEnumerableObjectCollection();

            foreach (IJumpListTask task in _tasks)
            {
                taskCollection.AddObject(task.GetShellRepresentation());
            }
            destinationList.AddUserTasks((IObjectArray)taskCollection);
        }
Example #4
0
        // Builds the collection of task items and adds them to the Task section of the Jump List. All tasks should be added to the canonical
        // "Tasks" category by calling ICustomDestinationList::AddUserTasks.
        private static void _AddTasksToList(ICustomDestinationList pcdl)
        {
            var poc = new IObjectCollection();
            var psl = _CreateShellLink("/Task1", "Task 1");

            poc.AddObject(psl);
            psl = _CreateShellLink("/Task2", "Second Task");
            poc.AddObject(psl);
            psl = _CreateSeparatorLink();
            poc.AddObject(psl);
            psl = _CreateShellLink("/Task3", "Task 3");
            poc.AddObject(psl);
            var poa = (IObjectArray)poc;

            // Add the tasks to the Jump List. Tasks always appear in the canonical "Tasks" category that is displayed at the bottom of the
            // Jump List, after all other categories.
            pcdl.AddUserTasks(poa);
        }
Example #5
0
        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 (IJumpListTask task in userTasks)
            {
                if (task is JumpListLink)
                {
                    taskContent.AddObject(((JumpListLink)task).NativeShellLink);
                }
                else if (task is JumpListSeparator)
                {
                    taskContent.AddObject(((JumpListSeparator)task).NativeShellLink);
                }
            }

            // Add tasks to the taskbar
            HRESULT hr = customDestinationList.AddUserTasks((IObjectArray)taskContent);

            if (!CoreErrorHelper.Succeeded((int)hr))
            {
                if ((uint)hr == 0x80040F03)
                {
                    throw new InvalidOperationException("The file type is not registered with this application.");
                }
                else
                {
                    Marshal.ThrowExceptionForHR((int)hr);
                }
            }
        }
Example #6
0
        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);
            }
        }
Example #7
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 AddUserTasks (ICustomDestinationList custom_destinationd_list)
		{
			IObjectCollection object_collection =
			    (IObjectCollection) Activator.CreateInstance (Type.GetTypeFromCLSID (CLSID.EnumerableObjectCollection));

			IShellLink search_notes = CreateShellLink (Catalog.GetString ("Search All Notes"), tomboy_path, "--search",
			                                           System.IO.Path.Combine (icons_path, SearchIcon),  -1);
			if (search_notes != null)
				object_collection.AddObject (search_notes);

			//IShellLink new_notebook = CreateShellLink("New Notebook", topmboy_path, "--new-notebook",
			//    icons_path, (int)TomboyIcons.NewNotebook);
			//if (new_notebook != null)
			//    object_collection.AddObject(new_notebook);

			IShellLink new_note = CreateShellLink (Catalog.GetString ("Create New Note"), tomboy_path, "--new-note",
			                                       System.IO.Path.Combine (icons_path, NewNoteIcon), -1);
			if (new_note != null)
				object_collection.AddObject (new_note);

			custom_destinationd_list.AddUserTasks ((IObjectArray) object_collection);

			Marshal.ReleaseComObject (object_collection);
			object_collection = null;
		}
Example #9
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
                    });
                }
            }
        }
Example #10
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 });
                    }
                }
            }
        }
Example #11
0
        internal void RefreshTasks(ICustomDestinationList destinationList)
        {
            if (_tasks.Count == 0)
                return;

            IObjectCollection taskCollection = (IObjectCollection)new CEnumerableObjectCollection();
            foreach (IJumpListTask task in _tasks)
            {
                HResult addObjectResult = taskCollection.AddObject(task.GetShellRepresentation());
                addObjectResult.ThrowIf();
            }
            HResult addUserTasksResult = destinationList.AddUserTasks((IObjectArray)taskCollection);
            addUserTasksResult.ThrowIf();
        }
Example #12
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
                        });
                    }
                }
            }
        }