예제 #1
0
        private JumpListLink ParseApplyJumpListTask(JumpListItemObject jumplistItem, int itemIndex)
        {
            JumpListLink task = new JumpListLink
            {
                Title = jumplistItem.ItemName
            };

            if (jumplistItem.ItemIconToString().Equals("Don't use an icon") != true)
            {
                // Icon processing
                string localIconPath = IconPathToLocal(jumplistItem.ItemIconPath, jumplistItem.ItemIconIndex, itemIndex, CurrentAppId, false);
                if (File.Exists(localIconPath))
                {
                    task.IconReference = new IconReference(localIconPath, 0);
                }
            }

            switch (jumplistItem.TaskAction)
            {
            case JumpListItemObject.ActionType.Keyboard:
                string kbdScriptName = GetKeyboardScriptFilename(jumplistItem, itemIndex);
                if (File.Exists(kbdScriptName))
                {    // It should already have been made
                    task.Path      = Common.Path_ProgramFiles + "\\AutoHotKey.exe";
                    task.Arguments = "\"" + kbdScriptName + "\"";
                }
                else
                {
                    return(null);
                }
                break;

            case JumpListItemObject.ActionType.CommandLine:
                if (jumplistItem.TaskCMDShowWindow)
                {
                    task.Path      = "cmd.exe";
                    task.Arguments = "/k \"" + jumplistItem.ItemCmdToString().Replace("\"", "\"\"") + "\"";
                }
                else
                {
                    task.Path      = jumplistItem.TaskCMDPath;
                    task.Arguments = jumplistItem.TaskCMDArgs;
                }
                break;

            case JumpListItemObject.ActionType.AutoHotKey:
                string ahkFilename = GetAhkScriptFilename(false, jumplistItem, itemIndex);
                if (File.Exists(ahkFilename))     // It should have already been made.
                {
                    task.Path      = Common.Path_ProgramFiles + "\\AutoHotKey.exe";
                    task.Arguments = "\"" + ahkFilename + "\"";
                }
                else
                {
                    return(null);
                }
                break;
            }
            return(task);
        }
예제 #2
0
        public bool ApplyJumplistToTaskbar()
        {
            bool result = false;

            try
            {
                JumpList newList = JumpList.CreateJumpListForAppId(CurrentAppId);

                ListBox.ObjectCollection jumplistItems = JumplistListBox.Items;
                for (int i = 0; i < jumplistItems.Count; i++)
                {
                    // Look for a category
                    JumpListItemObject.ItemTypeVar jumplistItemType = ((JumpListItemObject)jumplistItems[i]).ItemType;
                    if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category ||
                        jumplistItemType == JumpListItemObject.ItemTypeVar.CategoryTasks)
                    {
                        JumpListCustomCategory category = new JumpListCustomCategory(((JumpListItemObject)jumplistItems[i]).ItemName);

                        // Look for a task
                        for (int j = i + 1; j < jumplistItems.Count; j++)
                        {
                            i = j - 1; // When J loop is exited, i has to be less.
                            JumpListItemObject jumplistItem = (JumpListItemObject)jumplistItems[j];
                            switch (jumplistItem.ItemType)
                            {
                            case JumpListItemObject.ItemTypeVar.Category:
                            case JumpListItemObject.ItemTypeVar.CategoryTasks:
                                j = jumplistItems.Count;     // Exit the for loop
                                break;

                            case JumpListItemObject.ItemTypeVar.Task:
                                if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category)
                                {
                                    category.AddJumpListItems(
                                        ParseApplyJumpListTask(jumplistItem, j));
                                }
                                else
                                {
                                    newList.AddUserTasks(
                                        ParseApplyJumpListTask(jumplistItem, j));
                                }
                                break;

                            case JumpListItemObject.ItemTypeVar.FileFolder:
                                JumpListLink link = new JumpListLink
                                {
                                    Title     = jumplistItem.ItemName,
                                    Path      = "C:\\Windows\\explorer.exe",
                                    Arguments = jumplistItem.FilePath
                                };
                                if (jumplistItem.FileRunWithApp)
                                {
                                    link.Path = CurrentAppPath;
                                }
                                // Format icon
                                if (jumplistItem.ItemIconToString().Equals("Don't use an icon") != true)
                                {
                                    // Icon processing
                                    string localIconPath = IconPathToLocal(jumplistItem.ItemIconPath, jumplistItem.ItemIconIndex, j, CurrentAppId, false);
                                    if (File.Exists(localIconPath))
                                    {
                                        link.IconReference = new IconReference(localIconPath, 0);
                                    }
                                }

                                if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category)
                                {
                                    category.AddJumpListItems(link);
                                }
                                else
                                {
                                    newList.AddUserTasks(link);
                                }
                                break;

                            case JumpListItemObject.ItemTypeVar.Separator:
                                if (jumplistItemType == JumpListItemObject.ItemTypeVar.CategoryTasks)
                                {
                                    newList.AddUserTasks(new JumpListSeparator());
                                }
                                break;
                            }
                        }

                        if (jumplistItemType == JumpListItemObject.ItemTypeVar.Category)
                        {
                            newList.AddCustomCategories(category);
                        }
                    }
                }

                // ////////
                JumpList dummyList = JumpList.CreateJumpListForAppId(CurrentAppId);
                dummyList.AddUserTasks(new JumpListLink
                {
                    Title = "Dummy",
                    Path  = "%windir%\\explorer.exe"
                });
                dummyList.Refresh();
                newList.Refresh();
                // Remove appid from own window!
                SetAppIdBackAfterJumplist();
                result = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("JumpList applying not successful." + "\r\n"
                                + e.ToString());
            }

            return(result);
        }